diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-10-10 23:19:32 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-10-10 23:19:32 -0700 |
commit | 46a525574121efd4e2ad5d1420d2ba11a67e9a1c (patch) | |
tree | d93fc659d63ed70b9ea5f75b0ebe24a40f5bb1a9 | |
parent | c68ee2c432758a6fde0b79afbb0fdcc7db628a7b (diff) | |
download | txr-46a525574121efd4e2ad5d1420d2ba11a67e9a1c.tar.gz txr-46a525574121efd4e2ad5d1420d2ba11a67e9a1c.tar.bz2 txr-46a525574121efd4e2ad5d1420d2ba11a67e9a1c.zip |
Struct finalizers should be registered first.
* share/txr/stdlib/struct.tl (defstruct): Rearrange the
generated instance initialization function so that if a :fini
block was specified, it is performed first. Thus if the
remaining initialization code is abandoned, it is possible to
intercept that and invoke the finalizer, which can clean
up any mess left behind.
* txr.1: Document changed order.
-rw-r--r-- | share/txr/stdlib/struct.tl | 26 | ||||
-rw-r--r-- | txr.1 | 4 |
2 files changed, 15 insertions, 15 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl index dcfcc864..7213d9eb 100644 --- a/share/txr/stdlib/struct.tl +++ b/share/txr/stdlib/struct.tl @@ -121,19 +121,19 @@ (static-slot-set ,arg-sym ',@2 ,@3))) stat-si-forms))) ,(if (or inst-si-forms instance-init-form instance-fini-form) - ^(lambda (,arg-sym) - ,*(if inst-si-forms - ^((let ((,type-sym (struct-type ,arg-sym))) - ,*(mapcar (aret ^(unless (static-slot-p ,type-sym ',@2) - (slotset ,arg-sym ',@2 ,@3))) - inst-si-forms)))) - ,*(if (cdr instance-init-form) - ^((let ((,(car instance-init-form) ,arg-sym)) - ,*(cdr instance-init-form)))) - ,*(if (cdr instance-fini-form) - ^((finalize ,arg-sym (lambda (,(car instance-fini-form)) - ,*(cdr instance-fini-form)) - t))))) + ^(lambda (,arg-sym) + ,*(if (cdr instance-fini-form) + ^((finalize ,arg-sym (lambda (,(car instance-fini-form)) + ,*(cdr instance-fini-form)) + t))) + ,*(if inst-si-forms + ^((let ((,type-sym (struct-type ,arg-sym))) + ,*(mapcar (aret ^(unless (static-slot-p ,type-sym ',@2) + (slotset ,arg-sym ',@2 ,@3))) + inst-si-forms)))) + ,*(if (cdr instance-init-form) + ^((let ((,(car instance-init-form) ,arg-sym)) + ,*(cdr instance-init-form)))))) ,(when args (when (> (countql : args) 1) (throwf 'eval-error "~s: multiple colons in boa syntax" @@ -18025,8 +18025,8 @@ a finalization function which is associated with the structure instance, as if by use of the .code finalize function. This finalization registration takes place -as the last step when an instance of the structure -is created, after the slots are initialized and +as the first step when an instance of the structure +is created, before the slots are initialized and the .code :init code, if any, has been executed. The registration |