ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.21k stars 142 forks source link

script-file absolute path is resolved too late #922

Closed lassik closed 3 months ago

lassik commented 1 year ago

Given a file bug.scm with the contents:

(import (scheme base)
        (scheme write)
        (srfi 193)
        (chibi filesystem))

(change-directory "/")  ; <-- This line causes the bug.
(write (script-file))
(newline)

Running chibi-scheme bug.scm outputs "/bug.scm".

That's because raw-script-file is not resolved from a relative to an absolute pathname until (script-file) is called.

What would be a good place to resolve it? The relative pathname is set in main.c.

ashinn commented 1 year ago

The easiest way to fix this is to record the PWD in (srfi 193) on loading, however in pathological cases (dynamic loading of SRFI 193 after changing directory) that fails. So we probably need to resolve in main.c.