8000 In already_warned, replace _PyDict_GetItemWithError with PyDict_GetIt… · python/cpython@9062020 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9062020

Browse files
In already_warned, replace _PyDict_GetItemWithError with PyDict_GetItemRef
1 parent 8c6db45 commit 9062020

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Python/_warnings.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "pycore_sysmodule.h" // _PySys_GetAttr()
99
#include "pycore_traceback.h" // _Py_DisplaySourceLine()
1010

11+
#include <stdbool.h>
12+
1113
#include "clinic/_warnings.c.h"
1214

1315
#define MODULE_NAME "_warnings"
@@ -397,7 +399,7 @@ static int
397399
already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key,
398400
int should_set)
399401
{
400-
PyObject *version_obj, *already_warned;
402+
PyObject *already_warned;
401403

402404
if (key == NULL)
403405
return -1;
@@ -406,14 +408,18 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key,
406408
if (st == NULL) {
407409
return -1;
408410
}
409-
version_obj = _PyDict_GetItemWithError(registry, &_Py_ID(version));
410-
if (version_obj == NULL
411+
// EAA
412+
PyObject *version_obj;
413+
if (PyDict_GetItemRef(registry, &_Py_ID(version), &version_obj) < 0) {
414+
return -1;
415+
}
416+
bool should_update_version = (
417+
version_obj == NULL
411418
|| !PyLong_CheckExact(version_obj)
412-
|| PyLong_AsLong(version_obj) != st->filters_version)
413-
{
414-
if (PyErr_Occurred()) {
415-
return -1;
416-
}
419+
|| PyLong_AsLong(version_obj) != st->filters_version
420+
);
421+
Py_XDECREF(version_obj);
422+
if (should_update_version) {
417423
PyDict_Clear(registry);
418424
version_obj = PyLong_FromLong(st->filters_version);
419425
if (version_obj == NULL)

0 commit comments

Comments
 (0)
0