Repository: JuliaLang/julia
File: src/dlload.c (C)

Code before:
    }
#endif
    if (handle != NULL && close)
        dlclose(handle); // Undo ref count increment from `dlopen`
#endif
    return handle;
}

JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags, int throw_err)
{
    ios_t path, relocated;
    int i;
#ifdef _OS_WINDOWS_
    int err;
#endif
    uv_stat_t stbuf;
    void *handle;
    int abspath;
    int is_atpath;
    // number of extensions to try — if modname already ends with the
    // standard extension, then we don't try adding additional extensions
    int n_extensions = endswith_extension(modname) ? 1 : N_EXTENSIONS;

    // modname == NULL is a sentinel value requesting the handle of libjulia-internal
    if (modname == NULL)
        return jl_find_dynamic_library_by_addr(&jl_load_dynamic_library, throw_err, 1);

    abspath = jl_isabspath(modname);
    is_atpath = 0;

    JL_TIMING(DL_OPEN, DL_OPEN);
    if (!(flags & JL_RTLD_NOLOAD))
        jl_timing_puts(JL_TIMING_DEFAULT_BLOCK, modname);

    // Detect if our `modname` is something like `@rpath/libfoo.dylib`
#ifdef _OS_DARWIN_
    size_t nameLen = strlen(modname);
    const char *const atPaths[] = {"@executable_path/", "@loader_path/", "@rpath/"};
    for (i = 0; i < sizeof(atPaths)/sizeof(char*); ++i) {
        size_t atLen = strlen(atPaths[i]);
        if (nameLen >= atLen && 0 == strncmp(modname, atPaths[i], atLen)) {
            is_atpath = 1;
        }
    }
#endif

    ios_mem(&path, IOS_INLSIZE);
    ios_mem(&relocated, IOS_INLSIZE);

    /*
      this branch permutes all base paths in DL_LOAD_PATH with all extensions

Review comment (suggestion):
```suggestion
        return jl_libjulia_internal_handle;
```
(remove close parameter)

Code after:
        handle = dlopen("", RTLD_NOW | RTLD_NOLOAD | RTLD_LOCAL);
    }
#endif
    if (handle != NULL && close)
        dlclose(handle); // Undo ref count increment from `dlopen`
#endif
    return handle;
}

JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags, int throw_err)
{
    ios_t path, relocated;
    int i;
#ifdef _OS_WINDOWS_
    int err;
#endif
    uv_stat_t stbuf;
    void *handle;
    int abspath;
    int is_atpath;
    // number of extensions to try — if modname already ends with the
    // standard extension, then we don't try adding additional extensions
    int n_extensions = endswith_extension(modname) ? 1 : N_EXTENSIONS;

    // modname == NULL is a sentinel value requesting the handle of libjulia-internal
    if (modname == NULL)
        return jl_libjulia_internal_handle;

    abspath = jl_isabspath(modname);
    is_atpath = 0;

    JL_TIMING(DL_OPEN, DL_OPEN);
    if (!(flags & JL_RTLD_NOLOAD))
        jl_timing_puts(JL_TIMING_DEFAULT_BLOCK, modname);

    // Detect if our `modname` is something like `@rpath/libfoo.dylib`
#ifdef _OS_DARWIN_
    size_t nameLen = strlen(modname);
    const char *const atPaths[] = {"@executable_path/", "@loader_path/", "@rpath/"};
    for (i = 0; i < sizeof(atPaths)/sizeof(char*); ++i) {
        size_t atLen = strlen(atPaths[i]);
        if (nameLen >= atLen && 0 == strncmp(modname, atPaths[i], atLen)) {
            is_atpath = 1;
        }
    }
#endif

    ios_mem(&path, IOS_INLSIZE);
    ios_mem(&relocated, IOS_INLSIZE);

    /*