diff options
author | Armin Rigo <arigo@tunes.org> | 2004-09-27 19:27:51 (GMT) |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2004-09-27 19:27:51 (GMT) |
commit | 9f904398179bcbab4bf21b2500aa14aec01fbdb3 (patch) | |
tree | 6b4969e3c280dbc2313ccc35458fd012e525c18d /Modules/structmodule.c | |
parent | b562bc672bff106f1cbf2aad7770b654bfe374ec (diff) | |
download | cpython-9f904398179bcbab4bf21b2500aa14aec01fbdb3.zip cpython-9f904398179bcbab4bf21b2500aa14aec01fbdb3.tar.gz cpython-9f904398179bcbab4bf21b2500aa14aec01fbdb3.tar.bz2 |
Patch #1011240: SystemError generated by struct.pack('P', 'foo').
Diffstat (limited to 'Modules/structmodule.c')
-rw-r--r-- | Modules/structmodule.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Modules/structmodule.c b/Modules/structmodule.c index b78231f..33134e9 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -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; } |