aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-01-07 17:12:16 -0800
committerPaul Eggert2015-01-07 17:13:05 -0800
commitd71659fed4eb87eb3edbf8f83fb0e9ed2633fa74 (patch)
tree109e4b18fb8fb557a9dd58952c602627559b7a51 /src
parentad97127d9cd627f9c217738de81d88720a5c4c3a (diff)
downloademacs-d71659fed4eb87eb3edbf8f83fb0e9ed2633fa74.tar.gz
emacs-d71659fed4eb87eb3edbf8f83fb0e9ed2633fa74.zip
Port GFileMonitor * hack to Qnil==0 platforms
Reported by Glenn Morris in: http://bugs.gnu.org/15880#112 * gfilenotify.c (monitor_to_lisp, lisp_to_monitor): New functions. (dir_monitor_callback, Fgfile_add_watch, Fgfile_rm_watch): Use them.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/gfilenotify.c33
2 files changed, 30 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8680c5e231b..2fc3479129c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12015-01-08 Paul Eggert <eggert@cs.ucla.edu>
2
3 Port GFileMonitor * hack to Qnil==0 platforms
4 Reported by Glenn Morris in: http://bugs.gnu.org/15880#112
5 * gfilenotify.c (monitor_to_lisp, lisp_to_monitor): New functions.
6 (dir_monitor_callback, Fgfile_add_watch, Fgfile_rm_watch): Use them.
7
12015-01-06 Jan Djärv <jan.h.d@swipnet.se> 82015-01-06 Jan Djärv <jan.h.d@swipnet.se>
2 9
3 * nsterm.m (x_set_window_size): Call updateFrameSize to get real 10 * nsterm.m (x_set_window_size): Call updateFrameSize to get real
diff --git a/src/gfilenotify.c b/src/gfilenotify.c
index fe25ce9353e..88a40d4cbd9 100644
--- a/src/gfilenotify.c
+++ b/src/gfilenotify.c
@@ -31,6 +31,23 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31 31
32static Lisp_Object watch_list; 32static 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
38static Lisp_Object
39monitor_to_lisp (GFileMonitor *monitor)
40{
41 return XIL ((intptr_t) monitor + Lisp_Int0);
42}
43
44static GFileMonitor *
45lisp_to_monitor (Lisp_Object watch_descriptor)
46{
47 intptr_t int_monitor = XLI (watch_descriptor) - Lisp_Int0;
48 return (GFileMonitor *) int_monitor;
49}
50
34/* This is the callback function for arriving signals from 51/* This is the callback function for arriving signals from
35 g_file_monitor. It shall create a Lisp event, and put it into 52 g_file_monitor. It shall create a Lisp event, and put it into
36 Emacs input queue. */ 53 Emacs input queue. */
@@ -77,7 +94,7 @@ dir_monitor_callback (GFileMonitor *monitor,
77 } 94 }
78 95
79 /* Determine callback function. */ 96 /* Determine callback function. */
80 monitor_object = XIL ((intptr_t) monitor); 97 monitor_object = monitor_to_lisp (monitor);
81 eassert (INTEGERP (monitor_object)); 98 eassert (INTEGERP (monitor_object));
82 watch_object = assq_no_quit (monitor_object, watch_list); 99 watch_object = assq_no_quit (monitor_object, watch_list);
83 100
@@ -146,7 +163,7 @@ FILE is the name of the file whose event is being reported. FILE1
146will be reported only in case of the 'moved' event. */) 163will be reported only in case of the 'moved' event. */)
147 (Lisp_Object file, Lisp_Object flags, Lisp_Object callback) 164 (Lisp_Object file, Lisp_Object flags, Lisp_Object callback)
148{ 165{
149 Lisp_Object watch_descriptor, watch_object; 166 Lisp_Object watch_object;
150 GFile *gfile; 167 GFile *gfile;
151 GFileMonitor *monitor; 168 GFileMonitor *monitor;
152 GFileMonitorFlags gflags = G_FILE_MONITOR_NONE; 169 GFileMonitorFlags gflags = G_FILE_MONITOR_NONE;
@@ -176,10 +193,9 @@ will be reported only in case of the 'moved' event. */)
176 if (! monitor) 193 if (! monitor)
177 xsignal2 (Qfile_notify_error, build_string ("Cannot watch file"), file); 194 xsignal2 (Qfile_notify_error, build_string ("Cannot watch file"), file);
178 195
179 /* On all known glib platforms, converting MONITOR directly to a 196 Lisp_Object watch_descriptor = monitor_to_lisp (monitor);
180 Lisp_Object value results is a Lisp integer, which is safe. This 197
181 assumption is dicey, though, so check it now. */ 198 /* Check the dicey assumption that monitor_to_lisp is safe. */
182 watch_descriptor = XIL ((intptr_t) monitor);
183 if (! INTEGERP (watch_descriptor)) 199 if (! INTEGERP (watch_descriptor))
184 { 200 {
185 g_object_unref (monitor); 201 g_object_unref (monitor);
@@ -203,8 +219,6 @@ DEFUN ("gfile-rm-watch", Fgfile_rm_watch, Sgfile_rm_watch, 1, 1, 0,
203WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) 219WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */)
204 (Lisp_Object watch_descriptor) 220 (Lisp_Object watch_descriptor)
205{ 221{
206 intptr_t int_monitor;
207 GFileMonitor *monitor;
208 Lisp_Object watch_object = assq_no_quit (watch_descriptor, watch_list); 222 Lisp_Object watch_object = assq_no_quit (watch_descriptor, watch_list);
209 223
210 if (! CONSP (watch_object)) 224 if (! CONSP (watch_object))
@@ -212,8 +226,7 @@ WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */)
212 watch_descriptor); 226 watch_descriptor);
213 227
214 eassert (INTEGERP (watch_descriptor)); 228 eassert (INTEGERP (watch_descriptor));
215 int_monitor = XLI (watch_descriptor); 229 GFileMonitor *monitor = lisp_to_monitor (watch_descriptor);
216 monitor = (GFileMonitor *) int_monitor;
217 if (!g_file_monitor_cancel (monitor)) 230 if (!g_file_monitor_cancel (monitor))
218 xsignal2 (Qfile_notify_error, build_string ("Could not rm watch"), 231 xsignal2 (Qfile_notify_error, build_string ("Could not rm watch"),
219 watch_descriptor); 232 watch_descriptor);