Skip to content

Commit 0173c46

Browse files
committed
Some more terminology fixups.
1 parent a1e47b7 commit 0173c46

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Doc/c-api/init.rst

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,9 @@ code, or when embedding the Python interpreter:
12321232
12331233
.. c:function:: PyThreadState* PyThreadState_Get()
12341234
1235-
Return the current thread state. The global interpreter lock must be held.
1236-
When the current thread state is ``NULL``, this issues a fatal error (so that
1237-
the caller needn't check for ``NULL``).
1235+
Return the active :term:`thread state`. If there is no active :term:`thread state` (such
1236+
as when inside of :c:macro:`Py_BEGIN_ALLOW_THREADS` block), then this issues a fatal
1237+
error (so that the caller needn't check for ``NULL``).
12381238
12391239
See also :c:func:`PyThreadState_GetUnchecked`.
12401240
@@ -1252,9 +1252,12 @@ code, or when embedding the Python interpreter:
12521252
12531253
.. c:function:: PyThreadState* PyThreadState_Swap(PyThreadState *tstate)
12541254
1255-
Swap the current thread state with the thread state given by the argument
1256-
*tstate*, which may be ``NULL``. The global interpreter lock must be held
1257-
and is not released.
1255+
Swap the current :term:`thread state` with *tstate*.
1256+
1257+
If there is an attached :term:`thread state` for the current
1258+
thread, it will be detached. Upon returning from this function,
1259+
*tstate* will become attached instead if it's not ``NULL``. If it
1260+
is ``NULL``, then no :term:`thread state` will be attached upon returning.
12581261
12591262
12601263
The following functions use thread-local storage, and are not compatible
@@ -1263,7 +1266,7 @@ with sub-interpreters:
12631266
.. c:function:: PyGILState_STATE PyGILState_Ensure()
12641267
12651268
Ensure that the current thread is ready to call the Python C API regardless
1266-
of the current state of Python, or of the global interpreter lock. This may
1269+
of the current state of Python, or of the global interpreter lock.This may
12671270
be called as many times as desired by a thread as long as each call is
12681271
matched with a call to :c:func:`PyGILState_Release`. In general, other
12691272
thread-related APIs may be used between :c:func:`PyGILState_Ensure` and
@@ -1272,15 +1275,15 @@ with sub-interpreters:
12721275
:c:macro:`Py_BEGIN_ALLOW_THREADS` and :c:macro:`Py_END_ALLOW_THREADS` macros is
12731276
acceptable.
12741277
1275-
The return value is an opaque "handle" to the thread state when
1278+
The return value is an opaque "handle" to the :term:`thread state`` when
12761279
:c:func:`PyGILState_Ensure` was called, and must be passed to
12771280
:c:func:`PyGILState_Release` to ensure Python is left in the same state. Even
12781281
though recursive calls are allowed, these handles *cannot* be shared - each
12791282
unique call to :c:func:`PyGILState_Ensure` must save the handle for its call
12801283
to :c:func:`PyGILState_Release`.
12811284
1282-
When the function returns, the current thread will hold the GIL and be able
1283-
to call arbitrary Python code. Failure is a fatal error.
1285+
When the function returns, there will be an active :term:`thread state`
1286+
and the thread will be able to call arbitrary Python code. Failure is a fatal error.
12841287
12851288
.. note::
12861289
Calling this function from a thread when the runtime is finalizing will
@@ -1305,21 +1308,21 @@ with sub-interpreters:
13051308
13061309
.. c:function:: PyThreadState* PyGILState_GetThisThreadState()
13071310
1308-
Get the current thread state for this thread. May return ``NULL`` if no
1311+
Get the current :term:`thread state` for this thread. May return ``NULL`` if no
13091312
GILState API has been used on the current thread. Note that the main thread
13101313
always has such a thread-state, even if no auto-thread-state call has been
13111314
made on the main thread. This is mainly a helper/diagnostic function.
13121315
13131316
13141317
.. c:function:: int PyGILState_Check()
13151318
1316-
Return ``1`` if the current thread is holding the GIL and ``0`` otherwise.
1319+
Return ``1`` if the current thread is holding the :term:`GIL` and ``0`` otherwise.
13171320
This function can be called from any thread at any time.
13181321
Only if it has had its Python thread state initialized and currently is
1319-
holding the GIL will it return ``1``.
1322+
holding the :term:`GIL` will it return ``1``.
13201323
This is mainly a helper/diagnostic function. It can be useful
13211324
for example in callback contexts or memory allocation functions when
1322-
knowing that the GIL is locked can allow the caller to perform sensitive
1325+
knowing that the :term:`GIL` is locked can allow the caller to perform sensitive
13231326
actions or otherwise behave differently.
13241327
13251328
.. versionadded:: 3.4

0 commit comments

Comments
 (0)