From 62c5ca89a61c96df6abe5468354520ae16da805e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 2 Feb 2019 23:15:25 +0000 Subject: [PATCH] Minor refactoring of generated Python code --- Lib/python/pyapi.swg | 34 +++++++++++----------------------- Source/Modules/python.cxx | 8 ++------ 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/Lib/python/pyapi.swg b/Lib/python/pyapi.swg index 5c2c65c45..cb754db11 100644 --- a/Lib/python/pyapi.swg +++ b/Lib/python/pyapi.swg @@ -28,24 +28,18 @@ typedef struct swig_const_info { * Function to find the method definition with the correct docstring for the * proxy module as opposed to the low-level API * ----------------------------------------------------------------------------- */ -PyMethodDef* getProxyDoc(const char* name); +SWIGRUNTIME PyMethodDef *SWIG_PythonGetProxyDoc(const char *name); /* ----------------------------------------------------------------------------- * Wrapper of PyInstanceMethod_New() used in Python 3 * It is exported to the generated module, used for -fastproxy * ----------------------------------------------------------------------------- */ -SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) -{ +SWIGRUNTIME PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) { if (PyCFunction_Check(func)) { - /* Unpack the existing PyCFunction */ - PyMethodDef* ml = ((PyCFunctionObject*) func)->m_ml; - PyObject* self = ((PyCFunctionObject*) func)->m_self; - PyObject* module = ((PyCFunctionObject*) func)->m_module; - /* Use the copy with the modified docstring if available */ - ml = getProxyDoc(ml->ml_name); - if (ml != NULL) { - func = PyCFunction_NewEx(ml, self, module); - } + PyCFunctionObject *funcobj = (PyCFunctionObject *)func; + PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name); + if (ml) + func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module); } #if PY_VERSION_HEX >= 0x03000000 return PyInstanceMethod_New(func); @@ -58,18 +52,12 @@ SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), * Wrapper of PyStaticMethod_New() * It is exported to the generated module, used for -fastproxy * ----------------------------------------------------------------------------- */ -SWIGRUNTIME PyObject* SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) -{ +SWIGRUNTIME PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) { if (PyCFunction_Check(func)) { - /* Unpack the existing PyCFunction */ - PyMethodDef* ml = ((PyCFunctionObject*) func)->m_ml; - PyObject* self = ((PyCFunctionObject*) func)->m_self; - PyObject* module = ((PyCFunctionObject*) func)->m_module; - /* Use the copy with the modified docstring if available */ - ml = getProxyDoc(ml->ml_name); - if (ml != NULL) { - func = PyCFunction_NewEx(ml, self, module); - } + PyCFunctionObject *funcobj = (PyCFunctionObject *)func; + PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name); + if (ml) + func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module); } return PyStaticMethod_New(func); } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index acf1ecd57..271375362 100755 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -835,7 +835,7 @@ public: Printf(f_wrappers, "%s\n", methods_proxydocs); /* Need to define the function to find the proxy documentation after the proxy docs themselves */ - Printv(f_wrappers, "PyMethodDef* getProxyDoc(const char* name)\n", + Printv(f_wrappers, "SWIGRUNTIME PyMethodDef *SWIG_PythonGetProxyDoc(const char *name)\n", "{\n", " /* Find the function in the modified method table */\n", " size_t offset = 0;\n", @@ -848,11 +848,7 @@ public: " offset++;\n", " }\n", " /* Use the copy with the modified docstring if available */\n", - " if (found == 1) {\n", - " return &SwigMethods_proxydocs[offset];\n", - " } else {\n", - " return NULL;\n", - " }\n", + " return found ? &SwigMethods_proxydocs[offset] : NULL;\n", "}\n", NIL); if (builtin) {