diff options
| author | Paul Eggert | 2015-01-09 08:04:36 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-01-09 08:22:35 -0800 |
| commit | d1f848ffb9896fe2bd8eb9e7d70a49ca9ff9522f (patch) | |
| tree | 8789ccadf4cf2651edeec31aec5dc4695a399e88 | |
| parent | a749f1c648f2b9bf1a0b0b10e2da4c1c4e3d431d (diff) | |
| download | emacs-d1f848ffb9896fe2bd8eb9e7d70a49ca9ff9522f.tar.gz emacs-d1f848ffb9896fe2bd8eb9e7d70a49ca9ff9522f.zip | |
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.
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/gfilenotify.c | 24 | ||||
| -rw-r--r-- | src/lisp.h | 19 |
3 files changed, 32 insertions, 20 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c302f95d3fa..c11ba11715b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2015-01-09 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Refactor pointer-to-integer conversion | ||
| 4 | * gfilenotify.c (monitor_to_lisp, lisp_to_monitor): | ||
| 5 | Rename and move to lisp.h. All uses changed. | ||
| 6 | * lisp.h (XINTPTR, make_pointer_integer): New inline functions, | ||
| 7 | which are renamed from gfilenotify.c's lisp_to_monitor and | ||
| 8 | monitor_to_lisp, and with more-generic void * signatures. | ||
| 9 | |||
| 1 | 2015-01-08 Eli Zaretskii <eliz@gnu.org> | 10 | 2015-01-08 Eli Zaretskii <eliz@gnu.org> |
| 2 | 11 | ||
| 3 | * dispnew.c (buffer_posn_from_coords): Fix the value of the column | 12 | * dispnew.c (buffer_posn_from_coords): Fix the value of the column |
diff --git a/src/gfilenotify.c b/src/gfilenotify.c index 88222b5bf05..e03bec93541 100644 --- a/src/gfilenotify.c +++ b/src/gfilenotify.c | |||
| @@ -31,22 +31,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 31 | 31 | ||
| 32 | static Lisp_Object watch_list; | 32 | static Lisp_Object watch_list; |
| 33 | 33 | ||
| 34 | /* Convert a monitor to a Lisp integer and back. On all known glib | ||
| 35 | platforms, converting the sum of MONITOR and Lisp_Int0 directly to | ||
| 36 | a Lisp_Object value results in a Lisp integer, which is safe. */ | ||
| 37 | |||
| 38 | static Lisp_Object | ||
| 39 | monitor_to_lisp (GFileMonitor *monitor) | ||
| 40 | { | ||
| 41 | return XIL (TAG_PTR (Lisp_Int0, monitor)); | ||
| 42 | } | ||
| 43 | |||
| 44 | static GFileMonitor * | ||
| 45 | lisp_to_monitor (Lisp_Object watch_descriptor) | ||
| 46 | { | ||
| 47 | return XUNTAG (watch_descriptor, Lisp_Int0); | ||
| 48 | } | ||
| 49 | |||
| 50 | /* This is the callback function for arriving signals from | 34 | /* This is the callback function for arriving signals from |
| 51 | g_file_monitor. It shall create a Lisp event, and put it into | 35 | g_file_monitor. It shall create a Lisp event, and put it into |
| 52 | Emacs input queue. */ | 36 | Emacs input queue. */ |
| @@ -93,7 +77,7 @@ dir_monitor_callback (GFileMonitor *monitor, | |||
| 93 | } | 77 | } |
| 94 | 78 | ||
| 95 | /* Determine callback function. */ | 79 | /* Determine callback function. */ |
| 96 | monitor_object = monitor_to_lisp (monitor); | 80 | monitor_object = make_pointer_integer (monitor); |
| 97 | eassert (INTEGERP (monitor_object)); | 81 | eassert (INTEGERP (monitor_object)); |
| 98 | watch_object = assq_no_quit (monitor_object, watch_list); | 82 | watch_object = assq_no_quit (monitor_object, watch_list); |
| 99 | 83 | ||
| @@ -192,9 +176,9 @@ will be reported only in case of the 'moved' event. */) | |||
| 192 | if (! monitor) | 176 | if (! monitor) |
| 193 | xsignal2 (Qfile_notify_error, build_string ("Cannot watch file"), file); | 177 | xsignal2 (Qfile_notify_error, build_string ("Cannot watch file"), file); |
| 194 | 178 | ||
| 195 | Lisp_Object watch_descriptor = monitor_to_lisp (monitor); | 179 | Lisp_Object watch_descriptor = make_pointer_integer (monitor); |
| 196 | 180 | ||
| 197 | /* Check the dicey assumption that monitor_to_lisp is safe. */ | 181 | /* Check the dicey assumption that make_pointer_integer is safe. */ |
| 198 | if (! INTEGERP (watch_descriptor)) | 182 | if (! INTEGERP (watch_descriptor)) |
| 199 | { | 183 | { |
| 200 | g_object_unref (monitor); | 184 | g_object_unref (monitor); |
| @@ -225,7 +209,7 @@ WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) | |||
| 225 | watch_descriptor); | 209 | watch_descriptor); |
| 226 | 210 | ||
| 227 | eassert (INTEGERP (watch_descriptor)); | 211 | eassert (INTEGERP (watch_descriptor)); |
| 228 | GFileMonitor *monitor = lisp_to_monitor (watch_descriptor); | 212 | GFileMonitor *monitor = XINTPTR (watch_descriptor); |
| 229 | if (!g_file_monitor_cancel (monitor)) | 213 | if (!g_file_monitor_cancel (monitor)) |
| 230 | xsignal2 (Qfile_notify_error, build_string ("Could not rm watch"), | 214 | xsignal2 (Qfile_notify_error, build_string ("Could not rm watch"), |
| 231 | watch_descriptor); | 215 | watch_descriptor); |
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) | |||
| 1112 | #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR)) | 1112 | #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR)) |
| 1113 | #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE)) | 1113 | #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE)) |
| 1114 | 1114 | ||
| 1115 | /* Efficiently convert a pointer to a Lisp object and back. The | ||
| 1116 | pointer is represented as a Lisp integer, so the garbage collector | ||
| 1117 | does not know about it. The pointer should not have both Lisp_Int1 | ||
| 1118 | bits set, which makes this conversion inherently unportable. */ | ||
| 1119 | |||
| 1120 | INLINE void * | ||
| 1121 | XINTPTR (Lisp_Object a) | ||
| 1122 | { | ||
| 1123 | return XUNTAG (a, Lisp_Int0); | ||
| 1124 | } | ||
| 1125 | |||
| 1126 | INLINE Lisp_Object | ||
| 1127 | make_pointer_integer (void *p) | ||
| 1128 | { | ||
| 1129 | Lisp_Object a = XIL (TAG_PTR (Lisp_Int0, p)); | ||
| 1130 | eassert (INTEGERP (a) && XINTPTR (a) == p); | ||
| 1131 | return a; | ||
| 1132 | } | ||
| 1133 | |||
| 1115 | /* Type checking. */ | 1134 | /* Type checking. */ |
| 1116 | 1135 | ||
| 1117 | LISP_MACRO_DEFUN_VOID (CHECK_TYPE, | 1136 | LISP_MACRO_DEFUN_VOID (CHECK_TYPE, |