Skip to content

Commit 6b323fa

Browse files
carljmYhg1s
andauthored
Apply suggestions from code review
Co-authored-by: T. Wouters <[email protected]>
1 parent 9b938c7 commit 6b323fa

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

Doc/c-api/function.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ There are a few functions specific to Python functions.
177177
exception set on entry to the callback; in this case, the callback may not
178178
execute Python code or otherwise disturb the pending exception. Taking a
179179
reference in the callback to an about-to-be-destroyed function will resurrect
180-
it and prevent it from being freed.
180+
it, preventing it from being freed at this time. When the resurrected object is destroyed later,
181+
any watcher callbacks active at the time will be called again.
181182
182183
If the callback sets an exception, it must return ``-1``; this exception will
183184
be printed as an unraisable exception using :c:func:`PyErr_WriteUnraisable`.

Objects/codeobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ notify_code_watchers(PyCodeEvent event, PyCodeObject *co)
3737
Py_DECREF(repr);
3838
}
3939
if (context == NULL) {
40-
context = Py_None;
41-
Py_INCREF(context);
40+
context = Py_NewRef(Py_None);
4241
}
4342
PyErr_WriteUnraisable(context);
4443
Py_DECREF(context);

Objects/dictobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,7 +2311,7 @@ dict_dealloc(PyDictObject *mp)
23112311
assert(Py_REFCNT(mp) == 0);
23122312
Py_SET_REFCNT(mp, 1);
23132313
_PyDict_NotifyEvent(PyDict_EVENT_DEALLOCATED, mp, NULL, NULL);
2314-
if(Py_REFCNT(mp) > 1) {
2314+
if (Py_REFCNT(mp) > 1) {
23152315
Py_DECREF(mp);
23162316
return;
23172317
}
@@ -5757,8 +5757,7 @@ _PyDict_SendEvent(int watcher_bits,
57575757
// repr can call arbitrary code, so we invent a simpler version.
57585758
PyObject *context = PyUnicode_FromFormat("watcher callback for <dict at %p>", mp);
57595759
if (context == NULL) {
5760-
context = Py_None;
5761-
Py_INCREF(context);
5760+
context = Py_NewRef(Py_None);
57625761
}
57635762
PyErr_WriteUnraisable(context);
57645763
Py_DECREF(context);

Objects/funcobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ notify_func_watchers(PyInterpreterState *interp, PyFunction_WatchEvent event,
3232
Py_DECREF(repr);
3333
}
3434
if (context == NULL) {
35-
context = Py_None;
36-
Py_INCREF(context);
35+
context = Py_NewRef(Py_None);
3736
}
3837
PyErr_WriteUnraisable(context);
3938
Py_DECREF(context);

0 commit comments

Comments
 (0)