mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
Wrote down the invariants of some common objects whose structure is
exposed in header files. Fixed a few comments in these headers. As we might have expected, writing down invariants systematically exposed a (minor) bug. In this case, function objects have a writeable func_code attribute, which could be set to code objects with the wrong number of free variables. Calling the resulting function segfaulted the interpreter. Added a corresponding test.
This commit is contained in:
parent
063e1e846d
commit
89a39461bf
12 changed files with 98 additions and 25 deletions
|
@ -7,6 +7,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This is about the type 'builtin_function_or_method',
|
||||
not Python methods in user-defined classes. See classobject.h
|
||||
for the latter. */
|
||||
|
||||
PyAPI_DATA(PyTypeObject) PyCFunction_Type;
|
||||
|
||||
#define PyCFunction_Check(op) ((op)->ob_type == &PyCFunction_Type)
|
||||
|
@ -31,10 +35,11 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
|
|||
PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
|
||||
|
||||
struct PyMethodDef {
|
||||
char *ml_name;
|
||||
PyCFunction ml_meth;
|
||||
int ml_flags;
|
||||
char *ml_doc;
|
||||
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 */
|
||||
char *ml_doc; /* The __doc__ attribute, or NULL */
|
||||
};
|
||||
typedef struct PyMethodDef PyMethodDef;
|
||||
|
||||
|
@ -75,9 +80,9 @@ PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
|
|||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyMethodDef *m_ml;
|
||||
PyObject *m_self;
|
||||
PyObject *m_module;
|
||||
PyMethodDef *m_ml; /* Description of the C function to call */
|
||||
PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
|
||||
PyObject *m_module; /* The __module__ attribute, can be anything */
|
||||
} PyCFunctionObject;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue