[gambit-list] null device on windows

Ralph Moritz ralph.moeritz at outlook.com
Fri Apr 12 18:29:51 EDT 2013


On Unix the null device is /dev/null. On Windows NT+ the equivalent is
NUL. We can verify this by writing the following small C++11 program:

#include <cstdio>
int main() {
  auto f = fopen("NUL", "r");
  if (f == nullptr) {
    fprintf(stderr, "Cannot open file `NUL'.");
    return 0;
  }
  printf("Opened file `NUL' successfully.");
}

The above program, when compiled and run on Windows, will always print
"Opened file `NUL' successfully."

This brings me to Gambit, via Black Hole. BH contains some code (in
compile-load.scm and lib.scm) that assumes `/dev/null' exists. This is
obviously not true on Windows where instead we have `NUL'. It's easy
enough to modify BH accordingly but the problem remains that Gambit
tries to normalize all paths passed to `compile-file-to-target' so we
end up with `<absolute path to cwd>\NUL' instead of just `NUL'. This
essentially prevents us from using the null device as input to
`compile-file-to-target' on Windows & means the following code from BH
will fail on Windows:

(define (compile-sexp-to-c sexp
                           fn
                           #!key
                           (options '()))
  (##gc) ;; Avoid out-of-memory related crashes
  (let ((hook (lambda (_) sexp))
        (prev-hook #f))
    (dynamic-wind
        (lambda ()
          (set! prev-hook c#expand-source)
          (set! c#expand-source hook))
        (lambda ()
          (compile-file-to-target "/dev/null" ;; Change to "NUL" on Windows
                             output: fn
                             options: options))
        (lambda ()
          (set! c#expand-source prev-hook)))))

I've searched through the Gambit source code & tried to make the
necessary changes to get this working but have been unable to do so. I
probably just don't yet have a good enough understanding of the
code. (I tried modifying ___os_path_normalize_directory in
lib/os_files.c)

Is anyone able to help with this? I really want to run Black Hole on Windows!

Many thanks,
Ralph





More information about the Gambit-list mailing list