VM: make allot_alien() and ffi_dlsym() use cell instead of void*

this way we get rid of a bunch of superfluous casts
db4
Björn Lindqvist 2015-08-18 08:18:41 +02:00 committed by John Benediktsson
parent 1045f41778
commit a53d5be683
10 changed files with 40 additions and 50 deletions

View File

@ -47,8 +47,8 @@ cell factor_vm::allot_alien(cell delegate_, cell displacement) {
}
/* Allocates memory */
cell factor_vm::allot_alien(void* address) {
return allot_alien(false_object, (cell)address);
cell factor_vm::allot_alien(cell address) {
return allot_alien(false_object, address);
}
/* make an alien pointing at an offset of another alien */

View File

@ -125,7 +125,7 @@ void factor_vm::primitive_callback() {
cell func = callbacks->add(w.value(), return_rewind)->entry_point();
CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
ctx->push(allot_alien((void*)func));
ctx->push(allot_alien(func));
}
void factor_vm::primitive_free_callback() {

View File

@ -114,8 +114,8 @@ void factor_vm::primitive_set_innermost_stack_frame_quotation() {
/* Allocates memory (allot_alien) */
void factor_vm::primitive_callstack_bounds() {
ctx->push(allot_alien((void*)ctx->callstack_seg->start));
ctx->push(allot_alien((void*)ctx->callstack_seg->end));
ctx->push(allot_alien(ctx->callstack_seg->start));
ctx->push(allot_alien(ctx->callstack_seg->end));
}
}

View File

@ -149,31 +149,27 @@ cell factor_vm::compute_dlsym_address(array* parameters, cell index) {
dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
void* undefined_symbol = (void*)factor::undefined_symbol;
cell undefined_symbol = (cell)factor::undefined_symbol;
undefined_symbol = FUNCTION_CODE_POINTER(undefined_symbol);
if (d != NULL && !d->handle)
return (cell)undefined_symbol;
return undefined_symbol;
switch (tagged<object>(symbol).type()) {
case BYTE_ARRAY_TYPE: {
symbol_char* name = alien_offset(symbol);
void* sym = ffi_dlsym(d, name);
if (sym)
return (cell)sym;
else
return (cell)undefined_symbol;
cell sym = ffi_dlsym(d, name);
return sym ? sym : undefined_symbol;
}
case ARRAY_TYPE: {
array* names = untag<array>(symbol);
for (cell i = 0; i < array_capacity(names); i++) {
symbol_char* name = alien_offset(array_nth(names, i));
void* sym = ffi_dlsym(d, name);
cell sym = ffi_dlsym(d, name);
if (sym)
return (cell)sym;
return sym;
}
return (cell)undefined_symbol;
return undefined_symbol;
}
default:
return -1;
@ -187,30 +183,26 @@ cell factor_vm::compute_dlsym_toc_address(array* parameters, cell index) {
dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
void* undefined_toc = (void*)factor::undefined_symbol;
cell undefined_toc = (cell)factor::undefined_symbol;
undefined_toc = FUNCTION_TOC_POINTER(undefined_toc);
if (d != NULL && !d->handle)
return (cell)undefined_toc;
return undefined_toc;
switch (tagged<object>(symbol).type()) {
case BYTE_ARRAY_TYPE: {
symbol_char* name = alien_offset(symbol);
void* toc = ffi_dlsym_toc(d, name);
if (toc)
return (cell)toc;
else
return (cell)undefined_toc;
cell toc = ffi_dlsym_toc(d, name);
return toc ? toc : undefined_toc;
}
case ARRAY_TYPE: {
array* names = untag<array>(symbol);
for (cell i = 0; i < array_capacity(names); i++) {
symbol_char* name = alien_offset(array_nth(names, i));
void* toc = ffi_dlsym_toc(d, name);
cell toc = ffi_dlsym_toc(d, name);
if (toc)
return (cell)toc;
return toc;
}
return (cell)undefined_toc;
return undefined_toc;
}
default:
return -1;

View File

@ -121,7 +121,7 @@ context* factor_vm::new_context() {
/* Allocates memory */
void factor_vm::init_context(context* ctx) {
ctx->context_objects[OBJ_CONTEXT] = allot_alien(ctx);
ctx->context_objects[OBJ_CONTEXT] = allot_alien((cell)ctx);
}
/* Allocates memory (init_context(), but not parent->new_context() */

View File

@ -171,8 +171,9 @@ void factor_vm::primitive_fopen() {
path.untag_check(this);
FILE* file;
file = safe_fopen((char*)(path.untagged() + 1), (char*)(mode.untagged() + 1));
ctx->push(allot_alien(file));
file = safe_fopen((char*)(path.untagged() + 1),
(char*)(mode.untagged() + 1));
ctx->push(allot_alien((cell)file));
}
FILE* factor_vm::pop_file_handle() { return (FILE*)alien_offset(ctx->pop()); }

View File

@ -39,16 +39,16 @@ void factor_vm::ffi_dlopen(dll* dll) {
dll->handle = dlopen(alien_offset(dll->path), RTLD_LAZY | RTLD_GLOBAL);
}
void* factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
return dlsym(dll ? dll->handle : null_dll, symbol);
cell factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
return (cell)dlsym(dll ? dll->handle : null_dll, symbol);
}
void* factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol));
}
#ifdef FACTOR_PPC
void* factor_vm::ffi_dlsym_toc(dll* dll, symbol_char* symbol) {
cell factor_vm::ffi_dlsym_toc(dll* dll, symbol_char* symbol) {
return FUNCTION_TOC_POINTER(ffi_dlsym_raw(dll, symbol));
}
#endif
@ -384,12 +384,9 @@ void safe_close(int fd) {
bool check_write(int fd, void* data, ssize_t size) {
if (write(fd, data, size) == size)
return true;
else {
if (errno == EINTR)
return check_write(fd, data, size);
else
return false;
}
if (errno == EINTR)
return check_write(fd, data, size);
return false;
}
void safe_write(int fd, void* data, ssize_t size) {

View File

@ -14,12 +14,12 @@ void factor_vm::ffi_dlopen(dll* dll) {
dll->handle = LoadLibraryEx((WCHAR*)alien_offset(dll->path), NULL, 0);
}
void* factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
return (void*)GetProcAddress(dll ? (HMODULE) dll->handle : hFactorDll,
symbol);
cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
return (cell)GetProcAddress(dll ? (HMODULE) dll->handle : hFactorDll,
symbol);
}
void* factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
cell factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
return ffi_dlsym(dll, symbol);
}

View File

@ -39,7 +39,7 @@ namespace factor {
_(wrapper)
#define EACH_ALIEN_PRIMITIVE(_) \
_(signed_cell, fixnum, from_signed_cell, to_fixnum) \
_(signed_cell, fixnum, from_signed_cell, to_fixnum) \
_(unsigned_cell, cell, from_unsigned_cell, to_cell) \
_(signed_8, int64_t, from_signed_8, to_signed_8) \
_(unsigned_8, uint64_t, from_unsigned_8, to_unsigned_8) \
@ -51,7 +51,7 @@ namespace factor {
_(unsigned_1, uint8_t, from_unsigned_cell, to_cell) \
_(float, float, allot_float, to_float) \
_(double, double, allot_float, to_double) \
_(cell, void*, allot_alien, pinned_alien_offset)
_(cell, cell, allot_alien, pinned_alien_offset)
#define DECLARE_PRIMITIVE(name) \
VM_C_API void primitive_##name(factor_vm * parent);

View File

@ -659,7 +659,7 @@ struct factor_vm {
// alien
char* pinned_alien_offset(cell obj);
cell allot_alien(cell delegate_, cell displacement);
cell allot_alien(void* address);
cell allot_alien(cell address);
void primitive_displaced_alien();
void primitive_alien_address();
void* alien_pointer();
@ -738,10 +738,10 @@ struct factor_vm {
void move_file(const vm_char* path1, const vm_char* path2);
void init_ffi();
void ffi_dlopen(dll* dll);
void* ffi_dlsym(dll* dll, symbol_char* symbol);
void* ffi_dlsym_raw(dll* dll, symbol_char* symbol);
cell ffi_dlsym(dll* dll, symbol_char* symbol);
cell ffi_dlsym_raw(dll* dll, symbol_char* symbol);
#ifdef FACTOR_PPC
void* ffi_dlsym_toc(dll* dll, symbol_char* symbol);
cell ffi_dlsym_toc(dll* dll, symbol_char* symbol);
#endif
void ffi_dlclose(dll* dll);
void c_to_factor_toplevel(cell quot);