mirror of
https://github.com/python/cpython
synced 2026-09-29 10:15:30 +03:00
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.)
This commit is contained in:
parent
687dd13bfe
commit
25831652fd
21 changed files with 1223 additions and 823 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue