From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Using glib's g_file_monitor_file and g_file_monitor_directory Date: Mon, 03 Jun 2013 23:45:30 -0700 Organization: UCLA Computer Science Department Message-ID: <51AD8D0A.5060209@cs.ucla.edu> References: <87zjxxn6th.fsf@gmx.de> <83fvx7p1h4.fsf@gnu.org> <877gihc3qm.fsf@gmx.de> <83mwrd6c54.fsf@gnu.org> <87obbtaie8.fsf@gmx.de> <83bo7ozc0q.fsf@gnu.org> <87zjxxn6th.fsf@gmx.de> <87hajqpjn1.fsf@gmx.de> <8738t7pewc.fsf@gmx.de> <83fvx7p1h4.fsf@gnu.org> <877gihc3qm.fsf@gmx.de> <83mwrd6c54.fsf@gnu.org> <87obbtaie8.fsf@gmx.de> <83bo7ozc0q.fsf@gnu.org> <87bo7ngwj8.fsf@gmx.de> <83mwr7xm7b.fsf@gnu.org> <3d7gibw6sa.fsf@fencepost.gnu.org> <83bo7nxim8.fsf@gnu.org> <834ndfxh0g.fsf@gnu.org> <2cobbnt897.fsf@fencepost.gnu.org> <87ip1vq8wy.fsf@gmx.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1370328351 16544 80.91.229.3 (4 Jun 2013 06:45:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 4 Jun 2013 06:45:51 +0000 (UTC) Cc: emacs-devel@gnu.org To: Michael Albinus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 04 08:45:50 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ujl05-0006Ij-LT for ged-emacs-devel@m.gmane.org; Tue, 04 Jun 2013 08:45:45 +0200 Original-Received: from localhost ([::1]:55893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujl05-0000Bt-9d for ged-emacs-devel@m.gmane.org; Tue, 04 Jun 2013 02:45:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujkzw-0008U4-QE for emacs-devel@gnu.org; Tue, 04 Jun 2013 02:45:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ujkzs-0005RH-6A for emacs-devel@gnu.org; Tue, 04 Jun 2013 02:45:36 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:44916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujkzr-0005RA-TY for emacs-devel@gnu.org; Tue, 04 Jun 2013 02:45:32 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 1260639E8109; Mon, 3 Jun 2013 23:45:31 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t1CxkE+Fbyv1; Mon, 3 Jun 2013 23:45:30 -0700 (PDT) Original-Received: from [192.168.1.9] (pool-71-108-49-126.lsanca.fios.verizon.net [71.108.49.126]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 6F31639E8105; Mon, 3 Jun 2013 23:45:30 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 In-Reply-To: <87ip1vq8wy.fsf@gmx.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160070 Archived-At: A quick review of some of the C-level changes: * The XIL ((EMACS_INT) monitor) trick doesn't work in general, since the monitor address could look like a tagged Emacs object and the garbage collector could go kaflooey on it. Instead, perhaps use make_save_pointer, as it's designed for this sort of thing. * Faster and simpler than FUNCTIONP (CDR_SAFE (watch_object)) is CONSP (watch_object). Since the user can't modify the watch list we can rely on it to be a list of pairs. * report_file_error reads errno, so it's not suitable when errno's value is indeterminate. xsignal... (Qfile_error, ...) is preferable. Maybe something like the following patch? I couldn't get this stuff to work on my Fedora 17 host, either without or with the patch, but it should be necessary to apply something like the following. === modified file 'src/gfilenotify.c' --- src/gfilenotify.c 2013-06-03 13:03:05 +0000 +++ src/gfilenotify.c 2013-06-04 06:43:23 +0000 @@ -95,21 +95,26 @@ dir_monitor_callback (GFileMonitor* moni } /* Determine callback function. */ - watch_object = Fassoc (XIL ((EMACS_INT) monitor), watch_list); + for (watch_object = watch_list; + CONSP (watch_object); + watch_object = XCDR (watch_object)) + if (XSAVE_POINTER (XCAR (watch_object), 0) == monitor) + break; - if (FUNCTIONP (CDR_SAFE (watch_object))) + if (CONSP (watch_object)) { /* Construct an event. */ struct input_event event; EVENT_INIT (event); event.kind = FILE_NOTIFY_EVENT; event.frame_or_window = Qnil; - event.arg = oname - ? list2 (list4 (XIL ((EMACS_INT) monitor), symbol, - build_string (name), build_string (oname)), - CDR_SAFE (watch_object)) - : list2 (list3 (XIL ((EMACS_INT) monitor), symbol, build_string (name)), - CDR_SAFE (watch_object)); + event.arg = list2 (Fcons (XCAR (watch_object), + Fcons (symbol, + Fcons (build_string (name), + (oname + ? list1 (build_string (oname)) + : Qnil)))), + XCDR (watch_object)); /* Store it into the input event queue. */ kbd_buffer_store_event (&event); @@ -194,10 +199,10 @@ will be reported only in case of the 'mo g_signal_connect (monitor, "changed", (GCallback) dir_monitor_callback, NULL); else - report_file_error ("Cannot watch file", Fcons (file, Qnil)); + xsignal2 (Qfile_error, build_string ("Cannot watch file"), file); /* Store watch object in watch list. */ - watch_descriptor = XIL ((EMACS_INT) monitor); + watch_descriptor = make_save_pointer (monitor); watch_object = Fcons (watch_descriptor, callback); watch_list = Fcons (watch_object, watch_list); @@ -210,20 +215,20 @@ DEFUN ("gfile-rm-watch", Fgfile_rm_watch WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) (Lisp_Object watch_descriptor) { - Lisp_Object watch_object; - GFileMonitor *monitor = (GFileMonitor *) XLI (watch_descriptor); + GFileMonitor *monitor; + Lisp_Object watch_object = Fassq (watch_descriptor, watch_list); - watch_object = Fassoc (watch_descriptor, watch_list); - if (NILP (watch_object)) - report_file_error ("Not a watch descriptor", - Fcons (watch_descriptor, Qnil)); + if (! CONSP (watch_object)) + xsignal2 (Qfile_error, build_string ("Not a watch descriptor"), + watch_descriptor); + monitor = XSAVE_POINTER (XCAR (watch_object), 0); if (!g_file_monitor_cancel (monitor)) - report_file_error ("Could not rm watch", - Fcons (watch_descriptor, Qnil)); + xsignal2 (Qfile_error, build_string ("Could not rm watch"), + watch_descriptor); /* Remove watch descriptor from watch list. */ - watch_list = Fdelete (watch_object, watch_list); + watch_list = Fdelq (watch_object, watch_list); /* Cleanup. */ g_object_unref (monitor);