Lisandro wrote:
> As Greg pointed out, this has nothing to do with external
> declarations. The actual issue is when you need to implement in Cython
> code a callback function.
Sure, you will typically not need
cdef extern "declspec" func "realname" ()
because you can then use a header file. However, it is about creating a
syntax in Cython which is easy to learn and remember! And that means
making each feature working in any situation where one would "guess" it
would work and not put in arbitrary limits (I should know, the number of
complaints I get on the buffer-in-function-only restriction :-) ).
And making lots of special cases (this syntax is not allowed in this case
and this syntax is not allowed in that case) complicates the language a
lot.
> In my particular issue, these callbacks have to respect a standardized
> API. And the problem is that different implementations of that
> standardized API use different calling conventions... Then I want my
> Cython code to work with any of these implementation, but I only see
> two solutions:
>
> 1) Implement all my callbacks in C and include them with 'cdef
> extern'. But then I've just lost the power of Cython for implementing
> C functions, particularly when Python objects are involved and the GIL
> has to be properly managed.
>
> 2) Modify Cython to accept any string literal instead of just
> __stdcall/__cdecl/__fastcall. Then the contents of that literal could
> be a macro and I would be able to control its actual contents via the
> C preprocessor.
>
> Can any of you figure out an alternative to (2) to save me (or any
> other with similar issues) from (1) ??
Yes, as I proposed, some kind of syntax to declare your own calling
convention; e.g.
cdef callspec __mycall "__mycall"
cdef __mycall int foo(): return 3
This will avoid
cdef extern:
int "realfunc" func()
from silently compiling but producing unexpected code, without having to
arbitrarily disable parts of the language in a perfectly valid corner
case.
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev