Commit 9a47977f authored by Guido van Rossum's avatar Guido van Rossum

New newmethodobject() interface takes struct methodlist pointer

instead of individual components; initmodule3() now has doc string
argument as well
parent ac8ad1b4
...@@ -33,40 +33,39 @@ typedef extended va_double; ...@@ -33,40 +33,39 @@ typedef extended va_double;
typedef double va_double; typedef double va_double;
#endif #endif
/* initmodule3() has two additional parameters:
/* initmodule2() has an additional parameter, 'passthrough', which is - doc is the documentation string;
passed as 'self' to functions defined in the module. This is used - passthrough is passed as self to functions defined in the module.
e.g. by dynamically loaded modules on the Mac. */ */
object * object *
initmodule2(name, methods, passthrough) initmodule3(name, methods, doc, passthrough)
char *name; char *name;
struct methodlist *methods; struct methodlist *methods;
char *doc;
object *passthrough; object *passthrough;
{ {
object *m, *d, *v; object *m, *d, *v;
struct methodlist *ml; struct methodlist *ml;
char *namebuf;
if ((m = add_module(name)) == NULL) { if ((m = add_module(name)) == NULL) {
fprintf(stderr, "initializing module: %s\n", name); fprintf(stderr, "initializing module: %s\n", name);
fatal("can't create a module"); fatal("can't create a module");
} }
d = getmoduledict(m); d = getmoduledict(m);
for (ml = methods; ml->ml_name != NULL; ml++) { for (ml = methods; ml->ml_name != NULL; ml++) {
namebuf = NEW(char, strlen(name) + strlen(ml->ml_name) + 2); v = newmethodobject(ml, passthrough);
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);
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) { if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
fprintf(stderr, "initializing module: %s\n", name); fprintf(stderr, "initializing module: %s\n", name);
fatal("can't initialize module"); fatal("can't initialize module");
} }
DECREF(v); 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; return m;
} }
...@@ -77,7 +76,7 @@ initmodule(name, methods) ...@@ -77,7 +76,7 @@ initmodule(name, methods)
char *name; char *name;
struct methodlist *methods; struct methodlist *methods;
{ {
return initmodule2(name, methods, (object *)NULL); return initmodule3(name, methods, (char *)NULL, (object *)NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment