factor/native/unix/ffi.c

45 lines
733 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)
2004-12-17 12:22:16 -05:00
{
2005-06-08 04:49:05 -04:00
void *dllptr = dlopen(to_c_string(untag_string(dll->path)), RTLD_LAZY);
2004-12-17 12:22:16 -05:00
if(dllptr == NULL)
{
general_error(ERROR_FFI,tag_object(
from_c_string(dlerror())));
}
dll->dll = dllptr;
}
2004-12-25 05:49:30 -05:00
void *ffi_dlsym(DLL *dll, F_STRING *symbol)
2004-12-17 12:22:16 -05:00
{
void *handle = (dll == NULL ? null_dll : dll->dll);
void *sym = dlsym(handle,to_c_string(symbol));
2004-12-17 12:22:16 -05:00
if(sym == NULL)
{
general_error(ERROR_FFI,tag_object(
from_c_string(dlerror())));
}
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(
from_c_string(dlerror())));
}
dll->dll = NULL;
}