[Pyrex] Implicit conversions failing

David McNab david at rebirthing.co.nz
Sun May 18 16:43:03 CEST 2003


Hi,

I'm seeing cases where pyrex-generated code is failing to implicitly
convert between Python long objects and C long ints, eg:

  def pythonFunc(somelong):
     result = cFunc(somelong)
     ...

And the other way around, eg:

  cdef void someCfunc(long fred):
     ...
     pythonFunc(fred)

What seems to be happening is that exceptions are happening in the code
that aren't getting printed to stdout, and that the exceptions are
resulting from Pyrex losing track of the symbols, and inserting None()
calls, or treating formal parms as python globals etc.

The workaround that's got me out of disaster is doing explicit API calls
like PyLong_FromLong() and PyLong_AsLong() etc.

This turns the above into:

  def pythonFunc(somelong):
     cdef long cSomeLong
     cSomeLong = PyLong_AsLong(someLong)
     result = cFunc(cSomelong)
     ...

And the other way around, eg:

  cdef void someCfunc(long fred):
     ...
     pFred = PyLong_FromLong(fred)
     pythonFunc(pFred)

Am I just expecting too much of Pyrex?
Is it actually poor Pyrex coding practice to expect these implicit
conversions to happen properly?

-- 
Kind regards
David

--

leave this line intact so your email gets through my junk mail filter






More information about the Pyrex mailing list