Add a whole bunch of chicken runme scripts, and fix the bugs exposed by those scripts

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7155 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
John Lenz 2005-04-15 05:23:14 +00:00
commit b599732cdc
72 changed files with 1085 additions and 412 deletions

View file

@ -10,5 +10,3 @@ zlib -- a wrapping of the zlib compression library
You should be able to run make in each of the examples. By default, a shared
library will be built. Run make check to execute the test.
You can uncomment a few lines in the Makefile to build a static test exe.

View file

@ -7,7 +7,7 @@ TARGET = class
INCLUDE =
SWIGOPT =
CFLAGS =
VARIANT = _csc
VARIANT =
# uncomment the following lines to build a static exe (only pick one of the CHICKEN_MAIN lines)
#CHICKEN_MAIN = test-lowlevel-class.scm

View file

@ -64,8 +64,9 @@
(display "\nGuess I'll clean up now\n")
;; Note: this invokes the virtual destructor
(delete-Shape c)
(delete-Shape s)
(set! c #f)
(set! s #f)
(gc #t)
(set! s 3)
(display (Shape-nshapes))

View file

@ -20,7 +20,7 @@
;; ----- Access a static member -----
(display "\nA total of ")
(display (nshapes))
(display (Shape-nshapes))
(display " shapes were created\n")
;; ----- Member data access -----
@ -67,9 +67,9 @@
;; Note: Invoke the virtual destructors by forcing garbage collection
(set! c 77)
(set! s 88)
;(gc #t)
(gc #t)
(display (nshapes))
(display (Shape-nshapes))
(display " shapes remain\n")
(display "Goodbye\n")

View file

@ -1,8 +1,6 @@
;; run with './constants test-constants.scm'
;; feel free to uncomment and comment sections
(load-library 'example "constants.so")
(declare (uses example))
(load-library 'example "./constants.so")
(display "starting test ... you will see 'finished' if successful.\n")
(or (= (ICONST) 42) (exit 1))

View file

@ -2,7 +2,6 @@
;; feel free to uncomment and comment sections
(load-library 'example "multimap.so")
(declare (uses example))
(display "(gcd 90 12): ")
(display (gcd 90 12))

View file

@ -1,8 +1,6 @@
;; This file demonstrates the overloading capabilities of SWIG
(load-library 'example "overload.so")
(declare (uses example))
(declare (uses tinyclos))
;; Low level
;; ---------
@ -40,7 +38,7 @@ Trying TinyCLOS code ...
(foo 1)
(foo "some string")
(define A-FOO (make <Foo>))
(define ANOTHER-FOO (make <Foo> (slot-ref A-FOO 'swig-this))) ;; copy constructor
(define ANOTHER-FOO (make <Foo> A-FOO)) ;; copy constructor
(bar A-FOO 2)
(bar ANOTHER-FOO "another string" 3)

View file

@ -8,6 +8,6 @@
extern double My_variable;
extern int fact(int);
%name(mod) extern int my_mod(int n, int m);
%rename(mod) my_mod;
extern int my_mod(int n, int m);
extern char *get_time();

View file

@ -1,6 +1,5 @@
;; feel free to uncomment and comment sections
(load-library 'example "simple.so")
(declare (uses example))
(display "(My-variable): ")
(display (My-variable))
@ -14,31 +13,14 @@
(display (My-variable))
(display "\n")
(display "(My-variable 'a): ")
;;(display (My-variable 'a))
(display "\n")
(display "(My-variable 1.5 'b): ")
(display (My-variable 1.5 'b))
(display "\n")
(display "(fact 5): ")
(display (fact 5))
(display "\n")
(display "(fact 'a): ")
;;(display (fact 'a))
(display "\n")
(display "(mod 75 7): ")
(display (mod 75 7))
(display "\n")
(display "(my-mod 75 7): ")
(display (my-mod 75 7))
(display "\n")
(display "(get-time): ")
(display (get-time))
(display "\n")

View file

@ -5,27 +5,24 @@ SRCS =
CXXSRCS =
TARGET = zlib
INCLUDE =
SWIGOPT = -I/usr/include -mixed -prefix zlib
SWIGOPT = -I/usr/include
CFLAGS =
VARIANT =
LIBS = -lz
# comment out the following two lines to build a dynamic exe
CHICKEN_MAIN = test-zlib.scm
VARIANT = _static
VARIANT = _direct
all:: $(TARGET)
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)
clean::
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm example-generic.scm example-clos.scm
rm -f example.scm
rm -f $(TARGET)
check::
csi -batch simple.so test-zlib.scm
csi test-zlib.scm

View file

@ -1,45 +1,43 @@
;; run with './zlib test-zlib.scm'
(declare (uses example))
(declare (uses format))
(load-library 'example "./zlib.so")
;; Init zstream
(define s (zlib:new-z-stream))
(zlib:z-stream-zalloc-set s #f)
(zlib:z-stream-zfree-set s #f)
(zlib:z-stream-opaque-set s #f)
(zlib:deflate-init s (zlib:z-default-compression))
(define s (new-z-stream))
(z-stream-zalloc-set s #f)
(z-stream-zfree-set s #f)
(z-stream-opaque-set s #f)
(deflate-init s (Z-DEFAULT-COMPRESSION))
;; Deflate something small so we don't need to loop/stream data
(define in "some pony et jumping et jack et flash et had a jack pony")
(define out (make-string 1000))
(format #t "to be compressed: ~A~%to be compressed bytes: ~D~%~%" in (string-length in))
(zlib:z-stream-next-in-set s in)
(zlib:z-stream-avail-in-set s (string-length in))
(zlib:z-stream-next-out-set s out)
(zlib:z-stream-avail-out-set s (string-length out))
(printf "to be compressed: ~A~%to be compressed bytes: ~A~%~%" in (string-length in))
(z-stream-next-in-set s in)
(z-stream-avail-in-set s (string-length in))
(z-stream-next-out-set s out)
(z-stream-avail-out-set s (string-length out))
(let*
((saved-out (zlib:z-stream-save-next-out s))
(ret (zlib:deflate s (zlib:z-finish))))
((saved-out (z-stream-save-next-out s))
(ret (deflate s (Z-FINISH))))
(cond
((= ret (zlib:z-stream-end))
(format #t "deflated properly!~%compressed bytes: ~D~%compressed stream: ~S~%"
(zlib:z-stream-total-out-get s) (zlib:z-stream-get-next-chunk s saved-out)))
((= ret (zlib:z-ok))
((= ret (Z-STREAM-END))
(printf "deflated properly!~%compressed bytes: ~A~%compressed stream: ~A~%"
(z-stream-total-out-get s) (z-stream-get-next-chunk s saved-out)))
((= ret (Z-OK))
(display "only partial deflation ... not enough output space\n"))
(else
(format #t "deflate error(~D): ~A ~%" ret (zlib:z-stream-msg-get s)))))
(printf "deflate error(~D): ~A ~%" ret (z-stream-msg-get s)))))
;; Use simple compress routine, and set max output size to 100
(define c (zlib:compress 100 in))
(define c (compress 100 in))
(newline)
(let
((ret (car c))
(compressed (cadr c)))
(cond
((= ret (zlib:z-ok))
(format #t "compressed properly!~%compressed bytes: ~D~%compressed stream: ~S~%"
((= ret (Z-OK))
(printf "compressed properly!~%compressed bytes: ~A~%compressed stream: ~A~%"
(string-length compressed) compressed))
(else
(format #t "compress error(~D): ~A ~%" ret (zlib:z-error ret)))))
(printf "compress error(~D): ~A ~%" ret (z-error ret)))))
(exit 0)