summaryrefslogtreecommitdiff
path: root/src/lisp.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-01-09 08:04:36 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2015-01-09 08:22:35 -0800
commitd1f848ffb9896fe2bd8eb9e7d70a49ca9ff9522f (patch)
tree8789ccadf4cf2651edeec31aec5dc4695a399e88 /src/lisp.h
parenta749f1c648f2b9bf1a0b0b10e2da4c1c4e3d431d (diff)
downloademacs-d1f848ffb9896fe2bd8eb9e7d70a49ca9ff9522f.tar.gz
Refactor pointer-to-integer conversion
* gfilenotify.c (monitor_to_lisp, lisp_to_monitor): Rename and move to lisp.h. All uses changed. * lisp.h (XINTPTR, make_pointer_integer): New inline functions, which are renamed from gfilenotify.c's lisp_to_monitor and monitor_to_lisp, and with more-generic void * signatures.
Diffstat (limited to 'src/lisp.h')
-rw-r--r--src/lisp.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lisp.h b/src/lisp.h
index 5a4198ef683..4571c455a7b 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1112,6 +1112,25 @@ make_lisp_proc (struct Lisp_Process *p)
#define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
#define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE))
+/* Efficiently convert a pointer to a Lisp object and back. The
+ pointer is represented as a Lisp integer, so the garbage collector
+ does not know about it. The pointer should not have both Lisp_Int1
+ bits set, which makes this conversion inherently unportable. */
+
+INLINE void *
+XINTPTR (Lisp_Object a)
+{
+ return XUNTAG (a, Lisp_Int0);
+}
+
+INLINE Lisp_Object
+make_pointer_integer (void *p)
+{
+ Lisp_Object a = XIL (TAG_PTR (Lisp_Int0, p));
+ eassert (INTEGERP (a) && XINTPTR (a) == p);
+ return a;
+}
+
/* Type checking. */
LISP_MACRO_DEFUN_VOID (CHECK_TYPE,