J’ai un pont python natif vers du code C, qui renvoie un pointeur sur un tableau (tableau de structures). La structure contient des tableaux de caractères (chaînes). Mais comment puis-je passer d’un c_char_p_Array_NNN
à une chaîne Python réelle?
typedef struct td_Group { unsigned int group_id; char groupname[256]; char date_created[32]; char date_modified[32]; unsigned int user_modified; unsigned int user_created; } Group; int getGroups(LIBmanager *, Group **); ############# python code below: class Group(Structure): _fields_ = [("group_id", c_uint), ("groupname", c_char_p*256), ("date_created", c_char_p*32), ("date_modified", c_char_p*32), ("user_modified", c_uint), ("user_created", c_uint)] def somefunc(): myGroups = c_void_p() count = libnativetest.getGroups( nativePointer, byref(myGroups) ) print "got " + str(count) + " groups!!" myCastedGroups = cast( myGroups, POINTER(Group*count) ) for x in range(0,count): theGroup = cast( myCastedGroups[x], POINTER(Group) ) theGroupName = theGroup.contents.groupname ### Now how do I access theGroupName as a python ssortingng? # it is a c_char_p_Array_256 presently
Le type doit être c_char*256
, pas c_char_p*256
, car il s’agit d’un caractère char[256]
et non d’un caractère char *[256]
.
ssortingng_at (theGroupName, sizeof(theGroupName))