summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-28 20:15:13 +0100
committerJo-Philipp Wich <jo@mein.io>2022-01-29 23:33:07 +0100
commit2cb627f3ba79bfce98e4cf6ab4b2e8029e8cb09e (patch)
treed4080e561b42f0ae706efe07b7158e9555eab708 /lib.c
parent1094ffa276990fd53abe633e5b14869d7c538a16 (diff)
program: rename bytecode load/write functions, track path of executed file
Extend source objects with a `runpath` field which contains the original path of the source being executed by the VM. When instantiating source objects from file paths, the `runpath` will be set to the `filename`. When instantiating source buffers using `uc_source_new_buffer()`, the runpath is initially unset. A new function `uc_source_runpath_set()` can be used to adjust the runtime path being associated with a source object. Extend bytecode loading logic to set the source buffer runtime path to the precompiled bytecode file path being loaded and executed. This is required for `sourcepath()` and relative paths in `include()` to function correctly when executing precompiled programs. Finally rename `uc_program_from_file()` and `uc_program_to_file()` to `uc_program_load()` and `uc_program_write()` respectively since the load part now operates on an `uc_source_t` input buffer instead of a plain `FILE *` handle. Adjust users of these API functions accordingly. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index c211f78..e204ded 100644
--- a/lib.c
+++ b/lib.c
@@ -2141,7 +2141,7 @@ uc_include(uc_vm_t *vm, size_t nargs)
if (!closure)
return NULL;
- p = include_path(closure->function->program->source->filename, ucv_string_get(path));
+ p = include_path(closure->function->program->source->runpath, ucv_string_get(path));
if (!p) {
uc_vm_raise_exception(vm, EXCEPTION_RUNTIME,
@@ -2553,7 +2553,7 @@ uc_sourcepath(uc_vm_t *vm, size_t nargs)
continue;
}
- path = realpath(frame->closure->function->program->source->filename, NULL);
+ path = realpath(frame->closure->function->program->source->runpath, NULL);
break;
}