summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-10 23:19:32 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-10 23:19:32 -0700
commit46a525574121efd4e2ad5d1420d2ba11a67e9a1c (patch)
treed93fc659d63ed70b9ea5f75b0ebe24a40f5bb1a9
parentc68ee2c432758a6fde0b79afbb0fdcc7db628a7b (diff)
downloadtxr-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.tl26
-rw-r--r--txr.14
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"
diff --git a/txr.1 b/txr.1
index 09220df0..911eb2f8 100644
--- a/txr.1
+++ b/txr.1
@@ -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