How do I call super() in c extention ?
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; } -- http://mail.python.org/mailman/listinfo/python-list
how to determine for using c extension or not ?
Hello everyone. I use bisect module. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. now, I use id() function to determine for using c extension or not. >>> import bisect >>> id(bisect.bisect) 139679893708880 >>> import _bisect >>> id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. My check is correct ? right ? or you have more good idea ? -- https://mail.python.org/mailman/listinfo/python-list
how to determine for using c extension or not ?
Hello everyone. I use bisect module. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. now, I use id() function to determine for using c extension or not. >>> >>> import bisect >>> >>> id(bisect.bisect) 139679893708880 >>> >>> import _bisect >>> >>> id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. My check is correct ? right ? or you have more good idea ? -- https://mail.python.org/mailman/listinfo/python-list
how to determine for using c extension or not ?
Hello everyone. I use bisect module. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. now, I use id() function to determine for using c extension or not. >>> import bisect >>> id(bisect.bisect) 139679893708880 >>> import _bisect >>> id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. My check is correct ? right ? or you have more good idea ? -- https://mail.python.org/mailman/listinfo/python-list
Re: how to determine for using c extension or not ?
sorry, Joel, Skip, Steven, and python-list members. I think that I don't sent my mail to python-list@python.org or I don't have correct mail setting. so I send many mails. sorry... I should wait a day to get answer, sorry. On 2015年08月03日 22:36, Steven D'Aprano wrote: On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote: Hello everyone. I use bisect module. You asked the same question FOUR times. Have patience. Your question goes all over the world, people may be asleep, or working, or just not know the answer. If you ask a question, and get no answers, you should wait a full day before asking again. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. So does Python 2.7. now, I use id() function to determine for using c extension or not. The id() function doesn't tell you where objects come from or what language they are written in. But they will tell you if two objects are the same object. import bisect id(bisect.bisect) 139679893708880 import _bisect id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. Correct. Also, you can do this: py> import bisect py> bisect.__file__ '/usr/local/lib/python2.7/bisect.pyc' py> bisect.bisect.__module__ # Where does the bisect file come from? '_bisect' py> import _bisect py> _bisect.__file__ '/usr/local/lib/python2.7/lib-dynload/_bisect.so' So you can see that _bisect is a .so file (on Linux; on Windows it will be a .dll file), which means written in C. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to determine for using c extension or not ?
normal, no change >>> import bisect >>> bisect.bisect.__module__ '_bisect' I change from "from _bisect import *" to "pass" in bisect.py >>> import bisect >>> bisect.bisect.__module__ 'bisect' bisect.bisect.__module__ return different results. they are '_bisect' and 'bisect'. I know that c extension document recomended us to use _ for c extension name prefix. I use "bisect.bisect.__module__" sentence to determine for using c extension or not. thanks. On 2015年08月03日 23:11, Joel Goldstick wrote: On Mon, Aug 3, 2015 at 10:01 AM, umedoblock wrote: sorry, Joel, Skip, Steven, and python-list members. I think that I don't sent my mail to python-list@python.org or I don't have correct mail setting. so I send many mails. sorry... I should wait a day to get answer, sorry. On 2015年08月03日 22:36, Steven D'Aprano wrote: On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote: Hello everyone. I use bisect module. You asked the same question FOUR times. Have patience. Your question goes all over the world, people may be asleep, or working, or just not know the answer. If you ask a question, and get no answers, you should wait a full day before asking again. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. So does Python 2.7. now, I use id() function to determine for using c extension or not. The id() function doesn't tell you where objects come from or what language they are written in. But they will tell you if two objects are the same object. import bisect id(bisect.bisect) 139679893708880 import _bisect id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. Correct. Also, you can do this: py> import bisect py> bisect.__file__ '/usr/local/lib/python2.7/bisect.pyc' py> bisect.bisect.__module__ # Where does the bisect file come from? '_bisect' py> import _bisect py> _bisect.__file__ '/usr/local/lib/python2.7/lib-dynload/_bisect.so' So you can see that _bisect is a .so file (on Linux; on Windows it will be a .dll file), which means written in C. -- https://mail.python.org/mailman/listinfo/python-list Welcome to the mailing list, and as I see above, you got a good answer. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to determine for using c extension or not ?
On 2015年08月04日 03:11, Terry Reedy wrote: Posting three times under two different names is not polite. Please to not repeat. sorry... You should not care. If you think there is an undocumented difference in behavior, ask here if it is a bug. I don't think a bug in this question. I expect that that test/test_bisect.py runs the same tests on both versions. We have a test helper function for such situations. I didn't know test/support.py and support.import_fresh_module() function. I will use this function if I write some C accelerator. thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to determine for using c extension or not ?
On 2015年08月04日 00:05, Oscar Benjamin wrote: On Mon, 3 Aug 2015 at 15:58 umedoblock mailto:umedobl...@gmail.com>> wrote: I use "bisect.bisect.__module__" sentence to determine for using c extension or not. Why do you want to know if it uses the C extension? It shouldn't really matter. I wrote some C accelerator. I sometimes want to know that python3.x in another machine use C accelerator or not. Because if python3.x doesn't use C acc, I shuold make C acc for another machine. Therefore I'd like to determine for using C acc or not. And I want to know that another machine use C acc or not to use a simple script. But I had felt not good idea about my way to use id(). So I ask this mailing list. -- Oscar -- https://mail.python.org/mailman/listinfo/python-list