[pypy-commit] pypy default: Partially resync pyport.h with CPython2.7 and add missing constants PY_INT32_T, etc.
rlamy
pypy.commits at gmail.com
Thu Jan 9 10:01:51 EST 2020
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch:
Changeset: r98501:11fe1f50f3f8
Date: 2020-01-09 14:59 +0000
http://bitbucket.org/pypy/pypy/changeset/11fe1f50f3f8/
Log: Partially resync pyport.h with CPython2.7 and add missing constants
PY_INT32_T, etc.
diff --git a/pypy/module/cpyext/include/pyport.h b/pypy/module/cpyext/include/pyport.h
--- a/pypy/module/cpyext/include/pyport.h
+++ b/pypy/module/cpyext/include/pyport.h
@@ -28,10 +28,86 @@
#endif
#endif /* HAVE_LONG_LONG */
+/* a build with 30-bit digits for Python long integers needs an exact-width
+ * 32-bit unsigned integer type to store those digits. (We could just use
+ * type 'unsigned long', but that would be wasteful on a system where longs
+ * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines
+ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
+ * However, it doesn't set HAVE_UINT32_T, so we do that here.
+ */
+#ifdef uint32_t
+#define HAVE_UINT32_T 1
+#endif
+
+#ifdef HAVE_UINT32_T
+#ifndef PY_UINT32_T
+#define PY_UINT32_T uint32_t
+#endif
+#endif
+
+/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
+ * long integer implementation, when 30-bit digits are enabled.
+ */
+#ifdef uint64_t
+#define HAVE_UINT64_T 1
+#endif
+
+#ifdef HAVE_UINT64_T
+#ifndef PY_UINT64_T
+#define PY_UINT64_T uint64_t
+#endif
+#endif
+
+/* Signed variants of the above */
+#ifdef int32_t
+#define HAVE_INT32_T 1
+#endif
+
+#ifdef HAVE_INT32_T
+#ifndef PY_INT32_T
+#define PY_INT32_T int32_t
+#endif
+#endif
+
+#ifdef int64_t
+#define HAVE_INT64_T 1
+#endif
+
+#ifdef HAVE_INT64_T
+#ifndef PY_INT64_T
+#define PY_INT64_T int64_t
+#endif
+#endif
+
+/* uintptr_t is the C9X name for an unsigned integral type such that a
+ * legitimate void* can be cast to uintptr_t and then back to void* again
+ * without loss of information. Similarly for intptr_t, wrt a signed
+ * integral type.
+ */
+#ifdef HAVE_UINTPTR_T
+typedef uintptr_t Py_uintptr_t;
+typedef intptr_t Py_intptr_t;
+
+#elif SIZEOF_VOID_P <= SIZEOF_INT
+typedef unsigned int Py_uintptr_t;
+typedef int Py_intptr_t;
+
+#elif SIZEOF_VOID_P <= SIZEOF_LONG
+typedef unsigned long Py_uintptr_t;
+typedef long Py_intptr_t;
+
+#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
+typedef unsigned PY_LONG_LONG Py_uintptr_t;
+typedef PY_LONG_LONG Py_intptr_t;
+
+#else
+# error "Python needs a typedef for Py_uintptr_t in pyport.h."
+#endif /* HAVE_UINTPTR_T */
+
/* Largest possible value of size_t.
SIZE_MAX is part of C99, so it might be defined on some
platforms. If it is not defined, (size_t)-1 is a portable
- definition for C89, due to the way signed->unsigned
+ definition for C89, due to the way signed->unsigned
conversion is defined. */
#ifdef SIZE_MAX
#define PY_SIZE_MAX SIZE_MAX
@@ -39,35 +115,9 @@
#define PY_SIZE_MAX ((size_t)-1)
#endif
-/* CPython needs this for the c-extension datetime, which is pure python on PyPy
+/* CPython needs this for the c-extension datetime, which is pure python on PyPy
downstream packages assume it is here (Pandas for instance) */
-#include <time.h>
-
-/* uintptr_t is the C9X name for an unsigned integral type such that a
- * legitimate void* can be cast to uintptr_t and then back to void* again
- * without loss of information. Similarly for intptr_t, wrt a signed
- * integral type.
- */
-#ifdef HAVE_UINTPTR_T
-typedef uintptr_t Py_uintptr_t;
-typedef intptr_t Py_intptr_t;
-
-#elif SIZEOF_VOID_P <= SIZEOF_INT
-typedef unsigned int Py_uintptr_t;
-typedef int Py_intptr_t;
-
-#elif SIZEOF_VOID_P <= SIZEOF_LONG
-typedef unsigned long Py_uintptr_t;
-typedef long Py_intptr_t;
-
-#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
-typedef unsigned PY_LONG_LONG Py_uintptr_t;
-typedef PY_LONG_LONG Py_intptr_t;
-
-#else
-# error "Python needs a typedef for Py_uintptr_t in pyport.h."
-#endif /* HAVE_UINTPTR_T */
-
+#include <time.h>
/*******************************
* stat() and fstat() fiddling *
@@ -130,6 +180,13 @@
#define Py_ALIGNED(x)
#endif
+/* Eliminate end-of-loop code not reached warnings from SunPro C
+ * when using do{...}while(0) macros
+ */
+#ifdef __SUNPRO_C
+#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
+#endif
+
/*
* Older Microsoft compilers don't support the C99 long long literal suffixes,
* so these will be defined in PC/pyconfig.h for those compilers.
diff --git a/pypy/module/cpyext/parse/cpyext_object.h b/pypy/module/cpyext/parse/cpyext_object.h
--- a/pypy/module/cpyext/parse/cpyext_object.h
+++ b/pypy/module/cpyext/parse/cpyext_object.h
@@ -1,6 +1,6 @@
#pragma once
-typedef long Py_ssize_t;
+typedef long Py_ssize_t; /* CPython defines it in pyport.h */
#define PyObject_HEAD \
Py_ssize_t ob_refcnt; \
More information about the pypy-commit
mailing list