Skip to content

Commit

Permalink
talipot-python: Fix compilation and runtime errors with Python 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
anlambert committed Dec 21, 2024
1 parent b090c8e commit 5910b89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion library/talipot-python/src/ConsoleUtilsModule.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -212,6 +212,11 @@ static PyTypeObject consoleutils_ConsoleOutputType = {
,
0
#endif
#if PY_VERSION_HEX >= 0x030D0000
,
0
#endif

};

typedef struct {
Expand Down Expand Up @@ -312,6 +317,10 @@ static PyTypeObject consoleutils_ConsoleInputType = {
,
0
#endif
#if PY_VERSION_HEX >= 0x030D0000
,
0
#endif
};

static struct PyModuleDef consoleutilsModuleDef = {
Expand Down
7 changes: 6 additions & 1 deletion library/talipot-python/src/PythonInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -204,7 +206,9 @@ PythonInterpreter::PythonInterpreter()
#if PY_VERSION_HEX < 0x03090000
PyEval_InitThreads();
#endif
#if PY_VERSION_HEX < 0x030D0000
mainThreadState = PyEval_SaveThread();
#endif
}

holdGIL();
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 5910b89

Please sign in to comment.