summaryrefslogtreecommitdiffstats
path: root/Objects/funcobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-01-07 12:01:30 (GMT)
committerGuido van Rossum <guido@python.org>1995-01-07 12:01:30 (GMT)
commit5bd3805ae9fff911d06ad5817f9e59d8978ba1ef (patch)
tree1d2ecca191d4d3ca85b2211648f2430e29e3d04c /Objects/funcobject.c
parent8b14b4c733cb745410c00a0fe63d3e604e53954f (diff)
downloadcpython-5bd3805ae9fff911d06ad5817f9e59d8978ba1ef.zip
cpython-5bd3805ae9fff911d06ad5817f9e59d8978ba1ef.tar.gz
cpython-5bd3805ae9fff911d06ad5817f9e59d8978ba1ef.tar.bz2
Added __doc__ attribute (alias func_doc), initialized from first
constant in code object if it is a string, else None
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r--Objects/funcobject.c17
1 files changed, 16 insertions, 1 deletions
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);
}