Skip to content

Commit

Permalink
vm: removing dlsym-raw, it's not different enough
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Jul 31, 2024
1 parent 6071c8c commit f70f262
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 44 deletions.
6 changes: 1 addition & 5 deletions basis/alien/libraries/libraries.factor
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ PRIMITIVE: dll-valid? ( dll -- ? )
PRIMITIVE: (dlopen) ( path -- dll )
PRIMITIVE: (dlsym) ( name dll -- alien )
PRIMITIVE: dlclose ( dll -- )
PRIMITIVE: (dlsym-raw) ( name dll -- alien )

: dlopen ( path -- dll ) native-string>alien (dlopen) ;

: dlsym ( name dll -- alien ) [ string>symbol ] dip (dlsym) ;

: dlsym-raw ( name dll -- alien ) [ string>symbol ] dip (dlsym-raw) ;

HOOK: dlerror os ( -- message/f )

SYMBOL: libraries
Expand Down Expand Up @@ -88,8 +85,7 @@ M: library dispose dll>> [ dispose ] when* ;
lookup-library [ abi>> ] [ cdecl ] if* ;

: address-of ( name library -- value )
2dup library-dll dlsym-raw
[ 2nip ] [ no-such-symbol ] if* ;
2dup library-dll dlsym [ 2nip ] [ no-such-symbol ] if* ;

SYMBOL: deploy-libraries

Expand Down
4 changes: 0 additions & 4 deletions basis/bootstrap/image/primitives/primitives.factor
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ CONSTANT: all-primitives {
{
{ "(dlopen)" ( path -- dll ) "dlopen" { byte-array } { dll } f }
{ "(dlsym)" ( name dll -- alien ) "dlsym" { byte-array object } { c-ptr } f }
{
"(dlsym-raw)" ( name dll -- alien ) "dlsym_raw"
{ byte-array object } { c-ptr } f
}
{ "dlclose" ( dll -- ) "dlclose" { dll } { } f }
{ "dll-valid?" ( dll -- ? ) "dll_validp" { object } { object } f }
}
Expand Down
2 changes: 1 addition & 1 deletion basis/openssl/libssl/libssl.factor
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ FUNCTION: X509* SSL_get0_peer_certificate ( SSL* ssl )
FUNCTION: X509* SSL_get1_peer_certificate ( SSL* ssl )

: get-ssl-peer-certificate ( ssl -- x509 )
"SSL_get1_peer_certificate" "libssl" library-dll dlsym-raw
"SSL_get1_peer_certificate" "libssl" library-dll dlsym
[ SSL_get1_peer_certificate ] [ SSL_get_peer_certificate ] if ; inline

FUNCTION: int SSL_set_cipher_list ( SSL* ssl, c-string str )
Expand Down
2 changes: 1 addition & 1 deletion extra/readline/readline.factor
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ IN: readline
current-line readline.ffi:rl_point head ;

: has-readline? ( -- ? )
"readline" dup library-dll dlsym-raw >boolean ;
"readline" dup library-dll dlsym >boolean ;

: set-completion ( quot -- )
[
Expand Down
20 changes: 0 additions & 20 deletions vm/alien.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,6 @@ void factor_vm::primitive_dlsym() {
ctx->replace(allot_alien(ffi_dlsym(NULL, sym)));
}

// look up a symbol in a native library
// Allocates memory
void factor_vm::primitive_dlsym_raw() {
data_root<object> library(ctx->pop(), this);
data_root<byte_array> name(ctx->peek(), this);
check_tagged(name);

symbol_char* sym = name->data<symbol_char>();

if (to_boolean(library.value())) {
dll* d = untag_check<dll>(library.value());

if (d->handle == NULL)
ctx->replace(false_object);
else
ctx->replace(allot_alien(ffi_dlsym_raw(d, sym)));
} else
ctx->replace(allot_alien(ffi_dlsym_raw(NULL, sym)));
}

// close a native library handle
void factor_vm::primitive_dlclose() {
dll* d = untag_check<dll>(ctx->pop());
Expand Down
2 changes: 1 addition & 1 deletion vm/code_blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ cell factor_vm::compute_dlsym_address(array* parameters,

FACTOR_ASSERT(TAG(symbol) == BYTE_ARRAY_TYPE);
symbol_char* name = alien_offset(symbol);
cell sym = ffi_dlsym_raw(d, name);
cell sym = ffi_dlsym(d, name);
sym = toc ? FUNCTION_TOC_POINTER(sym) : FUNCTION_CODE_POINTER(sym);
return sym ? sym : undef;
}
Expand Down
6 changes: 1 addition & 5 deletions vm/os-unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ void factor_vm::ffi_dlopen(dll* dll) {
dll->handle = dlopen(alien_offset(dll->path), RTLD_LAZY | RTLD_GLOBAL);
}

cell factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
return (cell)dlsym(dll ? dll->handle : null_dll, symbol);
}

cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol));
return (cell)dlsym(dll ? dll->handle : null_dll, symbol);
}

void factor_vm::ffi_dlclose(dll* dll) {
Expand Down
4 changes: 0 additions & 4 deletions vm/os-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
symbol);
}

cell factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
return ffi_dlsym(dll, symbol);
}

void factor_vm::ffi_dlclose(dll* dll) {
FreeLibrary((HMODULE) dll->handle);
dll->handle = NULL;
Expand Down
2 changes: 1 addition & 1 deletion vm/primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace factor {
_(datastack_for) _(die) _(disable_ctrl_break) _(disable_gc_events) \
_(dispatch_stats) \
_(displaced_alien) _(dlclose) _(dll_validp) _(dlopen) _(dlsym) \
_(dlsym_raw) _(double_bits) _(enable_ctrl_break) _(enable_gc_events) \
_(double_bits) _(enable_ctrl_break) _(enable_gc_events) \
_(existsp) _(exit) \
_(fclose) _(fflush) _(fgetc) _(fixnum_divint) _(fixnum_divmod) \
_(fixnum_shift) _(fixnum_to_bignum) _(fixnum_to_float) _(float_add) \
Expand Down
2 changes: 0 additions & 2 deletions vm/vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ struct factor_vm {
void* alien_pointer();
void primitive_dlopen();
void primitive_dlsym();
void primitive_dlsym_raw();
void primitive_dlclose();
void primitive_dll_validp();
char* alien_offset(cell obj);
Expand Down Expand Up @@ -691,7 +690,6 @@ struct factor_vm {
void init_ffi();
void ffi_dlopen(dll* dll);
cell ffi_dlsym(dll* dll, symbol_char* symbol);
cell ffi_dlsym_raw(dll* dll, symbol_char* symbol);
void ffi_dlclose(dll* dll);
void c_to_factor_toplevel(cell quot);
void init_signals();
Expand Down

0 comments on commit f70f262

Please sign in to comment.