mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Patch #1011240: SystemError generated by struct.pack('P', 'foo').
This commit is contained in:
parent
b562bc672b
commit
9f90439817
2 changed files with 10 additions and 7 deletions
|
@ -54,6 +54,7 @@ if sz * 3 != sz3:
|
||||||
simple_err(struct.pack, 'iii', 3)
|
simple_err(struct.pack, 'iii', 3)
|
||||||
simple_err(struct.pack, 'i', 3, 3, 3)
|
simple_err(struct.pack, 'i', 3, 3, 3)
|
||||||
simple_err(struct.pack, 'i', 'foo')
|
simple_err(struct.pack, 'i', 'foo')
|
||||||
|
simple_err(struct.pack, 'P', 'foo')
|
||||||
simple_err(struct.unpack, 'd', 'flap')
|
simple_err(struct.unpack, 'd', 'flap')
|
||||||
s = struct.pack('ii', 1, 2)
|
s = struct.pack('ii', 1, 2)
|
||||||
simple_err(struct.unpack, 'iii', s)
|
simple_err(struct.unpack, 'iii', s)
|
||||||
|
|
|
@ -518,14 +518,16 @@ np_double(char *p, PyObject *v, const formatdef *f)
|
||||||
static int
|
static int
|
||||||
np_void_p(char *p, PyObject *v, const formatdef *f)
|
np_void_p(char *p, PyObject *v, const formatdef *f)
|
||||||
{
|
{
|
||||||
void *x = PyLong_AsVoidPtr(v);
|
void *x;
|
||||||
if (x == NULL && PyErr_Occurred()) {
|
|
||||||
/* ### hrm. PyLong_AsVoidPtr raises SystemError */
|
v = get_pylong(v);
|
||||||
if (PyErr_ExceptionMatches(PyExc_TypeError))
|
if (v == NULL)
|
||||||
PyErr_SetString(StructError,
|
return -1;
|
||||||
"required argument is not an integer");
|
assert(PyLong_Check(v));
|
||||||
|
x = PyLong_AsVoidPtr(v);
|
||||||
|
Py_DECREF(v);
|
||||||
|
if (x == NULL && PyErr_Occurred())
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
memcpy(p, (char *)&x, sizeof x);
|
memcpy(p, (char *)&x, sizeof x);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue