mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
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.
This commit is contained in:
parent
b91140fdb1
commit
3607ef43c4
2 changed files with 16 additions and 10 deletions
|
@ -1608,6 +1608,7 @@ class TestBreakpoint(unittest.TestCase):
|
||||||
def test_envar_unimportable(self):
|
def test_envar_unimportable(self):
|
||||||
for envar in (
|
for envar in (
|
||||||
'.', '..', '.foo', 'foo.', '.int', 'int.',
|
'.', '..', '.foo', 'foo.', '.int', 'int.',
|
||||||
|
'.foo.bar', '..foo.bar', '/./',
|
||||||
'nosuchbuiltin',
|
'nosuchbuiltin',
|
||||||
'nosuchmodule.nosuchcallable',
|
'nosuchmodule.nosuchcallable',
|
||||||
):
|
):
|
||||||
|
|
|
@ -141,11 +141,14 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
|
||||||
modulepath = PyUnicode_FromString("builtins");
|
modulepath = PyUnicode_FromString("builtins");
|
||||||
attrname = envar;
|
attrname = envar;
|
||||||
}
|
}
|
||||||
else {
|
else if (last_dot != envar) {
|
||||||
/* Split on the last dot; */
|
/* Split on the last dot; */
|
||||||
modulepath = PyUnicode_FromStringAndSize(envar, last_dot - envar);
|
modulepath = PyUnicode_FromStringAndSize(envar, last_dot - envar);
|
||||||
attrname = last_dot + 1;
|
attrname = last_dot + 1;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
goto warn;
|
||||||
|
}
|
||||||
if (modulepath == NULL) {
|
if (modulepath == NULL) {
|
||||||
PyMem_RawFree(envar);
|
PyMem_RawFree(envar);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -155,27 +158,29 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
|
||||||
Py_DECREF(modulepath);
|
Py_DECREF(modulepath);
|
||||||
|
|
||||||
if (module == NULL) {
|
if (module == NULL) {
|
||||||
goto error;
|
if (PyErr_ExceptionMatches(PyExc_ImportError)) {
|
||||||
|
goto warn;
|
||||||
|
}
|
||||||
|
PyMem_RawFree(envar);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *hook = PyObject_GetAttrString(module, attrname);
|
PyObject *hook = PyObject_GetAttrString(module, attrname);
|
||||||
Py_DECREF(module);
|
Py_DECREF(module);
|
||||||
|
|
||||||
if (hook == NULL) {
|
if (hook == NULL) {
|
||||||
goto error;
|
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||||
|
goto warn;
|
||||||
|
}
|
||||||
|
PyMem_RawFree(envar);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
PyMem_RawFree(envar);
|
PyMem_RawFree(envar);
|
||||||
PyObject *retval = _PyObject_FastCallKeywords(hook, args, nargs, keywords);
|
PyObject *retval = _PyObject_FastCallKeywords(hook, args, nargs, keywords);
|
||||||
Py_DECREF(hook);
|
Py_DECREF(hook);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
error:
|
warn:
|
||||||
if (!PyErr_ExceptionMatches(PyExc_ImportError)
|
|
||||||
&& !PyErr_ExceptionMatches(PyExc_AttributeError))
|
|
||||||
{
|
|
||||||
PyMem_RawFree(envar);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
/* If any of the imports went wrong, then warn and ignore. */
|
/* If any of the imports went wrong, then warn and ignore. */
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
int status = PyErr_WarnFormat(
|
int status = PyErr_WarnFormat(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue