summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatoshi Tagomori <[email protected]>2023-12-07 20:38:53 +0900
committerNobuyoshi Nakada <[email protected]>2023-12-14 17:39:42 +0900
commit8a37df8c8bc0311c4822ee989087d212af2bf73f ()
treeaedec147365812ed69cfb848bab08cf697ea8e38
parent35a6b69f6c3cda7afd84c686978cf7ac79f68e04 (diff)
dln_symbol: make dln_sym accessible Ruby internally
The symbol resolved by dln_symbol will eventually be passed to extensions. The error handling of dln_sym is also separated into dln_sym_func because the new call resolving symbols will not raise LoadError.
-rw-r--r--dln.c70
-rw-r--r--dln.h1
-rw-r--r--dmydln.c9
3 files changed, 59 insertions, 21 deletions
@@ -419,33 +419,63 @@ dln_open(const char *file)
static void *
dln_sym(void *handle, const char *symbol)
{
- void *func;
- const char *error;
-
#if defined(_WIN32)
- char message[1024];
- func = GetProcAddress(handle, symbol);
if (func == NULL) {
error = dln_strerror();
- goto failed;
- }
-
#elif defined(USE_DLN_DLOPEN)
- func = dlsym(handle, symbol);
- if (func == NULL) {
const size_t errlen = strlen(error = dln_strerror()) + 1;
error = memcpy(ALLOCA_N(char, errlen), error, errlen);
- goto failed;
- }
#endif
-
return func;
-
- failed:
- dln_loaderror("%s - %s", error, symbol);
}
#endif
#if defined(RUBY_DLN_CHECK_ABI) && defined(USE_DLN_DLOPEN)
static bool
@@ -464,9 +494,8 @@ dln_load(const char *file)
#ifdef RUBY_DLN_CHECK_ABI
typedef unsigned long long abi_version_number;
- typedef abi_version_number abi_version_func(void);
- abi_version_func *abi_version_fct = (abi_version_func *)dln_sym(handle, EXTERNAL_PREFIX "ruby_abi_version");
- abi_version_number binary_abi_version = (*abi_version_fct)();
if (binary_abi_version != ruby_abi_version() && abi_check_enabled_p()) {
dln_loaderror("incompatible ABI version of binary - %s", file);
}
@@ -474,10 +503,9 @@ dln_load(const char *file)
char *init_fct_name;
init_funcname(&init_fct_name, file);
- void (*init_fct)(void) = (void(*)(void))dln_sym(handle, init_fct_name);
/* Call the init code */
- (*init_fct)();
return handle;
@@ -25,6 +25,7 @@ RUBY_SYMBOL_EXPORT_BEGIN
char *dln_find_exe_r(const char*,const char*,char*,size_t DLN_FIND_EXTRA_ARG_DECL);
char *dln_find_file_r(const char*,const char*,char*,size_t DLN_FIND_EXTRA_ARG_DECL);
void *dln_load(const char*);
RUBY_SYMBOL_EXPORT_END
@@ -8,3 +8,12 @@ dln_load(const char *file)
UNREACHABLE_RETURN(NULL);
}