From 9f220319d0fe51f5f962ae21fbd2ff32a9c195d5 Mon Sep 17 00:00:00 2001 From: mos Date: Fri, 7 Mar 2025 16:58:22 +0100 Subject: [PATCH] Removed old Python code <3.10 --- src/App/FeaturePythonPyImp.h | 7 ++---- src/App/FeaturePythonPyImp.inl | 6 ----- src/Base/Interpreter.cpp | 10 -------- src/Base/PyObjectBase.cpp | 22 +----------------- src/Base/PyTools.c | 12 ---------- src/Gui/PythonConsole.cpp | 12 ---------- src/Gui/PythonDebugger.cpp | 39 +------------------------------- src/Gui/WidgetFactory.cpp | 4 ---- src/Mod/CAM/App/VoronoiPyImp.cpp | 7 ++---- 9 files changed, 6 insertions(+), 113 deletions(-) diff --git a/src/App/FeaturePythonPyImp.h b/src/App/FeaturePythonPyImp.h index d01190fe7d..3b0d56e328 100644 --- a/src/App/FeaturePythonPyImp.h +++ b/src/App/FeaturePythonPyImp.h @@ -48,12 +48,9 @@ #if PY_VERSION_HEX >= 0x030c0000 #define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -#elif PY_VERSION_HEX >= 0x03090000 -#define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -#elif PY_VERSION_HEX >= 0x03080000 -#define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 #else -#define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +#define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + #endif \ #define PYTHON_TYPE_IMP(_class_, _subclass_) \ diff --git a/src/App/FeaturePythonPyImp.inl b/src/App/FeaturePythonPyImp.inl index 67fd8b25f9..95f53ef790 100644 --- a/src/App/FeaturePythonPyImp.inl +++ b/src/App/FeaturePythonPyImp.inl @@ -34,11 +34,7 @@ PyTypeObject FeaturePythonPyT::Type = { 0, /*tp_itemsize*/ /* methods */ FeaturePyT::PyDestructor, /*tp_dealloc*/ -#if PY_VERSION_HEX >= 0x03080000 0, /*tp_vectorcall_offset*/ -#else - nullptr, /*tp_print*/ -#endif nullptr, /*tp_getattr*/ nullptr, /*tp_setattr*/ nullptr, /*tp_compare*/ @@ -83,12 +79,10 @@ PyTypeObject FeaturePythonPyT::Type = { nullptr, /*tp_del */ 0, /*tp_version_tag */ nullptr /*tp_finalize */ -#if PY_VERSION_HEX >= 0x03080000 ,0 /*tp_vectorcall */ #if PY_VERSION_HEX >= 0x030c0000 ,0 /*tp_watched */ #endif -#endif }; template diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index 41f592e4b8..561c7798d8 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -485,8 +485,6 @@ void InterpreterSingleton::runFile(const char* pxFileName, bool local) bool InterpreterSingleton::loadModule(const char* psModName) { - // buffer acrobatics - // PyBuf ModName(psModName); PyObject* module {}; PyGILStateLocker locker; @@ -567,10 +565,6 @@ const char* InterpreterSingleton::init(int argc, char* argv[]) " exec(open(activate_this).read(), {'__file__':activate_this})\n"); } -#if PY_VERSION_HEX < 0x03090000 - PyEval_InitThreads(); -#endif - size_t size = argc; static std::vector _argv(size); for (int i = 0; i < argc; i++) { @@ -774,11 +768,7 @@ void InterpreterSingleton::runMethod(PyObject* pobject, throw TypeError("InterpreterSingleton::RunMethod() wrong arguments"); } -#if PY_VERSION_HEX < 0x03090000 - presult = PyEval_CallObject(pmeth, pargs); /* run interpreter */ -#else presult = PyObject_CallObject(pmeth, pargs); /* run interpreter */ -#endif Py_DECREF(pmeth); Py_DECREF(pargs); diff --git a/src/Base/PyObjectBase.cpp b/src/Base/PyObjectBase.cpp index 279689f29a..8e7652836c 100644 --- a/src/Base/PyObjectBase.cpp +++ b/src/Base/PyObjectBase.cpp @@ -116,18 +116,13 @@ PyBaseProxy_dealloc(PyObject* self) } Py_TYPE(self)->tp_free(self); } - static PyTypeObject PyBaseProxyType = { PyVarObject_HEAD_INIT(nullptr, 0) "PyBaseProxy", /*tp_name*/ sizeof(PyBaseProxy), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyBaseProxy_dealloc, /*tp_dealloc*/ -#if PY_VERSION_HEX >= 0x03080000 0, /*tp_vectorcall_offset*/ -#else - nullptr, /*tp_print*/ -#endif nullptr, /*tp_getattr*/ nullptr, /*tp_setattr*/ nullptr, /*tp_compare*/ @@ -170,16 +165,11 @@ static PyTypeObject PyBaseProxyType = { nullptr, /*tp_del */ 0, /*tp_version_tag */ nullptr /*tp_finalize */ -#if PY_VERSION_HEX >= 0x03090000 ,0 //NOLINT /*tp_vectorcall */ #if PY_VERSION_HEX >= 0x030c0000 ,0 /*tp_watched */ #endif -#elif PY_VERSION_HEX >= 0x03080000 - ,0 /*tp_vectorcall */ - /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */ - ,0 /*tp_print */ -#endif + }; PyTypeObject PyObjectBase::Type = { @@ -189,11 +179,7 @@ PyTypeObject PyObjectBase::Type = { 0, /*tp_itemsize*/ /* --- methods ---------------------------------------------- */ PyDestructor, /*tp_dealloc*/ -#if PY_VERSION_HEX >= 0x03080000 0, /*tp_vectorcall_offset*/ -#else - nullptr, /*tp_print*/ -#endif nullptr, /*tp_getattr*/ nullptr, /*tp_setattr*/ nullptr, /*tp_compare*/ @@ -238,16 +224,10 @@ PyTypeObject PyObjectBase::Type = { nullptr, /*tp_del */ 0, /*tp_version_tag */ nullptr /*tp_finalize */ -#if PY_VERSION_HEX >= 0x03090000 ,0 //NOLINT /*tp_vectorcall */ #if PY_VERSION_HEX >= 0x030c0000 ,0 /*tp_watched */ #endif -#elif PY_VERSION_HEX >= 0x03080000 - ,0 /*tp_vectorcall */ - /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */ - ,0 /*tp_print */ -#endif }; #if defined(__clang__) diff --git a/src/Base/PyTools.c b/src/Base/PyTools.c index e71216a224..7af15b2f61 100644 --- a/src/Base/PyTools.c +++ b/src/Base/PyTools.c @@ -54,11 +54,7 @@ PP_Run_Method(PyObject *pobject, const char *method, if (PP_DEBUG) /* debug it too? */ presult = PP_Debug_Function(pmeth, pargs); else -#if PY_VERSION_HEX < 0x03090000 - presult = PyEval_CallObject(pmeth, pargs); /* run interpreter */ -#else presult = PyObject_CallObject(pmeth, pargs); /* run interpreter */ -#endif Py_DECREF(pmeth); Py_DECREF(pargs); @@ -131,11 +127,7 @@ PP_Run_Function(const char *modname, const char *funcname, /* load from if (PP_DEBUG && strcmp(modname, "pdb") != 0) /* debug this call? */ presult = PP_Debug_Function(func, args); /* run in pdb; incref'd */ else -#if PY_VERSION_HEX < 0x03090000 - presult = PyEval_CallObject(func, args); /* run function; incref'd */ -#else presult = PyObject_CallObject(func, args); /* run function; incref'd */ -#endif Py_DECREF(func); Py_DECREF(args); /* result may be None */ @@ -183,11 +175,7 @@ PP_Run_Known_Callable(PyObject *object, /* func|class|method */ if (PP_DEBUG) /* debug this call? */ presult = PP_Debug_Function(object, args); /* run in pdb; incref'd */ else -#if PY_VERSION_HEX < 0x03090000 - presult = PyEval_CallObject(object, args); /* run function; incref'd */ -#else presult = PyObject_CallObject(object, args); /* run function; incref'd */ -#endif Py_DECREF(args); /* result may be None */ return PP_Convert_Result(presult, resfmt, cresult); /* convert result to C*/ diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index 13b8e8c537..bac9242f9b 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -123,11 +123,7 @@ InteractiveInterpreter::InteractiveInterpreter() PyObject* func = PyObject_GetAttrString(module, "InteractiveInterpreter"); PyObject* args = Py_BuildValue("()"); d = new InteractiveInterpreterP; -#if PY_VERSION_HEX < 0x03090000 - d->interpreter = PyEval_CallObject(func,args); -#else d->interpreter = PyObject_CallObject(func,args); -#endif Py_DECREF(args); Py_DECREF(func); Py_DECREF(module); @@ -175,11 +171,7 @@ PyObject* InteractiveInterpreter::compile(const char* source) const Base::PyGILStateLocker lock; PyObject* func = PyObject_GetAttrString(d->interpreter, "compile"); PyObject* args = Py_BuildValue("(s)", source); -#if PY_VERSION_HEX < 0x03090000 - PyObject* eval = PyEval_CallObject(func,args); // must decref later -#else PyObject* eval = PyObject_CallObject(func,args); // must decref later -#endif Py_XDECREF(args); Py_XDECREF(func); @@ -211,11 +203,7 @@ int InteractiveInterpreter::compileCommand(const char* source) const Base::PyGILStateLocker lock; PyObject* func = PyObject_GetAttrString(d->interpreter, "compile"); PyObject* args = Py_BuildValue("(s)", source); -#if PY_VERSION_HEX < 0x03090000 - PyObject* eval = PyEval_CallObject(func,args); // must decref later -#else PyObject* eval = PyObject_CallObject(func,args); // must decref later -#endif Py_DECREF(args); Py_DECREF(func); diff --git a/src/Gui/PythonDebugger.cpp b/src/Gui/PythonDebugger.cpp index 0d398c4d17..773678a4df 100644 --- a/src/Gui/PythonDebugger.cpp +++ b/src/Gui/PythonDebugger.cpp @@ -176,9 +176,7 @@ Py::Object PythonDebugStdout::repr() Py::Object PythonDebugStdout::write(const Py::Tuple& args) { char *msg; - //PyObject* pObj; - ////args contains a single parameter which is the string to write. - //if (!PyArg_ParseTuple(args.ptr(), "Os:OutputString", &pObj, &msg)) + //args contains a single parameter which is the string to write. if (!PyArg_ParseTuple(args.ptr(), "s:OutputString", &msg)) throw Py::Exception(); @@ -186,9 +184,6 @@ Py::Object PythonDebugStdout::write(const Py::Tuple& args) { //send it to our stdout printf("%s\n",msg); - - //send it to the debugger as well - //g_DebugSocket.SendMessage(eMSG_OUTPUT, msg); } return Py::None(); } @@ -224,19 +219,12 @@ Py::Object PythonDebugStderr::repr() Py::Object PythonDebugStderr::write(const Py::Tuple& args) { char *msg; - //PyObject* pObj; //args contains a single parameter which is the string to write. - //if (!PyArg_ParseTuple(args.ptr(), "Os:OutputDebugString", &pObj, &msg)) if (!PyArg_ParseTuple(args.ptr(), "s:OutputDebugString", &msg)) throw Py::Exception(); if (strlen(msg) > 0) { - //send the message to our own stderr - //dprintf(msg); - - //send it to the debugger as well - //g_DebugSocket.SendMessage(eMSG_TRACE, msg); Base::Console().Error("%s", msg); } @@ -275,24 +263,6 @@ Py::Object PythonDebugExcept::excepthook(const Py::Tuple& args) PyErr_NormalizeException(&exc, &value, &tb); PyErr_Display(exc, value, tb); -/* - if (eEXCEPTMODE_IGNORE != g_eExceptionMode) - { - assert(tb); - - if (tb && (tb != Py_None)) - { - //get the pointer to the frame held by the bottom traceback object - this - //should be where the exception occurred. - tracebackobject* pTb = (tracebackobject*)tb; - while (pTb->tb_next != NULL) - { - pTb = pTb->tb_next; - } - PyFrameObject* frame = (PyFrameObject*)PyObject_GetAttr((PyObject*)pTb, PyString_FromString("tb_frame")); - EnterBreakState(frame, (PyObject*)pTb); - } - }*/ return Py::None(); } @@ -542,13 +512,6 @@ void PythonDebugger::hideDebugMarker(const QString& fn) } } -#if PY_VERSION_HEX < 0x030900B1 -static PyCodeObject* PyFrame_GetCode(PyFrameObject *frame) -{ - Py_INCREF(frame->f_code); - return frame->f_code; -} -#endif // http://www.koders.com/cpp/fidBA6CD8A0FE5F41F1464D74733D9A711DA257D20B.aspx?s=PyEval_SetTrace // http://code.google.com/p/idapython/source/browse/trunk/python.cpp diff --git a/src/Gui/WidgetFactory.cpp b/src/Gui/WidgetFactory.cpp index 82ee5d2f27..38662d1089 100644 --- a/src/Gui/WidgetFactory.cpp +++ b/src/Gui/WidgetFactory.cpp @@ -739,11 +739,7 @@ void SignalConnect::onExecute() /* Time to call the callback */ arglist = Py_BuildValue("(O)", myResource); -#if PY_VERSION_HEX < 0x03090000 - result = PyEval_CallObject(myCallback, arglist); -#else result = PyObject_CallObject(myCallback, arglist); -#endif Py_XDECREF(result); Py_DECREF(arglist); } diff --git a/src/Mod/CAM/App/VoronoiPyImp.cpp b/src/Mod/CAM/App/VoronoiPyImp.cpp index c0842f2f03..0c4d6ff892 100644 --- a/src/Mod/CAM/App/VoronoiPyImp.cpp +++ b/src/Mod/CAM/App/VoronoiPyImp.cpp @@ -190,11 +190,8 @@ static bool callbackWithVertex(Voronoi::diagram_type* dia, #endif PyObject* vx = new VoronoiVertexPy(new VoronoiVertex(dia, v)); PyObject* arglist = Py_BuildValue("(O)", vx); -#if PY_VERSION_HEX < 0x03090000 - PyObject* result = PyEval_CallObject(callback, arglist); -#else - PyObject* result = PyObject_CallObject(callback, arglist); -#endif + PyObject* result = PyObject_CallObject(callback, arglist); + Py_DECREF(arglist); Py_DECREF(vx); if (!result) {