summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-04 16:20:18 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-04 16:20:18 +0200
commita4c9f5bd436dae1d99845f50da55bae733129f56 (patch)
tree22a1718222ab8d76f928cfaa4740442a4d43c1fd /util.h
parenta0b4d1eafa4312b5970f7268441d848be5231e7b (diff)
Add fixnum-aware macros LRETAIN, LRELEASE, LDESTROY, LAUTORELEASE, LASSIGN_COPY, and LASSIGN.
Diffstat (limited to 'util.h')
-rw-r--r--util.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/util.h b/util.h
index 91cd92c..fbde2b2 100644
--- a/util.h
+++ b/util.h
@@ -19,6 +19,39 @@
}
+// Read this as “Lisp ASSIGN” etc..
+#define LASSIGN(VAR, VALUE) \
+ ({ LRELEASE (VAR); VAR = VALUE; LRETAIN (VAR); })
+
+#define LASSIGN_COPY(VAR, VALUE) \
+ ({ \
+ id ___object = VALUE; \
+ LRELEASE (VAR); \
+ if (MLKInstanceP (___object)) \
+ { \
+ VAR = [___object copy]; \
+ RETAIN (VAR); \
+ } \
+ else \
+ VAR = ___object; \
+ })
+
+#define LAUTORELEASE(VALUE) \
+ ({ id __object = VALUE; \
+ MLKInstanceP (__object) ? (id)AUTORELEASE(__object) : (id)__object; })
+
+#define LDESTROY(VAR) \
+ ({ LRELEASE (VAR); VAR = nil; })
+
+#define LRELEASE(VALUE) \
+ ({ id __object = VALUE; \
+ if (__object) RELEASE(__object); })
+
+#define LRETAIN(VALUE) \
+ ({ id __object = VALUE; \
+ MLKInstanceP (__object) ? (id)RETAIN(__object) : (id)__object; })
+
+
static id nullify (id value) __attribute__ ((pure, unused));
static id denullify (id value) __attribute__ ((pure, unused));
static id stringify (id value) __attribute__ ((pure, unused));