[pypy-dev] Cannot instantiate ctype 'struct *' of unknown size
Amaury Forgeot d'Arc
amauryfa at gmail.com
Wed May 20 12:27:25 CEST 2015
Haha, but there is a bug in cffi I think.
I just filed
https://bitbucket.org/cffi/cffi/issue/193/forward-declaration-of-struct-does-not
with a simpler test case.
2015-05-20 12:03 GMT+02:00 Yicong Huang <hengha.mao at gmail.com>:
> Oh, great thanks for you help!
> Finally, I found out the real issue.
> The whold code is this:
>
> @ffi.callback("struct api_ret*(char *)")
> def udf_api(arg0):
> return None
>
> ffi.cdef('''
> struct API {
> struct api_ret* (*pyudf)(char* str);
> };
> ''')
>
> ffi.cdef('''
> struct api_ret {
> char *ret1;
> char *ret2;
> char *ret3;
> };
> ''')
>
> result = ffi.new('struct api_ret*')
>
> And we should put the function callback annotion below struct api_ret
> definition. :)
>
> On Wed, May 20, 2015 at 5:51 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com>
> wrote:
>
>> 2015-05-20 11:44 GMT+02:00 Yicong Huang <hengha.mao at gmail.com>:
>>
>>> Hi,
>>>
>>> The below is the code we met troubles;
>>>
>>> ffi.cdef('''
>>> struct API {
>>> struct api_ret* (*pyudf)(char* str);
>>> };
>>> ''')
>>>
>>> ffi.cdef('''
>>> struct api_ret {
>>> char *ret1;
>>> char *ret2;
>>> char *ret3;
>>> };
>>> ''')
>>>
>>> result = ffi.new('struct api_ret*')
>>>
>>
>> This code works for me. What's the issue exactly?
>>
>>
>>>
>>> At first, we defined struct API with a function pointer that return a
>>> pointer to struct api_ret.
>>> And then we defined api_ret, and tried to new the object.
>>> The problem seems to happen when the function pointer and new structure
>>> are together.
>>> The below code had no problems.
>>>
>>> ffi.cdef('''
>>> struct API {
>>> struct api_ret* (*pyudf)(char* str);
>>> };
>>> ''')
>>>
>>> ffi.cdef('''
>>> struct api_ret2 {
>>> char *ret1;
>>> char *ret2;
>>> char *ret3;
>>> };
>>> ''')
>>> #we used different name api_ret2 to work around the issue.
>>> result = ffi.new('struct api_ret2*')
>>>
>>> _______________________________________________
>>> pypy-dev mailing list
>>> pypy-dev at python.org
>>> https://mail.python.org/mailman/listinfo/pypy-dev
>>>
>>>
>>
>>
>> --
>> Amaury Forgeot d'Arc
>>
>
>
--
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150520/d3b3a795/attachment.html>
More information about the pypy-dev
mailing list