Yongtao Huang
b9a4806430
gh-143164: Fix incorrect error message for ctypes bitfield overflow (GH-143165)
...
Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com >
2025-12-25 19:08:43 +02:00
Yongtao Huang
579c5b496b
gh-143145: Fix possible reference leak in ctypes _build_result() (GH-143131)
...
The result tuple was leaked if __ctypes_from_outparam__() failed for any item.
Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com >
2025-12-25 14:24:25 +00:00
Hugo van Kemenade
38ad651b67
gh-76007: Deprecate __version__ attribute in ctypes ( #142679 )
2025-12-15 13:30:23 +02:00
Dino Viehland
da8199f884
gh-123241: Don't modify ref count during visitation (GH-142232)
2025-12-11 09:54:29 +01:00
Donghee Na
c4ccaf4b10
gh-141770: Annotate anonymous mmap usage if "-X dev" is used (gh-142079)
2025-12-08 14:47:19 +00:00
Shamil
2a1c9bd616
Remove unreachable break statements in _ctypes_test.c ( #140585 )
2025-10-25 14:59:12 +00:00
Dung Nguyen
1ce05537a3
gh-138008: Fix segfaults in _ctypes due to invalid argtypes (GH-138285)
...
Signed-off-by: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com >
Signed-off-by: Nguyen Viet Dung <dung@ekluster.com >
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Yongzi Li <204532581+Yzi-Li@users.noreply.github.com >
2025-09-10 14:01:19 +02:00
Adam Turner
98b4cd6fe9
GH-135763: AC: Use `Py_ssize_t(allow_negative=False)` ( #138394 )
2025-09-02 21:29:05 +01:00
Adam Turner
918e3ba6c0
GH-137623: Use an AC decorator for docstring line length enforcement ( #137690 )
2025-08-18 18:29:00 +01:00
Peter Bierma
082f370cdd
gh-137514: Add a free-threading wrapper for mutexes (GH-137515)
...
Add `FT_MUTEX_LOCK`/`FT_MUTEX_UNLOCK`, which call `PyMutex_Lock` and `PyMutex_Unlock` on the free-threaded build, and no-op otherwise.
2025-08-07 11:24:50 -04:00
Serhiy Storchaka
3a89dfe32b
Revert "gh-112068: C API: Add support of nullable arguments in PyArg_Parse (GH-121303)" ( #136991 )
2025-07-22 16:39:50 +03:00
Nathan Goldbaum
89c220b93c
gh-133296: Publicly expose critical section API that accepts PyMutex (gh-135899)
...
This makes the following APIs public:
* `Py_BEGIN_CRITICAL_SECTION_MUTEX(mutex),`
* `Py_BEGIN_CRITICAL_SECTION2_MUTEX(mutex1, mutex2)`
* `void PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *mutex)`
* `void PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *mutex1, PyMutex *mutex2)`
The macros are identical to the corresponding `Py_BEGIN_CRITICAL_SECTION` and
`Py_BEGIN_CRITICAL_SECTION2` macros (e.g., they include braces), but they
accept a `PyMutex` instead of an object.
The new macros are still paired with the existing END macros
(`Py_END_CRITICAL_SECTION`, `Py_END_CRITICAL_SECTION2`).
2025-07-21 17:25:43 -04:00
Roman
09ac8e042f
Fix typo: "occured" =>"occurred" ( #134928 )
...
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com >
2025-07-19 11:48:04 +03:00
Petr Viktorin
9193efdeab
gh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (GH-135932)
2025-06-26 11:48:37 +02:00
Kumar Aditya
3c0525126e
gh-134637: Fix performance regression in calling ctypes function pointer in free threading. ( #134702 )
...
Fix performance regression in calling `ctypes` function pointer in `free threading`.
2025-05-26 18:26:40 +00:00
Collin Funk
b8f55266bf
gh-134486: Fix missing alloca() symbol in _ctypes on NetBSD ( #134487 )
...
Previously the module would fail to load because the `alloca()` symbol
was undefined. Now we check for GCC/Clang builtins for systems who do
not define `alloca()` in headers.
2025-05-23 13:11:04 +02:00
Max Bachmann
74c4e35ff1
Let PyUnicode_FromWideChar calculate the input length (GH-134045)
2025-05-15 11:56:50 +00:00
Kumar Aditya
9b9cdb6440
gh-100926: use explicit stginfo lock for pointer cache ( #133867 )
2025-05-11 08:24:20 +00:00
Kumar Aditya
70f9b3de36
gh-100926: fix thread safety of ctypes __pointer_type__ ( #133843 )
2025-05-10 17:38:06 +00:00
Xuehai Pan
f0f93ba5fa
gh-131942: Use the Python-specific Py_DEBUG macro rather than _DEBUG in Windows-related C code (GH-131944)
2025-05-08 15:01:25 +00:00
Sergey B Kirpichev
1bc16504ef
gh-61103: drop unused Py_HAVE_C_COMPLEX define (GH-133435)
...
Py_HAVE_C_COMPLEX was added in 3.14 so the removal doesn't need a deprecation
period even under a strict reading of PEP 387.
The Py_FFI_SUPPORT_C_COMPLEX check configure check implies support for
complex types in ctypes.
2025-05-05 15:50:57 +02:00
Sergey B Kirpichev
8d0e07eb89
gh-61103: don't use C _Complex types to implement F/D/G in ctypes (GH-133237)
...
According to the C standard, the memory representation of _Complex types
is equivalent to 2-element arrays. Unlike _Complex, arrays are always available.
- drop _complex.h header
- use appropriate real arrays to replace complex types
Co-authored-by: Lisandro Dalcin <dalcinl@gmail.com >
Co-authored-by: Petr Viktorin <encukou@gmail.com >
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com >
2025-05-05 11:23:30 +02:00
Sergey Miryanov
a0bc0c462f
gh-100926: Move ctype's pointers cache from _pointer_type_cache to StgInfo (GH-131282)
...
Deprecate _pointer_type_cache and calling POINTER on a string.
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com >
Co-authored-by: Jun Komoda <45822440+junkmd@users.noreply.github.com >
Co-authored-by: Petr Viktorin <encukou@gmail.com >
2025-05-02 19:06:37 +02:00
Petr Viktorin
2590774c9b
gh-133290: Use PyObject_SetAttr to set _type_ (GH-133292)
2025-05-02 14:47:07 +02:00
Sergey B Kirpichev
580888927c
gh-121249: fix naming of struct tagPyCArgObject members ( #132863 )
...
It seems, no code actually uses these names, only sizes of the unnamed
union members are important. Though, I think it's good to be here
consistent wrt type codes ('g' for long double, etc).
This amends 85f89cb3e6 .
2025-04-24 11:50:47 +02:00
Sergey B Kirpichev
85f89cb3e6
gh-121249: adjust formatting codes for complex types in struct/ctypes ( #132827 )
...
* F - for float _Complex
* D - for double _Complex
* G - for long double _Complex (not supported by the struct module)
2025-04-23 15:38:24 +02:00
dura0ok
3b4b56f46d
gh-132470: Prevent crash in ctypes.CField when byte_size is incorrect ( #132475 )
...
Fix: Prevent crash in ctypes.CField when byte_size does not match type size (gh-132470)
When creating a ctypes.CField with an incorrect byte_size (e.g., using `byte_size=2` for `ctypes.c_byte`), the code would previously abort due to the failed assertion `byte_size == info->size`.
This commit replaces the assertion with a proper error handling mechanism that raises a `ValueError` when `byte_size` does not match the expected type size. This prevents the crash and provides a more informative error message to the us
Co-authored-by: sobolevn <mail@sobolevn.me >
2025-04-22 16:13:00 +03:00
Kumar Aditya
5b06d2ceca
gh-127945: add lock held assertions in ctypes arrays ( #132720 )
2025-04-19 18:27:10 +05:30
Kumar Aditya
cf59bc3ae7
gh-127945: fix critical sections around ctypes array ( #132646 )
2025-04-17 18:44:14 +00:00
Kumar Aditya
2925462411
gh-127945: change _ctypes_test.c static globals to thread local ( #132575 )
2025-04-16 23:11:27 +05:30
Kumar Aditya
2ff5eb8582
gh-127945: move initialization of field desc to module exec in ctypes ( #132552 )
2025-04-15 19:30:33 +05:30
Kumar Aditya
be763e550e
gh-127945: fix thread safety and add lock held assertions to paramfunc in ctypes ( #132473 )
2025-04-14 14:05:06 +05:30
Gregory P. Smith
7a29c9883f
GH-115322: fix ctypes call_function audit hook on 32-bit platforms (GH-132496)
...
* GH-115322: fix ctypes call_function audit hook on 32-bit platforms.
It was using a signed conversion to communicate the function id (pointer) value.
2025-04-14 06:22:29 +00:00
Robin Jadoul
2666a06d33
GH-115322: Add missing audit hooks (GH-115624)
...
Add extra audit hooks to catch C function calling from ctypes,
reading/writing files through readline and executing external
programs through _posixsubprocess.
* Make audit-tests for open pass when readline.append_history_file is unavailable
* Less direct testing of _posixsubprocess for audit hooks
* Also remove the audit hook from call_cdeclfunction now that _ctypes_callproc does it instead.
* reword the NEWS entry.
* mention readline in NEWS
* add versionchanged markers
* fix audit_events.rst versionadded
* doc lint
---------
Co-authored-by: Gregory P. Smith <greg@krypto.org >
2025-04-13 21:46:20 +00:00
Nicolas Trangez
2aab2db146
GH-132417: ctypes: Fix potential Py_DECREF(NULL) when handling functions returning PyObject * ( #132418 )
...
Some functions (such as `PyErr_Occurred`) with a `restype` set to `ctypes.py_object` may return NULL without setting an exception.
2025-04-12 07:40:34 +00:00
Kumar Aditya
d47584aae6
gh-131336: fix thread safety for ctypes functions ( #132232 )
2025-04-09 18:18:40 +00:00
Serhiy Storchaka
487cf3c170
gh-132305: Make Argument Clinic code compatible with Python 3.10 ( #132306 )
2025-04-09 19:10:02 +01:00
Serhiy Storchaka
f5f1ac84b3
gh-112068: C API: Add support of nullable arguments in PyArg_Parse (GH-121303)
2025-04-08 22:08:00 +03:00
Peter Bierma
8e260b384a
gh-128182: switch ctypes locking to critical sections ( #132133 )
...
Co-authored-by: Kumar Aditya <kumaraditya@python.org >
2025-04-07 22:00:31 +05:30
Kumar Aditya
0dba59e689
gh-128182: add critical sections to ctypes arrays getters and setters ( #132152 )
2025-04-06 16:21:44 +05:30
Kumar Aditya
b9d8d99563
gh-128182: add critical section to _ctypes.Simple getters and setters ( #132081 )
2025-04-05 10:27:41 +00:00
Kumar Aditya
f7a8bc50db
gh-128182: add critical section to _ctypes.PyCData methods ( #132082 )
2025-04-05 15:24:58 +05:30
Peter Bierma
6e91d1f9aa
gh-131974: Fix usages of locked_deref in ctypes ( #131975 )
2025-04-02 17:04:25 +02:00
Kumar Aditya
46ada1e5e0
gh-127945: acquire critical section around PyCFuncPtr_call ( #131898 )
2025-03-30 11:01:12 +00:00
Kumar Aditya
28e476f6a2
gh-127945: make initialization of error_object_name thread safe in ctypes ( #131896 )
2025-03-30 10:50:35 +00:00
Kumar Aditya
bc5a028c13
gh-127945: fix thread safety of creating instances of ctypes structures ( #131716 )
2025-03-30 15:22:30 +05:30
Michael Droettboom
8614f86b71
gh-131525: Cache the result of tuple_hash ( #131529 )
...
* gh-131525: Cache the result of tuple_hash
* Fix debug builds
* Add blurb
* Fix formatting
* Pre-compute empty tuple singleton
* Mostly set the cache within tuple_alloc
* Fixes for TSAN
* Pre-compute empty tuple singleton
* Fix for 32-bit platforms
* Assert that op != NULL in _PyTuple_RESET_HASH_CACHE
* Use FT_ATOMIC_STORE_SSIZE_RELAXED macro
* Update Include/internal/pycore_tuple.h
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com >
* Fix alignment
* atomic load
* Update Objects/tupleobject.c
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com >
---------
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com >
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com >
2025-03-27 09:57:06 -04:00
Kumar Aditya
f1967e7249
gh-127945: fix thread safety of ctypes state ( #131710 )
...
This fixes thread safety of `array_cache` and `swapped_suffix` by initializing them in module exec to make it thread safety.
2025-03-25 17:03:05 +05:30
Kumar Aditya
96ef4c511f
gh-127945: add locking to malloc closure in free-threading ( #131662 )
...
The freelist is not thread safe in free-threading so this adds lock around it make it thread safe in free-threading.
2025-03-25 16:48:46 +05:30
Victor Stinner
abcd9d4f7d
gh-111178: Fix function signatures for test_ctypes ( #131660 )
2025-03-24 14:30:13 +01:00