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 <[email protected]>
wrote:
> 2015-05-20 11:44 GMT+02:00 Yicong Huang <[email protected]>:
>
>> 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
>> [email protected]
>> https://mail.python.org/mailman/listinfo/pypy-dev
>>
>>
>
>
> --
> Amaury Forgeot d'Arc
>
_______________________________________________
pypy-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-dev