Skip to content

Commit

Permalink
add PyErr_GetRaisedException compatibility macro
Browse files Browse the repository at this point in the history
Ugly hax. but appears to work
  • Loading branch information
813gan committed Sep 8, 2024
1 parent 625950a commit 8bddfe7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) \
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Cython
packaging
10 changes: 10 additions & 0 deletions subinterpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(); \
Expand Down

0 comments on commit 8bddfe7

Please sign in to comment.