On 2013-04-12, at 6:29 PM, Ralph Moritz ralph.moeritz@outlook.com wrote:
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!
There was an issue with opening UNC filenames (Universal Naming Convention) on Windows that I have now fixed. So now it is possible to use \.\nul for the nul device (so "/dev/null" should be replaced with "\\.\nul" on Windows). Note that the path-expansion algorithm will map "nul" to "<cwd>/nul" so a (open-output-file "nul") will open a local file called "nul". This consistency with Unix is a good thing.
Marc