From 5acde0389f0af14cdf7a5210b76d9cea1da9c639 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 12 May 2020 20:05:26 -0400 Subject: [PATCH] Handle changes to `PyTypeObject` in Python 3.8. --- .github/workflows/linux-ci.yml | 10 ++++++++++ Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp | 6 ++++-- .../Plasma/FeatureLib/pfPython/pyGlueHelpers.h | 18 +++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index a27199ed12..1a3a99e7aa 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -4,8 +4,18 @@ on: [push, pull_request] jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7, 3.8] + steps: - uses: actions/checkout@v2 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | sudo apt update diff --git a/Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp b/Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp index 4cf4aa8c15..114b3a8657 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp @@ -372,7 +372,7 @@ PYTHON_TYPE_START(EnumValue) sizeof(EnumValue), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)EnumValue_dealloc, /* tp_dealloc */ - EnumValue_print, /* tp_print */ + PYTHON_TP_PRINT_OR_VECTORCALL_OFFSET(EnumValue_print), 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_as_async */ @@ -416,6 +416,7 @@ PYTHON_TYPE_START(EnumValue) 0, /* tp_del */ 0, /* tp_version_tag */ 0, /* tp_finalize */ + PYTHON_TP_VECTORCALL_PRINT(EnumValue_print) PYTHON_TYPE_END; bool IsEnumValue(PyObject *obj) @@ -582,7 +583,7 @@ PYTHON_TYPE_START(Enum) sizeof(Enum), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)Enum_dealloc, /* tp_dealloc */ - 0, /* tp_print */ + PYTHON_TP_PRINT_OR_VECTORCALL_OFFSET(0), 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ @@ -627,6 +628,7 @@ PYTHON_TYPE_START(Enum) 0, /* tp_del */ 0, /* tp_version_tag */ 0, /* tp_finalize */ + PYTHON_TP_VECTORCALL_PRINT(0) PYTHON_TYPE_END; // creates and sets up the enum base class diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h b/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h index c43140470d..30b35271d6 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h @@ -176,6 +176,15 @@ int pythonClassName##___init__(pythonClassName *self, PyObject *args, PyObject * // message table default name #define PYTHON_DEFAULT_METHODS_TABLE(pythonClassName) pythonClassName##_methods +// tp_print moved to the end, and two new vectorcall fields inserted in Python 3.8... +#if (PY_MAJOR_VERSION >= 4) || ((PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION >= 8)) +# define PYTHON_TP_PRINT_OR_VECTORCALL_OFFSET(tp_print) 0 +# define PYTHON_TP_VECTORCALL_PRINT(tp_print) 0, tp_print, +#else +# define PYTHON_TP_PRINT_OR_VECTORCALL_OFFSET(tp_print) tp_print +# define PYTHON_TP_VECTORCALL_PRINT(tp_print) +#endif + // most glue classes can get away with this default structure #define PLASMA_DEFAULT_TYPE(pythonClassName, docString) \ PYTHON_TYPE_START(pythonClassName) \ @@ -183,7 +192,7 @@ PYTHON_TYPE_START(pythonClassName) \ sizeof(pythonClassName), /* tp_basicsize */ \ 0, /* tp_itemsize */ \ PYTHON_DEFAULT_DEALLOC(pythonClassName), /* tp_dealloc */ \ - 0, /* tp_print */ \ + PYTHON_TP_PRINT_OR_VECTORCALL_OFFSET(0), \ 0, /* tp_getattr */ \ 0, /* tp_setattr */ \ 0, /* tp_as_async */ \ @@ -226,6 +235,7 @@ PYTHON_TYPE_START(pythonClassName) \ 0, /* tp_del */ \ 0, /* tp_version_tag */ \ 0, /* tp_finalize */ \ + PYTHON_TP_VECTORCALL_PRINT(0) \ PYTHON_TYPE_END // default rich compare function name @@ -265,7 +275,7 @@ PYTHON_TYPE_END sizeof(pythonClassName), /* tp_basicsize */ \ 0, /* tp_itemsize */ \ PYTHON_DEFAULT_DEALLOC(pythonClassName), /* tp_dealloc */ \ - 0, /* tp_print */ \ + PYTHON_TP_PRINT_OR_VECTORCALL_OFFSET(0), \ 0, /* tp_getattr */ \ 0, /* tp_setattr */ \ 0, /* tp_as_async */ \ @@ -308,6 +318,7 @@ PYTHON_TYPE_END 0, /* tp_del */ \ 0, /* tp_version_tag */ \ 0, /* tp_finalize */ \ + PYTHON_TP_VECTORCALL_PRINT(0) \ PYTHON_TYPE_END // for conviencence when we just need a base class @@ -317,7 +328,7 @@ PYTHON_TYPE_START(pythonClassName) \ sizeof(pythonClassName), /* tp_basicsize */ \ 0, /* tp_itemsize */ \ PYTHON_DEFAULT_DEALLOC(pythonClassName), /* tp_dealloc */ \ - 0, /* tp_print */ \ + PYTHON_TP_PRINT_OR_VECTORCALL_OFFSET(0), \ 0, /* tp_getattr */ \ 0, /* tp_setattr */ \ 0, /* tp_compare */ \ @@ -360,6 +371,7 @@ PYTHON_TYPE_START(pythonClassName) \ 0, /* tp_del */ \ 0, /* tp_version_tag */ \ 0, /* tp_finalize */ \ + PYTHON_TP_VECTORCALL_PRINT(0) \ PYTHON_TYPE_END // small macros so that the type object can be accessed outside the glue file (for subclassing)