From: Kannan V. <kvi...@gr...> - 2010-03-17 20:11:34
|
Hi there, I've scoured online for details about resolving my current issue, and haven't made much headway. I'm trying to use swig to wrap a simple C api with less than a couple dozen functions. Some of the functions return a pointer to a struct, where the first element of the struct is a fixed-length UUID char array: #define UUID_LEN 37 struct domain_info { char id[UUID_LEN]; ... } I'm using the following typemap to lift this structure into python: %typemap(python, out) domain_info * { if($1 == NULL) { Py_INCREF(Py_None); $result = Py_None; } else { fprintf(stderr, "Lifting domain with id %s\n", $1->id); $result = SWIG_NewPointerObj($1, $1_descriptor, 0); } } %newobject get_domain In python, the actual 'id' value is corrupted: >>> x = get_domain() Lifting domain with id e5b4646a-0159-4e28-98a7-c58c140b01d5 >>> x.id '\x00\xc5\x93\x00\x00\x00\x00\x00\x80\x87\x93\x00\x00\x00\x00\x0028-98a7-c58c140b01d5' The first 16 bytes of the id are overwritten with some other data. I'm not sure why this is happening. Any help would be appreciated. For reference, I'm using Swig 1.3.39. Cheers. -kannan |