Subject: [clisp-list] ffi and tcl/tk

From: Basim Al-Shaikhli <[email-masked]>
Date: Fri Oct 17 11:42:02 2003

hi,

i've just made my first steps with the FFI-module. i thought it would be
nice to have access to tcl/tk (especially tk) from clisp. but it seems
that there's something very wrong in what i'm doing whenever i
execute the following code, clisp crashes with the following error:

*** - handle_fault error2 ! address = 0xc0000010 not in
[0x62fd5098,0x63000000)
SIGSEGV cannot be cured. Fault address = 0xc0000010.

that's what i have done so far:

;;; typedef struct {
;;; char */result/;
;;; Tcl_FreeProc */freeProc/;
;;; int /errorLine/;
;;; } Tcl_Interp;
(def-c-struct TCL_INTERP
   (result c-string)
 (freeProc c-pointer)
 (errorLine int))

;;; Tcl_Interp* Tcl_CreateInterp() <../TclLib/Interp.htm>
(def-call-out create-interp (:library "tcl84.dll")
 (:name "Tcl_CreateInterp")
 (:return-type (c-ptr TCL_INTERP)))

;;; int Tcl_Eval*(/interp, script/)
(def-call-out tcl-eval (:library "tcl84.dll")
 (:name "Tcl_Eval")
 (:arguments (interp (c-ptr TCL_INTERP))
         (script c-string))
 (:return-type int))

;;; testing
(setq interp (create-interpr)

(tcl-eval interp "set v 3")

it would be very helpful if someone would tell me where i'm doing 
something wrong.

Basim

---

From: Sam Steingold <[email-masked]>
Date: Fri Oct 17 12:06:08 2003

> * Basim Al-Shaikhli <[email-masked]> [2003-10-17 20:35:41 +0200]:
>
> ;;; typedef struct {
> ;;; char */result/;

try c-pointer instead of c-string for result.
the quick hack :

[5]> (ffi:default-foreign-language :stdc)
:STDC
[6]> (def-call-out create-interp (:library "tcl84.dll")
 (:name "Tcl_CreateInterp")
 (:return-type c-pointer))
CREATE-INTERP
[7]> (def-call-out tcl-eval (:library "tcl84.dll")
 (:name "Tcl_Eval")
 (:arguments (interp c-pointer) (script c-string))
 (:return-type int))
TCL-EVAL
[8]> (setq interp (create-interp))
#<FOREIGN-ADDRESS #x1018CF70>
[9]> (tcl-eval interp "set v 3")
0
[10]>

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
(lisp programmers do it better)

---

From: Basim Al-Shaikhli <[email-masked]>
Date: Fri Oct 17 12:18:05 2003

>[9]> (tcl-eval interp "set v 3")
thanks a lot :-)
Basim