Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19515

How do I call super() in c extention ?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <umedoblock@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'extension.': 0.09; 'null);': 0.09; 'null,': 0.09; 'def': 0.13; '(struct': 0.16; '*args,': 0.16; '*kwds)': 0.16; '*self,': 0.16; 'pyobject': 0.16; 'received:192.168.11': 0.16; 'ret);': 0.16; 'subject:() ': 0.16; 'int': 0.18; 'rewrite': 0.18; 'ret': 0.23; 'static': 0.24; 'subject: ?': 0.24; 'code.': 0.26; "i'm": 0.27; 'skip:" 30': 0.28; 'class': 0.29; 'null)': 0.30; 'null;': 0.30; 'object.': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; '0);': 0.30; 'skip:( 20': 0.31; 'message-id:@gmail.com': 0.33; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.34; 'subject:How': 0.35; 'everyone.': 0.36; 'skip:" 10': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'skip:_ 10': 0.37; 'skip:& 10': 0.37; 'received:209.85': 0.38; 'received:192': 0.38; "i'd": 0.39; 'help': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.40; 'meet': 0.61; 'below': 0.63; 'super': 0.64; 'charset:iso-2022-jp': 0.76; 'subject:call': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=fkRmCPW4AOOted727y9QLmxIQcaBOqMvbjF0/X7bLxo=; b=vCvHcjd3PHBQBoQz+slyekUD+56YfO7KGZNKhBpezHfifYaDyLl3gXBu8auy3lXdYG T6ZwCUDumZ5dg/yQkuuRwk3ioZr3q7wuCoC2dD5FhQZPPYpdn1DGUoR0Njf6jzkGZOCC B0I9re1ZN5Hj75qZSeDLQbZqfvN+gp+H8L9FY=
Date Fri, 27 Jan 2012 11:03:57 +0900
From umedoblock <umedoblock@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111229 Thunderbird/9.0
MIME-Version 1.0
To python-list@python.org
Subject How do I call super() in c extention ?
Content-Type text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5147.1327629862.27778.python-list@python.org> (permalink)
Lines 82
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327629862 news.xs4all.nl 6934 [2001:888:2000:d::a6]:42014
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19515

Show key headers only | View raw


Hi, nice to meet you, everyone.
I'm umedoblock.

I'd like to call super() in c extension.
I'd like to rewrite class Baa as c extension.
Please see below code.
Now, I can make super object.

But I cannot understand how to use super_init(), super_descr_get() and
super_getattro().

Please please help me...

------------------------------------------------------------
baa.py

class Baa(object):
    def __init__(self):
        print('call __init__() in Baa.')
    def sample(self):
        print('call sample() in Baa.')
class Foo(Baa):
    def __init__(self):
        print('call __init__() in Foo.')
        super().sample()
        super().__init__()
class Baz(Foo):
    def __init__(self):
        print('call __init__() in Baz.')
        super().__init__()
--
pyfoo.c

static int
Foo_init(FooObject *self, PyObject *args, PyObject *kwds)
{
    int ret = 0;
    PyTypeObject *super_type = &PySuper_Type;
    PyObject *super_obj;
    PyObject *empty_tuple;

    super_obj = super_type->tp_alloc(super_type, 0);

    empty_tuple = Py_BuildValue("()");
    ret = super_type->tp_init(super_obj, empty_tuple, NULL);

    fprintf(stderr, "super_obj = %p\n", super_obj);
    PyObject_Print((PyObject *)super_obj, stderr, 0); fprintf(stderr,
"\n\n");
    fprintf(stderr, "super_type->tp_init(super_obj=%p, empty_tuple=%p,
NULL)=%d\n", super_obj, empty_tuple, ret);

    return 0;
}

PyMODINIT_FUNC
PyInit__foo(void)
{
    PyObject *m;
    PyObject *import_baa = NULL, *Baa = NULL;
    PyObject *Baa_str;

    import_baa = PyImport_ImportModule("baa");
    Baa_str = Py_BuildValue("s", "Baa");
    Baa = PyObject_GetAttr(import_baa, Baa_str);
    Foo_Type.tp_base = (struct _typeobject *)Baa;
    Py_INCREF(Foo_Type.tp_base);

    Foo_Type.tp_new = Foo_new;
    if (PyType_Ready(&Foo_Type) < 0)
        return NULL;
    Py_INCREF(&Foo_Type);

    m = PyModule_Create(&Foo_module);
    if (m == NULL)
        return NULL;
    PyModule_AddObject(m, "Foo", (PyObject *)&Foo_Type);

    PyModule_AddStringConstant(m, "CONST", "C_EXTENSION");

    return m;
}

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

How do I call super() in c extention ? umedoblock <umedoblock@gmail.com> - 2012-01-27 11:03 +0900

csiph-web