[Pyrex] possible bug with public function declarations

Robby Dermody robbyd at u20.org
Mon Feb 21 16:57:13 CET 2005


On Mon, 2005-02-21 at 14:20 +1300, Greg Ewing wrote:
> Robby Dermody wrote:
> > 
> > I'm thinking there may be a possible bug with public C function
> > declarations in Pyrex 0.93.
> > 
> > The project is set up so that foo.pyx and bar.pyx are linked together,
> 
> Linking two Pyrex-generated modules together isn't
> really supported, and strange things might happen if
> you try it. You might get away with it if one of them
> restricts itself to C-only declarations and operations,
> but Pythonish things are likely to go haywire.
> 
> All the .pxi stuff is pretty much deprecated now. A
> better way to make cross-pyx C calls is to make them
> C methods of an extension type. (Directly calling
> top-level C functions of another module isn't supported
> yet, but may be in a future version.)
> 

After doing some tests and looking at the code generated, it looks like
converting each of my modules to python extension types seems to be a
good route to try. I'd rather not have to hack around pyrex to get
things to work, especially since it seems that a lot of the things I
ended up relying on, such as pyrex include files, are considered
depreciated.

One of my main worries was that the overhead of calls between methods of
an extension type (and methods between extension types) would be
undesirable. This is true if the method being called is a Python method.
However, if the method is a C method, the overhead looks negligible.
Here's some C code generated when MyDS.testfuncC() is being called from
a function in the same extension type:

  __pyx_1 = ((struct __pyx_vtabstruct_12dataservices_MyDS
*)__pyx_v_self->__pyx_vtab)->testfuncC(__pyx_v_self); if (!__pyx_1)
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

I see two extra pointer dereferences and a possible Py_DECREF over what
I would have had through a direct top level C function call, given that
most of the stuff after the function call is for exception handling. I
don't think that's a big deal. I had gotten the mechanics behind C
method calls confused with that of python method calls I guess.

I'm going to try to convert a part of my codebase to be pyrex extension
types, and see if I run into any issues. Sorry about making so much
traffic on this thread, and thanks for clarifying things.

Robby

-- 
Robby Dermody <robbyd at u20.org>




More information about the Pyrex mailing list