From 5bd3805ae9fff911d06ad5817f9e59d8978ba1ef Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 7 Jan 1995 12:01:30 +0000 Subject: Added __doc__ attribute (alias func_doc), initialized from first constant in code object if it is a string, else None --- Objects/funcobject.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 9255b57..304fb37 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -35,14 +35,26 @@ newfuncobject(code, globals) { funcobject *op = NEWOBJ(funcobject, &Functype); if (op != NULL) { + object *doc; + object *consts; INCREF(code); op->func_code = code; INCREF(globals); op->func_globals = globals; - op->func_name = ((codeobject*)(op->func_code))->co_name; + op->func_name = ((codeobject *)code)->co_name; INCREF(op->func_name); op->func_argcount = -1; /* Unknown */ op->func_argdefs = NULL; /* No default arguments */ + consts = ((codeobject *)code)->co_consts; + if (gettuplesize(consts) >= 1) { + doc = gettupleitem(consts, 0); + if (!is_stringobject(doc)) + doc = None; + } + else + doc = None; + INCREF(doc); + op->func_doc = doc; } return (object *)op; } @@ -117,6 +129,8 @@ static struct memberlist func_memberlist[] = { {"func_name", T_OBJECT, OFF(func_name), READONLY}, {"func_argcount",T_INT, OFF(func_argcount), READONLY}, {"func_argdefs",T_OBJECT, OFF(func_argdefs), READONLY}, + {"func_doc", T_OBJECT, OFF(func_doc)}, + {"__doc__", T_OBJECT, OFF(func_doc)}, {NULL} /* Sentinel */ }; @@ -135,6 +149,7 @@ func_dealloc(op) DECREF(op->func_code); DECREF(op->func_globals); XDECREF(op->func_argdefs); + XDECREF(op->func_doc); DEL(op); } -- cgit v0.12