summaryrefslogtreecommitdiff
path: root/Include/methodobject.h
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2004-10-28 16:32:00 +0000
committerArmin Rigo <arigo@tunes.org>2004-10-28 16:32:00 +0000
commit89a39461bff04b80bb4857790350e1ab30ff2df9 (patch)
tree54bc00a9ad30e8e49849874cfbca8543de62fa58 /Include/methodobject.h
parent063e1e846dc5c3fe593cef5b14cc429369dcd2c2 (diff)
downloadcpython-git-89a39461bff04b80bb4857790350e1ab30ff2df9.tar.gz
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.
Diffstat (limited to 'Include/methodobject.h')
-rw-r--r--Include/methodobject.h19
1 files changed, 12 insertions, 7 deletions
diff --git a/Include/methodobject.h b/Include/methodobject.h
index 0f605499ee..9736dc3f1a 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -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