Skip to content

Commit 7501925

Browse files
Move PyDict_Next strong ref note closer to free-threading section
1 parent f3caa2d commit 7501925

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Doc/c-api/dict.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,6 @@ Dictionary Objects
258258
value represents offsets within the internal dictionary structure, and
259259
since the structure is sparse, the offsets are not consecutive.
260260
261-
.. note::
262-
263-
On the free-threaded build, this function can be used safely inside a
264-
critical section. However, the references returned for *pkey* and *pvalue*
265-
are :term:`borrowed <borrowed reference>` and are only valid while the
266-
critical section is held. If you need to use these objects outside the
267-
critical section or when the critical section can be suspended, create a
268-
:term:`strong reference <strong reference>` (for example, using
269-
:c:func:`Py_NewRef`).
270-
271-
272261
For example::
273262
274263
PyObject *key, *value;
@@ -308,10 +297,19 @@ Dictionary Objects
308297
309298
Py_BEGIN_CRITICAL_SECTION(self->dict);
310299
while (PyDict_Next(self->dict, &pos, &key, &value)) {
311-
...
300+
...
312301
}
313302
Py_END_CRITICAL_SECTION();
314303
304+
.. note::
305+
306+
On the free-threaded build, this function can be used safely inside a
307+
critical section. However, the references returned for *pkey* and *pvalue*
308+
are :term:`borrowed <borrowed reference>` and are only valid while the
309+
critical section is held. If you need to use these objects outside the
310+
critical section or when the critical section can be suspended, create a
311+
:term:`strong reference <strong reference>` (for example, using
312+
:c:func:`Py_NewRef`).
315313
316314
.. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)
317315

0 commit comments

Comments
 (0)