[Cython] More concerns over extern ctypedefs

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Sat Jul 19 14:21:06 CEST 2008


Dag Sverre Seljebotn wrote:
> Consider this code:
> 
> cdef extern from "t.h":
>      ctypedef long hullo
> 
> def foo(hullo h): pass
> 
> I noticed that it creates code like this:
> PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "l", __pyx_argnames, 
> &__pyx_v_h))
> 
> Which could probably destroy the stack if we don't have the exact 
> typedef, right? Which means: One should either write our own parsing 
> code instead (generate for each parameter signature), or generate the 
> typestring at runtime, or insert C checks for the sizeof(the typedefs). 

Just realized that a dynamic typestring could be generated at module 
load time, which should be perfectly unnoticeable. So this might be the 
way to go.

Each extern ctypedef would grow a function similar to what is mentioned 
in the "buffer must know exact C types thread", but switching on size 
instead:

switch (sizeof(T)) {
case sizeof(int): return 'i';
...

The thing is, I could then use this for my buffer format checking as 
well. (Not a priority though).

-- 
Dag Sverre


More information about the Cython-dev mailing list