diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-01 09:03:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 09:03:39 (GMT) |
commit | 41c57b335330ff48af098d47e379e0f9ba09d233 (patch) | |
tree | 15cdef099182eddb04b2276dc51375b8faf28278 /Python | |
parent | f02ea6225bc3b71bd5fe66224d199a6e3e23b14d (diff) | |
download | cpython-41c57b335330ff48af098d47e379e0f9ba09d233.zip cpython-41c57b335330ff48af098d47e379e0f9ba09d233.tar.gz cpython-41c57b335330ff48af098d47e379e0f9ba09d233.tar.bz2 |
bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)
Only AttributeError should be silenced.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 8 | ||||
-rw-r--r-- | Python/sysmodule.c | 14 |
2 files changed, 8 insertions, 14 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 63e5812..5053f7a 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2255,16 +2255,12 @@ builtin_vars(PyObject *self, PyObject *args) return NULL; if (v == NULL) { d = PyEval_GetLocals(); - if (d == NULL) - return NULL; - Py_INCREF(d); + Py_XINCREF(d); } else { - d = _PyObject_GetAttrId(v, &PyId___dict__); - if (d == NULL) { + if (_PyObject_LookupAttrId(v, &PyId___dict__, &d) == 0) { PyErr_SetString(PyExc_TypeError, "vars() argument must have __dict__ attribute"); - return NULL; } } return d; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 0635e9d..8509aaf 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -224,16 +224,12 @@ PySys_Audit(const char *event, const char *argFormat, ...) ts->tracing++; ts->use_tracing = 0; while ((hook = PyIter_Next(hooks)) != NULL) { + _Py_IDENTIFIER(__cantrace__); PyObject *o; - int canTrace = -1; - o = PyObject_GetAttrString(hook, "__cantrace__"); + int canTrace = _PyObject_LookupAttrId(hook, &PyId___cantrace__, &o); if (o) { canTrace = PyObject_IsTrue(o); Py_DECREF(o); - } else if (_PyErr_Occurred(ts) && - _PyErr_ExceptionMatches(ts, PyExc_AttributeError)) { - _PyErr_Clear(ts); - canTrace = 0; } if (canTrace < 0) { break; @@ -579,7 +575,10 @@ sys_displayhook_unencodable(PyThreadState *tstate, PyObject *outf, PyObject *o) if (encoded == NULL) goto error; - buffer = _PyObject_GetAttrId(outf, &PyId_buffer); + if (_PyObject_LookupAttrId(outf, &PyId_buffer, &buffer) < 0) { + Py_DECREF(encoded); + goto error; + } if (buffer) { result = _PyObject_CallMethodIdOneArg(buffer, &PyId_write, encoded); Py_DECREF(buffer); @@ -589,7 +588,6 @@ sys_displayhook_unencodable(PyThreadState *tstate, PyObject *outf, PyObject *o) Py_DECREF(result); } else { - _PyErr_Clear(tstate); escaped_str = PyUnicode_FromEncodedObject(encoded, stdout_encoding_str, "strict"); |