Cannot instantiate ctype 'struct *' of unknown size

78 views
Skip to first unread message

Yicong Huang

unread,
May 20, 2015, 5:44:23 AM5/20/15
to pypy-dev, pytho...@googlegroups.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*')

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*')

Yicong Huang

unread,
May 20, 2015, 6:03:14 AM5/20/15
to Amaury Forgeot d'Arc, pypy-dev, pytho...@googlegroups.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 <amau...@gmail.com> wrote:
2015-05-20 11:44 GMT+02:00 Yicong Huang <hengh...@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...@python.org
https://mail.python.org/mailman/listinfo/pypy-dev




--
Amaury Forgeot d'Arc

Reply all
Reply to author
Forward
0 new messages