Skip to content

Commit

Permalink
Handle changes to PyTypeObject in Python 3.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoikas committed Jun 4, 2020
1 parent 08df2aa commit 78e6a58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,23 @@ 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) \
"Plasma." #pythonClassName, /* tp_name */ \
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 */ \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */ \
Expand Down Expand Up @@ -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
Expand All @@ -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 */ \
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 78e6a58

Please sign in to comment.