From 3fb229f1f9be8922b010cbecc05339256545aab9 Mon Sep 17 00:00:00 2001 From: Aaron Jomy Date: Thu, 24 Sep 2026 23:09:19 +0200 Subject: [PATCH] [cpyrt] Drop the dead ROOT signal-longjmp guard --- src/cpyrt/CPPMethod.cxx | 68 ++---------------------------- src/cpyrt/CPPMethod.h | 1 - src/cpyrt/SignalTryCatch.h | 84 -------------------------------------- 3 files changed, 4 insertions(+), 149 deletions(-) delete mode 100644 src/cpyrt/SignalTryCatch.h diff --git a/src/cpyrt/CPPMethod.cxx b/src/cpyrt/CPPMethod.cxx index e8cccc5..a225efb 100644 --- a/src/cpyrt/CPPMethod.cxx +++ b/src/cpyrt/CPPMethod.cxx @@ -9,7 +9,6 @@ using namespace cppjit; #include "Executors.h" #include "ProxyWrappers.h" #include "PyStrings.h" -#include "SignalTryCatch.h" #include "TypeManip.h" #include "Utility.h" #include "cppjit_interop.h" @@ -20,7 +19,6 @@ using namespace cppjit; #include #include #include -#include #include #include #include @@ -195,56 +193,6 @@ inline PyObject* cpyrt::CPPMethod::ExecuteFast(void* self, ptrdiff_t offset, return result; } -//---------------------------------------------------------------------------- -inline PyObject* cpyrt::CPPMethod::ExecuteProtected(void* self, - ptrdiff_t offset, - CallContext* ctxt) { - // helper code to prevent some code duplication; this code embeds a - // "try/catch" block that saves the call environment for restoration in case - // of an otherwise fatal signal - PyObject* result = 0; - - CLING_EXCEPTION_TRY { // copy call environment to be able to jump back on - // signal - result = ExecuteFast(self, offset, ctxt); - } - CLING_EXCEPTION_CATCH(excode) { - // report any outstanding Python exceptions first - if (PyErr_Occurred()) { - std::cerr << "Python exception outstanding during C++ longjmp:" - << std::endl; - PyErr_Print(); - std::cerr << std::endl; - } - - // unfortunately, the excodes are not the ones from signal.h, but enums from - // TSysEvtHandler.h - if (excode == 0) - PyErr_SetString(gBusException, - "bus error in C++; program state was reset"); - else if (excode == 1) - PyErr_SetString(gSegvException, - "segfault in C++; program state was reset"); - else if (excode == 4) - PyErr_SetString(gIllException, - "illegal instruction in C++; program state was reset"); - else if (excode == 5) - PyErr_SetString(gAbrtException, - "abort from C++; program state was reset"); - else if (excode == 12) - PyErr_SetString( - PyExc_FloatingPointError, - "floating point exception in C++; program state was reset"); - else - PyErr_SetString(PyExc_SystemError, - "problem in C++; program state was reset"); - result = 0; - } - CLING_EXCEPTION_ENDTRY; - - return result; -} - //---------------------------------------------------------------------------- bool cpyrt::CPPMethod::InitConverters_() { // build buffers for argument dispatching @@ -1015,18 +963,10 @@ bool cpyrt::CPPMethod::ConvertAndSetArgs(cpyrt_PyArgs_t args, size_t nargsf, //---------------------------------------------------------------------------- PyObject* cpyrt::CPPMethod::Execute(void* self, ptrdiff_t offset, CallContext* ctxt) { - // call the interface method - PyObject* result = 0; - - if (CallContext::sSignalPolicy != CallContext::kProtected && - !(ctxt->fFlags & CallContext::kProtected)) { - // bypasses try block (i.e. segfaults will abort) - result = ExecuteFast(self, offset, ctxt); - } else { - // at the cost of ~10% performance, don't abort the interpreter on any - // signal - result = ExecuteProtected(self, offset, ctxt); - } + // call the interface method; the kProtected signal policy is accepted for + // API compatibility but has no separate path: without a signal handler + // that longjmps back into the call there is nothing to protect + PyObject* result = ExecuteFast(self, offset, ctxt); if (!result && PyErr_Occurred()) SetPyError_(0); diff --git a/src/cpyrt/CPPMethod.h b/src/cpyrt/CPPMethod.h index 8c66a1d..2278733 100644 --- a/src/cpyrt/CPPMethod.h +++ b/src/cpyrt/CPPMethod.h @@ -101,7 +101,6 @@ class CPPMethod : public PyCallable { bool VerifyArgCount_(Py_ssize_t); PyObject* ExecuteFast(void*, ptrdiff_t, CallContext*); - PyObject* ExecuteProtected(void*, ptrdiff_t, CallContext*); bool InitConverters_(); diff --git a/src/cpyrt/SignalTryCatch.h b/src/cpyrt/SignalTryCatch.h deleted file mode 100644 index 3ab04d2..0000000 --- a/src/cpyrt/SignalTryCatch.h +++ /dev/null @@ -1,84 +0,0 @@ -// Partial reproduction of ROOT's TException.h - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef CPYRT_SIGNALTRYCATCH_H -#define CPYRT_SIGNALTRYCATCH_H - -#include -#include "cpyrt/CommonDefs.h" - -#ifndef _WIN32 -#define NEED_SIGJMP 1 -#endif - -// By default, the ExceptionContext_t class is expected in the namespace -// CppyyLegacy, If it is expected in no namespace, one can explicitly define -// NO_CPPJIT_LEGACY_NAMESPACE at build time (e.g. if one wants to use ROOT). - -#ifndef NO_CPPJIT_LEGACY_NAMESPACE -namespace CppyyLegacy { -#endif -struct ExceptionContext_t { -#ifdef NEED_SIGJMP - sigjmp_buf fBuf; -#else - jmp_buf fBuf; -#endif -}; -#ifndef NO_CPPJIT_LEGACY_NAMESPACE -} - -using cppjit_interopExceptionContext_t = CppyyLegacy::ExceptionContext_t; -#else -using cppjit_interopExceptionContext_t = ExceptionContext_t; -#endif - -// FIXME: This is a dummy, replace with cling equivalent of gException -static cppjit_interopExceptionContext_t DummyException; -static cppjit_interopExceptionContext_t* gException = &DummyException; - -#ifdef NEED_SIGJMP -#define CLING_EXCEPTION_SETJMP(buf) sigsetjmp(buf, 1) -#else -#define CLING_EXCEPTION_SETJMP(buf) setjmp(buf) -#endif - -#define CLING_EXCEPTION_RETRY \ - { \ - static cppjit_interopExceptionContext_t R__curr, *R__old = gException; \ - int R__code; \ - gException = &R__curr; \ - R__code = CLING_EXCEPTION_SETJMP(gException->fBuf); \ - if (R__code) { \ - }; \ - { - -#define CLING_EXCEPTION_TRY \ - { \ - static cppjit_interopExceptionContext_t R__curr, *R__old = gException; \ - int R__code; \ - gException = &R__curr; \ - if ((R__code = CLING_EXCEPTION_SETJMP(gException->fBuf)) == 0) { - -#define CLING_EXCEPTION_CATCH(n) \ - gException = R__old; \ - } \ - else { \ - int n = R__code; \ - gException = R__old; - -#define CLING_EXCEPTION_ENDTRY \ - } \ - gException = R__old; \ - } - -CPYRT_IMPORT cppjit_interopExceptionContext_t* gException; - -#endif