Added dlopen, dlclose, dlerror, dlsym, malloc, and free to
(ikarus system $foreign).
This commit is contained in:
@@ -407,6 +407,8 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
|
||||
#define page_index(x) (((unsigned long int)(x)) >> pageshift)
|
||||
|
||||
#define pointer_tag ((ikptr) 0x107)
|
||||
#define disp_pointer_data (1 * wordsize)
|
||||
#define pointer_size (2 * wordsize)
|
||||
#define off_pointer_data (disp_pointer_data - vector_tag)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
|
||||
#include "ikarus-data.h"
|
||||
#include <dlfcn.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
ikptr
|
||||
ikrt_isapointer(ikptr x, ikpcb* pcb){
|
||||
@@ -56,3 +59,75 @@ ikrt_bn_to_pointer(ikptr x, ikpcb* pcb) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
ikptr
|
||||
ikrt_pointer_null(ikptr x /*, ikpcb* pcb*/) {
|
||||
return ref(x, off_pointer_data) ? true_object : false_object;
|
||||
}
|
||||
#endif
|
||||
|
||||
ikptr
|
||||
ikrt_dlerror(ikpcb* pcb) {
|
||||
char* str = dlerror();
|
||||
if (str == NULL) {
|
||||
return false_object;
|
||||
}
|
||||
int len = strlen(str);
|
||||
ikptr bv = ik_safe_alloc(pcb, align(disp_bytevector_data + len + 1));
|
||||
ref(bv, 0) = fix(len);
|
||||
memcpy((void*)(bv+disp_bytevector_data), str, len+1);
|
||||
return bv+bytevector_tag;
|
||||
}
|
||||
|
||||
ikptr
|
||||
ikrt_dlopen(ikptr x, ikptr load_lazy, ikptr load_global, ikpcb* pcb) {
|
||||
int flags =
|
||||
((load_lazy == false_object) ? RTLD_NOW : RTLD_LAZY) |
|
||||
((load_global == false_object) ? RTLD_LOCAL : RTLD_GLOBAL);
|
||||
char* name =
|
||||
(x == false_object)
|
||||
? NULL
|
||||
: (char*)(x + off_bytevector_data);
|
||||
void* p = dlopen(name, flags);
|
||||
if (p == NULL) {
|
||||
return false_object;
|
||||
} else {
|
||||
return make_pointer((long int) p, pcb);
|
||||
}
|
||||
}
|
||||
|
||||
ikptr
|
||||
ikrt_dlclose(ikptr x /*, ikpcb* pcb*/) {
|
||||
int r = dlclose((void*) ref(x, off_pointer_data));
|
||||
return (r == 0) ? true_object : false_object;
|
||||
}
|
||||
|
||||
|
||||
ikptr
|
||||
ikrt_dlsym(ikptr handle, ikptr sym, ikpcb* pcb) {
|
||||
void* p = dlsym((void*)ref(handle, off_pointer_data),
|
||||
((char*)sym) + off_bytevector_data);
|
||||
if (p == NULL) {
|
||||
return false_object;
|
||||
} else {
|
||||
return make_pointer((long int) p, pcb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ikptr
|
||||
ikrt_malloc(ikptr len, ikpcb* pcb) {
|
||||
void* p = malloc(unfix(len));
|
||||
if (p == NULL) {
|
||||
return false_object;
|
||||
} else {
|
||||
return make_pointer((long int) p, pcb);
|
||||
}
|
||||
}
|
||||
|
||||
ikptr
|
||||
ikrt_free(ikptr x) {
|
||||
free((void*) ref(x, off_pointer_data));
|
||||
return void_object;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user