unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Glenn Morris <rgm@gnu.org>, 15880@debbugs.gnu.org
Subject: bug#15880: Compute C declarations for DEFSYMs automatically.
Date: Wed, 07 Jan 2015 17:16:41 -0800	[thread overview]
Message-ID: <54ADDA79.3050105@cs.ucla.edu> (raw)
In-Reply-To: <s7fwynty4.fsf@fencepost.gnu.org>

[-- Attachment #1: Type: text/plain, Size: 217 bytes --]

Glenn Morris wrote:
>
> This change causes `make check' to fail; specifically in file-notify-tests.

Thanks for reporting that bug.  I reproduced the problem and installed the 
attached patch, which fixes it for me.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Port-GFileMonitor-hack-to-Qnil-0-platforms.patch --]
[-- Type: text/x-patch; name="0001-Port-GFileMonitor-hack-to-Qnil-0-platforms.patch", Size: 4157 bytes --]

From d71659fed4eb87eb3edbf8f83fb0e9ed2633fa74 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 7 Jan 2015 17:12:16 -0800
Subject: [PATCH] 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.
---
 src/ChangeLog     |  7 +++++++
 src/gfilenotify.c | 33 +++++++++++++++++++++++----------
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 8680c5e..2fc3479 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-08  Paul Eggert  <eggert@cs.ucla.edu>
+
+	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.
+
 2015-01-06  Jan Djärv  <jan.h.d@swipnet.se>
 
 	* nsterm.m (x_set_window_size): Call updateFrameSize to get real
diff --git a/src/gfilenotify.c b/src/gfilenotify.c
index fe25ce9..88a40d4 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/>.  */
 \f
 static Lisp_Object watch_list;
 
+/* Convert a monitor to a Lisp integer and back.  On all known glib
+   platforms, converting the sum of MONITOR and Lisp_Int0 directly to
+   a Lisp_Object value results in a Lisp integer, which is safe.  */
+
+static Lisp_Object
+monitor_to_lisp (GFileMonitor *monitor)
+{
+  return XIL ((intptr_t) monitor + Lisp_Int0);
+}
+
+static GFileMonitor *
+lisp_to_monitor (Lisp_Object watch_descriptor)
+{
+  intptr_t int_monitor = XLI (watch_descriptor) - Lisp_Int0;
+  return (GFileMonitor *) int_monitor;
+}
+
 /* This is the callback function for arriving signals from
    g_file_monitor.  It shall create a Lisp event, and put it into
    Emacs input queue.  */
@@ -77,7 +94,7 @@ dir_monitor_callback (GFileMonitor *monitor,
     }
 
   /* Determine callback function.  */
-  monitor_object = XIL ((intptr_t) monitor);
+  monitor_object = monitor_to_lisp (monitor);
   eassert (INTEGERP (monitor_object));
   watch_object = assq_no_quit (monitor_object, watch_list);
 
@@ -146,7 +163,7 @@ FILE is the name of the file whose event is being reported.  FILE1
 will be reported only in case of the 'moved' event.  */)
   (Lisp_Object file, Lisp_Object flags, Lisp_Object callback)
 {
-  Lisp_Object watch_descriptor, watch_object;
+  Lisp_Object watch_object;
   GFile *gfile;
   GFileMonitor *monitor;
   GFileMonitorFlags gflags = G_FILE_MONITOR_NONE;
@@ -176,10 +193,9 @@ will be reported only in case of the 'moved' event.  */)
   if (! monitor)
     xsignal2 (Qfile_notify_error, build_string ("Cannot watch file"), file);
 
-  /* On all known glib platforms, converting MONITOR directly to a
-     Lisp_Object value results is a Lisp integer, which is safe.  This
-     assumption is dicey, though, so check it now.  */
-  watch_descriptor = XIL ((intptr_t) monitor);
+  Lisp_Object watch_descriptor = monitor_to_lisp (monitor);
+
+  /* Check the dicey assumption that monitor_to_lisp is safe.  */
   if (! INTEGERP (watch_descriptor))
     {
       g_object_unref (monitor);
@@ -203,8 +219,6 @@ DEFUN ("gfile-rm-watch", Fgfile_rm_watch, Sgfile_rm_watch, 1, 1, 0,
 WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'.  */)
      (Lisp_Object watch_descriptor)
 {
-  intptr_t int_monitor;
-  GFileMonitor *monitor;
   Lisp_Object watch_object = assq_no_quit (watch_descriptor, watch_list);
 
   if (! CONSP (watch_object))
@@ -212,8 +226,7 @@ WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'.  */)
 	      watch_descriptor);
 
   eassert (INTEGERP (watch_descriptor));
-  int_monitor = XLI (watch_descriptor);
-  monitor = (GFileMonitor *) int_monitor;
+  GFileMonitor *monitor = lisp_to_monitor (watch_descriptor);
   if (!g_file_monitor_cancel (monitor))
     xsignal2 (Qfile_notify_error, build_string ("Could not rm watch"),
 	      watch_descriptor);
-- 
2.1.0


  reply	other threads:[~2015-01-08  1:16 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-13  0:33 bug#15880: Compute C declarations for DEFSYMs automatically Paul Eggert
2013-11-13  3:54 ` Eli Zaretskii
2013-11-13  5:00   ` Paul Eggert
2013-11-13  4:19 ` Stefan Monnier
2013-11-13  5:12   ` Paul Eggert
2013-11-13 13:36     ` Stefan Monnier
2013-11-13 16:25       ` Paul Eggert
2013-11-14  0:26         ` Stefan Monnier
2013-11-14  1:32           ` Paul Eggert
2013-11-14  2:29             ` Stefan Monnier
2013-11-14  4:13               ` Paul Eggert
2013-11-14  5:06                 ` Stefan Monnier
2013-11-14  5:26                   ` Paul Eggert
2013-11-14 16:28                 ` Eli Zaretskii
2013-11-14 20:25                   ` Paul Eggert
2013-11-15  7:59                     ` Eli Zaretskii
2013-11-15 13:58                       ` Stefan Monnier
2013-11-13 16:07   ` Eli Zaretskii
2013-11-13 22:00     ` Stefan Monnier
2013-11-14  3:47       ` Eli Zaretskii
2013-11-14  4:59         ` Stefan Monnier
2013-11-14 16:29           ` Eli Zaretskii
2014-12-20  1:55 ` Paul Eggert
2014-12-23 17:15   ` Stefan Monnier
2014-12-23 23:51     ` Paul Eggert
2015-01-05 16:51       ` Stefan Monnier
2015-01-05 17:25         ` Paul Eggert
2015-01-05 17:55           ` Stefan Monnier
2015-01-05 18:17             ` Paul Eggert
2015-01-05 18:56               ` Eli Zaretskii
2015-01-05 19:24                 ` Paul Eggert
2015-01-05 19:48                   ` Eli Zaretskii
2015-01-05 22:20                     ` Paul Eggert
2015-01-06  3:28                       ` Eli Zaretskii
2015-01-07 21:48                         ` Glenn Morris
2015-01-08  1:16                           ` Paul Eggert [this message]
2015-01-08 13:28                             ` Eli Zaretskii
2015-01-09 16:33                               ` Paul Eggert
2015-01-09 20:06                                 ` Eli Zaretskii
2015-01-09 20:08                                   ` Andreas Schwab
2015-01-09 20:50                                     ` Eli Zaretskii
2015-01-09 21:10                                       ` Andreas Schwab
2015-01-09 21:48                                       ` Stefan Monnier
2015-01-10 11:30                                         ` Eli Zaretskii
2015-01-05 19:27                 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54ADDA79.3050105@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=15880@debbugs.gnu.org \
    --cc=rgm@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).