[Cython] Fused Types

mark florisson markflorisson88 at gmail.com
Tue Apr 26 16:23:51 CEST 2011


Hey,

I've been working a bit on fused types
(http://wiki.cython.org/enhancements/fusedtypes), and I've got it to
generate code for every permutation of specific types. Currently it
only works for cdef functions. Now in SimpleCallNode I'm trying to use
PyrexTypes.best_match() to find the function with the best signature,
but it doesn't seem to take care of coercions, e.g. it calls
'assignable_from' on the dst_type (e.g. char *), but for
BuiltinObjectType (a str) this returns false. Why is this the case,
don't calls to overloaded C++ methods need to dispatch properly here
also?

Other issues are public and api declarations. So should we support
that at all? We could define a macro that calls a function that does
the dispatch. So e.g. for this

ctypedef cython.fused_type(typeA, typeB) dtype

cdef func(dtype x):
    ...

we would get two generated functions, say, __pyx_typeA_func and
__pyx_typeB_func. So we could have a macro get_func(dtype) or
something that then substitutes __pyx_get_func(#dtype), where
__pyx_get_func returns the pointer to the right function based on the
type names. I'm not sure we should support it, right now I just put
the mangled names in the header. At least the cdef functions will be
sharable between Cython implementation files.

I also noticed that for cdef functions with optional argument it gets
a struct as argument, but this struct doesn't seem to end up in the
header file when the function is declared public. I believe that also
the typedefs for ctypedef-ed things in the .pyx file don't make it
there when used to type a cdef function's arguments. Should that be
fixed?

Cheers,

Mark


More information about the cython-devel mailing list