Skip to content

Commit 90b4e0d

Browse files
committed
Fix libpython dlopen for free-threaded Python
Free-threaded Python 3.13+ uses a 't' suffix in library name (e.g., libpython3.13t.so instead of libpython3.13.so). Add patterns for free-threaded library names when Py_GIL_DISABLED is defined at compile time.
1 parent 41f9860 commit 90b4e0d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

c_src/py_nif.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,26 @@ static ERL_NIF_TERM nif_py_init(ErlNifEnv *env, int argc, const ERL_NIF_TERM arg
474474
char libpython[256];
475475
void *handle = NULL;
476476

477-
/* Try various library name patterns */
477+
#ifdef Py_GIL_DISABLED
478+
/* Free-threaded Python has 't' suffix in library name (e.g., libpython3.13t.so) */
479+
const char *patterns[] = {
480+
"libpython%d.%dt.so.1.0", /* Linux free-threaded with full version */
481+
"libpython%d.%dt.so", /* Linux/FreeBSD free-threaded */
482+
"libpython%d.%dt.so.1", /* Some systems free-threaded */
483+
"libpython%d.%d.so.1.0", /* Fallback: Linux with full version */
484+
"libpython%d.%d.so", /* Fallback: Linux/FreeBSD */
485+
"libpython%d.%d.so.1", /* Fallback: Some systems */
486+
NULL
487+
};
488+
#else
489+
/* Standard Python library names */
478490
const char *patterns[] = {
479491
"libpython%d.%d.so.1.0", /* Linux with full version */
480492
"libpython%d.%d.so", /* Linux/FreeBSD */
481493
"libpython%d.%d.so.1", /* Some systems */
482494
NULL
483495
};
496+
#endif
484497

485498
for (int i = 0; patterns[i] && !handle; i++) {
486499
snprintf(libpython, sizeof(libpython), patterns[i],

0 commit comments

Comments
 (0)