Subject: [clisp-list] linux FFI: What/where is _IO_stdin/out/err_?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Tue Apr 1 06:21:14 2003

Hi,

linux:stdin etc. support seems broken (clisp-2.30):

linux.lisp says:
(def-c-var _IO_stdin_ (:type c-pointer))
(def-c-var _IO_stdout_ (:type c-pointer))
(def-c-var _IO_stderr_ (:type c-pointer))
(define-symbol-macro stdin _IO_stdin_)
(define-symbol-macro stdout _IO_stdout_)
(define-symbol-macro stderr _IO_stderr_)

As a result, linux.c contains:
extern void* _IO_stdin_; 
extern void* _IO_stdout_;
extern void* _IO_stderr_;
  register_foreign_variable(&_IO_stdin_,"_IO_stdin_",0,sizeof(_IO_stdin_));   
  register_foreign_variable(&_IO_stdout_,"_IO_stdout_",0,sizeof(_IO_stdout_));
  register_foreign_variable(&_IO_stderr_,"_IO_stderr_",0,sizeof(_IO_stderr_));

But I found only (no trailing '_'):
> find /usr/include/. -type f -exec fgrep -Hn IO_std {} \;
/usr/include/./libio.h:330:#define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))  
/usr/include/./libio.h:331:#define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
/usr/include/./libio.h:332:#define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
/usr/include/./libio.h:334:extern _IO_FILE *_IO_stdin;                       
/usr/include/./libio.h:335:extern _IO_FILE *_IO_stdout;                      
/usr/include/./libio.h:336:extern _IO_FILE *_IO_stderr;                      
/usr/include/./libio.h:479:  (__builtin_expect (&_IO_stdin_used == NULL, 0)) 
/usr/include/./libio.h:480:extern const int _IO_stdin_used;                  
/usr/include/./libio.h:481:weak_extern (_IO_stdin_used);

yet linux.c was compilable, and linkable.
However linux:stdout appears unusable (core dump)

What's going on? Where's the pointer to stdin/stdout/stderr coming from?

FFI[13]> (linux:fprintf0 linux:stdout "hi")                                                                                 
*** - handle_fault error2 ! address = 0xFBAD20CA not in [0x68057E50,0x68086000) !
SIGSEGV cannot be cured. Fault address = 0xFBAD20CA.                             
Segmentation fault

while this works:
(linux:printf0 (coerce '(#\a #\newline) 'string))

Thanks for enlightment,
	Jörg Höhle.

---

From: Sam Steingold <[email-masked]>
Date: Tue Apr 1 06:54:27 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] linux FFI: What/where is _IO_stdin/out/err_?"
> * Sent on Tue, 1 Apr 2003 15:24:54 +0200
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>
> linux:stdin etc. support seems broken

I suspect that this mess is similar to errno.

> (clisp-2.30):

please use CVS head.
I created a nightly source snapshot and diffs specifically for you!

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
(let ((a "(let ((a %c%s%c)) (format a 34 a 34))")) (format a 34 a 34))

---

From: Sam Steingold <[email-masked]>
Date: Tue Apr 1 07:07:02 2003

> linux:stdin etc. support seems broken (clisp-2.30):

with the appended patch:

[1]> (linux:fprintf0 linux:stdout (format nil "hi~%"))
hi
3
[2]> (linux:getpwent)
#S(LINUX:passwd :|pw_name| "root" :|pw_passwd| "x" :|pw_uid| 0 :|pw_gid| 0
   :|pw_gecos| "root" :|pw_dir| "/root" :|pw_shell| "/bin/bash")
[3]> (linux::putpwent (linux:getpwent) linux:stdout)

*** - handle_fault error2 ! address = 0x0 not in [0x20228000,0x203673ac) !
SIGSEGV cannot be cured. Fault address = 0x0.
Segmentation fault

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Only a fool has no doubts.

--- linux.lisp.~1.19.~	2003-03-29 10:02:55.000000000 -0500
+++ linux.lisp	2003-04-01 09:59:38.000000000 -0500
@@ -1795,12 +1815,9 @@
 
 (defconstant P_tmpdir "/tmp")
 
-(def-c-var _IO_stdin_ (:type c-pointer))
-(def-c-var _IO_stdout_ (:type c-pointer))
-(def-c-var _IO_stderr_ (:type c-pointer))
-(define-symbol-macro stdin _IO_stdin_)
-(define-symbol-macro stdout _IO_stdout_)
-(define-symbol-macro stderr _IO_stderr_)
+(def-c-var stdin (:type c-pointer))
+(def-c-var stdout (:type c-pointer))
+(def-c-var stderr (:type c-pointer))
 
 (def-call-out clearerr (:arguments (fp c-pointer)) (:return-type nil))
 (def-call-out fclose (:arguments (fp c-pointer)) (:return-type int))