summaryrefslogtreecommitdiff
path: root/dln.c
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-04-23 14:30:31 -0400
committerPeter Zhu <[email protected]>2024-04-23 15:29:42 -0400
commitb9109b270d129561f06bc2dcd6feaf5c43e82360 (patch)
treefbdae06fd3fcbadf2f15e7294b41069dc407251e /dln.c
parent81433fd0f52b4214c0e788b6cd9f534b79ec03ba (diff)
Get error from dln_open when USE_SHARED_GC
Before, if dln_open failed to open RUBY_GC_LIBRARY_PATH, it would segfault because it would try to raise an error, which cannot happen because the GC has not been initialized yet. This commit changes dln_open to return the error that occurred so the caller can handle the error.
Diffstat (limited to 'dln.c')
-rw-r--r--dln.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/dln.c b/dln.c
index 3e08728a6b..ca520acd06 100644
--- a/dln.c
+++ b/dln.c
@@ -340,10 +340,9 @@ dln_disable_dlclose(void)
#if defined(_WIN32) || defined(USE_DLN_DLOPEN)
void *
-dln_open(const char *file)
+dln_open(const char *file, const char **error)
{
static const char incompatible[] = "incompatible library version";
- const char *error = NULL;
void *handle;
#if defined(_WIN32)
@@ -360,15 +359,15 @@ dln_open(const char *file)
free(winfile);
if (!handle) {
- error = dln_strerror();
- goto failed;
+ *error = dln_strerror();
+ return NULL;
}
# if defined(RUBY_EXPORT)
if (!rb_w32_check_imported(handle, rb_libruby_handle())) {
FreeLibrary(handle);
- error = incompatible;
- goto failed;
+ *error = incompatible;
+ return NULL;
}
# endif
@@ -387,8 +386,8 @@ dln_open(const char *file)
/* Load file */
handle = dlopen(file, RTLD_LAZY|RTLD_GLOBAL);
if (handle == NULL) {
- error = dln_strerror();
- goto failed;
+ *error = dln_strerror();
+ return NULL;
}
# if defined(RUBY_EXPORT)
@@ -413,8 +412,8 @@ dln_open(const char *file)
if (libruby_name) {
dln_loaderror("linked to incompatible %s - %s", libruby_name, file);
}
- error = incompatible;
- goto failed;
+ *error = incompatible;
+ return NULL;
}
}
}
@@ -422,9 +421,6 @@ dln_open(const char *file)
#endif
return handle;
-
- failed:
- dln_loaderror("%s - %s", error, file);
}
void *
@@ -501,7 +497,12 @@ void *
dln_load(const char *file)
{
#if defined(_WIN32) || defined(USE_DLN_DLOPEN)
- void *handle = dln_open(file);
+ const char *error = NULL;
+ void *handle = dln_open(file, &error);
+
+ if (handle == NULL) {
+ dln_loaderror("%s - %s", error, file);
+ }
#ifdef RUBY_DLN_CHECK_ABI
typedef unsigned long long abi_version_number;