Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 1288:9fed5726a36d legacy-trunk
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.)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 19 May 1993 14:50:45 +0000 |
| parents | 14369a5e6167 |
| children | 4d292c7857d4 |
line wrap: on
line diff
--- a/Python/import.c Mon May 17 08:34:16 1993 +0000 +++ b/Python/import.c Wed May 19 14:50:45 1993 +0000 @@ -54,7 +54,7 @@ /* 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 @@ 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; }
