From 93cc7cd178349b062a8effa8548fb3fe87a93655 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Fri, 29 Sep 2023 00:58:59 +0200 Subject: [PATCH] Protect Python accessor wrapper from C++ thrown exceptions. --- .../src/isobar/hurricane/isobar/PyHurricane.h | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h index 6d79829c..69ae20c8 100644 --- a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h +++ b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h @@ -337,8 +337,10 @@ extern "C" { static PyObject* PY_FUNC_NAME ( PY_SELF_TYPE *self, PyObject* args ) \ { \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#FUNC_NAME"()") \ + HTRY \ if (cobject->FUNC_NAME()) \ Py_RETURN_TRUE; \ + HCATCH \ Py_RETURN_FALSE; \ } @@ -383,7 +385,11 @@ extern "C" { static PyObject* PY_FUNC_NAME ( PY_SELF_TYPE *self, PyObject* args ) \ { \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#FUNC_NAME"()") \ - return Py_BuildValue ("I",cobject->FUNC_NAME()); \ + PyObject* rvalue = NULL; \ + HTRY \ + rvalue = Py_BuildValue ("I",cobject->FUNC_NAME()); \ + HCATCH \ + return rvalue; \ } @@ -394,7 +400,11 @@ extern "C" { static PyObject* PY_FUNC_NAME ( PY_SELF_TYPE *self, PyObject* args ) \ { \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#FUNC_NAME"()") \ - return Isobar::PyDbU_FromLong(cobject->FUNC_NAME()); \ + PyObject* rvalue = NULL; \ + HTRY \ + rvalue = Isobar::PyDbU_FromLong(cobject->FUNC_NAME()); \ + HCATCH \ + return rvalue; \ } @@ -405,7 +415,11 @@ extern "C" { static PyObject* PY_FUNC_NAME ( PY_SELF_TYPE *self, PyObject* args ) \ { \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#FUNC_NAME"()") \ - return Py_BuildValue ("d",cobject->FUNC_NAME()); \ + PyObject* rvalue = NULL; \ + HTRY \ + rvalue = Py_BuildValue ("d",cobject->FUNC_NAME()); \ + HCATCH \ + return rvalue; \ } @@ -416,7 +430,11 @@ extern "C" { static PyObject* PY_FUNC_NAME ( PY_SELF_TYPE *self ) \ { \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#FUNC_NAME"()") \ - return Py_BuildValue ("s",cobject->FUNC_NAME().c_str()); \ + PyObject* rvalue = NULL; \ + HTRY \ + rvalue = Py_BuildValue ("s",cobject->FUNC_NAME().c_str()); \ + HCATCH \ + return rvalue; \ } @@ -427,14 +445,18 @@ extern "C" { static PyObject* PY_FUNC_NAME ( PY_SELF_TYPE *self ) \ { \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#FUNC_NAME"()") \ - return Py_BuildValue ("s",getString(cobject->FUNC_NAME()).c_str()); \ + PyObject* rvalue = NULL; \ + HTRY \ + rvalue = Py_BuildValue ("s",getString(cobject->FUNC_NAME()).c_str()); \ + HCATCH \ + return rvalue; \ } # define accessorLayerFromVoid(FUNC_NAME,PY_SELF_TYPE,SELF_TYPE) \ static PyObject* PY_SELF_TYPE##_##FUNC_NAME ( PY_SELF_TYPE* self ) \ { \ - cdebug_log(20,0) << #PY_SELF_TYPE "_" #FUNC_NAME "()" << endl; \ + cdebug_log(20,0) << #PY_SELF_TYPE "_" #FUNC_NAME "()" << endl; \ \ Layer* rlayer = NULL; \ \