Debian Codegraph @

src/tests/normal-tests/mixed.lsp

raw
1 ;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
3
4 ;;;; Contains: Various regression tests for ECL
5
6 (in-package :cl-test)
7
8 (suite 'mixed)
9
10
11 ;;; (EXT:PACKAGE-LOCK) returned the wrong value.
12 ;;; Fixed in 77a267c7e42860affac8eddfcddb8e81fccd44e5
13
14 (test mix.0001.package-lock
15 ;; Don't know the first state
16 (ext:package-lock "CL-USER" nil)
17 (is-false (ext:package-lock "CL-USER" t))
18 (is-true (ext:package-lock "CL-USER" nil))
19 (is-false (ext:package-lock "CL-USER" nil)))
20
21
22 ;; Bugs from sourceforge
23
24 (test mix.0002.mvb-not-evaled
25 (is (eq :ok (block nil
26 (tagbody
27 (return (multiple-value-bind ()
28 (go :fail) :bad))
29 :fail
30 (return :ok))))))
31
32
33
34 (ext:with-clean-symbols (foo)
35 (declaim (ftype (function (cons) t) foo)
36 (ftype (function (t cons) t) (setf foo)))
37
38 (defun foo (cons)
39 (first cons))
40
41 (defun (setf foo) (value cons)
42 (setf (first cons) value))
43
44 (test mix.0003.declaim-type
45 (let ((*bar* (cons 'x 'y)))
46 (is (eq (foo *bar*) 'x))
47 (is (eq (setf (foo *bar*) 'z) 'z) "signals on error:
48 ;; Z is not of type CONS.
49 ;; [Condition of type TYPE-ERROR]"))))
50
51
52
53 (test mix.0004.style-warning-argument-order
54 (let ((warning nil))
55 (is (eq :ok
56 (handler-bind
57 ((style-warning
58 (lambda (c)
59 (format t "got style-warning: ~s~%" c)
60 (setf warning c))))
61 (block nil
62 (tagbody
63 (return (multiple-value-bind () (go :fail) :bad))
64 :fail
65 (return :ok))))))
66 (is-false warning)))
67
68 (test mix.0005.write-hash-readable
69 (is (= (hash-table-count
70 (read-from-string
71 (write-to-string (make-hash-table)
72 :readably t))))))
73
74 (test mix.0006.find-package
75 (is
76 (let ((string ":cl-user"))
77 (find-package
78 (let ((*package* (find-package :cl)))
79 (read-from-string string)))))
80 (is
81 (let ((string ":cl-user"))
82 (let ((*package* (find-package :cl)))
83 (find-package
84 (read-from-string string))))))
85
86
87
88 ;;; Date: 2016-05-21 (Masataro Asai)
89 ;;; Description:
90 ;;;
91 ;;; RESTART-CASE investigates the body in an incorrect manner,
92 ;;; then remove the arguments to SIGNAL, which cause the slots of
93 ;;; the conditions to be not set properly.
94 ;;;
95 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/247
96 ;;;
97 (ext:with-clean-symbols (x)
98 (define-condition x () ((y :initarg :y)))
99 (test mix.0007.restart-case-body
100 (is-false (handler-bind ((x (lambda (c) (slot-value c 'y))))
101 (restart-case
102 (signal 'x :y 1))))))
103
104
105 ;;; Date: 2016-04-21 (Juraj)
106 ;;; Fixed: 2016-06-21 (Daniel Kochmański)
107 ;;; Description:
108 ;;;
109 ;;; Trace did not respect *TRACE-OUTPUT*.
110 ;;;
111 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/236
112 ;;;
113 (ext:with-clean-symbols (fact)
114 (defun fact (n) (if (zerop n) :boom (fact (1- n))))
115 (test mix.0008.trace-output
116 (is
117 (not (zerop
118 (length
119 (with-output-to-string (*trace-output*)
120 (trace fact)
121 (fact 3)
122 (untrace fact)
123 *trace-output*)))))))
124
125
126 ;;;; Author: Daniel Kochmański
127 ;;;; Created: 2015-09-21
128 ;;;; Contains: Random state tests
129 (test mix.0009.random-states
130 (is (numberp (random 18)) "Can't generate trivial random number")
131 (is (numberp (random 18 #$1))
132 "Can't generate a number from read (#$1) random state")
133 (is (numberp (random 18 (make-random-state)))
134 "Can't generate a number from a new random state")
135 (is (numberp (random 18 (make-random-state #$1)))
136 "Can't generate a number from a new random state from reader")
137 (is (= (random 18 #$1)
138 (random 18 #$1)
139 (random 18 #$1))
140 "The same seed produces different results")
141 (is (let ((*print-readably* t)
142 (rs (make-random-state #$1)))
143 (equalp
144 (prin1-to-string #$1)
145 (prin1-to-string rs)))
146 "The same seed gives different random states")
147 (is (let* ((*print-readably* t)
148 (rs (make-random-state #$1))
149 (rs-read (read-from-string
150 (prin1-to-string rs))))
151 (equalp
152 (prin1-to-string rs-read)
153 (prin1-to-string rs)))
154 "Can't read back a random state"))
155
156
157 ;;; Date: 2016-08-04 (jd)
158 ;;; Fixed: 2016-08-04 (jd)
159 ;;; Description:
160 ;;;
161 ;;; file-stream-fd caused internal error if fed with non-file ANSI
162 ;;; stream
163 ;;;
164 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/271
165 ;;;
166 (test mix.0010.file-stream-fd
167 (signals type-error (ext:file-stream-fd ""))
168 (signals type-error (ext:file-stream-fd (make-string-output-stream))))
169
170
171 ;;; Date: 2016-12-20
172 ;;; Reported by: Kris Katterjohn
173 ;;; Fixed: Daniel Kochmański
174 ;;; Description:
175 ;;;
176 ;;; atan signalled `division-by-zero' exception when the second
177 ;;; argument was signed zero. Also inconsistent behavior on invalid
178 ;;; operation (atan 0.0 0.0).
179 ;;;
180 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/329
181 (test mix.0012.atan-signed-zero
182 (finishes (atan 1.0 -0.0)))
183
184
185 ;;; Date: 2016-12-21
186 ;;; Description:
187 ;;;
188 ;;; `sleep' uses `ECL_WITHOUT_FPE_BEGIN' which didn't restore fpe
189 ;;; correctly.
190 ;;;
191 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/317
192 #+floating-point-exceptions
193 (test mix.0013.sleep-without-fpe
194 (sleep 0.1)
195 (let ((a 1.0)
196 (b 0.0))
197 ;; nb: normally operation signals `division-by-zero', but OSX
198 ;; signals `floating-point-overflow'. It's OK I suppose.
199 (signals arithmetic-error (/ a b))))
200
201
202 ;;; Date: 2017-01-20
203 ;;; Description:
204 ;;;
205 ;;; `dolist' macroexpansion yields result which doesn't have a
206 ;;; correct scope.
207 ;;;
208 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/348
209 (test mix.0014.dolist
210 (is-false
211 (nth-value 1
212 (compile nil
213 (lambda ()
214 (dolist (s '("foo" "bar" "baz") s)
215 (declare (type string s))
216 (check-type s string)
217 (format nil "~s" s))))))
218 (finishes (eval '(dolist (e '(1 2 3 4) e)
219 (print e)
220 (go :next)
221 (print 'skip)
222 :next))))
223
224
225 ;;; Date: 2017-07-02
226 ;;; Description:
227 ;;;
228 ;;; Function `ecl_new_binding_index' called `si_set_finalizer',
229 ;;; which resetted `env->nvalues' leading to invalid binding in mvb
230 ;;; during the first function run.
231 ;;;
232 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/233
233 (test mix.0015.mvb
234 (with-compiler ("aux-cl-0003.lsp" :load t)
235 `(progn
236 (defvar mix.0015.v1 'booya)
237 (defun mix.0015.fun ()
238 (let ((share_t))
239 (multiple-value-bind (mix.0015.v1 woops)
240 (case share_t
241 ((nil)
242 (values 1 2)))
243 woops)))))
244 (ignore-errors
245 (delete-file "aux-cl-0003.lsp")
246 (delete-file "aux-cl-0003.fas")
247 (delete-file "aux-cl-0003.fasc"))
248 (is-eql 2 (mix.0015.fun)))
249
250 ;;; Date: 2018-05-08
251 ;;; Description:
252 ;;;
253 ;;; Better handling of fifos.
254 ;;;
255 ;;; Bug: https://gitlab.com/embeddable-common-lisp/ecl/issues/242
256 #-windows
257 (test mix.0016.fifo-tests
258 (ext:run-program "mkfifo" '("my-fifo") :output t)
259 ;; 1) reader (first) and writer (inside)
260 (with-open-file (stream "my-fifo" :nonblock t)
261 (is (null (file-length stream)))
262 (is (null (listen stream)))
263 (is (eql :foo (read-line stream nil :foo)))
264 (is (eql :fifo (ext:file-kind stream nil)))
265 (with-open-file (stream2 "my-fifo" :direction :output :nonblock t)
266 ;; Even for output it should not block on Unix.
267 (finishes (write-line "foobar" stream2)))
268 ;; there is nobody on the other side, data is lost
269 (is (equal :foo (read-line stream nil :foo))))
270 ;; 2) writer (first) and reader (second)
271 (signals file-error (open "my-fifo" :direction :output :nonblock t))
272 (with-open-file (stream "my-fifo" :direction :input :nonblock t)
273 (is (eql :foo (read-line stream nil :foo))))
274 ;; clean up
275 (delete-file "my-fifo"))
276
277
278 ;;; Date: 2018-12-02
279 ;;; Description:
280 ;;;
281 ;;; Serialization/Deserialization tests
282 #+externalizable
283 (test mix.0017.serialization
284 (let* ((vector (make-array 4 :element-type 'ext:byte16 :initial-contents #(1 2 3 4)))
285 (object-table
286 ;; vector of (object . compare-function)
287 (vector '(nil . eql) ; empty list
288 '('(1 2) . equalp) ; non-empty list
289 '(#\q . eql) ; character
290 '(42 . eql) ; fixnum
291 (cons (+ 10 most-positive-fixnum) 'eql) ; bignum
292 '(2/3 . eql) ; ratio
293 '(12.3f4 . eql) ; floats
294 '(13.2d4 . eql)
295 '(14.2l3 . eql)
296 '(#c(4 7) . eql) ; complexes
297 '(#c(1.0f0 2.0f0) . eql)
298 '(#c(1.0d0 2.0d0) . eql)
299 '(#c(1.0l0 2.0l0) . eql)
300 '(#.(find-package "COMMON-LISP-USER") . eq) ; package
301 '(q . eql) ; symbol
302 ;; hash-table
303 (cons (let ((ht (make-hash-table)))
304 (setf (gethash :foo ht) :abc)
305 (setf (gethash :bar ht) :def)
306 ht)
307 #'(lambda (x y)
308 (loop for key being the hash-keys of x
309 if (not (eq (gethash key x)
310 (gethash key y)))
311 return nil
312 finally (return t))))
313 ;; array
314 (cons (let ((a (make-array '(2 2) :initial-element 0)))
315 (setf (aref a 0 0) 'q)
316 (setf (aref a 0 1) 1/5)
317 a)
318 'equalp)
319 (cons vector 'equalp) ; non-displaced vector
320 ;; displaced vector
321 (cons (make-array 3 :element-type 'ext:byte16
322 :displaced-to vector
323 :displaced-index-offset 1)
324 #'(lambda (x y)
325 (and (equalp x y)
326 (equalp (multiple-value-list (array-displacement x))
327 (multiple-value-list (array-displacement y))))))
328 '("a∩b∈c" . equal) ; string
329 (cons (make-string 3 :initial-element #\q :element-type 'base-char) 'equal) ; base-string
330 (cons (make-array 6 :element-type 'bit :initial-contents #(0 1 0 1 1 0)) 'equal) ; bit-vector
331 ;; stream: not externalizable?
332 ;; random-state
333 (cons (let ((r (make-random-state)))
334 (random 10 r)
335 r)
336 'equalp)
337 ;; readtable: not externalizable
338 '(#P"/foo/bar/whatever.gif" . equal) ; pathname
339 ;; TODO: other objects
340 ))
341 (to-be-serialized
342 (map 'vector #'first object-table))
343 (deserialized (si::deserialize (si::serialize to-be-serialized))))
344 (is-true (= (length to-be-serialized) (length deserialized)))
345 (loop for i below (length to-be-serialized)
346 do (is-true (funcall (cdr (elt object-table i))
347 (elt to-be-serialized i)
348 (elt deserialized i))))))
349
350 ;;; Date: 2019-12-26
351 ;;; Description:
352 ;;;
353 ;;; Stack overflow detection and recovery
354 (test mix.0018.stack-overflow
355 (signals ext:stack-overflow (labels ((f (x) (f (1+ x))))
356 (f 1))))
357
358 ;;; Date 2020-04-22
359 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/merge_requests/197
360 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/576
361 ;;; Description:
362 ;;;
363 ;;; Ensure that with-input-from-string and with-output-to-string
364 ;;; close the streams that they provide.
365 (test mix.0019.with-string-io-close-streams
366 (let (stream-var)
367 (with-input-from-string (inner-stream-var "test")
368 (setf stream-var inner-stream-var)
369 (is (open-stream-p stream-var)))
370 (is (not (open-stream-p stream-var)))
371 (with-output-to-string (inner-stream-var)
372 (setf stream-var inner-stream-var)
373 (is (open-stream-p stream-var)))
374 (is (not (open-stream-p stream-var)))))
375
376 ;;;; Author: Tarn W. Burton
377 ;;;; Created: 2021-06-05
378 ;;;; Contains: *ed-functions* tests
379 (test mix.0020.ed-functions
380 (let ((ext:*ed-functions* (list (lambda (x)
381 (equal x "foo"))
382 (lambda (x)
383 (equal x "bar"))
384 (lambda (x)
385 (when (equal x "baz")
386 (error 'file-error :pathname x))))))
387 (is (ed "foo"))
388 (is (ed "bar"))
389 (signals simple-error (ed "qux"))
390 (signals file-error (ed "baz"))))
391
392 ;;;; Author: Tarn W. Burton
393 ;;;; Created: 2021-12-21
394 ;;;; Contains: pretty printer tests for real valued columns
395 (defclass pp-stream-test (gray:fundamental-character-output-stream)
396 ((column :accessor gray:stream-line-column
397 :initform (random .5))
398 (value :accessor pp-stream-test-value
399 :initform (make-array 10 :adjustable t :fill-pointer 0
400 :element-type 'character))))
401 (defmethod gray:stream-write-char ((stream pp-stream-test) char)
402 (if (eql char #\Newline)
403 (setf (gray:stream-line-column stream) (random .5))
404 (incf (gray:stream-line-column stream)))
405 (vector-push-extend char (pp-stream-test-value stream)))
406 (test mix.0021.pretty-printer
407 (let ((stream (make-instance 'pp-stream-test))
408 (*print-right-margin* 15))
409 (pprint '(let ((fu 1) (bar 2)) (+ fu bar 7))
410 stream)
411 (is-eql (sys:file-column stream) 15)
412 (is (gray:stream-advance-to-column stream 20))
413 (write-char #\A stream)
414 (is-equal (pp-stream-test-value stream)
415 "
416 (LET ((FU 1)
417 (BAR 2))
418 (+ FU BAR 7)) A")))
419
420 ;; Created: 2022-04-27
421 ;; Contains: a smoke test for a new operator si:adjust-vector
422 (test mix.0022.adjust-vector
423 (let ((vector (si:make-vector t 10 t nil nil nil)))
424 (si:adjust-vector vector 20)
425 (is (= 20 (array-total-size vector)))))
426
427 ;;; Created: 2022-11-10
428 ;;; Contains: tests for the logarithm of very small or very large
429 ;;; numbers where the number coerced to a single-float is 0 or
430 ;;; infinity but its logarithm can be represented as a finite
431 ;;; single-float.
432 (test mix.0023.log-floating-point-overflow
433 (let ((x (ash 1 1024)))
434 (finishes (log x))
435 (finishes (log (- x)))
436 (finishes (log (/ 1 x)))
437 (finishes (log (- (/ 1 x))))))
438
439 ;;; Created: 2023-01-02
440 ;;; Contains: tests checking that (log x y) does not unnecessarily
441 ;;; lose precision through intermediate single-float calculations when
442 ;;; the final result is a double or long float.
443 (test mix.0024.log-loss-of-precision
444 (is (eql (log 2 2d0) 1d0))
445 (is (eql (realpart (log -2 2d0)) 1d0))
446 (is (eql (log (ash 1 1024) 2d0) 1024d0))
447 (is (eql (realpart (log (- (ash 1 1024)) 2d0)) 1024d0))
448 (is (eql (log 1/2 2d0) -1d0))
449 (is (eql (realpart (log -1/2 2d0)) -1d0))
450 (is (eql (log 2s0 2d0) 1d0))
451 (is (eql (realpart (log -2s0 2d0)) 1d0))
452
453 (is (eql (log 2 2l0) 1l0))
454 (is (eql (realpart (log -2 2l0)) 1l0))
455 (is (eql (log (ash 1 1024) 2l0) 1024l0))
456 (is (eql (realpart (log (- (ash 1 1024)) 2l0)) 1024l0))
457 (is (eql (log 1/2 2l0) -1l0))
458 (is (eql (realpart (log -1/2 2l0)) -1l0))
459 (is (eql (log 2s0 2l0) 1l0))
460 (is (eql (realpart (log -2s0 2l0)) 1l0))
461 (is (eql (log 2d0 2l0) 1l0))
462 (is (eql (realpart (log -2d0 2l0)) 1l0)))
463
464 ;;; Created: 2023-01-07
465 ;;; Contains: tests checking for illegal format parameters that occur
466 ;;; after at signs or colons.
467 (test mix.0025.illegal-format-parameters
468 (signals error (format nil "a~@4A" nil))
469 (signals error (format nil "a~:4A" nil))
470 (signals error (format nil "a~:@4A" nil))
471 (signals error (format nil "a~@:4A" nil))
472 (is (equal (format nil "a~4@A" nil) "a NIL"))
473 (is (equal (format nil "a~4:A" nil) "a() "))
474 (is (equal (format nil "a~4:@A" nil) "a ()"))
475 (is (equal (format nil "a~4@:A" nil) "a ()")))
476
477 ;;; Created: 2023-01-16
478 ;;; Contains: tests checking that listen returns nil if we are at the
479 ;;; end of a file
480 (test mix.0026.file-listen
481 (is (equal (progn
482 (with-open-file (blah "nada.txt" :direction :output
483 :if-does-not-exist :create
484 :if-exists :supersede)
485 (write-char #\a blah))
486 (with-open-file (blah "nada.txt" :direction :input)
487 (list (listen blah)
488 (read-char blah)
489 (listen blah))))
490 (list t #\a nil))))
491
492 ;;; Created: 2023-02-20
493 ;;; Contains: test to look for NIL in format directive forms.
494 ;;;
495 ;;; Simple LOOP requires only compound forms. Hence NIL is not
496 ;;; permitted. Some FORMAT directives (like newline) return NIL
497 ;;; as the form when they have nothing to add to the body.
498 ;;; Normally this is fine since BLOCK accepts NIL as a form. On
499 ;;; the other hand, when the newline directive is inside of an
500 ;;; iteration directive this will produce something like
501 ;;; (LOOP (fu) nil (bar)) which is not acceptable. To verify
502 ;;; that this is not happening we make sure we are not getting
503 ;;; (BLOCK NIL NIL) since this is easier to test for.
504 (test mix.0027.format-no-nil-form
505 (is (equal (third (second (macroexpand-1 '(formatter "~
506 "))))
507 '(block nil))))
508
509 ;;; Created: 2023-12-04 Gray stream proposal is a bit ambiguous about
510 ;;; the return value of STREAM-READ-LINE. The return from this
511 ;;; generic function is described as "A string is returned as the
512 ;;; first value. The second value is true if the string was terminated
513 ;;; by end-of-file instead of the end of a line." A literal reading of
514 ;;; this indicates that an EOF with no newline should be returned as
515 ;;; (VALUES "" T) which is what the default method in the proposal
516 ;;; does. The following tests ensure that the default Gray method's
517 ;;; returns are understood by CL:READ-LINE.
518 (require :gray-streams)
519
520 (defclass character-input-stream
521 (gray:fundamental-character-input-stream)
522 ((value :reader value
523 :initarg :value)
524 (index :accessor index
525 :initform 0)))
526
527 (defmethod gray:stream-read-char ((stream character-input-stream))
528 (with-accessors ((value value)
529 (index index))
530 stream
531 (if (< index (length value))
532 (prog1 (char value index)
533 (incf index))
534 :eof)))
535
536 (defmethod gray:stream-unread-char ((stream character-input-stream) character)
537 (with-accessors ((value value)
538 (index index))
539 stream
540 (when (zerop index)
541 (error "Stream is at beginning, cannot unread character"))
542 (when (char/= character (char value (decf index)))
543 (error "Cannot unread a character that does not match."))
544 nil))
545
546 (test mix.0028.read-line-eof
547 (signals end-of-file
548 (read-line (make-instance 'character-input-stream :value ""))))
549
550 (test mix.0029.read-line-eof
551 (is (equal (multiple-value-list (read-line (make-instance 'character-input-stream :value "") nil :wibble))
552 '(:wibble t))))
553
554 (test mix.0029.read-line-eof
555 (is (equal (multiple-value-list (read-line (make-instance 'character-input-stream :value "a
556 ")))
557 '("a" nil))))
558
559 ;;;; Author: Tarn W. Burton
560 ;;;; Created: 2024-05-10
561 ;;;; Description:
562 ;;;; Test to ensure that write-char returns the correct value. An
563 ;;;; incorrect value or stack smashing indicated a buffer overrun
564 ;;;; caused by an encoding buffer that is too small.
565
566 (test mix.0030.write-char-encode-buffer
567 (is (equal (with-open-file (s "/tmp/whatever.txt"
568 :if-does-not-exist :create
569 :if-exists :supersede
570 :external-format :ucs-4
571 :direction :output)
572 (write-char #\a s))
573 #\a)))
574
575 ;;;; Reported by: Charles Zhang
576 ;;;; Fixed: Daniel Kochmański
577 ;;;; Created: 2024-05-12
578 ;;;; Issue: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/742
579 ;;;; Description:
580 ;;;; Test to ensure that defining a no-op non-terminating macro on a digit
581 ;;;; does not break readers for composite tokens like #x123. See #742.
582 (test mix.0031.redefine-digit
583 (let ((standard-readtable (copy-readtable nil))
584 (*readtable* (copy-readtable nil)))
585 (set-macro-character #\1 (lambda (stream char)
586 (unread-char char stream)
587 (let ((*readtable* standard-readtable))
588 (read stream t nil t)))
589 t)
590 (finishes (read-from-string "#x123"))))
591
592 ;;; Author: Daniel Kochmański
593 ;;; Created: 2025-05-09
594 ;;; Issue: https://gitlab.com/embeddable-common-lisp/ecl/-/merge_requests/346#note_2492489716
595 ;;; Description
596 ;;;
597 ;;; Moving locals from heap to the stack revealed an issue where stack
598 ;;; frames are invalidated after the lisp stack is resized. That causes
599 ;;; a risk of local variables to be garbage collected.
600 ;;;
601 ;;; | Call DO-ENTRIES* | #x1000 [TRASH] | #x1000 [TRASH] |
602 ;;; | Resize the stack | #x1000 [TRASH] | #x2000 [TRASH] |
603 ;;; | Bind a local var | #x1000 [value] | #x2000 [TRASH] |
604 ;;; | Allocations-> GC | #x1000 [what?] | #x2000 [TRASH] |
605 ;;; | Load a local var | #x1000 [what?] | #x2000 [TRASH] |
606 ;;;
607 ;;; We bind the variable after the stack has been resized, so when we copy the
608 ;;; memory during the stack resize only [TRASH] is transferred.
609 ;;;
610 ;;; Since the lisp stack is allocated with ecl_alloc_atomic, referenced values must
611 ;;; be explicitly marked -- and it is done so in ecl_mark_env. This is very sane
612 ;;; thing to do, because if we had marked whole vector (even above top), then we'd
613 ;;; retain old references, and generally we'd mark 32K instead of say 200 addresses.
614 ;;;
615 ;;; But, when we grow the stack, the old vector is replaced, and ecl_mark_env does
616 ;;; not mark the old stack, effectively allowing to reuse up our [value] by GC.
617 ;;;
618 ;;; Note that usually stack frames are filled eagerly to complete argument list, so
619 ;;; this issue is irrelevant to them (because we don't change values after resize),
620 ;;; so this prolbem did not manifest itself until now.
621
622 (deftest mix.0031.invalidate-stack-frames ()
623 (macrolet ((ntimes (n form)
624 `(progn ,@(make-list n :initial-element form))))
625 (labels ((resize-lisp-stack ()
626 (let* ((old-limit (ext:get-limit 'ext:lisp-stack))
627 (new-limit (* old-limit 2)))
628 (ext:set-limit 'ext:lisp-stack new-limit)))
629 (invoke-test-case ()
630 (resize-lisp-stack)
631 (let ((n 0))
632 (ntimes 2048 (apply #'append (make-list 2048 :initial-element '(:foo))))
633 (is (typep n 'number)))))
634 (invoke-test-case))))
635
636 ;;; Reported by: Artyom Bologov
637 ;;; Created: 2025-06-26
638 ;;; Issue: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/784
639 ;;; Description
640 ;;;
641 ;;; When working with multiple wild components in the directory we've
642 ;;; entered an infinite recursion becaue find_list_wildcards created a
643 ;;; circular list due to invalid interfacing with find_wildcards.
644 ;;;
645 ;;; Moreover, for a similar cause, we didn't translate correctly such
646 ;;; pathnames even after fixing the issue. copy_wildcards did not anticipate
647 ;;; that for a :WILD component the result could a list from find_wildcards.
648 (deftest mix.0032.logical-pathname-with-multiple-wildcards ()
649 (setf (logical-pathname-translations "x")
650 `(("X:a;*;b;*;*.*" "/hello/*/hi/*/what/*.*")))
651 ;; We don't use #P"x:a;bonjour;b;barev;greetings.me" because then the reader
652 ;; constructs the pathname before the logical pathname translation is defined
653 ;; - in that case it is not recognized as logical and won't be translated.
654 (let* ((pathname (parse-namestring "x:a;bonjour;b;barev;greetings.me"))
655 (result (translate-logical-pathname pathname))
656 (expect #P"/hello/bonjour/hi/barev/what/greetings.me"))
657 (is (equalp result expect))))