Fixes so that fastproxy and autodoc work correctly with both low-level C API and high-level Python Shadow API

This commit is contained in:
Alec Woods 2019-01-25 08:06:17 -05:00
commit 86e08c8e34
5 changed files with 163 additions and 42 deletions

View file

@ -24,6 +24,11 @@ typedef struct swig_const_info {
swig_type_info **ptype;
} 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);
/* -----------------------------------------------------------------------------
* Wrapper of PyInstanceMethod_New() used in Python 3
@ -31,6 +36,17 @@ typedef struct swig_const_info {
* ----------------------------------------------------------------------------- */
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);
}
}
#if PY_VERSION_HEX >= 0x03000000
return PyInstanceMethod_New(func);
#else
@ -38,6 +54,26 @@ SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self),
#endif
}
/* -----------------------------------------------------------------------------
* Wrapper of PyStaticMethod_New()
* It is exported to the generated module, used for -fastproxy
* ----------------------------------------------------------------------------- */
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);
}
}
return PyStaticMethod_New(func);
}
#ifdef __cplusplus
}
#endif