]> gitweb.factorcode.org Git - factor.git/commitdiff
moved utility functions and fatal_error out of vm struct since doesn't need state
authorPhil Dawes <phil@phildawes.net>
Tue, 25 Aug 2009 07:20:58 +0000 (08:20 +0100)
committerPhil Dawes <phil@phildawes.net>
Wed, 16 Sep 2009 07:20:10 +0000 (08:20 +0100)
vm/errors.cpp
vm/errors.hpp
vm/mach_signal.cpp
vm/os-genunix.cpp
vm/os-linux.cpp
vm/os-unix.cpp
vm/utilities.cpp
vm/utilities.hpp
vm/vm.hpp

index 09e6313f29f5700a7565556acb01e8382fd6bb09..f483fb4a0919a01c887f5903c584c5393a74847f 100755 (executable)
@@ -17,7 +17,7 @@ void factorvm::out_of_memory()
        exit(1);
 }
 
-void factorvm::fatal_error(const char* msg, cell tagged)
+void fatal_error(const char* msg, cell tagged)
 {
        print_string("fatal_error: "); print_string(msg);
        print_string(": "); print_cell_hex(tagged); nl();
index 8725941920a2a79b8695f0c3225a69d42a1c29b1..4f45c55c736d4d4a91946704eb758d374cc7feda 100755 (executable)
@@ -27,6 +27,7 @@ PRIMITIVE(die);
 PRIMITIVE(call_clear);
 PRIMITIVE(unimplemented);
 
+void fatal_error(const char* msg, cell tagged);
 void memory_signal_handler_impl();
 void fp_signal_handler_impl();
 void misc_signal_handler_impl();
index c1d263527df7213fe73f7c15c220a66ab938eafb..ecded49c0fdfcfee7dbcea1e0f207a4a437cb0c1 100644 (file)
@@ -203,13 +203,13 @@ void mach_initialize ()
        /* Allocate a port on which the thread shall listen for exceptions.  */
        if (mach_port_allocate (self, MACH_PORT_RIGHT_RECEIVE, &our_exception_port)
                != KERN_SUCCESS)
-               vm->fatal_error("mach_port_allocate() failed",0);
+               fatal_error("mach_port_allocate() failed",0);
 
        /* See http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/mach_port_insert_right.html.  */
        if (mach_port_insert_right (self, our_exception_port, our_exception_port,
                MACH_MSG_TYPE_MAKE_SEND)
                != KERN_SUCCESS)
-               vm->fatal_error("mach_port_insert_right() failed",0);
+               fatal_error("mach_port_insert_right() failed",0);
 
        /* The exceptions we want to catch. */
        mask = EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC;
@@ -226,7 +226,7 @@ void mach_initialize ()
        if (task_set_exception_ports (self, mask, our_exception_port,
                EXCEPTION_DEFAULT, MACHINE_THREAD_STATE)
                != KERN_SUCCESS)
-               vm->fatal_error("task_set_exception_ports() failed",0);
+               fatal_error("task_set_exception_ports() failed",0);
 }
 
 }
index 9e7804caf09656e9fecd2e0ea3736179a2636c84..29c3e79859dbada3061adc2cc053b200a22408e5 100644 (file)
@@ -31,7 +31,7 @@ const char *default_image_path()
        const char *iter = path;
        while(*iter) { len++; iter++; }
 
-       char *new_path = (char *)vm->safe_malloc(PATH_MAX + SUFFIX_LEN + 1);
+       char *new_path = (char *)safe_malloc(PATH_MAX + SUFFIX_LEN + 1);
        memcpy(new_path,path,len + 1);
        memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1);
        return new_path;
index c21f8142a1f5d5b5ed7cc22bd2287bb17774f23e..7929701d4157423431addf50f357f9c14bf3ae96 100644 (file)
@@ -6,18 +6,18 @@ namespace factor
 /* Snarfed from SBCL linux-so.c. You must free() this yourself. */
 const char *vm_executable_path()
 {
-       char *path = (char *)vm->safe_malloc(PATH_MAX + 1);
+       char *path = (char *)safe_malloc(PATH_MAX + 1);
 
        int size = readlink("/proc/self/exe", path, PATH_MAX);
        if (size < 0)
        {
-               vm->fatal_error("Cannot read /proc/self/exe",0);
+               fatal_error("Cannot read /proc/self/exe",0);
                return NULL;
        }
        else
        {
                path[size] = '\0';
-               return vm->safe_strdup(path);
+               return safe_strdup(path);
        }
 }
 
index 4de5ede70467a2481f545c4013ed80c313c6acff..832b93b39238b6d684c5466688f632edadf6c7de 100644 (file)
@@ -8,11 +8,11 @@ void *start_thread(void *(*start_routine)(void *),void *args)
        pthread_attr_t attr;
        pthread_t thread;
        if (pthread_attr_init (&attr) != 0)
-               vm->fatal_error("pthread_attr_init() failed",0);
+               fatal_error("pthread_attr_init() failed",0);
        if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0)
-               vm->fatal_error("pthread_attr_setdetachstate() failed",0);
+               fatal_error("pthread_attr_setdetachstate() failed",0);
        if (pthread_create (&thread, &attr, start_routine, args) != 0)
-               vm->fatal_error("pthread_create() failed",0);
+               fatal_error("pthread_create() failed",0);
        pthread_attr_destroy (&attr);
        return (void*)thread;
 }
@@ -85,12 +85,12 @@ segment *alloc_segment(cell size)
                vm->out_of_memory();
 
        if(mprotect(array,pagesize,PROT_NONE) == -1)
-               vm->fatal_error("Cannot protect low guard page",(cell)array);
+               fatal_error("Cannot protect low guard page",(cell)array);
 
        if(mprotect(array + pagesize + size,pagesize,PROT_NONE) == -1)
-               vm->fatal_error("Cannot protect high guard page",(cell)array);
+               fatal_error("Cannot protect high guard page",(cell)array);
 
-       segment *retval = (segment *)vm->safe_malloc(sizeof(segment));
+       segment *retval = (segment *)safe_malloc(sizeof(segment));
 
        retval->start = (cell)(array + pagesize);
        retval->size = size;
@@ -107,7 +107,7 @@ void dealloc_segment(segment *block)
                pagesize + block->size + pagesize);
        
        if(retval)
-               vm->fatal_error("dealloc_segment failed",0);
+               fatal_error("dealloc_segment failed",0);
 
        free(block);
 }
@@ -165,7 +165,7 @@ static void sigaction_safe(int signum, const struct sigaction *act, struct sigac
        while(ret == -1 && errno == EINTR);
 
        if(ret == -1)
-               vm->fatal_error("sigaction failed", 0);
+               fatal_error("sigaction failed", 0);
 }
 
 void unix_init_signals()
@@ -227,7 +227,7 @@ extern "C" {
 void safe_close(int fd)
 {
        if(close(fd) < 0)
-               vm->fatal_error("error closing fd",errno);
+               fatal_error("error closing fd",errno);
 }
 
 bool check_write(int fd, void *data, ssize_t size)
@@ -246,7 +246,7 @@ bool check_write(int fd, void *data, ssize_t size)
 void safe_write(int fd, void *data, ssize_t size)
 {
        if(!check_write(fd,data,size))
-               vm->fatal_error("error writing fd",errno);
+               fatal_error("error writing fd",errno);
 }
 
 bool safe_read(int fd, void *data, ssize_t size)
@@ -258,7 +258,7 @@ bool safe_read(int fd, void *data, ssize_t size)
                        return safe_read(fd,data,size);
                else
                {
-                       vm->fatal_error("error reading fd",errno);
+                       fatal_error("error reading fd",errno);
                        return false;
                }
        }
@@ -277,7 +277,7 @@ void *stdin_loop(void *arg)
                        break;
 
                if(buf[0] != 'X')
-                       vm->fatal_error("stdin_loop: bad data on control fd",buf[0]);
+                       fatal_error("stdin_loop: bad data on control fd",buf[0]);
 
                for(;;)
                {
@@ -314,19 +314,19 @@ void open_console()
        int filedes[2];
 
        if(pipe(filedes) < 0)
-               vm->fatal_error("Error opening control pipe",errno);
+               fatal_error("Error opening control pipe",errno);
 
        control_read = filedes[0];
        control_write = filedes[1];
 
        if(pipe(filedes) < 0)
-               vm->fatal_error("Error opening size pipe",errno);
+               fatal_error("Error opening size pipe",errno);
 
        size_read = filedes[0];
        size_write = filedes[1];
 
        if(pipe(filedes) < 0)
-               vm->fatal_error("Error opening stdin pipe",errno);
+               fatal_error("Error opening stdin pipe",errno);
 
        stdin_read = filedes[0];
        stdin_write = filedes[1];
@@ -341,7 +341,7 @@ VM_C_API void wait_for_stdin()
                if(errno == EINTR)
                        wait_for_stdin();
                else
-                       vm->fatal_error("Error writing control fd",errno);
+                       fatal_error("Error writing control fd",errno);
        }
 }
 
index 4f4da9a1bc70d0d50ff6fc28d6333df52495bffd..94f010d0509223a51d879f918f0210c3feab46f5 100755 (executable)
@@ -4,14 +4,14 @@ namespace factor
 {
 
 /* If memory allocation fails, bail out */
-void *factorvm::safe_malloc(size_t size)
+void *safe_malloc(size_t size)
 {
        void *ptr = malloc(size);
        if(!ptr) fatal_error("Out of memory in safe_malloc", 0);
        return ptr;
 }
 
-vm_char *factorvm::safe_strdup(const vm_char *str)
+vm_char *safe_strdup(const vm_char *str)
 {
        vm_char *ptr = STRDUP(str);
        if(!ptr) fatal_error("Out of memory in safe_strdup", 0);
@@ -21,38 +21,38 @@ vm_char *factorvm::safe_strdup(const vm_char *str)
 
 /* We don't use printf directly, because format directives are not portable.
 Instead we define the common cases here. */
-void factorvm::nl()
+void nl()
 {
        fputs("\n",stdout);
 }
 
-void factorvm::print_string(const char *str)
+void print_string(const char *str)
 {
        fputs(str,stdout);
 }
 
 
-void factorvm::print_cell(cell x)
+void print_cell(cell x)
 {
        printf(CELL_FORMAT,x);
 }
 
-void factorvm::print_cell_hex(cell x)
+void print_cell_hex(cell x)
 {
        printf(CELL_HEX_FORMAT,x);
 }
 
-void factorvm::print_cell_hex_pad(cell x)
+void print_cell_hex_pad(cell x)
 {
        printf(CELL_HEX_PAD_FORMAT,x);
 }
 
-void factorvm::print_fixnum(fixnum x)
+void print_fixnum(fixnum x)
 {
        printf(FIXNUM_FORMAT,x);
 }
 
-cell factorvm::read_cell_hex()
+cell read_cell_hex()
 {
        cell cell;
        if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
index 412ef35bb4403ee39e5aa0ef975114ad79a07a9b..68e0c97b255acbea8e120e5e4008d56363744f84 100755 (executable)
@@ -1,4 +1,12 @@
 namespace factor
 {
-
+       void *safe_malloc(size_t size);
+       vm_char *safe_strdup(const vm_char *str);
+       void print_string(const char *str);
+       void nl();
+       void print_cell(cell x);
+       void print_cell_hex(cell x);
+       void print_cell_hex_pad(cell x);
+       void print_fixnum(fixnum x);
+       cell read_cell_hex();
 }
index 384c98186ab72b62f0a58b318bd91a332dd4361e..0a0393700c7e66e2668e6d9af94cc40851f2a743 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -66,7 +66,6 @@ struct factorvm {
        unsigned int signal_fpu_status;
        stack_frame *signal_callstack_top;
        void out_of_memory();
-       void fatal_error(const char* msg, cell tagged);
        void critical_error(const char* msg, cell tagged);
        void throw_error(cell error, stack_frame *callstack_top);
        void not_implemented_error();
@@ -658,20 +657,6 @@ struct factorvm {
        void factor_yield();
        void factor_sleep(long us);
 
-       //utilities
-       void *safe_malloc(size_t size);
-       vm_char *safe_strdup(const vm_char *str);
-       void nl();
-       void print_string(const char *str);
-       void print_cell(cell x);
-       void print_cell_hex(cell x);
-       void print_cell_hex_pad(cell x);
-       void print_fixnum(fixnum x);
-       cell read_cell_hex();
-
-       
-
-
        // os-*
        inline void vmprim_existsp();
        long thread_id();