Fix image save on Windows

db4
Doug Coleman 2010-01-22 01:17:18 -06:00
parent 3c09c7052c
commit 40cf302d2d
3 changed files with 11 additions and 10 deletions

View 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 -- )

View File

@ -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++)

View File

@ -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 */