py: handle nil module pointers in RunCode by ac1982 · Pull Request #260 · go-python/gpython
Repository navigation
py: handle nil module pointers in RunCode - #260
Open
ac1982 wants to merge 1 commit into go-python:main from ac1982:fix-nil-module-run-code
Open
py: handle nil module pointers in RunCode #260 ac1982 wants to merge 1 commit into go-python:main from ac1982:fix-nil-module-run-code
Conversation
ac1982 commented Oct 11, 2026
Copy link Copy Markdown
Passing a typed nil *py.Module to RunCode currently dereferences mod.Globals and panics. This affects callers that carry a module pointer through a loop and initialize it on the first RunFile/RunSrc call, as reported by @SolarLune in #249 .
Treat a nil module pointer like an untyped nil: create and return a new module. Non-nil module pointers still execute against the existing globals. Document the typed-nil behavior and exercise RunCode, RunSrc, and RunFile, followed by reuse of the returned module.
Fixes #249 .
Validation on Linux/arm64:
- Each of the three entry-point regressions panics before the fix and passes afterward.
- Go 1.27.1: the full project runner
go run ./ci/run-tests.go -tags=ci -race -coverpkg=github.com/go-python/gpython/...passes. - Go 1.18.10: targeted regression passes; Staticcheck 2022.1.3 passes for all packages.
goimportsandgit diff --checkpass. Standalone Go 1.27.1go vet ./...reports the same 182 existing diagnostics on unchanged main (unkeyed literals and unreachable code); no new diagnostics.- Windows, macOS, and browser/WASM execution were not run.
Required author registration: go-python/license#24 .
AI assistance: implementation and tests were developed and verified with an AI coding agent.
py: handle nil module pointers in RunCode
068ce1b
ac1982
mentioned this pull request
Oct 11, 2026
stdlib: resolve absolute script paths independently of sys.path
#261
Open
drew-512
mentioned this pull request
Nov 10, 2026
py.RunFile / RunCode doesn't handle a nil module pointer
#249
Open
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment