[Python-checkins] cpython: Issue #18408: handle PySys_GetObject() failure, raise a RuntimeError
victor.stinner
python-checkins at python.org
Tue Jul 16 23:09:23 CEST 2013
http://hg.python.org/cpython/rev/6bd01a59762a
changeset: 84676:6bd01a59762a
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jul 16 22:26:05 2013 +0200
summary:
Issue #18408: handle PySys_GetObject() failure, raise a RuntimeError
files:
Modules/_pickle.c | 8 ++++++--
Modules/main.c | 4 +++-
Python/bltinmodule.c | 5 +++++
Python/import.c | 14 ++++++++------
4 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -1361,8 +1361,10 @@
search:
modules_dict = PySys_GetObject("modules");
- if (modules_dict == NULL)
+ if (modules_dict == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules");
return NULL;
+ }
i = 0;
module_name = NULL;
@@ -5542,8 +5544,10 @@
}
modules_dict = PySys_GetObject("modules");
- if (modules_dict == NULL)
+ if (modules_dict == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules");
return NULL;
+ }
module = PyDict_GetItemWithError(modules_dict, module_name);
if (module == NULL) {
diff --git a/Modules/main.c b/Modules/main.c
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -260,8 +260,10 @@
/* argv0 is usable as an import source, so put it in sys.path[0]
and import __main__ */
sys_path = PySys_GetObject("path");
- if (sys_path == NULL)
+ if (sys_path == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path");
goto error;
+ }
if (PyList_SetItem(sys_path, 0, argv0)) {
argv0 = NULL;
goto error;
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1550,6 +1550,11 @@
return NULL;
if (file == NULL || file == Py_None) {
file = PySys_GetObject("stdout");
+ if (file == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+ return NULL;
+ }
+
/* sys.stdout may be None when FILE* stdout isn't connected */
if (file == Py_None)
Py_RETURN_NONE;
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -85,8 +85,10 @@
int err = 0;
path_hooks = PySys_GetObject("path_hooks");
- if (path_hooks == NULL)
+ if (path_hooks == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path_hooks");
goto error;
+ }
if (Py_VerboseFlag)
PySys_WriteStderr("# installing zipimport hook\n");
@@ -944,11 +946,11 @@
PyImport_GetImporter(PyObject *path) {
PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL;
- if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) {
- if ((path_hooks = PySys_GetObject("path_hooks"))) {
- importer = get_path_importer(path_importer_cache,
- path_hooks, path);
- }
+ path_importer_cache = PySys_GetObject("path_importer_cache");
+ path_hooks = PySys_GetObject("path_hooks");
+ if (path_importer_cache != NULL && path_hooks != NULL) {
+ importer = get_path_importer(path_importer_cache,
+ path_hooks, path);
}
Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */
return importer;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list