[Pyrex] External functions and extension types: Was: Please support
len-l at telus.net
Wed Oct 26 23:26:27 CEST 2005
Greg Ewing wrote:
>>David M. Cooke wrote:
>> On Oct 18, 2005, at 17:59, Greg Ewing wrote:
>>> object PyArray_ContiguousFromObject(object op, ...)
>> True enough, but that doesn't help: I can't cast it to ArrayType
>> <ArrayType>, because PyObject * is used instead.
>You shouldn't need to cast it at all; Pyrex should
>accept assignment to something of type ArrayType
>The downside is that it will insert a runtime type
>check that isn't really necessary. I'll have to think
>some more about how to address that. Perhaps there
>needs to be some way to declare that "this function
>is declared in C as returning PyObject *, but it really
>return something of type whatever".
I was wondering if any decision has been made as to how external
functions returning extension types will be handled. Right now my C++
changes handle the case where a function defined to return PyObject *
in the .h file is logically defined in Pyrex to return an extension
type. This was somewhat by accident but could remain a permanent
What is not handled is the case where a function is logically defined
to return 'object' but in fact returns something else in the .h file.
I have only looked at it a little and may be able to handle it as
well. The plan is to always C cast the return value of an external
function returning a Python object but not functions defined in
Pyrex. I am hoping CTypedefType can help me here. But I do not wish
to explore this any further until a decision is made.
If a special declaration is to be used then may I suggest something
cdef extern from "something.h":
cdef class EXTTYPE ...
cdef <EXTTYPE> somefunc(...)
<len-l at telus.net>
More information about the Pyrex