summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-05-19 14:50:45 (GMT)
committerGuido van Rossum <guido@python.org>1993-05-19 14:50:45 (GMT)
commit25831652fd4c03323066d4cafdc0551c396a993e (patch)
tree69588df0f98b3280402cad3ed95865d06fa21702 /Python/import.c
parent687dd13bfec51849c93db7c538ff41d4c8ecddcb (diff)
downloadcpython-25831652fd4c03323066d4cafdc0551c396a993e.zip
cpython-25831652fd4c03323066d4cafdc0551c396a993e.tar.gz
cpython-25831652fd4c03323066d4cafdc0551c396a993e.tar.bz2
Several changes in one:
(1) dictionaries/mappings now have attributes values() and items() as well as keys(); at the C level, use the new function mappinggetnext() to iterate over a dictionary. (2) "class C(): ..." is now illegal; you must write "class C: ...". (3) Class objects now know their own name (finally!); and minor improvements to the way how classes, functions and methods are represented as strings. (4) Added an "access" statement and semantics. (This is still experimental -- as long as you don't use the keyword 'access' nothing should be changed.)
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c43
1 files changed, 12 insertions, 31 deletions
diff --git a/Python/import.c b/Python/import.c
index 4310afa..ec21b4c 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -54,7 +54,7 @@ extern char *argv0;
/* Magic word to reject .pyc files generated by other Python versions */
-#define MAGIC 0x99BE3AL
+#define MAGIC 0x999901L /* Increment by one for each incompatible change */
static object *modules;
@@ -353,46 +353,27 @@ reload_module(m)
return get_module(m, getmodulename(m), (object **)NULL);
}
-static void
-cleardict(d)
- object *d;
-{
- int i;
- for (i = getdictsize(d); --i >= 0; ) {
- char *k;
- k = getdictkey(d, i);
- if (k != NULL)
- (void) dictremove(d, k);
- }
-}
-
void
doneimport()
{
if (modules != NULL) {
- int i;
+ int pos;
+ object *modname, *module;
/* Explicitly erase all modules; this is the safest way
to get rid of at least *some* circular dependencies */
- for (i = getdictsize(modules); --i >= 0; ) {
- object *k;
- k = getdict2key(modules, i);
- if (k != NULL) {
- object *m;
- m = dict2lookup(modules, k);
- if (m == NULL)
- err_clear();
- else if (is_moduleobject(m)) {
- object *d;
- d = getmoduledict(m);
- if (d != NULL && is_dictobject(d)) {
- cleardict(d);
- }
- }
+ pos = 0;
+ while (mappinggetnext(modules, &pos, &modname, &module)) {
+ if (is_moduleobject(module)) {
+ object *dict;
+ dict = getmoduledict(module);
+ if (dict != NULL && is_dictobject(dict))
+ mappingclear(dict);
}
}
- cleardict(modules);
+ mappingclear(modules);
}
DECREF(modules);
+ modules = NULL;
}