[Cython] Reason for __Pyx_PyObject_Call2Args, __Pyx_PyObject_Call3Args

Stefan Behnel stefan_ml at behnel.de
Thu Jun 13 17:23:04 EDT 2019


Jeroen Demeyer schrieb am 13.06.19 um 15:14:
> Is there any particular reason why Cython has specific code like
> __Pyx_PyObject_Call2Args, __Pyx_PyObject_Call3Args, ...
> 
> And then there is even more complicated Python code in PyMethodCallNode
> generating something like __Pyx_PyObject_Call2Args for an arbitrary number
> of arguments.
> 
> This could be simplified a lot by just writing code once to deal with n
> arguments and then letting the C compiler do the clever stuff: if you write
> a loop where the number of iterations is a small compile-time constant, the
> compiler should unroll it.
> 
> I checked that GCC-6.4.0 is able to do this and the much simpler code with
> a for loop is as efficient as the current code. But maybe there are other
> compilers that don't do this (or there used to be such compilers when that
> code was written)?
> 
> I stumbled on this while working on
> https://github.com/cython/cython/issues/2996

It was originally written that way because there were slight differences,
and only 0/1 args were special cased initially. The method optimisation
then showed that it's worth special casing the self argument, which gave
rise to the other helpers.

I've seen your PR, which cleans this up very nicely. Thanks!

Stefan


More information about the cython-devel mailing list