]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix image save on Windows
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 22 Jan 2010 07:17:18 +0000 (01:17 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 22 Jan 2010 18:59:36 +0000 (12:59 -0600)
core/memory/memory.factor
vm/image.cpp
vm/os-windows.hpp

index 0fba4dee774f39ec066b85868637a68edcc992be..a1e977f553901d7c58e13010cbe275597f90e693 100644 (file)
@@ -8,7 +8,7 @@ IN: memory
     [ all-instances ] dip filter ; inline
 
 : saving-path ( path -- saving-path path )
-    [ ".saving" append-path ] keep
+    [ ".saving" append ] keep
     [ native-string>alien ] bi@ ;
 
 : save-image ( path -- )
index bfc9f3daca8714009d1f15b6af7ac193d8920c9d..ba9fb4e6e6eb9e253789efc8677e44cac4b65dc3 100755 (executable)
@@ -276,7 +276,7 @@ bool factor_vm::save_image(const vm_char *saving_filename, const vm_char *filena
        file = OPEN_WRITE(saving_filename);
        if(file == NULL)
        {
-               std::cout << "Cannot open image file: " << filename << std::endl;
+               std::cout << "Cannot open image file: " << saving_filename << std::endl;
                std::cout << strerror(errno) << std::endl;
                return false;
        }
@@ -303,9 +303,10 @@ bool factor_vm::save_image(const vm_char *saving_filename, const vm_char *filena
        if(safe_fwrite(code->allocator->first_block(),h.code_size,1,file) != 1) ok = false;
        if(safe_fclose(file)) ok = false;
 
-       MOVE_FILE(saving_filename,filename);
        if(!ok)
                std::cout << "save-image failed: " << strerror(errno) << std::endl;
+       else
+               MOVE_FILE(saving_filename,filename); 
 
        return ok;
 }
@@ -315,10 +316,10 @@ void factor_vm::primitive_save_image()
        /* do a full GC to push everything into tenured space */
        primitive_compact_gc();
 
-       data_root<byte_array> path1(ctx->pop(),this);
-       path1.untag_check(this);
        data_root<byte_array> path2(ctx->pop(),this);
        path2.untag_check(this);
+       data_root<byte_array> path1(ctx->pop(),this);
+       path1.untag_check(this);
        save_image((vm_char *)(path1.untagged() + 1 ),(vm_char *)(path2.untagged() + 1));
 }
 
@@ -327,10 +328,10 @@ void factor_vm::primitive_save_image_and_exit()
        /* We unbox this before doing anything else. This is the only point
        where we might throw an error, so we have to throw an error here since
        later steps destroy the current image. */
-       data_root<byte_array> path1(ctx->pop(),this);
-       path1.untag_check(this);
        data_root<byte_array> path2(ctx->pop(),this);
        path2.untag_check(this);
+       data_root<byte_array> path1(ctx->pop(),this);
+       path1.untag_check(this);
 
        /* strip out special_objects data which is set on startup anyway */
        for(cell i = 0; i < special_object_count; i++)
index 0569d85b61e30bdf6b9a26f8c921e9fe8cff8388..30e3eea9c975b8933501318e10bc773f655d9e1e 100755 (executable)
@@ -39,10 +39,10 @@ typedef wchar_t vm_char;
 
 #define OPEN_READ(path) _wfopen((path),L"rb")
 #define OPEN_WRITE(path) _wfopen((path),L"wb")
-#define MOVE_FILE(path1,path2) \
+#define MOVE_FILE(path1,path2)\
 do {\
-       if(MoveFile((path1),(path2)) == 0)\
-               general_error(ERROR_IO,tag_fixnum(GetLastError()),false_object,NULL);\
+       if(MoveFileEx((path1),(path2),MOVEFILE_REPLACE_EXISTING) == false)\
+               std::cout << "MoveFile() failed: error " << GetLastError() << std::endl;\
 } while(0)
 
 /* Difference between Jan 1 00:00:00 1601 and Jan 1 00:00:00 1970 */