Skip to content

Commit

Permalink
Use a mutex around _ctypes_init_fielddesc
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou committed Dec 9, 2024
1 parent 870a038 commit 1b41ace
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ P_get(void *ptr, Py_ssize_t size)

/* Table with info about all formats.
* Must be accessed via _ctypes_get_fielddesc, which initializes it on
* first use.
* first use. After initialization it's treated as constant & read-only.
*/

struct formattable {
Expand Down Expand Up @@ -1464,12 +1464,14 @@ _Py_COMP_DIAG_POP
struct fielddesc *
_ctypes_get_fielddesc(const char *fmt)
{
static int initialized = 0;
static bool initialized = 0;
static PyMutex mutex = {0};
PyMutex_Lock(&mutex);
if (!initialized) {
_ctypes_init_fielddesc();

initialized = 1;
}
PyMutex_Unlock(&mutex);
struct fielddesc *result = NULL;
switch(fmt[0]) {
/*[python input]
Expand Down

0 comments on commit 1b41ace

Please sign in to comment.