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 May 13, 2020
1 parent 68a69ab commit fc968c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 44 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
40 changes: 1 addition & 39 deletions Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,45 +946,7 @@ PYTHON_START_METHODS_TABLE(ptImportHook)
PYTHON_METHOD(ptImportHook, load_module, "Params: module_name \\nReturns the module given by module_name, if it exists in python.pak"),
PYTHON_END_METHODS_TABLE;

PYTHON_TYPE_START(ptImportHook)
"Plasma.ptImportHook",
sizeof(ptImportHook), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)ptImportHook_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"PEP 302 Import Hook", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PYTHON_DEFAULT_METHODS_TABLE(ptImportHook), /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
PYTHON_DEFAULT_INIT(ptImportHook), /* tp_init */
0, /* tp_alloc */
ptImportHook_new /* tp_new */
PYTHON_TYPE_END;
PLASMA_DEFAULT_TYPE(ptImportHook, "PEP 302 Import Hook");

void ptImportHook_AddPlasmaClasses(PyObject* m)
{
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 compare/rich compare function name
Expand Down Expand Up @@ -261,7 +271,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 */ \
pythonClassName##_COMPARE, /* tp_compare */ \
Expand Down Expand Up @@ -304,6 +314,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 @@ -313,7 +324,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 @@ -356,6 +367,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 fc968c9

Please sign in to comment.