3.6 Debugging compiled code
dynamic-extent
declarations should only affect the amount of dynamic memory used by your program. If code that containsdynamic-extent
declarations is behaving incorrectly, the declarations could be incorrect. You can check the use of dynamic-extent
declarations by disabling stack list allocation with a call to the functiondisable-stack-lists
. For example, the following two functions incorrectly declare their&rest
arguments to be stack lists; when these functions exit, the&rest
argument list structure is still accessible through the global variables*f*
and*g*
.
(compile (defun f (&rest arguments) (declare (dynamic-extent arguments) (special *f*)) (setq *f* arguments)))When stack list allocation is enabled, the program behaves incorrectly. The values of(compile (defun g (&rest arguments) (declare (dynamic-extent arguments) (special *g*)) (setq *g* arguments)))
*f*
and*g*
are undefined outside the function calls that set them. A call to the functiong
may have side effects on*f*
, even though*f*
is not explicitly manipulated by the functiong
:> (enable-stack-lists) TWhen stack list allocation is disabled, the program behaves correctly, which indicates that the program probably contains incorrect> (f 1 2 3) (1 2 3)
> *f* (1 2 3)
> (g 4 5 6 7) (4 5 6 7)
;; The results of evaluating *f* are unpredictable. > *f* (5 6 7)
> *g* (4 5 6 7)
dynamic-extent
declarations:> (disable-stack-lists) T> (f 1 2 3) (1 2 3)
> *f* (1 2 3)
> (g 4 5 6 7) (4 5 6 7)
> *f* (1 2 3)
> *g* (4 5 6 7)
Generated with Harlequin WebMaker