/* OS-specific initialization */
early_init();
- const vm_char* executable_path = vm_executable_path();
-
- if (executable_path)
- p->executable_path = executable_path;
+ p->executable_path = vm_executable_path();
if (p->image_path == NULL) {
if (embedded_image_p()) {
p->embedded_image = true;
- p->image_path = p->executable_path;
+ p->image_path = safe_strdup(p->executable_path);
} else
p->image_path = default_image_path();
}
cell aliens[][2] = {
{OBJ_CPU, (cell)FACTOR_CPU_STRING},
- {OBJ_EXECUTABLE, (cell)p->executable_path},
+ {OBJ_EXECUTABLE, (cell)safe_strdup(p->executable_path)},
+ {OBJ_IMAGE, (cell)safe_strdup(p->image_path)},
{OBJ_OS, (cell)FACTOR_OS_STRING},
{OBJ_VM_COMPILE_TIME, (cell)FACTOR_COMPILE_TIME},
{OBJ_VM_COMPILER, (cell)FACTOR_COMPILER_VERSION},
callback_size = 256;
}
-void vm_parameters::init_from_args(int argc, vm_char** argv) {
- executable_path = argv[0];
+vm_parameters::~vm_parameters() {
+ free((vm_char *)image_path);
+ free((vm_char *)executable_path);
+}
+void vm_parameters::init_from_args(int argc, vm_char** argv) {
int i = 0;
for (i = 1; i < argc; i++) {
;
else if (factor_arg(arg, STRING_LITERAL("-callbacks=%d"), &callback_size))
;
- else if (STRNCMP(arg, STRING_LITERAL("-i="), 3) == 0)
- image_path = arg + 3;
+ else if (STRNCMP(arg, STRING_LITERAL("-i="), 3) == 0) {
+ /* In case you specify -i more than once. */
+ if (image_path) {
+ free((vm_char *)image_path);
+ }
+ image_path = safe_strdup(arg + 3);
+ }
else if (STRCMP(arg, STRING_LITERAL("-fep")) == 0)
fep = true;
else if (STRCMP(arg, STRING_LITERAL("-nosignals")) == 0)
cell data_offset = data->tenured->start - h.data_relocation_base;
cell code_offset = code->allocator->start - h.code_relocation_base;
fixup_heaps(data_offset, code_offset);
-
- /* Store image path name */
- special_objects[OBJ_IMAGE] = allot_alien(false_object, (cell)p->image_path);
}
/* Save the current image to disk. We don't throw any exceptions here
cell callback_size;
vm_parameters();
+ ~vm_parameters();
void init_from_args(int argc, vm_char** argv);
};
#define SUFFIX ".image"
#define SUFFIX_LEN 6
-/* You must delete[] the result yourself. */
+/* You must free() the result yourself. */
const char* default_image_path() {
const char* path = vm_executable_path();
if (!path)
- return "factor.image";
+ return strdup("factor.image");
int len = strlen(path);
- char* new_path = new char[len + SUFFIX_LEN + 1];
+ char* new_path = (char *)malloc(len + SUFFIX_LEN + 1);
memcpy(new_path, path, len);
memcpy(new_path + len, SUFFIX, SUFFIX_LEN + 1);
free(const_cast<char*>(path));