mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-127945: move initialization of field desc to module exec in ctypes (#132552)
This commit is contained in:
parent
b6c552f9e6
commit
2ff5eb8582
3 changed files with 6 additions and 18 deletions
|
@ -6239,6 +6239,8 @@ _ctypes_mod_exec(PyObject *mod)
|
|||
}
|
||||
Py_ffi_closure_free(ptr);
|
||||
|
||||
_ctypes_init_fielddesc();
|
||||
|
||||
ctypes_state *st = get_module_state(mod);
|
||||
st->_unpickle = PyObject_GetAttrString(mod, "_unpickle");
|
||||
if (st->_unpickle == NULL) {
|
||||
|
|
|
@ -1461,8 +1461,8 @@ _Py_COMP_DIAG_PUSH
|
|||
|
||||
/* Delayed initialization. Windows cannot statically reference dynamically
|
||||
loaded addresses from DLLs. */
|
||||
static void
|
||||
_ctypes_init_fielddesc_locked(void)
|
||||
void
|
||||
_ctypes_init_fielddesc(void)
|
||||
{
|
||||
/* Fixed-width integers */
|
||||
|
||||
|
@ -1659,30 +1659,14 @@ print(f" formattable.simple_type_chars[i] = 0;")
|
|||
#undef FIXINT_FIELDDESC_FOR
|
||||
_Py_COMP_DIAG_POP
|
||||
|
||||
static void
|
||||
_ctypes_init_fielddesc(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
static PyMutex mutex = {0};
|
||||
PyMutex_Lock(&mutex);
|
||||
if (!initialized) {
|
||||
_ctypes_init_fielddesc_locked();
|
||||
initialized = true;
|
||||
}
|
||||
PyMutex_Unlock(&mutex);
|
||||
}
|
||||
|
||||
char *
|
||||
_ctypes_get_simple_type_chars(void) {
|
||||
_ctypes_init_fielddesc();
|
||||
return formattable.simple_type_chars;
|
||||
}
|
||||
|
||||
struct fielddesc *
|
||||
_ctypes_get_fielddesc(const char *fmt)
|
||||
{
|
||||
_ctypes_init_fielddesc();
|
||||
|
||||
struct fielddesc *result = NULL;
|
||||
switch(fmt[0]) {
|
||||
/*[python input]
|
||||
|
|
|
@ -537,6 +537,8 @@ extern int _ctypes_simple_instance(ctypes_state *st, PyObject *obj);
|
|||
|
||||
PyObject *_ctypes_get_errobj(ctypes_state *st, int **pspace);
|
||||
|
||||
extern void _ctypes_init_fielddesc(void);
|
||||
|
||||
#ifdef USING_MALLOC_CLOSURE_DOT_C
|
||||
void Py_ffi_closure_free(void *p);
|
||||
void *Py_ffi_closure_alloc(size_t size, void** codeloc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue