summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-06-16 08:48:40 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-06-16 08:48:40 (GMT)
commit70128a1ba693d399177714e657e13c08a2056b45 (patch)
treecc65d1fe0374edb1220753ca20cf60e0ad1453d6 /Objects
parent918f2c722a3789d683e62ad6e49dbf632f900c71 (diff)
downloadcpython-70128a1ba693d399177714e657e13c08a2056b45.zip
cpython-70128a1ba693d399177714e657e13c08a2056b45.tar.gz
cpython-70128a1ba693d399177714e657e13c08a2056b45.tar.bz2
PyLong_{As, From}VoidPtr: cleanup, replacing assumptions in comments with
#if/#error constructs.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index be9430a..048b8e5 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -508,18 +508,22 @@ PyLong_AsDouble(PyObject *vv)
PyObject *
PyLong_FromVoidPtr(void *p)
{
-#if SIZEOF_VOID_P == SIZEOF_LONG
+#if SIZEOF_VOID_P <= SIZEOF_LONG
return PyInt_FromLong((long)p);
#else
+
+#ifndef HAVE_LONG_LONG
+# error "PyLong_FromVoidPtr: sizeof(void*) > sizeof(long), but no long long"
+#endif
+#if SIZEOF_LONG_LONG < SIZEOF_VOID_P
+# error "PyLong_FromVoidPtr: sizeof(LONG_LONG) < sizeof(void*)"
+#endif
/* optimize null pointers */
- if ( p == NULL )
+ if (p == NULL)
return PyInt_FromLong(0);
-
- /* we can assume that HAVE_LONG_LONG is true. if not, then the
- configuration process should have bailed (having big pointers
- without long longs seems non-sensical) */
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) */
@@ -531,25 +535,29 @@ PyLong_AsVoidPtr(PyObject *vv)
then the PyLong_AsLong*() functions will raise the exception:
PyExc_SystemError, "bad argument to internal function"
*/
-
-#if SIZEOF_VOID_P == SIZEOF_LONG
+#if SIZEOF_VOID_P <= SIZEOF_LONG
long x;
- if ( PyInt_Check(vv) )
+ if (PyInt_Check(vv))
x = PyInt_AS_LONG(vv);
else
x = PyLong_AsLong(vv);
#else
- /* we can assume that HAVE_LONG_LONG is true. if not, then the
- configuration process should have bailed (having big pointers
- without long longs seems non-sensical) */
+
+#ifndef HAVE_LONG_LONG
+# 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;
- if ( PyInt_Check(vv) )
+ if (PyInt_Check(vv))
x = PyInt_AS_LONG(vv);
else
x = PyLong_AsLongLong(vv);
-#endif /* SIZEOF_VOID_P == SIZEOF_LONG */
+
+#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */
if (x == -1 && PyErr_Occurred())
return NULL;