summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1990-10-21 22:12:30 (GMT)
committerGuido van Rossum <guido@python.org>1990-10-21 22:12:30 (GMT)
commite87203afde79c8f78f78179eef20e4d8cba01fc0 (patch)
treea04d8ee5bbfdd9c75d8be354ce4b560950b84eb1 /Objects
parent5c52b6a75a4fdda6e1c04f663865b1d4123eca80 (diff)
downloadcpython-e87203afde79c8f78f78179eef20e4d8cba01fc0.zip
cpython-e87203afde79c8f78f78179eef20e4d8cba01fc0.tar.gz
cpython-e87203afde79c8f78f78179eef20e4d8cba01fc0.tar.bz2
Added __dict to module getattr.
New errors.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/moduleobject.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 7b9e0e9..09bbae9 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -37,7 +37,7 @@ getmoduledict(m)
object *m;
{
if (!is_moduleobject(m)) {
- errno = EBADF;
+ err_badarg();
return NULL;
}
return ((moduleobject *)m) -> md_dict;
@@ -48,10 +48,14 @@ setmoduledict(m, v)
object *m;
object *v;
{
- if (!is_moduleobject(m))
- return errno = EBADF;
- if (!is_dictobject(v))
- return errno = EINVAL;
+ if (!is_moduleobject(m)) {
+ err_badarg();
+ return -1;
+ }
+ if (!is_dictobject(v)) {
+ err_badarg();
+ return -1;
+ }
DECREF(((moduleobject *)m) -> md_dict);
INCREF(v);
((moduleobject *)m) -> md_dict = v;
@@ -94,7 +98,12 @@ modulegetattr(m, name)
moduleobject *m;
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)
err_setstr(NameError, name);
else
@@ -108,6 +117,12 @@ modulesetattr(m, name, v)
char *name;
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)
return dictremove(m->md_dict, name);
else