mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
PyLong_{As, From}VoidPtr: cleanup, replacing assumptions in comments with
#if/#error constructs.
This commit is contained in:
parent
918f2c722a
commit
70128a1ba6
1 changed files with 24 additions and 16 deletions
|
@ -508,18 +508,22 @@ PyLong_AsDouble(PyObject *vv)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyLong_FromVoidPtr(void *p)
|
PyLong_FromVoidPtr(void *p)
|
||||||
{
|
{
|
||||||
#if SIZEOF_VOID_P == SIZEOF_LONG
|
#if SIZEOF_VOID_P <= SIZEOF_LONG
|
||||||
return PyInt_FromLong((long)p);
|
return PyInt_FromLong((long)p);
|
||||||
#else
|
#else
|
||||||
/* optimize null pointers */
|
|
||||||
if ( p == NULL )
|
|
||||||
return PyInt_FromLong(0);
|
|
||||||
|
|
||||||
/* we can assume that HAVE_LONG_LONG is true. if not, then the
|
#ifndef HAVE_LONG_LONG
|
||||||
configuration process should have bailed (having big pointers
|
# error "PyLong_FromVoidPtr: sizeof(void*) > sizeof(long), but no long long"
|
||||||
without long longs seems non-sensical) */
|
#endif
|
||||||
|
#if SIZEOF_LONG_LONG < SIZEOF_VOID_P
|
||||||
|
# error "PyLong_FromVoidPtr: sizeof(LONG_LONG) < sizeof(void*)"
|
||||||
|
#endif
|
||||||
|
/* optimize null pointers */
|
||||||
|
if (p == NULL)
|
||||||
|
return PyInt_FromLong(0);
|
||||||
return PyLong_FromLongLong((LONG_LONG)p);
|
return PyLong_FromLongLong((LONG_LONG)p);
|
||||||
#endif /* SIZEOF_VOID_P == SIZEOF_LONG */
|
|
||||||
|
#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a C pointer from a long object (or an int object in some cases) */
|
/* Get a C pointer from a long object (or an int object in some cases) */
|
||||||
|
@ -531,25 +535,29 @@ PyLong_AsVoidPtr(PyObject *vv)
|
||||||
then the PyLong_AsLong*() functions will raise the exception:
|
then the PyLong_AsLong*() functions will raise the exception:
|
||||||
PyExc_SystemError, "bad argument to internal function"
|
PyExc_SystemError, "bad argument to internal function"
|
||||||
*/
|
*/
|
||||||
|
#if SIZEOF_VOID_P <= SIZEOF_LONG
|
||||||
#if SIZEOF_VOID_P == SIZEOF_LONG
|
|
||||||
long x;
|
long x;
|
||||||
|
|
||||||
if ( PyInt_Check(vv) )
|
if (PyInt_Check(vv))
|
||||||
x = PyInt_AS_LONG(vv);
|
x = PyInt_AS_LONG(vv);
|
||||||
else
|
else
|
||||||
x = PyLong_AsLong(vv);
|
x = PyLong_AsLong(vv);
|
||||||
#else
|
#else
|
||||||
/* we can assume that HAVE_LONG_LONG is true. if not, then the
|
|
||||||
configuration process should have bailed (having big pointers
|
#ifndef HAVE_LONG_LONG
|
||||||
without long longs seems non-sensical) */
|
# error "PyLong_AsVoidPtr: sizeof(void*) > sizeof(long), but no long long"
|
||||||
|
#endif
|
||||||
|
#if SIZEOF_LONG_LONG < SIZEOF_VOID_P
|
||||||
|
# error "PyLong_AsVoidPtr: sizeof(LONG_LONG) < sizeof(void*)"
|
||||||
|
#endif
|
||||||
LONG_LONG x;
|
LONG_LONG x;
|
||||||
|
|
||||||
if ( PyInt_Check(vv) )
|
if (PyInt_Check(vv))
|
||||||
x = PyInt_AS_LONG(vv);
|
x = PyInt_AS_LONG(vv);
|
||||||
else
|
else
|
||||||
x = PyLong_AsLongLong(vv);
|
x = PyLong_AsLongLong(vv);
|
||||||
#endif /* SIZEOF_VOID_P == SIZEOF_LONG */
|
|
||||||
|
#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */
|
||||||
|
|
||||||
if (x == -1 && PyErr_Occurred())
|
if (x == -1 && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue