diff options
| author | Paul Eggert | 2013-06-06 00:04:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-06-06 00:04:35 -0700 |
| commit | 7d300d644cc3c1595d2ac67e37fde1d3d865af24 (patch) | |
| tree | e9971162da1ef49fd497486891d78388602d10d9 /src | |
| parent | 93df970c5e7219d08c49fe0cb4c2a2b32a1b3d99 (diff) | |
| download | emacs-7d300d644cc3c1595d2ac67e37fde1d3d865af24.tar.gz emacs-7d300d644cc3c1595d2ac67e37fde1d3d865af24.zip | |
A few porting etc. fixes for the new file monitor code.
See the thread containing
<http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00109.html>.
* gfilenotify.c (dir_monitor_callback, Fgfile_add_watch)
(Fgfile_rm_watch): Don't assume EMACS_INT is the same width as a pointer.
(dir_monitor_callback, Fgfile_rm_watch):
Use assq_no_quit instead of Fassoc, for speed.
(dir_monitor_callback, Fgfile_rm_watch):
eassert that the monitor is a fixnum.
(dir_monitor_callback): No need for CDR_SAFE.
Simplify building of lisp with alternative tails.
(Fgfile_add_watch, Fgfile_rm_watch):
Do not assume glib functions set errno reliably on failure.
(Fgfile_add_watch): Check that the monitor survives the XIL trick,
and signal an error otherwise.
(Fgfile_rm_watch): Prefer CONSP to !NILP.
Use Fdelq instead of Fdelete, for speed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 20 | ||||
| -rw-r--r-- | src/gfilenotify.c | 70 |
2 files changed, 62 insertions, 28 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 1cee3c86ab5..11aaef4d2e8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,23 @@ | |||
| 1 | 2013-06-06 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | A few porting etc. fixes for the new file monitor code. | ||
| 4 | See the thread containing | ||
| 5 | <http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00109.html>. | ||
| 6 | * gfilenotify.c (dir_monitor_callback, Fgfile_add_watch) | ||
| 7 | (Fgfile_rm_watch): Don't assume EMACS_INT is the same width as a pointer. | ||
| 8 | (dir_monitor_callback, Fgfile_rm_watch): | ||
| 9 | Use assq_no_quit instead of Fassoc, for speed. | ||
| 10 | (dir_monitor_callback, Fgfile_rm_watch): | ||
| 11 | eassert that the monitor is a fixnum. | ||
| 12 | (dir_monitor_callback): No need for CDR_SAFE. | ||
| 13 | Simplify building of lisp with alternative tails. | ||
| 14 | (Fgfile_add_watch, Fgfile_rm_watch): | ||
| 15 | Do not assume glib functions set errno reliably on failure. | ||
| 16 | (Fgfile_add_watch): Check that the monitor survives the XIL trick, | ||
| 17 | and signal an error otherwise. | ||
| 18 | (Fgfile_rm_watch): Prefer CONSP to !NILP. | ||
| 19 | Use Fdelq instead of Fdelete, for speed. | ||
| 20 | |||
| 1 | 2013-06-05 Eli Zaretskii <eliz@gnu.org> | 21 | 2013-06-05 Eli Zaretskii <eliz@gnu.org> |
| 2 | 22 | ||
| 3 | * xdisp.c (handle_tool_bar_click): When mouse-highlight is off, | 23 | * xdisp.c (handle_tool_bar_click): When mouse-highlight is off, |
diff --git a/src/gfilenotify.c b/src/gfilenotify.c index 9b93961f172..c8d12ce8fa0 100644 --- a/src/gfilenotify.c +++ b/src/gfilenotify.c | |||
| @@ -53,13 +53,13 @@ static Lisp_Object watch_list; | |||
| 53 | g_file_monitor. It shall create a Lisp event, and put it into | 53 | g_file_monitor. It shall create a Lisp event, and put it into |
| 54 | Emacs input queue. */ | 54 | Emacs input queue. */ |
| 55 | static gboolean | 55 | static gboolean |
| 56 | dir_monitor_callback (GFileMonitor* monitor, | 56 | dir_monitor_callback (GFileMonitor *monitor, |
| 57 | GFile* file, | 57 | GFile *file, |
| 58 | GFile* other_file, | 58 | GFile *other_file, |
| 59 | GFileMonitorEvent event_type, | 59 | GFileMonitorEvent event_type, |
| 60 | gpointer user_data) | 60 | gpointer user_data) |
| 61 | { | 61 | { |
| 62 | Lisp_Object symbol, watch_object; | 62 | Lisp_Object symbol, monitor_object, watch_object; |
| 63 | char *name = g_file_get_parse_name (file); | 63 | char *name = g_file_get_parse_name (file); |
| 64 | char *oname = other_file ? g_file_get_parse_name (other_file) : NULL; | 64 | char *oname = other_file ? g_file_get_parse_name (other_file) : NULL; |
| 65 | 65 | ||
| @@ -95,21 +95,23 @@ dir_monitor_callback (GFileMonitor* monitor, | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | /* Determine callback function. */ | 97 | /* Determine callback function. */ |
| 98 | watch_object = Fassoc (XIL ((EMACS_INT) monitor), watch_list); | 98 | monitor_object = XIL ((intptr_t) monitor); |
| 99 | eassert (INTEGERP (monitor_object)); | ||
| 100 | watch_object = assq_no_quit (monitor_object, watch_list); | ||
| 99 | 101 | ||
| 100 | if (FUNCTIONP (CDR_SAFE (watch_object))) | 102 | if (CONSP (watch_object)) |
| 101 | { | 103 | { |
| 102 | /* Construct an event. */ | 104 | /* Construct an event. */ |
| 103 | struct input_event event; | 105 | struct input_event event; |
| 106 | Lisp_Object otail = oname ? list1 (build_string (oname)) : Qnil; | ||
| 104 | EVENT_INIT (event); | 107 | EVENT_INIT (event); |
| 105 | event.kind = FILE_NOTIFY_EVENT; | 108 | event.kind = FILE_NOTIFY_EVENT; |
| 106 | event.frame_or_window = Qnil; | 109 | event.frame_or_window = Qnil; |
| 107 | event.arg = oname | 110 | event.arg = list2 (Fcons (monitor_object, |
| 108 | ? list2 (list4 (XIL ((EMACS_INT) monitor), symbol, | 111 | Fcons (symbol, |
| 109 | build_string (name), build_string (oname)), | 112 | Fcons (build_string (name), |
| 110 | CDR_SAFE (watch_object)) | 113 | otail))), |
| 111 | : list2 (list3 (XIL ((EMACS_INT) monitor), symbol, build_string (name)), | 114 | XCDR (watch_object)); |
| 112 | CDR_SAFE (watch_object)); | ||
| 113 | 115 | ||
| 114 | /* Store it into the input event queue. */ | 116 | /* Store it into the input event queue. */ |
| 115 | kbd_buffer_store_event (&event); | 117 | kbd_buffer_store_event (&event); |
| @@ -165,7 +167,7 @@ will be reported only in case of the 'moved' event. */) | |||
| 165 | { | 167 | { |
| 166 | Lisp_Object watch_descriptor, watch_object; | 168 | Lisp_Object watch_descriptor, watch_object; |
| 167 | GFile *gfile; | 169 | GFile *gfile; |
| 168 | GFileMonitor* monitor; | 170 | GFileMonitor *monitor; |
| 169 | GFileMonitorFlags gflags = G_FILE_MONITOR_NONE; | 171 | GFileMonitorFlags gflags = G_FILE_MONITOR_NONE; |
| 170 | 172 | ||
| 171 | /* Check parameters. */ | 173 | /* Check parameters. */ |
| @@ -190,14 +192,23 @@ will be reported only in case of the 'moved' event. */) | |||
| 190 | 192 | ||
| 191 | /* Enable watch. */ | 193 | /* Enable watch. */ |
| 192 | monitor = g_file_monitor (gfile, gflags, NULL, NULL); | 194 | monitor = g_file_monitor (gfile, gflags, NULL, NULL); |
| 193 | if (monitor != NULL) | 195 | if (! monitor) |
| 194 | g_signal_connect (monitor, "changed", | 196 | xsignal2 (Qfile_error, build_string ("Cannot watch file"), file); |
| 195 | (GCallback) dir_monitor_callback, NULL); | 197 | |
| 196 | else | 198 | /* On all known glib platforms, converting MONITOR directly to a |
| 197 | report_file_error ("Cannot watch file", Fcons (file, Qnil)); | 199 | Lisp_Object value results is a Lisp integer, which is safe. This |
| 200 | assumption is dicey, though, so check it now. */ | ||
| 201 | watch_descriptor = XIL ((intptr_t) monitor); | ||
| 202 | if (! INTEGERP (watch_descriptor)) | ||
| 203 | { | ||
| 204 | g_object_unref (monitor); | ||
| 205 | xsignal2 (Qfile_error, build_string ("Unsupported file watcher"), file); | ||
| 206 | } | ||
| 207 | |||
| 208 | g_signal_connect (monitor, "changed", | ||
| 209 | (GCallback) dir_monitor_callback, NULL); | ||
| 198 | 210 | ||
| 199 | /* Store watch object in watch list. */ | 211 | /* Store watch object in watch list. */ |
| 200 | watch_descriptor = XIL ((EMACS_INT) monitor); | ||
| 201 | watch_object = Fcons (watch_descriptor, callback); | 212 | watch_object = Fcons (watch_descriptor, callback); |
| 202 | watch_list = Fcons (watch_object, watch_list); | 213 | watch_list = Fcons (watch_object, watch_list); |
| 203 | 214 | ||
| @@ -210,20 +221,23 @@ DEFUN ("gfile-rm-watch", Fgfile_rm_watch, Sgfile_rm_watch, 1, 1, 0, | |||
| 210 | WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) | 221 | WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) |
| 211 | (Lisp_Object watch_descriptor) | 222 | (Lisp_Object watch_descriptor) |
| 212 | { | 223 | { |
| 213 | Lisp_Object watch_object; | 224 | intptr_t int_monitor; |
| 214 | GFileMonitor *monitor = (GFileMonitor *) XLI (watch_descriptor); | 225 | GFileMonitor *monitor; |
| 226 | Lisp_Object watch_object = assq_no_quit (watch_descriptor, watch_list); | ||
| 215 | 227 | ||
| 216 | watch_object = Fassoc (watch_descriptor, watch_list); | 228 | if (! CONSP (watch_object)) |
| 217 | if (NILP (watch_object)) | 229 | xsignal2 (Qfile_error, build_string ("Not a watch descriptor"), |
| 218 | report_file_error ("Not a watch descriptor", | 230 | watch_descriptor); |
| 219 | Fcons (watch_descriptor, Qnil)); | ||
| 220 | 231 | ||
| 232 | eassert (INTEGERP (watch_descriptor)); | ||
| 233 | int_monitor = XLI (watch_descriptor); | ||
| 234 | monitor = (GFileMonitor *) int_monitor; | ||
| 221 | if (!g_file_monitor_cancel (monitor)) | 235 | if (!g_file_monitor_cancel (monitor)) |
| 222 | report_file_error ("Could not rm watch", | 236 | xsignal2 (Qfile_error, build_string ("Could not rm watch"), |
| 223 | Fcons (watch_descriptor, Qnil)); | 237 | watch_descriptor); |
| 224 | 238 | ||
| 225 | /* Remove watch descriptor from watch list. */ | 239 | /* Remove watch descriptor from watch list. */ |
| 226 | watch_list = Fdelete (watch_object, watch_list); | 240 | watch_list = Fdelq (watch_object, watch_list); |
| 227 | 241 | ||
| 228 | /* Cleanup. */ | 242 | /* Cleanup. */ |
| 229 | g_object_unref (monitor); | 243 | g_object_unref (monitor); |