Patch #1011240: SystemError generated by struct.pack('P', 'foo').

This commit is contained in:
Armin Rigo 2004-09-27 19:27:51 +00:00
parent b562bc672b
commit 9f90439817
2 changed files with 10 additions and 7 deletions

View file

@ -518,14 +518,16 @@ np_double(char *p, PyObject *v, const formatdef *f)
static int
np_void_p(char *p, PyObject *v, const formatdef *f)
{
void *x = PyLong_AsVoidPtr(v);
if (x == NULL && PyErr_Occurred()) {
/* ### hrm. PyLong_AsVoidPtr raises SystemError */
if (PyErr_ExceptionMatches(PyExc_TypeError))
PyErr_SetString(StructError,
"required argument is not an integer");
void *x;
v = get_pylong(v);
if (v == NULL)
return -1;
assert(PyLong_Check(v));
x = PyLong_AsVoidPtr(v);
Py_DECREF(v);
if (x == NULL && PyErr_Occurred())
return -1;
}
memcpy(p, (char *)&x, sizeof x);
return 0;
}