From 5910b89afe685a46e990cdbd3f41ae28b72f4f4e Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Sat, 21 Dec 2024 22:32:17 +0100 Subject: [PATCH] talipot-python: Fix compilation and runtime errors with Python 3.13 --- library/talipot-python/src/ConsoleUtilsModule.cpp | 11 ++++++++++- library/talipot-python/src/PythonInterpreter.cpp | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/library/talipot-python/src/ConsoleUtilsModule.cpp b/library/talipot-python/src/ConsoleUtilsModule.cpp index d0f4ddd6bb..2bb7d6df0f 100644 --- a/library/talipot-python/src/ConsoleUtilsModule.cpp +++ b/library/talipot-python/src/ConsoleUtilsModule.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2019-2023 The Talipot developers + * Copyright (C) 2019-2024 The Talipot developers * * Talipot is a fork of Tulip, created by David Auber * and the Tulip development Team from LaBRI, University of Bordeaux @@ -212,6 +212,11 @@ static PyTypeObject consoleutils_ConsoleOutputType = { , 0 #endif +#if PY_VERSION_HEX >= 0x030D0000 + , + 0 +#endif + }; typedef struct { @@ -312,6 +317,10 @@ static PyTypeObject consoleutils_ConsoleInputType = { , 0 #endif +#if PY_VERSION_HEX >= 0x030D0000 + , + 0 +#endif }; static struct PyModuleDef consoleutilsModuleDef = { diff --git a/library/talipot-python/src/PythonInterpreter.cpp b/library/talipot-python/src/PythonInterpreter.cpp index 348f8c40d6..90d3638220 100644 --- a/library/talipot-python/src/PythonInterpreter.cpp +++ b/library/talipot-python/src/PythonInterpreter.cpp @@ -49,7 +49,9 @@ extern QString mainScriptFileName; PyMODINIT_FUNC initconsoleutils(); PyMODINIT_FUNC inittalipotutils(); +#if PY_VERSION_HEX < 0x030D0000 static PyThreadState *mainThreadState; +#endif static PyGILState_STATE gilState; @@ -204,7 +206,9 @@ PythonInterpreter::PythonInterpreter() #if PY_VERSION_HEX < 0x03090000 PyEval_InitThreads(); #endif +#if PY_VERSION_HEX < 0x030D0000 mainThreadState = PyEval_SaveThread(); +#endif } holdGIL(); @@ -310,9 +314,10 @@ PythonInterpreter::~PythonInterpreter() { consoleOuputString = ""; runString( "sys.stdout = sys.__stdout__; sys.stderr = sys.__stderr__; sys.stdin = sys.__stdin__\n"); +#if PY_VERSION_HEX < 0x030D0000 PyEval_ReleaseLock(); PyEval_RestoreThread(mainThreadState); - +#endif holdGIL(); Py_Finalize(); }