unusual (print buffering on FreeBSD

Started by CaveGuy, August 06, 2017, 12:44:24 PM

Previous topic - Next topic

CaveGuy

The following test program runs just fine on both windows and ubuntu Linux but has print buffering problems and fails on FreeBSD 11.1.


;; (load "test.lsp")
#
; pressing key1 returns true, key2 returns nil, all other keys ignored
(define (torf key1 key2)
   (setq keypress2 "")
   (while (and (!= keypress2 key1) (!= keypress2 key2))
          (setq keypress2 (upper-case (char (read-key)))))
   (= keypress2 key1) )
#
; dummy compile/link code for testing
(define (linkme)
    (setq compile true
          exename "test")
    (println "ncompile/link code runs here")
    nil) ; return no errors
#
; mainline program edited for testing
(define (doit)
     (println "do main program here")
     (sleep 5000) ; pause for effect
     (println "then exit")
     (fake-exit) )
#
; entry point for this test
(define (run)
   (if (not compiled)
      (begin
         (print "n "C"ompile or "R"un ? " )
         (if (torf "C" "R")
              (begin
                   (if (not (linkme))
                         (println (string "n Compile of " exename " was successful. "))
                         (println (string "n Compile of " exename " failed! ")))
                   (print " "E"xit or "T"est ? ")
                   (if (torf "T" "E")
                       (doit)
                       (print "nfinished")))
             (doit)))
      (doit))
  true
  )
  true
  ;eof


here is a sample good run on ubuntu.


newLISP v.10.7.1 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h

> (load "test.lsp")
true
> (run)

 "C"ompile or "R"un ?  [i]; entered "c" for compile[/i]
compile/link code runs here

 Compile of test was successful.
 "E"xit or "T"est ?
finished


and failing example on BSD


root@bsd1:/home/bob # newlisp
newLISP v.10.6.2 64-bit on BSD IPv4/6 UTF-8 libffi, options: newlisp -h

> (load "test.lsp")
true
> (run)
;[i] the program stops at this point waiting on input with no prompt.
; enter an "c" to exit as if the prompt was there and it
; flushes the print buffer and continues.[/i]
 "C"ompile or "R"un ?
compile/link code runs here
[i]; and stops again waiting on input with no prompt.
; enter an "e" to exit as if the prompt was there again
; flushes the print buffer and we continue to the exit.[/i]
Compile of test was successful.
"E"xit or "T"est ?
finished
>


This leaves me clueless, I will test later on cent-os as soon as I can get another VM running.
Bob the Caveguy aka Lord High Fixer.

rickyboy

#1
Try using `write` with the length argument, as it seems to be non-buffering in this case.


$ diff -u test.lsp test-new.lsp
--- test.lsp    Mon Aug  7 08:51:48 2017
+++ test-new.lsp        Mon Aug  7 08:53:45 2017
@@ -20,18 +20,20 @@
      (sleep 5000) ; pause for effect
      (println "then exit")
      (fake-exit) )
+
+(define (prompt-user STR) (write 1 STR (length STR)))
 #
 ; entry point for this test
 (define (run)
    (if (not compiled)
       (begin
-         (print "n "C"ompile or "R"un ? " )
+         (prompt-user "n "C"ompile or "R"un ? " )
          (if (torf "C" "R")
               (begin
                    (if (not (linkme))
                          (println (string "n Compile of " exename " was successful. "))
                          (println (string "n Compile of " exename " failed! ")))
-                   (print " "E"xit or "T"est ? ")
+                   (prompt-user " "E"xit or "T"est ? ")
                    (if (torf "T" "E")
                        (doit)
                        (print "nfinished")))
(λx. x x) (λx. x x)

CaveGuy

#2
Thanks that works just fine :)



I will use that trick in some other common code ie. (myprintln ...  and all should be fixed.



Thanks again ...
Bob the Caveguy aka Lord High Fixer.

Lutz

#3
In newLISP version 10.7.3 'print' to standard out will also flush on macOS and other BSDs:



http://newlisp.nfshost.com/downloads/development/inprogress/">http://newlisp.nfshost.com/downloads/de ... nprogress/">http://newlisp.nfshost.com/downloads/development/inprogress/

CaveGuy

#4
This one reared it's ugly head again this time testing 10.7.3 on ubuntu 17.10



newLISP v.10.7.3 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h



> (setq x 0) (while (!= (char "x") (read-key true)) (sleep 1000)(println (inc x))) nil

0

1

2

x3

3

nil



> (setq x 0) (while (!= (char "x") (read-key true)) (sleep 1000)(print (inc x))) nil

0

x1234566

nil
Bob the Caveguy aka Lord High Fixer.