Skip to content

Commit 67354b2

Browse files
authored
gh-145563: Add thread-safety annotation for PyCapsule C-API (#146612)
1 parent b4fac15 commit 67354b2

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Doc/data/threadsafety.dat

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,33 @@ PyByteArray_GET_SIZE:atomic:
123123

124124
# Raw data - no locking; mutating it is unsafe if the bytearray object is shared between threads
125125
PyByteArray_AsString:compatible:
126-
PyByteArray_AS_STRING:compatible:
126+
PyByteArray_AS_STRING:compatible:
127+
128+
# Capsule objects (Doc/c-api/capsule.rst)
129+
130+
# Type check - read ob_type pointer, always safe
131+
PyCapsule_CheckExact:atomic:
132+
133+
# Creation - pure allocation, no shared state
134+
PyCapsule_New:atomic:
135+
136+
# Validation - reads pointer and name fields; safe on distinct objects
137+
PyCapsule_IsValid:distinct:
138+
139+
# Getters - read struct fields; safe on distinct objects but
140+
# concurrent access to the same capsule requires external synchronization
141+
PyCapsule_GetPointer:distinct:
142+
PyCapsule_GetName:distinct:
143+
PyCapsule_GetDestructor:distinct:
144+
PyCapsule_GetContext:distinct:
145+
146+
# Setters - write struct fields; safe on distinct objects but
147+
# concurrent access to the same capsule requires external synchronization
148+
PyCapsule_SetPointer:distinct:
149+
PyCapsule_SetName:distinct:
150+
PyCapsule_SetDestructor:distinct:
151+
PyCapsule_SetContext:distinct:
152+
153+
# Import - looks up a capsule from a module attribute and
154+
# calls PyCapsule_GetPointer; may call arbitrary code
155+
PyCapsule_Import:compatible:

0 commit comments

Comments
 (0)