chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] reloading dso files


From: Mark Baily
Subject: Re: [Chicken-users] reloading dso files
Date: Mon, 7 Feb 2005 11:45:56 +1100

Here is a sample session of changing C functions dynamically with Gambit-C.

address@hidden dynamic]# ls
c  compile.scm  gambit.h  test1.scm  test2.scm  test3.scm





address@hidden dynamic]# ls c
testc1.c  testc2.c  testc3.c





address@hidden dynamic]# cat test1.scm
(define mytest
  (c-lambda (int) int "mytest"))

(define (wer) 4)





address@hidden dynamic]# cat test2.scm
(define mytest
  (c-lambda (int) int "mytest"))

(define (wer) 5)





address@hidden dynamic]# cat test3.scm
(define mytest
  (c-lambda (int) int "mytest"))

(define (wer) 6)





address@hidden dynamic]# cat c/testc1.c
int mytest(int a) {
        return a+10;
}





address@hidden dynamic]# cat c/testc2.c
int mytest(int a) {
        return a+20;
}





address@hidden dynamic]# cat c/testc3.c
int mytest(int a) {
        return a+30;
}





address@hidden dynamic]# cat compile.scm
(define-macro (pr . args)
 `(begin
         (display ,@args)
         (newline)))

(define tests '((wer) (mytest 3)))
(define (dotests)
        (map (lambda (x) (write x) (display " => ") (pr (eval x))) tests))


(compile-file-to-c "test1")
(link-flat '("test1") "test.o1.c")
(shell-command "gcc -shared -D___DYNAMIC test1.c test.o1.c c/testc1.c -o 
test.o1")
(load "test.o1")
(pr "test.o1")
(pr "-------")
(dotests)
(newline)
;--------------------------------------------------------
(compile-file-to-c "test2")
(link-flat '("test2") "test.o2.c")
(shell-command "gcc -shared -D___DYNAMIC test2.c test.o2.c c/testc2.c -o 
test.o2")
(load "test.o2")
(pr "test.o2")
(pr "-------")
(dotests)
(newline)
;--------------------------------------------------------
(compile-file-to-c "test3")
(link-flat '("test3") "test.o3.c")
(shell-command "gcc -shared -D___DYNAMIC test3.c test.o3.c c/testc3.c -o 
test.o3")
(load "test.o3")
(pr "test.o3")
(pr "-------")
(dotests)
(newline)





address@hidden dynamic]# gsc
Gambit Version 4.0 beta 12

> (load "compile.scm")
test.o1
-------
(wer) => 4
(mytest 3) => 13

test.o2
-------
(wer) => 5
(mytest 3) => 23

test.o3
-------
(wer) => 6
(mytest 3) => 33

"/root/gambtest/dynamic/compile.scm"
>
*** EOF again to exit
address@hidden dynamic]#


On Sat, 5 Feb 2005, felix winkelmann wrote:

> On Sat, 5 Feb 2005 09:04:03 +1100, Mark Baily <address@hidden> wrote:
> >
> > What I want to do is to dynamically change the definitions of the functions
> > here, say change func2 to return i*i, and change scheme-func to return 10.
> > Then recompile and reload like so..
> >
> > csc -s test.scm functions.c -o test.o2
> > (require "test.o2")
> >
> > I find that the change to scheme functions is reflected but the change to
> > C functions is not. Is there a way to get it to use the new C functions?
> > (You can do this in Gambit-C).
> >
>
> Can you show me the code you use for running this example in Gambit
> (and the performed compiler invocations) ?
>
> (Probably some dlopen hackery. Gambit seems to use RTLD_NOW for
> dlopen, I will investigate...)
>
>
> cheers,
> felix
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]