From c343400d9807e8969a279170f33e65b424bc0795 Mon Sep 17 00:00:00 2001 From: "Jonathan G. Underwood" Date: Sat, 10 Feb 2018 21:36:14 +0000 Subject: [PATCH] Update bundled py3c headers to version 1.0 files --- py3c/py3c/comparison.h | 20 ++++++++++++++++++++ py3c/py3c/compat.h | 6 +++--- py3c/py3c/py3shims.h | 17 ++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/py3c/py3c/comparison.h b/py3c/py3c/comparison.h index 61c6239e..9d3765a4 100644 --- a/py3c/py3c/comparison.h +++ b/py3c/py3c/comparison.h @@ -13,6 +13,26 @@ return Py_INCREF(Py_NotImplemented), Py_NotImplemented #endif +#ifndef Py_UNREACHABLE +#define Py_UNREACHABLE() abort() +#endif + +#ifndef Py_RETURN_RICHCOMPARE +#define Py_RETURN_RICHCOMPARE(val1, val2, op) \ + do { \ + switch (op) { \ + case Py_EQ: if ((val1) == (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ + case Py_NE: if ((val1) != (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ + case Py_LT: if ((val1) < (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ + case Py_GT: if ((val1) > (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ + case Py_LE: if ((val1) <= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ + case Py_GE: if ((val1) >= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ + default: \ + Py_UNREACHABLE(); \ + } \ + } while (0) +#endif + #define PY3C_RICHCMP(val1, val2, op) \ ((op) == Py_EQ) ? PyBool_FromLong((val1) == (val2)) : \ ((op) == Py_NE) ? PyBool_FromLong((val1) != (val2)) : \ diff --git a/py3c/py3c/compat.h b/py3c/py3c/compat.h index b80c9735..15d32def 100644 --- a/py3c/py3c/compat.h +++ b/py3c/py3c/compat.h @@ -28,7 +28,7 @@ #define PyStr_InternFromString PyUnicode_InternFromString #define PyStr_Decode PyUnicode_Decode -#define PyStr_AsUTF8String PyUnicode_AsUTF8String // returns PyBytes +#define PyStr_AsUTF8String PyUnicode_AsUTF8String /* returns PyBytes */ #define PyStr_AsUTF8 PyUnicode_AsUTF8 #define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize @@ -74,11 +74,11 @@ #define PyStr_Decode PyString_Decode #ifdef __GNUC__ -static PyObject * PyStr_Concat(PyObject *left, PyObject *right) __attribute__ ((unused)); +static PyObject *PyStr_Concat(PyObject *left, PyObject *right) __attribute__ ((unused)); #endif static PyObject *PyStr_Concat(PyObject *left, PyObject *right) { PyObject *str = left; - Py_INCREF(left); // reference to old left will be stolen + Py_INCREF(left); /* reference to old left will be stolen */ PyString_Concat(&str, right); if (str) { return str; diff --git a/py3c/py3c/py3shims.h b/py3c/py3c/py3shims.h index b1375a4b..947595e9 100644 --- a/py3c/py3c/py3shims.h +++ b/py3c/py3c/py3shims.h @@ -3,7 +3,7 @@ */ /* - * Shims for the PyMem_Raw* functions added inPython 3.3 + * Shims for new functionality from in Python 3.3+ * * See https://docs.python.org/3/c-api/memory.html#raw-memory-interface */ @@ -14,6 +14,19 @@ #include +/* Py_UNUSED - added in Python 3.4, documneted in 3.7 */ + +#ifndef Py_UNUSED +#ifdef __GNUC__ +#define Py_UNUSED(name) _unused_ ## name __attribute__((unused)) +#else +#define Py_UNUSED(name) _unused_ ## name +#endif +#endif + + +/* PyMem_Raw{Malloc,Realloc,Free} - added in Python 3.4 */ + #if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4) #define PyMem_RawMalloc(n) malloc((n) || 1) #define PyMem_RawRealloc(p, n) realloc(p, (n) || 1) @@ -21,6 +34,8 @@ #endif /* version < 3.4 */ +/* PyMem_RawCalloc - added in Python 3.5 */ + #if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 5) #define PyMem_RawCalloc(n, s) calloc((n) || 1, (s) || 1) #endif /* version < 3.5 */