mirror of
https://github.com/python/cpython.git
synced 2025-10-28 01:00:34 +00:00
"Compiling" version
This commit is contained in:
parent
226d79eb4a
commit
3f5da24ea3
72 changed files with 3363 additions and 2061 deletions
|
|
@ -1,36 +1,8 @@
|
|||
/* Module support implementation */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "PROTO.h"
|
||||
#include "object.h"
|
||||
#include "intobject.h"
|
||||
#include "stringobject.h"
|
||||
#include "tupleobject.h"
|
||||
#include "listobject.h"
|
||||
#include "methodobject.h"
|
||||
#include "moduleobject.h"
|
||||
#include "allobjects.h"
|
||||
#include "modsupport.h"
|
||||
#include "import.h"
|
||||
#include "errors.h"
|
||||
|
||||
|
||||
/* Find a method in a module's method table.
|
||||
Usually called from a module's getattr method. */
|
||||
|
||||
object *
|
||||
findmethod(ml, op, name)
|
||||
struct methodlist *ml;
|
||||
object *op;
|
||||
char *name;
|
||||
{
|
||||
for (; ml->ml_name != NULL; ml++) {
|
||||
if (strcmp(name, ml->ml_name) == 0)
|
||||
return newmethodobject(ml->ml_name, ml->ml_meth, op);
|
||||
}
|
||||
err_setstr(NameError, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
object *
|
||||
|
|
@ -40,21 +12,24 @@ initmodule(name, methods)
|
|||
{
|
||||
object *m, *d, *v;
|
||||
struct methodlist *ml;
|
||||
if ((m = new_module(name)) == NULL) {
|
||||
char namebuf[256];
|
||||
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++) {
|
||||
v = newmethodobject(ml->ml_name, ml->ml_meth, (object *)NULL);
|
||||
sprintf(namebuf, "%s.%s", name, ml->ml_name);
|
||||
v = newmethodobject(strdup(namebuf), ml->ml_meth,
|
||||
(object *)NULL);
|
||||
/* XXX The strdup'ed memory is never freed */
|
||||
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
|
||||
fprintf(stderr, "initializing module: %s\n", name);
|
||||
fatal("can't initialize module");
|
||||
}
|
||||
DECREF(v);
|
||||
}
|
||||
DECREF(m);
|
||||
return m; /* Yes, it still exists, in sys.modules... */
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue