summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-01-15 11:26:38 (GMT)
committerGitHub <noreply@github.com>2019-01-15 11:26:38 (GMT)
commit3607ef43c4a1a24d44f39ff54a77fc0af5bfa09a (patch)
tree47a493a1fbdeba4a16ddc0b071542ee00239974f
parentb91140fdb17472d03a7b7971f143c08a40fde923 (diff)
downloadcpython-3607ef43c4a1a24d44f39ff54a77fc0af5bfa09a.zip
cpython-3607ef43c4a1a24d44f39ff54a77fc0af5bfa09a.tar.gz
cpython-3607ef43c4a1a24d44f39ff54a77fc0af5bfa09a.tar.bz2
bpo-35742: Fix test_envar_unimportable in test_builtin. (GH-11561)
Handle the case of an empty module name in PYTHONBREAKPOINT. Fixes a regression introduced in bpo-34756.
-rw-r--r--Lib/test/test_builtin.py1
-rw-r--r--Python/sysmodule.c25
2 files changed, 16 insertions, 10 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index e2a4f2f..5674ea8 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1608,6 +1608,7 @@ class TestBreakpoint(unittest.TestCase):
def test_envar_unimportable(self):
for envar in (
'.', '..', '.foo', 'foo.', '.int', 'int.',
+ '.foo.bar', '..foo.bar', '/./',
'nosuchbuiltin',
'nosuchmodule.nosuchcallable',
):
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 869834b..5ea3772 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -141,11 +141,14 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
modulepath = PyUnicode_FromString("builtins");
attrname = envar;
}
- else {
+ else if (last_dot != envar) {
/* Split on the last dot; */
modulepath = PyUnicode_FromStringAndSize(envar, last_dot - envar);
attrname = last_dot + 1;
}
+ else {
+ goto warn;
+ }
if (modulepath == NULL) {
PyMem_RawFree(envar);
return NULL;
@@ -155,27 +158,29 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
Py_DECREF(modulepath);
if (module == NULL) {
- goto error;
+ if (PyErr_ExceptionMatches(PyExc_ImportError)) {
+ goto warn;
+ }
+ PyMem_RawFree(envar);
+ return NULL;
}
PyObject *hook = PyObject_GetAttrString(module, attrname);
Py_DECREF(module);
if (hook == NULL) {
- goto error;
+ if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ goto warn;
+ }
+ PyMem_RawFree(envar);
+ return NULL;
}
PyMem_RawFree(envar);
PyObject *retval = _PyObject_FastCallKeywords(hook, args, nargs, keywords);
Py_DECREF(hook);
return retval;
- error:
- if (!PyErr_ExceptionMatches(PyExc_ImportError)
- && !PyErr_ExceptionMatches(PyExc_AttributeError))
- {
- PyMem_RawFree(envar);
- return NULL;
- }
+ warn:
/* If any of the imports went wrong, then warn and ignore. */
PyErr_Clear();
int status = PyErr_WarnFormat(