factor/native/unix/ffi.c

54 lines
868 B
C
Raw Normal View History

2004-12-17 12:22:16 -05:00
#include "../factor.h"
2004-12-25 05:49:30 -05:00
DLL *ffi_dlopen(F_STRING *path)
2004-12-17 12:22:16 -05:00
{
#ifdef FFI
void* dllptr;
DLL* dll;
2004-12-25 05:49:30 -05:00
dllptr = dlopen(to_c_string(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 = allot_object(DLL_TYPE,sizeof(DLL));
dll->dll = dllptr;
2004-12-25 05:49:30 -05:00
return dll;
2004-12-17 12:22:16 -05:00
#else
general_error(ERROR_FFI_DISABLED,F);
#endif
}
2004-12-25 05:49:30 -05:00
void *ffi_dlsym(DLL *dll, F_STRING *symbol)
2004-12-17 12:22:16 -05:00
{
#ifdef FFI
2004-12-25 05:49:30 -05:00
void* sym = dlsym(dll ? dll->dll : NULL, 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
#else
general_error(ERROR_FFI_DISABLED,F);
#endif
}
2004-12-25 05:49:30 -05:00
void ffi_dlclose(DLL *dll)
2004-12-17 12:22:16 -05:00
{
#ifdef FFI
if(dlclose(dll->dll) == -1)
{
general_error(ERROR_FFI,tag_object(
from_c_string(dlerror())));
}
dll->dll = NULL;
#else
general_error(ERROR_FFI_DISABLED,F);
#endif
}