s-expressionists / Eclector

A portable Common Lisp reader that is highly customizable, can recover from errors and can return concrete syntax trees
https://s-expressionists.github.io/Eclector/
BSD 2-Clause "Simplified" License
108 stars 9 forks source link

READ-CST of long lists can blow the stack #43

Closed Bike closed 5 years ago

Bike commented 5 years ago

Reproducible by e.g., (eclector.concrete-syntax-tree:cst-read (make-string-input-stream (format nil "(~{~A~^ ~})" (make-list 20000 :initial-element 1)))), though of course the required size might vary.

I believe this is due to the recursion in make-cons-cst in read-cst.lisp. On Clasp, the stack trace looks like

[...]
frame #19640: 0x000000010c7beaf8 clasp`::LAMBDA^COMMON-LISP^FN^^() at read-cst.lisp:0
frame #19641: 0x000000010c7beaf8 clasp`::LAMBDA^COMMON-LISP^FN^^() at read-cst.lisp:0
frame #19642: 0x000000010c7beaf8 clasp`::LAMBDA^COMMON-LISP^FN^^() at read-cst.lisp:0
frame #19643: 0x000000010c7beaf8 clasp`::LAMBDA^COMMON-LISP^FN^^() at read-cst.lisp:0
frame #19644: 0x000000010c7be2d7 clasp`::MAKE-EXPRESSION-RESULT^ECLECTOR.PARSE-RESULT^((CST-CLIENT T T T))^METHOD^^() at read-cst.lisp:0

i.e. the make-expression-result is the last intelligible call.

Bike commented 5 years ago

With the iterative-make-cons-cst branch patch, I no longer seem to have a problem.