unusual (print buffering on FreeBSD

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?

unusual (print buffering on FreeBSD

Postby CaveGuy » Sun Aug 06, 2017 7:44 pm

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

Code: Select all
;; (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.

Code: Select all
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

Code: Select all
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.
CaveGuy
 
Posts: 111
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Re: unusual (print buffering on FreeBSD

Postby rickyboy » Mon Aug 07, 2017 12:57 pm

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

Code: Select all
$ 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)
rickyboy
 
Posts: 549
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: unusual (print buffering on FreeBSD

Postby CaveGuy » Mon Aug 07, 2017 3:45 pm

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.
CaveGuy
 
Posts: 111
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Re: unusual (print buffering on FreeBSD

Postby Lutz » Tue Aug 08, 2017 2:27 pm

In newLISP version 10.7.3 ‘print’ to standard out will also flush on macOS and other BSDs:

http://newlisp.nfshost.com/downloads/de ... nprogress/
Lutz
 
Posts: 5233
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to newLISP and the O.S.

Who is online

Users browsing this forum: No registered users and 1 guest

cron