Subject: [clisp-list] exporting reader functions for slots?

From: Pascal Bourguignon <[email-masked]>
Date: Sun Mar 30 04:15:11 2003

Shouldn't the  reader functions for slots of  def-c-struct be exported
from LINUX?

[67]> (LINUX:|stat-st_ino| sbuf)
*** - READ from #<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM> #<IO SYNONYM-STREAM *DEBUG-IO*>>: #<PACKAGE LINUX> has no external symbol with name "stat-st_ino"
[68]> (LINUX::|stat-st_ino| sbuf)
142158

Since  LINUX  export  the   |stat|  function  that  returns  a  |stat|
structure, it would seem logical to export the reader functions too.

-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.

---

From: Sam Steingold <[email-masked]>
Date: Sun Mar 30 13:03:10 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] exporting reader functions for slots?"
> * Sent on Sun, 30 Mar 2003 14:13:57 +0200 (CEST)
> * Honorable Pascal Bourguignon <[email-masked]> writes:
>

would you be happy with the appended patch?

actually, I am somewhat uneasy with this.
def-c-struct defines both a C struct and a LISP structure type.
how is this passed into the FFI?
i.e., suppose I create a passwd with linux:MAKE-passwd.
can I pass it to linux:putpwent?

I cannot check that because even 
(linux::putpwent (linux:getpwent) linux:stdout)
crashes:

(gdb) where
#0  0x080b1283 in nls_asciiext_wcstombs (encoding={one_o = 539610993}, stream=
      {one_o = 0}, srcp=0xbfff8de8, srcend=0x203dc16c, destp=0xbfff8de0, 
    destend=0x404 <Address 0x404 out of bounds>) at encoding.d:1616
#1  0x081879a9 in convert_to_foreign (fvd={one_o = 136519537}, obj=
      {one_o = 540918101}, data=0xbfff8fa0) at foreign.d:1848
#2  0x08187d45 in convert_to_foreign (fvd={one_o = 540726929}, obj=
      {one_o = 540918233}, data=0xbfff8fa0) at foreign.d:1904
#3  0x08188e71 in convert_to_foreign_nomalloc (fvd={one_o = 540726929}, obj=
      {one_o = 540918233}, data=0xbfff8fa0) at foreign.d:2174
#4  0x0818cf5b in C_foreign_call_out (argcount=2, rest_args_pointer=0x401dc088)
    at foreign.d:3251
#5  0x0809d4eb in funcall_subr (fun={one_o = 136474578}, args_on_stack=2)
    at eval.d:5229
#6  0x0809c94b in funcall (fun={one_o = 136474578}, args_on_stack=3)
    at eval.d:4831
#7  0x0809a272 in eval_ffunction (ffun={one_o = 540727585}) at eval.d:3900
#8  0x08097090 in eval1 (form={one_o = 1745141891}) at eval.d:2978
#9  0x08096b90 in eval (form={one_o = 1745141891}) at eval.d:2834
#10 0x0813adf7 in C_read_eval_print () at debug.d:309
#11 0x0809d599 in funcall_subr (fun={one_o = 136456434}, args_on_stack=2)
    at eval.d:5232
#12 0x0809c9be in funcall (fun={one_o = 136480085}, args_on_stack=2)
    at eval.d:4838
#13 0x080a0b8b in interpret_bytecode_ (closure={one_o = 540264193}, 
    codeptr=0x2033c6d0, 
    byteptr_in=0x2033c6e2 "ÅP\030.\001\024.\002\024.\003\024s\003\023.\004\0240\005\037\002.\006Q\031\001\031\001") at eval.d:6883
#14 0x0809e410 in funcall_closure (closure={one_o = 540264193}, 
    args_on_stack=0) at eval.d:5678
#15 0x0809c976 in funcall (fun={one_o = 540264193}, args_on_stack=0)
    at eval.d:4833
#16 0x080ac32b in C_driver () at control.d:1903
#17 0x080a0cbe in interpret_bytecode_ (closure={one_o = 540264237}, 
    codeptr=0x2033c688, byteptr_in=0x2033c69a "Å\017\001Ü1U Æ3 \021\v")
    at eval.d:6889
#18 0x0809e410 in funcall_closure (closure={one_o = 540264237}, 
    args_on_stack=0) at eval.d:5678
#19 0x0809c976 in funcall (fun={one_o = 540264237}, args_on_stack=0)
    at eval.d:4833
#20 0x080a1684 in interpret_bytecode_ (closure={one_o = 540875949}, 
    codeptr=0x202cfcc8, byteptr_in=0x202cfcda "") at eval.d:6939
#21 0x0809e410 in funcall_closure (closure={one_o = 540875949}, 
    args_on_stack=0) at eval.d:5678
#22 0x0809c976 in funcall (fun={one_o = 540875949}, args_on_stack=0)
    at eval.d:4833
#23 0x0813b166 in driver () at debug.d:375
#24 0x0808df36 in main (argc=11, argv=0xbfffe174) at spvw.d:2963
#25 0x420154a0 in __libc_start_main () from /lib/tls/libc.so.6
(gdb) 

Joerg, what's up?!

-- 
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>
If Perl is the solution, you're solving the wrong problem. - Erik Naggum

--- linux.lisp.~1.19.~	2003-03-29 10:02:55.000000000 -0500
+++ linux.lisp	2003-03-30 15:43:39.000000000 -0500
@@ -105,11 +105,30 @@
                  `(progn
                     (defmacro ,new-macro-name (name &rest more)
                       `(progn
-                         (export ',(if (consp name) (car name) name))
+                         (export ',name)
                          (,',original-macro-name ,name ,@(sublis substitution more))
                        )
                   ) )
              ) )
+             (exporting-slots (defining-macro-name)
+               (let ((original-macro-name (intern (string-upcase defining-macro-name) "FFI"))
+                     (new-macro-name (intern defining-macro-name "LINUX")))
+                 `(defmacro ,new-macro-name (name &rest more)
+                    (let ((sname (if (consp name) (car name) name)))
+                      `(progn
+                         (export '(,sname
+                                   ,@(let ((cname (sys::string-concat
+                                                   (symbol-name sname) "-")))
+                                       (list*
+                                        (sys::concat-pnames "COPY-" cname)
+                                        (sys::concat-pnames "MAKE-" cname)
+                                        (sys::concat-pnames cname "-P")
+                                        (mapcar (lambda (slot)
+                                                  (sys::concat-pnames
+                                                   cname (car slot)))
+                                                more)))))
+                         (,',original-macro-name
+                          ,name ,@(sublis substitution more)))))))
              (normal (defining-macro-name)
                (let ((original-macro-name (intern (string-upcase defining-macro-name) "FFI"))
                      (new-macro-name (intern defining-macro-name "LINUX")))
@@ -125,7 +144,7 @@
     (exporting "define-symbol-macro")
     (exporting "def-c-type")
     (exporting "def-c-enum")
-    (exporting "def-c-struct")
+    (exporting-slots "def-c-struct")
     (exporting "def-c-var")
     (exporting "def-call-out")
     (normal "c-lines")