From df8ccdb7abbd544bfa96ed20cbb66d33ee57ad18 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 13 Aug 2019 17:48:32 +0200 Subject: [PATCH] Add support for Python 3.8 --- .../interfaceMakerPythonNative.cxx | 11 ++- dtool/src/interrogatedb/dtool_super_base.cxx | 9 +- dtool/src/interrogatedb/py_compat.h | 2 +- dtool/src/interrogatedb/py_wrappers.cxx | 83 ++++++++++++++++--- makepanda/makepanda.py | 4 +- makepanda/makewheel.py | 7 +- 6 files changed, 100 insertions(+), 16 deletions(-) diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 58cbf3770c..bb7556644b 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -2863,8 +2863,13 @@ write_module_class(ostream &out, Object *obj) { // destructor tp_dealloc; out << " &Dtool_FreeInstance_" << ClassName << ",\n"; - // printfunc tp_print; + + out << "#if PY_VERSION_HEX >= 0x03080000\n"; + out << " 0, // tp_vectorcall_offset\n"; + out << "#else\n"; write_function_slot(out, 4, slots, "tp_print"); + out << "#endif\n"; + // getattrfunc tp_getattr; write_function_slot(out, 4, slots, "tp_getattr"); // setattrfunc tp_setattr; @@ -3055,6 +3060,10 @@ write_module_class(ostream &out, Object *obj) { out << "#if PY_VERSION_HEX >= 0x03040000\n"; out << " nullptr, // tp_finalize\n"; out << "#endif\n"; + // vectorcallfunc tp_vectorcall + out << "#if PY_VERSION_HEX >= 0x03080000\n"; + out << " nullptr, // tp_vectorcall\n"; + out << "#endif\n"; out << " },\n"; // It's tempting to initialize the type handle here, but this causes static diff --git a/dtool/src/interrogatedb/dtool_super_base.cxx b/dtool/src/interrogatedb/dtool_super_base.cxx index 9422084299..918ab36cc8 100644 --- a/dtool/src/interrogatedb/dtool_super_base.cxx +++ b/dtool/src/interrogatedb/dtool_super_base.cxx @@ -80,7 +80,7 @@ Dtool_PyTypedObject *Dtool_GetSuperBase() { sizeof(Dtool_PyInstDef), 0, // tp_itemsize &Dtool_FreeInstance_DTOOL_SUPER_BASE, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr #if PY_MAJOR_VERSION >= 3 @@ -129,6 +129,13 @@ Dtool_PyTypedObject *Dtool_GetSuperBase() { nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }, TypeHandle::none(), Dtool_PyModuleClassInit_DTOOL_SUPER_BASE, diff --git a/dtool/src/interrogatedb/py_compat.h b/dtool/src/interrogatedb/py_compat.h index 11771d1948..a0d52c7fdc 100644 --- a/dtool/src/interrogatedb/py_compat.h +++ b/dtool/src/interrogatedb/py_compat.h @@ -139,7 +139,7 @@ typedef long Py_hash_t; /* Python 3.6 */ -#ifndef _PyObject_CallNoArg +#if PY_VERSION_HEX < 0x03080000 && !defined(_PyObject_CallNoArg) INLINE PyObject *_PyObject_CallNoArg(PyObject *func) { static PyTupleObject empty_tuple = {PyVarObject_HEAD_INIT(nullptr, 0)}; #ifdef Py_TRACE_REFS diff --git a/dtool/src/interrogatedb/py_wrappers.cxx b/dtool/src/interrogatedb/py_wrappers.cxx index 9f463c9f92..6aed3d2bbb 100644 --- a/dtool/src/interrogatedb/py_wrappers.cxx +++ b/dtool/src/interrogatedb/py_wrappers.cxx @@ -541,7 +541,7 @@ static PyObject *Dtool_MappingWrapper_keys(PyObject *self, PyObject *) { sizeof(Dtool_SequenceWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -582,6 +582,13 @@ static PyObject *Dtool_MappingWrapper_keys(PyObject *self, PyObject *) { nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; static bool registered = false; @@ -675,7 +682,7 @@ static PyObject *Dtool_MappingWrapper_values(PyObject *self, PyObject *) { sizeof(Dtool_MappingWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -716,6 +723,13 @@ static PyObject *Dtool_MappingWrapper_values(PyObject *self, PyObject *) { nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; static bool registered = false; @@ -817,7 +831,7 @@ static PyObject *Dtool_MappingWrapper_items(PyObject *self, PyObject *) { sizeof(Dtool_MappingWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -858,6 +872,13 @@ static PyObject *Dtool_MappingWrapper_items(PyObject *self, PyObject *) { nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; static bool registered = false; @@ -1192,7 +1213,7 @@ Dtool_SequenceWrapper *Dtool_NewSequenceWrapper(PyObject *self, const char *name sizeof(Dtool_SequenceWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -1233,6 +1254,13 @@ Dtool_SequenceWrapper *Dtool_NewSequenceWrapper(PyObject *self, const char *name nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; static bool registered = false; @@ -1296,7 +1324,7 @@ Dtool_MutableSequenceWrapper *Dtool_NewMutableSequenceWrapper(PyObject *self, co sizeof(Dtool_MutableSequenceWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -1337,6 +1365,13 @@ Dtool_MutableSequenceWrapper *Dtool_NewMutableSequenceWrapper(PyObject *self, co nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; static bool registered = false; @@ -1404,7 +1439,7 @@ Dtool_MappingWrapper *Dtool_NewMappingWrapper(PyObject *self, const char *name) sizeof(Dtool_MappingWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -1445,6 +1480,13 @@ Dtool_MappingWrapper *Dtool_NewMappingWrapper(PyObject *self, const char *name) nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; static bool registered = false; @@ -1517,7 +1559,7 @@ Dtool_MappingWrapper *Dtool_NewMutableMappingWrapper(PyObject *self, const char sizeof(Dtool_MappingWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -1558,6 +1600,13 @@ Dtool_MappingWrapper *Dtool_NewMutableMappingWrapper(PyObject *self, const char nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; static bool registered = false; @@ -1594,7 +1643,7 @@ Dtool_NewGenerator(PyObject *self, iternextfunc gen_next) { sizeof(Dtool_GeneratorWrapper), 0, // tp_itemsize Dtool_WrapperBase_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_compare @@ -1635,6 +1684,13 @@ Dtool_NewGenerator(PyObject *self, iternextfunc gen_next) { nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; if (PyType_Ready(&wrapper_type) < 0) { @@ -1663,7 +1719,7 @@ Dtool_NewStaticProperty(PyTypeObject *type, const PyGetSetDef *getset) { sizeof(PyGetSetDescrObject), 0, // tp_itemsize (destructor)Dtool_StaticProperty_dealloc, - nullptr, // tp_print + 0, // tp_vectorcall_offset nullptr, // tp_getattr nullptr, // tp_setattr nullptr, // tp_reserved @@ -1696,7 +1752,7 @@ Dtool_NewStaticProperty(PyTypeObject *type, const PyGetSetDef *getset) { nullptr, // tp_init nullptr, // tp_alloc nullptr, // tp_new - nullptr, // tp_del + nullptr, // tp_free nullptr, // tp_is_gc nullptr, // tp_bases nullptr, // tp_mro @@ -1704,6 +1760,13 @@ Dtool_NewStaticProperty(PyTypeObject *type, const PyGetSetDef *getset) { nullptr, // tp_subclasses nullptr, // tp_weaklist nullptr, // tp_del + 0, // tp_version_tag, +#if PY_VERSION_HEX >= 0x03040000 + nullptr, // tp_finalize +#endif +#if PY_VERSION_HEX >= 0x03080000 + nullptr, // tp_vectorcall +#endif }; if (PyType_Ready(&wrapper_type) < 0) { diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 24e20089a9..13064ec16a 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -2918,7 +2918,9 @@ if '__file__' in locals(): bindir = os.path.join(os.path.dirname(__file__), '..', 'bin') if os.path.isdir(bindir): - if not os.environ.get('PATH'): + if hasattr(os, 'add_dll_directory'): + os.add_dll_directory(bindir) + elif not os.environ.get('PATH'): os.environ['PATH'] = bindir else: os.environ['PATH'] = bindir + os.pathsep + os.environ['PATH'] diff --git a/makepanda/makewheel.py b/makepanda/makewheel.py index 5535e803d9..97177345fc 100644 --- a/makepanda/makewheel.py +++ b/makepanda/makewheel.py @@ -168,15 +168,18 @@ questions. PANDA3D_TOOLS_INIT = """import os, sys import panda3d +dir = os.path.dirname(panda3d.__file__) +del panda3d + if sys.platform in ('win32', 'cygwin'): path_var = 'PATH' + if hasattr(os, 'add_dll_directory'): + os.add_dll_directory(dir) elif sys.platform == 'darwin': path_var = 'DYLD_LIBRARY_PATH' else: path_var = 'LD_LIBRARY_PATH' -dir = os.path.dirname(panda3d.__file__) -del panda3d if not os.environ.get(path_var): os.environ[path_var] = dir else: