pocketlang icon indicating copy to clipboard operation
pocketlang copied to clipboard

SIGSEGV on "import io" (and similar) when compiled without libs

Open SmallJoker opened this issue 6 months ago • 0 comments

How to reproduce:

  1. Modify Makefile.
    • Append -DPK_NO_LIBS to the CFLAGS
    • Remove the ./src/libs/ from SRC_DIRS
  2. make clean and rebuild
  3. Run ./pocket -c "import io" and observe the segfault

Proposed fix:

diff --git a/src/core/vm.c b/src/core/vm.c
index 8b8eeaa..243dcc5 100644
--- a/src/core/vm.c
+++ b/src/core/vm.c
@@ -466,6 +466,7 @@ Var vmImportModule(PKVM* vm, String* from, String* path) {
   uint32_t search_path_idx = 0;
 
   do {
+    if (!vm->config.resolve_path_fn) break; // when compiled without libs
     // If we reached here. It's not a native module (ie. module's absolute path
     // is required to import and cache).
     _resolved = vm->config.resolve_path_fn(vm, from_path, path->data);

SmallJoker avatar Feb 24 '24 20:02 SmallJoker