summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-05-14 21:54:20 (GMT)
committerGuido van Rossum <guido@python.org>1996-05-14 21:54:20 (GMT)
commit6dabc984005c02c0289a17d8d173dc800214b44f (patch)
treec1e5091fc25e27675c8add10a2402324e4e1ebd7 /Objects/classobject.c
parent3355be3f352d905a02031bdec6d91a339489b1c8 (diff)
downloadcpython-6dabc984005c02c0289a17d8d173dc800214b44f.zip
cpython-6dabc984005c02c0289a17d8d173dc800214b44f.tar.gz
cpython-6dabc984005c02c0289a17d8d173dc800214b44f.tar.bz2
Added __name__ attribute to class instance method objects.
Removed im_doc attribute; __name__ and __doc__ are now handled by special casing in instancemethodgetattr(). This saves a few bytes and INCREF/DECREF calls per i.m. object allocation/deallocation.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r--Objects/classobject.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 550ee1c..48ea2e7 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -1131,7 +1131,6 @@ typedef struct {
object *im_func; /* The function implementing the method */
object *im_self; /* The instance it is bound to, or NULL */
object *im_class; /* The class that defined the method */
- object *im_doc; /* The documentation string */
} instancemethodobject;
object *
@@ -1154,8 +1153,6 @@ newinstancemethodobject(func, self, class)
im->im_self = self;
INCREF(class);
im->im_class = class;
- XINCREF(((funcobject *)func)->func_doc);
- im->im_doc = ((funcobject *)func)->func_doc;
return (object *)im;
}
@@ -1200,8 +1197,9 @@ static struct memberlist instancemethod_memberlist[] = {
{"im_func", T_OBJECT, OFF(im_func)},
{"im_self", T_OBJECT, OFF(im_self)},
{"im_class", T_OBJECT, OFF(im_class)},
- {"im_doc", T_OBJECT, OFF(im_doc)},
- {"__doc__", T_OBJECT, OFF(im_doc)},
+ /* Dummies that are not handled by getattr() except for __members__ */
+ {"__doc__", T_INT, 0},
+ {"__name__", T_INT, 0},
{NULL} /* Sentinel */
};
@@ -1210,7 +1208,18 @@ instancemethod_getattr(im, name)
register instancemethodobject *im;
char *name;
{
- if (name[0] != '_' && getrestricted()) {
+ if (name[0] == '_') {
+ funcobject *func = (funcobject *)(im->im_func);
+ if (strcmp(name, "__name__") == 0) {
+ INCREF(func->func_name);
+ return func->func_name;
+ }
+ if (strcmp(name, "__doc__") == 0) {
+ INCREF(func->func_doc);
+ return func->func_doc;
+ }
+ }
+ if (getrestricted()) {
err_setstr(RuntimeError,
"instance-method attributes not accessible in restricted mode");
return NULL;
@@ -1225,7 +1234,6 @@ instancemethod_dealloc(im)
DECREF(im->im_func);
XDECREF(im->im_self);
DECREF(im->im_class);
- XDECREF(im->im_doc);
free((ANY *)im);
}