Added __dict to module getattr.

New errors.
This commit is contained in:
Guido van Rossum 1990-10-21 22:12:30 +00:00
parent 5c52b6a75a
commit e87203afde
1 changed files with 21 additions and 6 deletions

View File

@ -37,7 +37,7 @@ getmoduledict(m)
object *m; object *m;
{ {
if (!is_moduleobject(m)) { if (!is_moduleobject(m)) {
errno = EBADF; err_badarg();
return NULL; return NULL;
} }
return ((moduleobject *)m) -> md_dict; return ((moduleobject *)m) -> md_dict;
@ -48,10 +48,14 @@ setmoduledict(m, v)
object *m; object *m;
object *v; object *v;
{ {
if (!is_moduleobject(m)) if (!is_moduleobject(m)) {
return errno = EBADF; err_badarg();
if (!is_dictobject(v)) return -1;
return errno = EINVAL; }
if (!is_dictobject(v)) {
err_badarg();
return -1;
}
DECREF(((moduleobject *)m) -> md_dict); DECREF(((moduleobject *)m) -> md_dict);
INCREF(v); INCREF(v);
((moduleobject *)m) -> md_dict = v; ((moduleobject *)m) -> md_dict = v;
@ -94,7 +98,12 @@ modulegetattr(m, name)
moduleobject *m; moduleobject *m;
char *name; char *name;
{ {
object *res = dictlookup(m->md_dict, name); object *res;
if (strcmp(name, "__dict") == 0) {
INCREF(m->md_dict);
return m->md_dict;
}
res = dictlookup(m->md_dict, name);
if (res == NULL) if (res == NULL)
err_setstr(NameError, name); err_setstr(NameError, name);
else else
@ -108,6 +117,12 @@ modulesetattr(m, name, v)
char *name; char *name;
object *v; object *v;
{ {
if (strcmp(name, "__dict") == 0) {
/* Can't allow assignment to __dict, it would screw up
module's functions which still use the old dictionary. */
err_setstr(NameError, "__dict is a reserved member name");
return NULL;
}
if (v == NULL) if (v == NULL)
return dictremove(m->md_dict, name); return dictremove(m->md_dict, name);
else else