]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: make allot_alien() and ffi_dlsym() use cell instead of void*
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 18 Aug 2015 06:18:41 +0000 (08:18 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 24 Aug 2015 01:36:31 +0000 (18:36 -0700)
this way we get rid of a bunch of superfluous casts

vm/alien.cpp
vm/callbacks.cpp
vm/callstack.cpp
vm/code_blocks.cpp
vm/contexts.cpp
vm/io.cpp
vm/os-unix.cpp
vm/os-windows.cpp
vm/primitives.hpp
vm/vm.hpp

index 8c31ac5b63665f804b1423b351e4594d3e7f9ad5..9768908f2ff4b397f5ad73220c83e7ee8c1e54a3 100644 (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 */
index baaa7da1dd7e2da295cd8f4e1c45e9f556571551..a4700c3912f068d7115a673378582980c5cd2a74 100644 (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() {
index 411073305d0f55720a18da931feddb056b679714..52a2b20c76d9cd636e72597b57cf5d251625bed5 100644 (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));
 }
 
 }
index 72bd86c47c0d867580493b58a225f5af3875780f..892dfd2a47ec89384e047592bc6bfcbe7545f8d8 100644 (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;
index 3cd1d052d61a40730572d8e5d958ddfa9f3f8ae1..a58365b4fa8b13630efe23da892dd69405ff0c26 100644 (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() */
index 1e862cd109a5b090a1764a586dae877a1b785dcc..7b78ad6dbd678586a7d28c4450397d40c695e724 100644 (file)
--- a/vm/io.cpp
+++ b/vm/io.cpp
@@ -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()); }
index b9b1dcbef1fdf54c7094007fe662a9aaf09a9ffb..bbaaf5cbba48cc37cc90d5579d35bba2ab7c1d98 100644 (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) {
index 5ac44999d67f732abdc1679fc81c71ccf4c6070b..6870fd3e4c4f6edabb37f45ab28dccacfab5e9d9 100644 (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);
 }
 
index 97005df1478c4df959cd965355152420bc43d7c4..26d520699838453a22b3c14c43e648aba98bfb9a 100644 (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);
index 545cab10c1928db21260f753c45e2b95ef0ed0f5..5084be7d8861cfe30a21d02f8120e8229dacb19c 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -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);