]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/image.cpp
Fix image save on Windows
[factor.git] / vm / image.cpp
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++)