3.6 Debugging compiled code

3.6.3 DYNAMIC-EXTENT declarations

Usingdynamic-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)))

(compile (defun g (&rest arguments) (declare (dynamic-extent arguments) (special *g*)) (setq *g* arguments)))

When stack list allocation is enabled, the program behaves incorrectly. The values of*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)
T

> (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)

When stack list allocation is disabled, the program behaves correctly, which indicates that the program probably contains incorrectdynamic-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)


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker