[Pyrex] Structure wrapping issue

Jergosh Slodkovic jergosh at wp.pl
Sun Nov 14 14:10:29 CET 2004


I was trying to wrap libgadu (library handling the protocol of a popular
Polish IM) following the instructions in the 'Michael's Guide to Pyrex'
at ldots.org and I sumbled upon a following problem:

Fragment of the original header (libgadu.h):

typedef uint32_t uin_t;
(...)
struct gg_login_params {
	uin_t uin;
	char *password;	
	(...)
};

Code of my padu.pyx:

cdef extern from "libgadu.h":
	(...)
	ctypedef struct gg_login_params:
		int uin 	# uint32_t --> int [?]
		char* password
		(...)

cdef class login_params:
	cdef gg_login_params params
	def __new__(self, number = 0, passw = ""):
		self.params.uin = number
		self.params.password = passw
	def __dealloc__(self):
		pass

Then, I do the following:

jer:~/Python/padu# pyrexc padu.pyx
jer:~/Python/padu# gcc -c -fPIC -I/usr/include/python2.3/ padu.c
padu.c:46: error: parse error before "gg_login_params"
padu.c:46: warning: no semicolon at end of struct or union
padu.c: In function `__pyx_f_4padu_12login_params___new__':
padu.c:76: error: dereferencing pointer to incomplete type
padu.c:80: error: dereferencing pointer to incomplete type
padu.c: At top level:
padu.c:221: error: invalid application of `sizeof' to an incomplete type

The problem seems to be here:

44: struct __pyx_obj_4padu_login_params {
45:   PyObject_HEAD
46:   gg_login_params params;
47: };

I figured out that if I changed line 46 into:
46:   struct gg_login_params params
it would compile but it doesn't look like the correct solution.

jer:~/Python/padu# gcc -shared padu.o -lgadu -o padu.so

Apart from that, after importing the module into Python and creating an
instance of login_params class, attributes from gg_login_params aren't
accessible. Am I doing something wrong?

[I am using Pyrex 0.9.3 and Python 2.3.4 under Debian unstable]

TIA,
-- 
| |_  |___  _ _ _______ ___| | |  @pai.net.pl      |
|   | / -_\/ '_\ _ \ _ \__ <   | |J. J. Slodkovic  |
|   | \___/_/  \_  /___/___/_|_| |GG: 3311290      |
|  /_/          /_/                                |



More information about the Pyrex mailing list