Skip to content

Fix: Enable function/class access from imported sol_N modules#2

Open
MonteCrypto999 wants to merge 1 commit intoSolanaPython:solanafrom
MonteCrypto999:fix/module-function-access
Open

Fix: Enable function/class access from imported sol_N modules#2
MonteCrypto999 wants to merge 1 commit intoSolanaPython:solanafrom
MonteCrypto999:fix/module-function-access

Conversation

@MonteCrypto999
Copy link
Copy Markdown

When importing a module via import sol_0, functions and classes defined in that module were not accessible (NameError), while variables worked correctly.

Root cause: The source code import path used obj_run(module, code) which internally calls pikaVM_run without setting proper globals. This caused the DEF instruction handler to store functions on the wrong object (not the module).

Fix: Use pikaVM_run_ex with explicit cfg.globals = module to ensure functions are defined on the module object, mirroring how the bytecode import path already handled this correctly.

Test results:

  • test_vm_only.js: 158/158 passed
  • test_import_module.js: 12/13 passed (Test 8 "import sol_0 calls function" now works!)
  • test_vfs.js: 12/13 passed (failed test isn't related)

When importing a module via `import sol_0`, functions and classes
defined in that module were not accessible (NameError), while
variables worked correctly.

Root cause: The source code import path used `obj_run(module, code)`
which internally calls `pikaVM_run` without setting proper globals.
This caused the DEF instruction handler to store functions on the
wrong object (not the module).

Fix: Use `pikaVM_run_ex` with explicit `cfg.globals = module` to
ensure functions are defined on the module object, mirroring how
the bytecode import path already handled this correctly.

Test results:
- test_vm_only.js: 158/158 passed
- test_import_module.js: 12/13 passed (Test 8 "import sol_0 calls function" now works!)
- test_vfs.js: 12/13 passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant