[New-bugs-announce] [issue41895] PyMethodDef does NOT have any field contains context in embedded C

dexter report at bugs.python.org
Wed Sep 30 13:38:05 EDT 2020


New submission from dexter <nan.nine at outlook.com>:

I am trying to create app embedded python as interpreter, and I use PyImport_AppendInittab to import some helper functions to python. on website the example is excellent when you already know how many functions we want to import. but when my functions are based on a runtime dynamic list, even I create all PyModuleDef and PyMethodDef, but when the function all goes to PyCFunction which only has two PyObject* and return PyObject* i lost context information about C. may be I am not clear, but what I am expecting is PyMethodDef should define like
struct PyMethodDef {
    const char  *ml_name;   /* The name of the built-in function/method */
    PyCFunction ml_meth;    /* The C function that implements it */
    int         ml_flags;   /* Combination of METH_xxx flags, which mostly
                               describe the args expected by the C func */
    const char  *ml_doc;    /* The __doc__ attribute, or NULL */
    void* extra; /* <================= here is NEW */ 
};

and PyCFunction should define like

typedef PyObject *(*PyCFunction)(PyObject *, PyObject *, void * /* for extra void* */);

----------
components: C API
messages: 377714
nosy: dexter
priority: normal
severity: normal
status: open
title: PyMethodDef does NOT have any field contains context in embedded C
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41895>
_______________________________________


More information about the New-bugs-announce mailing list