Skip to content

Commit 9f272d9

Browse files
Apply suggestions from code review
Co-authored-by: Bénédikt Tran <[email protected]>
1 parent bdee2b2 commit 9f272d9

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

Doc/library/ctypes.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,15 +872,17 @@ invalid non-\ ``NULL`` pointers would crash Python)::
872872

873873
.. _ctypes-thread-safety:
874874

875-
Thread Safety Without The GIL
875+
Thread safety without the GIL
876876
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
877877

878878
In Python 3.13, the :term:`GIL` may be disabled on :term:`experimental free threaded <free threading>` builds.
879-
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects.::
879+
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:
880880

881-
>>> number = c_int(42)
882-
>>> pointer_a = pointer(number)
883-
>>> pointer_b = pointer(number)
881+
.. code-block:: pycon
882+
883+
>>> number = c_int(42)
884+
>>> pointer_a = pointer(number)
885+
>>> pointer_b = pointer(number)
884886
885887
In the above, it's only safe for one object to read and write to the address at once if the :term:`GIL` is disabled.
886888
So, ``pointer_a`` can be shared and written to across multiple threads, but only if ``pointer_b``
@@ -898,7 +900,7 @@ to synchronize access to memory.::
898900

899901
.. seealso::
900902

901-
:func:`sys._is_gil_enabled` if you would like to dynamically synchronize your application.
903+
Use :func:`sys._is_gil_enabled` to dynamically synchronize your application.
902904

903905
.. _ctypes-type-conversions:
904906

Lib/test/test_ctypes/test_arrays.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ def run():
280280
buffer[0] = b"j"
281281

282282
with threading_helper.catch_threading_exception() as cm:
283-
with threading_helper.start_threads((Thread(target=run) for _ in range(25))):
283+
threads = (Thread(target=run) for _ in range(25))
284+
with threading_helper.start_threads(threads):
284285
pass
285286

286287
self.assertIsNone(cm.exc_value)

Modules/_ctypes/ctypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,15 @@ static inline void
562562
locked_memcpy_to(CDataObject *self, void *buf, Py_ssize_t size)
563563
{
564564
LOCK_PTR(self);
565-
memcpy(self->b_ptr, buf, size);
565+
(void)memcpy(self->b_ptr, buf, size);
566566
UNLOCK_PTR(self);
567567
}
568568

569569
static inline void
570570
locked_memcpy_from(void *buf, CDataObject *self, Py_ssize_t size)
571571
{
572572
LOCK_PTR(self);
573-
memcpy(buf, self->b_ptr, size);
573+
(void)memcpy(buf, self->b_ptr, size);
574574
UNLOCK_PTR(self);
575575
}
576576

0 commit comments

Comments
 (0)