summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-01-07 12:43:18 (GMT)
committerGuido van Rossum <guido@python.org>1995-01-07 12:43:18 (GMT)
commit50620fa9b8cbebb2ac085ea19fca3e14f48e7944 (patch)
tree7eca5d2ae73a691e369a51849bb8ab73ad4d2526 /Python
parent1f4fa501766ad79beb0602685dc0f69f9389fc5d (diff)
downloadcpython-50620fa9b8cbebb2ac085ea19fca3e14f48e7944.zip
cpython-50620fa9b8cbebb2ac085ea19fca3e14f48e7944.tar.gz
cpython-50620fa9b8cbebb2ac085ea19fca3e14f48e7944.tar.bz2
New newmethodobject() interface takes struct methodlist pointer
instead of individual components; initmodule3() now has doc string argument as well
Diffstat (limited to 'Python')
-rw-r--r--Python/modsupport.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c
index f196095..9c5dbf9 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -33,40 +33,39 @@ typedef extended va_double;
typedef double va_double;
#endif
-
-/* initmodule2() has an additional parameter, 'passthrough', which is
- passed as 'self' to functions defined in the module. This is used
- e.g. by dynamically loaded modules on the Mac. */
+/* initmodule3() has two additional parameters:
+ - doc is the documentation string;
+ - passthrough is passed as self to functions defined in the module.
+*/
object *
-initmodule2(name, methods, passthrough)
+initmodule3(name, methods, doc, passthrough)
char *name;
struct methodlist *methods;
+ char *doc;
object *passthrough;
{
object *m, *d, *v;
struct methodlist *ml;
- char *namebuf;
if ((m = add_module(name)) == NULL) {
fprintf(stderr, "initializing module: %s\n", name);
fatal("can't create a module");
}
d = getmoduledict(m);
for (ml = methods; ml->ml_name != NULL; ml++) {
- namebuf = NEW(char, strlen(name) + strlen(ml->ml_name) + 2);
- if (namebuf == NULL)
- fatal("out of mem for method name");
- sprintf(namebuf, "%s.%s", name, ml->ml_name);
- v = newmethodobject(namebuf, ml->ml_meth,
- (object *)passthrough,
- (ml->ml_varargs ? METH_VARARGS : 0) |
- METH_FREENAME);
+ v = newmethodobject(ml, passthrough);
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
fprintf(stderr, "initializing module: %s\n", name);
fatal("can't initialize module");
}
DECREF(v);
}
+ if (doc != NULL) {
+ v = newstringobject(doc);
+ if (v == NULL || dictinsert(d, "__doc__", v) != 0)
+ fatal("can't add doc string");
+ DECREF(v);
+ }
return m;
}
@@ -77,7 +76,7 @@ initmodule(name, methods)
char *name;
struct methodlist *methods;
{
- return initmodule2(name, methods, (object *)NULL);
+ return initmodule3(name, methods, (char *)NULL, (object *)NULL);
}