factor/native/unix/ffi.c

56 lines
879 B
C
Raw Normal View History

2004-12-17 12:22:16 -05:00
#include "../factor.h"
static void *null_dll;
void init_ffi(void)
{
null_dll = dlopen(NULL,RTLD_LAZY);
}
void ffi_dlopen(DLL *dll, bool error)
2004-12-17 12:22:16 -05:00
{
void *dllptr = dlopen(to_c_string(untag_string(dll->path),true), RTLD_LAZY);
2004-12-17 12:22:16 -05:00
if(dllptr == NULL)
{
if(error)
{
general_error(ERROR_FFI,tag_object(
2006-02-07 19:09:46 -05:00
from_c_string(dlerror())),true);
}
else
dll->dll = NULL;
return;
2004-12-17 12:22:16 -05:00
}
dll->dll = dllptr;
}
void *ffi_dlsym(DLL *dll, F_STRING *symbol, bool error)
2004-12-17 12:22:16 -05:00
{
void *handle = (dll == NULL ? null_dll : dll->dll);
void *sym = dlsym(handle,to_c_string(symbol,true));
2004-12-17 12:22:16 -05:00
if(sym == NULL)
{
if(error)
{
general_error(ERROR_FFI,tag_object(
2006-02-07 19:09:46 -05:00
from_c_string(dlerror())),true);
}
return NULL;
2004-12-17 12:22:16 -05:00
}
2004-12-25 05:49:30 -05:00
return sym;
2004-12-17 12:22:16 -05:00
}
2004-12-25 05:49:30 -05:00
void ffi_dlclose(DLL *dll)
2004-12-17 12:22:16 -05:00
{
2005-06-16 18:50:49 -04:00
if(dlclose(dll->dll))
2004-12-17 12:22:16 -05:00
{
general_error(ERROR_FFI,tag_object(
2006-02-07 19:09:46 -05:00
from_c_string(dlerror())),true);
2004-12-17 12:22:16 -05:00
}
dll->dll = NULL;
}