mirror of
https://github.com/python/cpython.git
synced 2024-12-01 11:15:56 +01:00
d6a9e84c81
Closes SF patch #103123. funcobject.h: PyFunctionObject: add the func_dict slot. funcobject.c: PyFunction_New(): Initialize the func_dict slot to NULL. func_getattr(): Rename to func_getattro() and change the signature. It's more efficient to use attro methods and dig the C string out than it is to re-convert a C string to a PyString. Also, add support for getting the __dict__ (a.k.a. func_dict) attribute, and for getting an arbitrary function attribute. func_setattr(): Rename to func_setattro() and change the signature for the same reason. Also add support for setting __dict__ (a.k.a. func_dict) and any arbitrary function attribute. func_dealloc(): Be sure to DECREF the func_dict slot. func_traverse(): Be sure to traverse func_dict too. PyFunction_Type: make the necessary func_?etattro() changes. classobject.c: instancemethod_memberlist: Add __dict__ instancemethod_setattro(): New method to set arbitrary attributes on methods (really the underlying im_func). Raise TypeError when the instance is bound or when you're trying to set one of the reserved im_* attributes. instancemethod_getattr(): Renamed to instancemethod_getattro() since that's what it really is. Also, added support fo getting arbitrary attributes through the im_func. PyMethod_Type: Do the ?etattr{,o} dance.
43 lines
1.2 KiB
C
43 lines
1.2 KiB
C
|
|
/* Function object interface */
|
|
|
|
#ifndef Py_FUNCOBJECT_H
|
|
#define Py_FUNCOBJECT_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
PyObject *func_code;
|
|
PyObject *func_globals;
|
|
PyObject *func_defaults;
|
|
PyObject *func_doc;
|
|
PyObject *func_name;
|
|
PyObject *func_dict;
|
|
} PyFunctionObject;
|
|
|
|
extern DL_IMPORT(PyTypeObject) PyFunction_Type;
|
|
|
|
#define PyFunction_Check(op) ((op)->ob_type == &PyFunction_Type)
|
|
|
|
extern DL_IMPORT(PyObject *) PyFunction_New(PyObject *, PyObject *);
|
|
extern DL_IMPORT(PyObject *) PyFunction_GetCode(PyObject *);
|
|
extern DL_IMPORT(PyObject *) PyFunction_GetGlobals(PyObject *);
|
|
extern DL_IMPORT(PyObject *) PyFunction_GetDefaults(PyObject *);
|
|
extern DL_IMPORT(int) PyFunction_SetDefaults(PyObject *, PyObject *);
|
|
|
|
/* Macros for direct access to these values. Type checks are *not*
|
|
done, so use with care. */
|
|
#define PyFunction_GET_CODE(func) \
|
|
(((PyFunctionObject *)func) -> func_code)
|
|
#define PyFunction_GET_GLOBALS(func) \
|
|
(((PyFunctionObject *)func) -> func_globals)
|
|
#define PyFunction_GET_DEFAULTS(func) \
|
|
(((PyFunctionObject *)func) -> func_defaults)
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* !Py_FUNCOBJECT_H */
|