Skip to content

Commit cd3cac6

Browse files
committed
Split posix-specific dlopen logic
This allows us to have an quick return in the dlopen(None) case instead of having to follow the main main b_dlopen function all the way to the end. Signed-off-by: Rodrigo Tobar <[email protected]>
1 parent 7d53c3a commit cd3cac6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/c/_cffi_backend.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4375,6 +4375,15 @@ static void *b_handle_or_error(void *handle, const char *printable_filename)
43754375
return handle;
43764376
}
43774377

4378+
static void *b_do_dlopen_posix(const char *filename_or_null, int flags, const char *printable_filename)
4379+
{
4380+
if ((flags & (RTLD_NOW | RTLD_LAZY)) == 0)
4381+
flags |= RTLD_NOW;
4382+
4383+
void *handle = dlopen(filename_or_null, flags);
4384+
return b_handle_or_error(handle, printable_filename);
4385+
}
4386+
43784387
#ifdef MS_WIN32
43794388
static void *b_do_dlopen_win32(PyObject *filename_unicode, int flags, const char *printable_filename)
43804389
{
@@ -4417,8 +4426,8 @@ static void *b_do_dlopen(PyObject *args, const char **p_printable_filename,
44174426
if (!PyArg_ParseTuple(args, "|Oi:load_library",
44184427
&dummy, &flags))
44194428
return NULL;
4420-
filename_or_null = NULL;
44214429
*p_printable_filename = "<None>";
4430+
return b_do_dlopen_posix(NULL, flags, *p_printable_filename);
44224431
#endif
44234432
}
44244433
else if (CData_Check(PyTuple_GET_ITEM(args, 0)))
@@ -4466,13 +4475,9 @@ static void *b_do_dlopen(PyObject *args, const char **p_printable_filename,
44664475
return NULL;
44674476
}
44684477
}
4469-
if ((flags & (RTLD_NOW | RTLD_LAZY)) == 0)
4470-
flags |= RTLD_NOW;
4471-
4472-
handle = dlopen(filename_or_null, flags);
4478+
handle = b_do_dlopen_posix(filename_or_null, flags, *p_printable_filename);
44734479
PyMem_Free(filename_or_null);
4474-
4475-
return b_handle_or_error(handle, *p_printable_filename);
4480+
return handle;
44764481
}
44774482

44784483
static PyObject *b_load_library(PyObject *self, PyObject *args)

0 commit comments

Comments
 (0)