Buffer Interface, can't get PyObject_AsReadBuffer to work?
Kevin Cazabon
kevin at cazabon.com
Wed Apr 3 00:45:58 EST 2002
More growing pains... I can't seem to get PyObject_AsReadBuffer to
work for me, any suggestions based on the following code? "ok" always
ends up as 0, meaning that the operation failed...
Thanks! Kevin.
----------------------------------
static PyObject *
pyHasp(PyObject *self, PyObject *args)
{
// declarations
PyObject *inBuffer = NULL;
void *pInBuffer = NULL;
ULONG Service = 0;
ULONG SeedCode = 0;
ULONG LptNum = 0;
ULONG Pass1 = 0;
ULONG Pass2 = 0;
ULONG p1 = 0;
ULONG p2 = 0;
ULONG p3 = 0;
int p4size = 0;
int ok = 0;
void *EncodeDecodeBuffer;
EncodeDecodeBuffer = malloc(1001);
if (EncodeDecodeBuffer == NULL) {
return Py_BuildValue("llls", -9994, -9994, -9994, "Could not
allocate memory for the EncodeDecodeBuffer!");
}
memset (EncodeDecodeBuffer, 0, 1001);
// parse the PyObject arguments, assign to variables accordingly,
this works fine, inBuffer is a Python array ('B'), and ParseTuple
succeeds (returns 1)
ok = PyArg_ParseTuple(args, "llllllllOl", &Service, &SeedCode,
&LptNum, &Pass1, &Pass2, &p1, &p2, &p3, &inBuffer, &p4size);
if (!ok) {
printf("Could not parse the Python Tuple in pyHasp.dll!\n");
return Py_BuildValue("llls", -9999, -9999, -9999, "Could not
access the passed string as a Python buffer!");
}
// Convert the pInBuffer from PyObject to a PyBuffer (readable),
THIS DOESN'T WORK (the Python object type that is passed in as
inBuffer is a 'B' array)
if (PyObject_CheckReadBuffer(inBuffer)) {
//this ALWAYS returns 0, meaning unsuccessful... what's wrong???
ok = PyObject_AsReadBuffer(inBuffer, &pInBuffer, &p4size);
if (!ok) {
printf("PyObject_AsReadBuffer failed\n");
return Py_BuildValue("llls", -9995, -9995, -9995, "Could not
access the passed array as a Python buffer!");
}
}
/* The rest of the code is here, never gets there though. */
More information about the Python-list
mailing list