From 8bddfe7c78b76fedbdb526d7ec297647914f91a5 Mon Sep 17 00:00:00 2001 From: 813gan <813gan@protonmail.com> Date: Sun, 8 Sep 2024 03:23:17 +0200 Subject: [PATCH] add PyErr_GetRaisedException compatibility macro Ugly hax. but appears to work --- Makefile | 9 ++++++++- requirements.txt | 1 + subinterpreter.c | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ecf3d7e..c72d102 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,13 @@ CLANGFORMAT := true # darwin form gh CI have no clang-format endif endif +ifeq (, $(shell which pkg-config)) +$(error "No pkg-config found.") +endif + +IS_PYTHON_OLD := $(shell ${PYTHON} -c 'import platform;from packaging import version as v; \ +print("-DPYTHON311OLDER") if (v.parse(platform.python_version()) < v.parse("3.12.0")) else exit(0)') + .PHONY: all clean test_module_assertions test test_ert test_formatting test_valgrind all: emacspy-module.so @@ -32,7 +39,7 @@ emacspy-module.so: PKGCONFIG_PATH=$(shell ${PYTHON} -c \ emacspy-module.so: LIBPYTHON_NAME=$(shell ${PYTHON} -c \ 'import sysconfig; print(sysconfig.get_config_var("LDLIBRARY"))') emacspy-module.so: emacspy.c stub.c subinterpreter.c - gcc -fPIC -g -DCYTHON_FAST_THREAD_STATE=0 -DCYTHON_PEP489_MULTI_PHASE_INIT=0 \ + gcc -fPIC -g -DCYTHON_FAST_THREAD_STATE=0 -DCYTHON_PEP489_MULTI_PHASE_INIT=0 ${IS_PYTHON_OLD} \ -Wall -Wextra -Werror ${OPTIMALISATION_FLAGS} ${HARDENING_FLAGS} ${GCC_NO_WARN} \ emacspy.c stub.c \ ${BLDLIBRARY} -DLIBPYTHON_NAME=$(LIBPYTHON_NAME) \ diff --git a/requirements.txt b/requirements.txt index 002d1b9..77ddf61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Cython +packaging diff --git a/subinterpreter.c b/subinterpreter.c index 439197c..7e5cfd4 100644 --- a/subinterpreter.c +++ b/subinterpreter.c @@ -6,6 +6,16 @@ #define MAX_INTERPRETER_NAME_LEN 100 +#ifdef PYTHON311OLDER +#define PyErr_GetRaisedException() \ + ({ \ + PyObject *type, *value, *traceback; \ + PyErr_Fetch(&type, &value, &traceback); \ + PyErr_NormalizeException(&type, &value, &traceback); \ + value; \ + }) +#endif + #define SUBINTERPRETER_SWITCH \ struct interpr *sub_interpreter = get_interpreter(interpreter_name); \ PyGILState_STATE gil = PyGILState_Ensure(); \