After checking the mercurial repository, I noticed that in changeset
3358:47c1ba8093e3, David Barnett had already checked in a test case
for the "ctypedef templated type" problem (but he had not created a
track ticket). But I guess having two different test cases for the
same problem is not a problem.

However, this changeset contains another test case that surprised me
because it concerns a feature I did not even know about. Apparently,
cython can automatically convert C struct to python dictionnaries.
Furthermore, it provides a "C++ constructor-like" constructor function
for the struct, even in C-mode (and even in cython<0.13). Thus, the
following code is valid. And, for example, foo(5,9) will return
{first:5, second:9}.

""""""
ctypedef struct myStruct:
    int first
    int second

def foo(int first,int second):
    cdef myStruct ms
    ms=myStruct(first,second)
    return ms
"""""""

This is nice, but appears a bit tricky to use. For example, the
following alternate definition of foo
"""""""
def foo(int first,int second):
    return myStruct(first,second)
"""""""
brings the following error:

"""""
    return myStruct(first,second)
                  ^
/home/fabien/progs/cython13tests/bug7.pyx:9:19: Cannot interpret dict
as type 'Python object'
"""""

Furthermore, the feature is broken when the language is set to C++.
Then, the generated code contains a line like :
"""""
__pyx_t_4bug7_myStruct;
"""""
and gcc complains with: "error: declaration does not declare anything"

Therefore, I want to know: Is this feature officially supported? Is it
already in the doc? Should it be added to the doc?. If it is an
official feature, then I should file a new ticket and test case (the
one from David Barnett seems to concern a different problem), since it
is broken in c++ mode.

Toki
_______________________________________________
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to