Skip to content

Commit 4237683

Browse files
Move PyDict_Next strong ref note closer to free-threading section
1 parent 5e7c4e1 commit 4237683

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Doc/c-api/dict.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,23 @@ Dictionary Objects
295295
:c:macro:`Py_BEGIN_CRITICAL_SECTION` to lock the dictionary while iterating
296296
over it::
297297
298-
.. note::
298+
.. note::
299299
300-
On the :term:`free threaded <free threading>` build, this function can be used safely inside
301-
a critical section. However, the references returned for *pkey* and
302-
*pvalue* are :term:`borrowed <borrowed reference>` and only valid while the critical section is
303-
held. If you need to use these objects outside the critical section or when the critical section
304-
can be suspended, create :term:`strong references <strong reference>` (for example, with
305-
:c:func:`Py_NewRef`).
300+
On the :term:`free threaded <free threading>` build, this function can be used safely inside
301+
a critical section. However, the references returned for *pkey* and
302+
*pvalue* are :term:`borrowed <borrowed reference>` and only valid while the critical section is
303+
held. If you need to use these objects outside the critical section or when the critical section
304+
can be suspended, create :term:`strong reference <strong reference>` (for example, with
305+
:c:func:`Py_NewRef`).
306+
307+
.. code-block:: c
308+
309+
Py_BEGIN_CRITICAL_SECTION(self->dict);
310+
while (PyDict_Next(self->dict, &pos, &key, &value)) {
311+
...
312+
}
313+
Py_END_CRITICAL_SECTION();
306314
307-
Py_BEGIN_CRITICAL_SECTION(self->dict);
308-
while (PyDict_Next(self->dict, &pos, &key, &value)) {
309-
...
310-
}
311-
Py_END_CRITICAL_SECTION();
312315
313316
314317
.. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)

0 commit comments

Comments
 (0)