summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2002-03-15 10:35:36 (GMT)
committerMichael W. Hudson <mwh@python.net>2002-03-15 10:35:36 (GMT)
commit78f70880e2920bcb5b85ec3582ab4415fed0e265 (patch)
treefa42781ee518b365f307fcc0110d91b6f6ab6395
parent8b23905d92efb1f4d0156b1ebef3ef01b743ad84 (diff)
downloadcpython-78f70880e2920bcb5b85ec3582ab4415fed0e265.zip
cpython-78f70880e2920bcb5b85ec3582ab4415fed0e265.tar.gz
cpython-78f70880e2920bcb5b85ec3582ab4415fed0e265.tar.bz2
backport gvanrossum's checkin of
revision 2.41 of moduleobject.c Fix for SF bug #529050 - ModuleType.__new__ crash. There were several places that assumed the md_dict field was always set, but it needn't be. Fixed these to be more careful. I changed PyModule_GetDict() to initialize md_dict to a new dictionary if it's NULL. Bugfix candidate.
-rw-r--r--Objects/moduleobject.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 180f7bc..12a3591 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -43,24 +43,31 @@ PyModule_New(char *name)
PyObject *
PyModule_GetDict(PyObject *m)
{
+ PyObject *d;
if (!PyModule_Check(m)) {
PyErr_BadInternalCall();
return NULL;
}
- return ((PyModuleObject *)m) -> md_dict;
+ d = ((PyModuleObject *)m) -> md_dict;
+ if (d == NULL)
+ ((PyModuleObject *)m) -> md_dict = d = PyDict_New();
+ return d;
}
char *
PyModule_GetName(PyObject *m)
{
+ PyObject *d;
PyObject *nameobj;
if (!PyModule_Check(m)) {
PyErr_BadArgument();
return NULL;
}
- nameobj = PyDict_GetItemString(((PyModuleObject *)m)->md_dict,
- "__name__");
- if (nameobj == NULL || !PyString_Check(nameobj)) {
+ d = ((PyModuleObject *)m)->md_dict;
+ if (d == NULL ||
+ (nameobj = PyDict_GetItemString(d, "__name__")) == NULL ||
+ !PyString_Check(nameobj))
+ {
PyErr_SetString(PyExc_SystemError, "nameless module");
return NULL;
}
@@ -70,14 +77,17 @@ PyModule_GetName(PyObject *m)
char *
PyModule_GetFilename(PyObject *m)
{
+ PyObject *d;
PyObject *fileobj;
if (!PyModule_Check(m)) {
PyErr_BadArgument();
return NULL;
}
- fileobj = PyDict_GetItemString(((PyModuleObject *)m)->md_dict,
- "__file__");
- if (fileobj == NULL || !PyString_Check(fileobj)) {
+ d = ((PyModuleObject *)m)->md_dict;
+ if (d == NULL ||
+ (fileobj = PyDict_GetItemString(d, "__file__")) == NULL ||
+ !PyString_Check(fileobj))
+ {
PyErr_SetString(PyExc_SystemError, "module filename missing");
return NULL;
}
@@ -99,6 +109,8 @@ _PyModule_Clear(PyObject *m)
PyObject *d;
d = ((PyModuleObject *)m)->md_dict;
+ if (d == NULL)
+ return;
/* First, clear only names starting with a single underscore */
pos = 0;