diff --git a/Makefile b/Makefile index 43369c08..632ac3fd 100644 --- a/Makefile +++ b/Makefile @@ -144,6 +144,9 @@ include/chibi/install.h: Makefile sexp.o: sexp.c gc.c opt/bignum.c $(INCLUDES) Makefile $(CC) -c $(XCPPFLAGS) $(XCFLAGS) $(CLIBFLAGS) -o $@ $< +sexp-ulimit.o: sexp.c gc.c opt/bignum.c $(INCLUDES) Makefile + $(CC) -c $(XCPPFLAGS) $(XCFLAGS) $(CLIBFLAGS) -DSEXP_USE_LIMITED_MALLOC -o $@ $< + eval.o: eval.c opcodes.c vm.c opt/simplify.c $(INCLUDES) include/chibi/eval.h Makefile $(CC) -c $(XCPPFLAGS) $(XCFLAGS) $(CLIBFLAGS) -o $@ $< @@ -162,6 +165,9 @@ chibi-scheme$(EXE): main.o libchibi-scheme$(SO) chibi-scheme-static$(EXE): main.o eval.o sexp.o $(CC) $(XCFLAGS) $(STATICFLAGS) -o $@ $^ $(LDFLAGS) $(GCLDFLAGS) -lm +chibi-scheme-ulimit$(EXE): main.o eval.o sexp-ulimit.o + $(CC) $(XCFLAGS) $(STATICFLAGS) -o $@ $^ $(LDFLAGS) $(GCLDFLAGS) -lm + clibs.c: $(GENSTATIC) lib lib/chibi lib/srfi chibi-scheme$(EXE) libs $(CHIBI) $< > $@ @@ -214,7 +220,7 @@ test-basic: chibi-scheme$(EXE) fi; \ done -test-memory: +test-memory: chibi-scheme-ulimit$(EXE) ./tests/memory/memory-tests.sh test-build: diff --git a/tests/memory/memory-tests.sh b/tests/memory/memory-tests.sh new file mode 100755 index 00000000..5dc69550 --- /dev/null +++ b/tests/memory/memory-tests.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +for f in tests/memory/*.scm; do + ./chibi-scheme-ulimit $f >${f%.scm}.out 2>${f%.scm}.err + if diff -q ${f%.scm}.out ${f%.scm}.res \ + && diff -q ${f%.scm}.err ${f%.scm}.err-res; then + echo "[PASS] ${f%.scm}" + rm -f ${f%.scm}.out ${f%.scm}.err + else + echo "[FAIL] ${f%.scm}" + fi +done diff --git a/tests/memory/test00-read-string.err-res b/tests/memory/test00-read-string.err-res new file mode 100644 index 00000000..5ebc44a8 --- /dev/null +++ b/tests/memory/test00-read-string.err-res @@ -0,0 +1 @@ +ERROR: out of memory diff --git a/tests/memory/test00-read-string.res b/tests/memory/test00-read-string.res new file mode 100644 index 00000000..d0b82be5 --- /dev/null +++ b/tests/memory/test00-read-string.res @@ -0,0 +1 @@ +string: "aaa... diff --git a/tests/memory/test00-read-string.scm b/tests/memory/test00-read-string.scm new file mode 100644 index 00000000..8a1ca665 --- /dev/null +++ b/tests/memory/test00-read-string.scm @@ -0,0 +1,16 @@ + +(define (show-string str) + (display "string: ") + (display (substring str 0 (min (string-length str) 4))) + (display "...\n")) + +(define str-length (inexact->exact (round (* 2 1024 1024)))) ;; 2MB +(define str1 + (let ((tmp (make-string str-length #\a))) + (string-set! tmp 0 #\") + (string-set! tmp (- str-length 1) #\") + tmp)) +(show-string str1) + +(define str2 (call-with-input-string str1 read)) +(show-string str2) diff --git a/tests/memory/test01-read-symbol.err-res b/tests/memory/test01-read-symbol.err-res new file mode 100644 index 00000000..5ebc44a8 --- /dev/null +++ b/tests/memory/test01-read-symbol.err-res @@ -0,0 +1 @@ +ERROR: out of memory diff --git a/tests/memory/test01-read-symbol.res b/tests/memory/test01-read-symbol.res new file mode 100644 index 00000000..60902799 --- /dev/null +++ b/tests/memory/test01-read-symbol.res @@ -0,0 +1 @@ +string: aaaa... diff --git a/tests/memory/test01-read-symbol.scm b/tests/memory/test01-read-symbol.scm new file mode 100644 index 00000000..c4a72e36 --- /dev/null +++ b/tests/memory/test01-read-symbol.scm @@ -0,0 +1,12 @@ + +(define (show-string str) + (display "string: ") + (display (substring str 0 (min (string-length str) 4))) + (display "...\n")) + +(define str-length (inexact->exact (round (* 2 1024 1024)))) ;; 2MB +(define str1 (make-string str-length #\a)) +(show-string str1) + +(define str2 (call-with-input-string str1 read)) +(show-string str2)