diff options
| author | Thomas Heller <theller@ctypes.org> | 2006-07-10 09:10:28 +0000 |
|---|---|---|
| committer | Thomas Heller <theller@ctypes.org> | 2006-07-10 09:10:28 +0000 |
| commit | 5ab31fde4030df731dc58dc73ade4ff8d92bc122 (patch) | |
| tree | 1f2d8062e1856f488a695382e2ffbb4b65e4afff /Modules | |
| parent | d602ffa919ce55e6fe9924988a7056ec2c837058 (diff) | |
| download | cpython-5ab31fde4030df731dc58dc73ade4ff8d92bc122.tar.gz | |
Fix bug #1518190: accept any integer or long value in the
ctypes.c_void_p constructor.
Diffstat (limited to 'Modules')
| -rw-r--r-- | Modules/_ctypes/cfield.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index c5895f095e..b147ae2ed9 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1486,16 +1486,27 @@ P_set(void *ptr, PyObject *value, unsigned size) *(void **)ptr = NULL; _RET(value); } - - v = PyLong_AsVoidPtr(value); - if (PyErr_Occurred()) { - /* prevent the SystemError: bad argument to internal function */ - if (!PyInt_Check(value) && !PyLong_Check(value)) { - PyErr_SetString(PyExc_TypeError, - "cannot be converted to pointer"); - } + + if (!PyInt_Check(value) && !PyLong_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "cannot be converted to pointer"); return NULL; } + +#if SIZEOF_VOID_P <= SIZEOF_LONG + v = (void *)PyInt_AsUnsignedLongMask(value); +#else +#ifndef HAVE_LONG_LONG +# error "PyLong_AsVoidPtr: sizeof(void*) > sizeof(long), but no long long" +#elif SIZEOF_LONG_LONG < SIZEOF_VOID_P +# error "PyLong_AsVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)" +#endif + v = (void *)PyInt_AsUnsignedLongLongMask(value); +#endif + + if (PyErr_Occurred()) + return NULL; + *(void **)ptr = v; _RET(value); } |
