Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cython calls ExtType.__init__() as Python function #19

Open
robertwb opened this issue Jul 28, 2016 · 6 comments
Open

Cython calls ExtType.__init__() as Python function #19

robertwb opened this issue Jul 28, 2016 · 6 comments

Comments

@robertwb
Copy link
Owner

Reported by robertwb on 6 May 2008 00:14 UTC
When subclasses of extension types call the init() method of their supertype, Cython generates code that looks up the "init" attribute of the instance and then calls it through Python using arg tuple/kwargs. This is because the special init() method ("tp_init" slot) uses this call signature.

Cython should recognise calls to this method and at least call it directly.

In the (presumably very common) case that the arguments do not use starargs, a more advanced approach would be to split the init() method into an internal plain C-function replacement and a tp_init wrapper, and then call the internal function directly, without doing any tuple packing etc. Not sure if it's worth it, though, as the call is already preceded by an (expensive) object allocation.

Migrated-From: http://trac.cython.org/ticket/3

@robertwb
Copy link
Owner Author

Modified by robertwb on 6 May 2008 00:23 UTC

@robertwb
Copy link
Owner Author

Comment by gfurnish on 26 May 2008 04:35 UTC
One of the first things I do is make my own c wrappers for creating objects. Even with the expensive new call the savings it noticeable.

@robertwb
Copy link
Owner Author

Modified by robertwb on 19 Aug 2008 03:56 UTC

@robertwb robertwb added this to the wishlist milestone Jul 28, 2016
@robertwb
Copy link
Owner Author

Comment by scoder on 6 Mar 2009 19:49 UTC
The same idea is reported in #141. This should use cpdef semantics.

@robertwb
Copy link
Owner Author

Comment by scoder on 8 Mar 2009 12:04 UTC
The same applies to other special methods like __call__. (noted here to close #141 as a duplicate)

@robertwb
Copy link
Owner Author

Comment by scoder on 15 Oct 2011 07:58 UTC
The test in tests/run/special_methods_T561.pyx has some test code for this:

cython/cython@6ae0222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant