I am translating a linked list with Python SIP.
I have a generic open type structure - a struct to hold the data in bytes (const unsigned char *) and the number of octets. When I pass this data to the void pointer 'holding' the data of the list in python I get: TypeError: an integer is required
I tried passing id(dataFirstNode) but its not the address of dataFirstNode.
The SIP wrapper should ask for the address of a void pointer object not an int?! The generated SIP code looks fine to me, but I could have missed something (not an expert).
How could I solve this without changing the c++ code?
The linked list in c++ is working fine:
// datatype for first NodeDataType dataFirstNode;
int rawData = 11;
dataFirstNode.numocts = sizeof(rawData);
dataFirstNode.data = reinterpret_cast<const unsigned char *>(&rawData);
// node to be passed to testList
ListNode firstNode;
firstNode.data = &dataFirstNode;
firstNode.next = nullptr;
firstNode.prev = nullptr;
The equivalent in python:
// datatype for first Node
dataFirstNode = DataType()
rawData = 12
size = ctypes.sizeof(ctypes.c_int)
dataFirstNode.data = rawData.to_bytes(size, sys.byteorder)
dataFirstNode.numocts = size
# node to be passed to testList
firstNode = ListNode()
firstNode.data = dataFirstNode # Error here!
firstNode.next = None
firstNode.prev = None
Excerpt of code from the sip file:
struct ListNode {
%TypeHeaderCode
#include ...
%End
void* data;
struct ListNode* next;
struct ListNode* prev;
};
struct DataType { /* generic open type data structure */
%TypeHeaderCode
#include ...
%End
const unsigned char* data;
int numocts;
};
Does someone have an idea?
Thanx
Johnny
Aucun commentaire:
Enregistrer un commentaire