2004-12-17 12:22:16 -05:00
|
|
|
#include "../factor.h"
|
|
|
|
|
2005-04-30 00:43:39 -04:00
|
|
|
static void *null_dll;
|
|
|
|
|
|
|
|
void init_ffi(void)
|
|
|
|
{
|
|
|
|
null_dll = dlopen(NULL,RTLD_LAZY);
|
|
|
|
}
|
|
|
|
|
2005-08-15 15:34:00 -04:00
|
|
|
void ffi_dlopen(DLL *dll, bool error)
|
2004-12-17 12:22:16 -05:00
|
|
|
{
|
2005-12-12 18:51:45 -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)
|
|
|
|
{
|
2005-08-15 15:34:00 -04:00
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
general_error(ERROR_FFI,tag_object(
|
2006-02-07 19:09:46 -05:00
|
|
|
from_c_string(dlerror())),true);
|
2005-08-15 15:34:00 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
dll->dll = NULL;
|
|
|
|
|
|
|
|
return;
|
2004-12-17 12:22:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
dll->dll = dllptr;
|
|
|
|
}
|
|
|
|
|
2005-08-15 15:34:00 -04:00
|
|
|
void *ffi_dlsym(DLL *dll, F_STRING *symbol, bool error)
|
2004-12-17 12:22:16 -05:00
|
|
|
{
|
2005-04-30 00:43:39 -04:00
|
|
|
void *handle = (dll == NULL ? null_dll : dll->dll);
|
2005-12-12 18:51:45 -05:00
|
|
|
void *sym = dlsym(handle,to_c_string(symbol,true));
|
2004-12-17 12:22:16 -05:00
|
|
|
if(sym == NULL)
|
|
|
|
{
|
2005-08-15 15:34:00 -04:00
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
general_error(ERROR_FFI,tag_object(
|
2006-02-07 19:09:46 -05:00
|
|
|
from_c_string(dlerror())),true);
|
2005-08-15 15:34:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|