summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-05-03 03:19:39 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-05-03 03:19:39 (GMT)
commit64a4bbeb259026e6bb3e4a8864870b1ed35ffab2 (patch)
tree895e181342f2856f8c3912787eb33dc022550dc1 /Python
parentab9cc1b7ad87f4f6d921ce9599aaeb6a1839fe3b (diff)
downloadcpython-64a4bbeb259026e6bb3e4a8864870b1ed35ffab2.zip
cpython-64a4bbeb259026e6bb3e4a8864870b1ed35ffab2.tar.gz
cpython-64a4bbeb259026e6bb3e4a8864870b1ed35ffab2.tar.bz2
Fix the C implementation of 'warnings' to infer the filename of the module that
raised an exception properly when __file__ is not set, __name__ == '__main__', and sys.argv[0] is a false value. Closes issue2743.
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 3477fb1..d843af6 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -487,8 +487,21 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
if (module_str && strcmp(module_str, "__main__") == 0) {
PyObject *argv = PySys_GetObject("argv");
if (argv != NULL && PyList_Size(argv) > 0) {
+ int is_true;
*filename = PyList_GetItem(argv, 0);
Py_INCREF(*filename);
+ /* If sys.argv[0] is false, then use '__main__'. */
+ is_true = PyObject_IsTrue(*filename);
+ if (is_true < 0) {
+ Py_DECREF(*filename);
+ goto handle_error;
+ }
+ else if (!is_true) {
+ Py_DECREF(*filename);
+ *filename = PyString_FromString("__main__");
+ if (*filename == NULL)
+ goto handle_error;
+ }
}
else {
/* embedded interpreters don't have sys.argv, see bug #839151 */