Subject: [clisp-list] Program stack overflow

From: "Rolf Wester" <[email-masked]>
Date: Wed Sep 5 05:10:02 2001

Hi,

I'm using CLISP on Windows NT. When running:

(defun read-file (name)
  (let ((x (make-array '(1046529) :element-type :single-float :initial-element 0.0 :fill-pointer 0 
:adjustable t))
	    (y (make-array '(1046529) :element-type :single-float :initial-element 0.0 :fill-pointer 0 
:adjustable t))
        (z (make-array '(1046529) :element-type :single-float :initial-element 0.0 :fill-pointer 0 
:adjustable t)))
       (with-open-file (in name)
	     (do ((xx (read in nil 'eof) (read in nil 'eof))
              (yy (read in nil 'eof) (read in nil 'eof))
              (zz (read in nil 'eof) (read in nil 'eof)))
			 ((eql zz 'eof)) 
             (progn (vector-push-extend xx x)
                    (vector-push-extend yy y)
                    (vector-push-extend zz z))))
         (values x y z)))
(compile 'read-file)
(setf result (multiple-value-bind (mx my mz) (read-file "big_file.txt") (list mx my mz)))
(progn
 (setq result (multiple-value-call #'list (read-file "big_file.txt")))
 nil)

on a big file (about 27 MB) I get the message:

*** - Program stack overflow. RESET
*** - Program stack overflow. RESET

and so on. With a small file everything works as expected. I originally posted this to 
comp.lang.lisp and got an answer from Sam Steingold. He wrote:

> I am pretty sure this is the printer problem: you probably have
> *print-circle* set to T or something. 

*print-circle* is set to NIL.

>try

>(progn
 >(setq result (multiple-value-call #'list (read-file "big_file.txt")))
 >nil)

I tried this but got the same error messages as before.

I would be very appreciative for help.

Rolf Wester

-------------------------------------
Rolf Wester
[email-masked]

---

From: Sam Steingold <[email-masked]>
Date: Wed Sep 5 06:16:07 2001

> * In message <3B96320E.11873.2F5FBAB2@localhost>
> * On the subject of "[clisp-list] Program stack overflow"
> * Sent on Wed, 5 Sep 2001 14:09:18 +0200
> * Honorable "Rolf Wester" <[email-masked]> writes:
>
>   (let ((x (make-array '(1046529) :element-type :single-float

:SINGLE-FLOAT is not a type.  you need 'SINGLE-FLOAT
(this is irrelevant to your problem)

> :initial-element 0.0 :fill-pointer 0 :adjustable t))

I suggest adding error checking here - use
 (vector-push-extend (float xx 1f0) x)

> *** - Program stack overflow. RESET

how many numbers are there in the file?
could you please find out what the threshold is?
just count the records as they are read and print messages "100 records
read", "1000 records read" etc.

a good way to speed up the whole thing is something like this (untested):

(defun read-file1 (name)
  (let* ((list
          (with-open-file (fi name :direction :input)
            (with-input-from-string (beg "(")
              (with-input-from-string (end ")")
                (let ((in (make-concatenated-stream beg fi end)))
                  (unwind-protect (read in)
                    (close in)))))))
         (len (ceiling (length list) 3))
         (x (make-array len))
         (y (make-array len))
         (z (make-array len)))
    (dotimes (i len (values x y z))
      (setf (aref x i) (pop list)
            (aref y i) (pop list)
            (aref z i) (pop list)))))

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
cogito cogito ergo cogito sum

---

From: Sam Steingold <[email-masked]>
Date: Fri Oct 5 08:43:03 2001

> * In message <3B965BA9.26098.3002410B@localhost>
> * On the subject of "Re: [clisp-list] Program stack overflow"
> * Sent on Wed, 5 Sep 2001 17:06:49 +0200
>   (let ((x (make-array '(1046529) :element-type 'single-float :initial-element 0.0 :fill-pointer 0 :adjustable t))
> 	    (y (make-array '(1046529) :element-type 'single-float :initial-element 0.0 :fill-pointer 0 :adjustable t))
>         (z (make-array '(1046529) :element-type 'single-float :initial-element 0.0 :fill-pointer 0 :adjustable t)))
> 	     (do ((n 0 (+ 1 n))
>               (xx (read in nil 'eof) (read in nil 'eof))
>              (progn (vector-push-extend (float xx 1f0) x)
>                     (vector-push-extend (float yy 1f0) y)
>                     (vector-push-extend (float zz 1f0) z)
> 					(print n))))
>          (values x y z)))
> (compile 'read-file)
> (progn
>    (setq result (multiple-value-call #'list (read-file "test2.txt")))
>  nil)
> 
> The last number printed before the error message was 223346. 

I can no longer reproduce this with the current CVS CLISP.

could you please be so kind as to get the CLISP sources from the CVS,
build them and try your code again?

thanks a lot!

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Life is like a diaper -- short and loaded.