From: Doug Coleman Date: Fri, 22 Jan 2010 07:17:18 +0000 (-0600) Subject: Fix image save on Windows X-Git-Tag: 0.97~5022^2~14 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=40cf302d2d7fe4a2960169605f8042a9f1fb1eab Fix image save on Windows --- diff --git a/core/memory/memory.factor b/core/memory/memory.factor index 0fba4dee77..a1e977f553 100644 --- a/core/memory/memory.factor +++ b/core/memory/memory.factor @@ -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 -- ) diff --git a/vm/image.cpp b/vm/image.cpp index bfc9f3daca..ba9fb4e6e6 100755 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -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 path1(ctx->pop(),this); - path1.untag_check(this); data_root path2(ctx->pop(),this); path2.untag_check(this); + data_root 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 path1(ctx->pop(),this); - path1.untag_check(this); data_root path2(ctx->pop(),this); path2.untag_check(this); + data_root 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++) diff --git a/vm/os-windows.hpp b/vm/os-windows.hpp index 0569d85b61..30e3eea9c9 100755 --- a/vm/os-windows.hpp +++ b/vm/os-windows.hpp @@ -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 */