From: myriam <mab...@gm...> - 2002-01-29 17:42:03
|
Hi! How do you make an ffi call to something like gethostname where the value of host is passed through a pointer and not returned? TIA myriam |
From: myriam <mab...@gm...> - 2002-01-31 14:24:43
|
> How do you make an ffi call to something like gethostname where the > value of host is passed through a pointer and not returned? > Unfortunately, I still don't have an answer for that. I did: (defconstant *hostname* (make-string 15)) (def-call-out gethostname (:arguments (hostname c-string) (len int)) (:return-type int)) (gethostname *hostname* 15) but that does not set the value of *hostname*. myriam |
From: Erik W. <ae...@xs...> - 2002-01-31 15:05:39
|
myriam <mab...@gm...> writes: > (defconstant *hostname* (make-string 15)) [...] > (gethostname *hostname* 15) Isn't that because you declared *hostname* to be a constant, hence its value cannot be changed anymore subsequently? Try defvar instead. |
From: Sam S. <sd...@gn...> - 2002-01-31 15:31:56
|
> * In message <cdg...@su...> > * On the subject of "Re: [clisp-list] FFI question" > * Sent on 31 Jan 2002 09:23:09 -0500 > * Honorable myriam <mab...@gm...> writes: > > > How do you make an ffi call to something like gethostname where the > > value of host is passed through a pointer and not returned? > > Unfortunately, I still don't have an answer for that. commented out in CLISP/modules/bindings/linuxlibc6/linux.lisp: (def-c-call-out gethostname (:arguments (name c-pointer) (len size_t)) ; ?? (:return-type int)) (def-c-call-out sethostname (:arguments (name (c-pointer) (len sizet)) ; ?? (:return-type int)) please try this and report the results. Bruno should be able to give an authoritative question, but he is busy. -- Sam Steingold (http://www.podval.org/~sds) Keep Jerusalem united! <http://www.onejerusalem.org/Petition.asp> Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/> OK, so you're a Ph.D. Just don't touch anything. |
From: myriam <mab...@gm...> - 2002-01-31 16:06:15
|
> commented out in CLISP/modules/bindings/linuxlibc6/linux.lisp: > > (def-c-call-out gethostname (:arguments (name c-pointer) (len size_t)) ; ?? > (:return-type int)) > > (def-c-call-out sethostname (:arguments (name (c-pointer) (len sizet)) ; ?? > (:return-type int)) > > > please try this and report the results. Okay, I've defined gethostname as above and tried: (defvar *hostname* (make-string 15)) ;; I thought that a defconstant would make sure that the string does ;; not get garbage collected. (gethostname *hostname* 15) *** - " |
From: Reini U. <ru...@x-...> - 2002-02-02 21:11:50
|
myriam schrieb: > > > commented out in CLISP/modules/bindings/linuxlibc6/linux.lisp: > > > > (def-c-call-out gethostname (:arguments (name c-pointer) (len size_t)) ; ?? > > (:return-type int)) > > > > (def-c-call-out sethostname (:arguments (name (c-pointer) (len sizet)) ; ?? > > (:return-type int)) > > > > > > please try this and report the results. > > Okay, I've defined gethostname as above and tried: > > (defvar *hostname* (make-string 15)) > ;; I thought that a defconstant would make sure that the string does > ;; not get garbage collected. > > (gethostname *hostname* 15) > *** - " > foreign type FFI:C-POINTER > > Any ideas? defvar assigns a variable on the lisp heap, but the def-c-call-out gethostname needs a memory location on the extra c-heap, which is similar to a simple malloc there. does gethostname() strcpy the name to char* name or points to the string on the system heap? you would need something like this (untested) with a strcpy'ing gethostname. (ffi:def-c-call-out gethostname (:arguments (name c-string) (len size_t))(:return-type int)) (ffi:def-c-var c-hostname (:type c-string) (:alloc :malloc-free)) (if (zerop (linux:gethostname c-hostname 15) ; 0 on success (defvar hostname (ffi:deref c-hostname))) ; deref converts c-string to lisp type and link the glibc to clisp. don't know if the dynamic-ffi works here. I've written a short and simple summary and overview of various FFI's at http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html -- Reini Urban http://xarch.tu-graz.ac.at/home/rurban/ http://tv.mur.at/ (kulturelles) |
From: Myriam A. <abr...@ai...> - 2002-02-05 15:42:16
|
Thanks but it's my understanding that def-c-var has to be the name of a c variable. You can't make your own c-variables on the lisp side. Since there is no such c variable, the code below does not link: Undefined first referenced symbol in file _lisp__c_2Dhostname foreign.o ld: fatal: Symbol referencing errors. No output written to lisp.run > > Any ideas? > > defvar assigns a variable on the lisp heap, but the def-c-call-out gethostname > needs > a memory location on the extra c-heap, which is similar to a simple malloc > there. > does gethostname() strcpy the name to char* name or points to the string on > the system heap? > > you would need something like this (untested) with a strcpy'ing gethostname. > > (ffi:def-c-call-out gethostname (:arguments (name c-string) (len > size_t))(:return-type int)) > (ffi:def-c-var c-hostname (:type c-string) (:alloc :malloc-free)) > (if (zerop (linux:gethostname c-hostname 15) ; 0 on success > (defvar hostname (ffi:deref c-hostname))) ; deref converts c-string > to lisp type > > and link the glibc to clisp. don't know if the dynamic-ffi works here. > > I've written a short and simple summary and overview of various FFI's at > http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html > -- > Reini Urban > http://xarch.tu-graz.ac.at/home/rurban/ > http://tv.mur.at/ (kulturelles) > > _______________________________________________ > clisp-list mailing list > cli...@li... > https://lists.sourceforge.net/lists/listinfo/clisp-list -- myriam |