unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 15880@debbugs.gnu.org
Subject: bug#15880: Compute C declarations for DEFSYMs automatically.
Date: Fri, 09 Jan 2015 08:33:53 -0800	[thread overview]
Message-ID: <54B002F1.4030305@cs.ucla.edu> (raw)
In-Reply-To: <83387l7670.fsf@gnu.org>

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

Eli Zaretskii wrote:
> Could we instead just keep the previous semantics of XIL and XLI,
> please?  They are used in a few places outside lisp.h, so now all of
> those places need to be audited and most probably changed.  Why isn't
> it better to change the implementation of just 2 macros instead?

XIL and XLI haven't changed, and have the same semantics as before: they convert 
between Lisp_Object and EMACS_INT without altering the bits (i.e., they are 
no-ops at the machine level).  I expect it's better to keep them no-ops, for 
efficiency in the kernel of the Emacs Lisp interpreter.

I audited all the places XIL and XLI are used, and the uses in non-w32 code are 
all fine.  I don't know the w32 code, but most likely some or all of its uses 
need to be changed.  I moved the new conversion operations to lisp.h (installed 
on master) and wrote the attached untested patch for the w32 code.


[-- Attachment #2: 0001-Fix-pointer-to-integer-conversion-in-w32-code.patch --]
[-- Type: text/x-patch, Size: 7429 bytes --]

From 126c396d0b780742c785461d82d3b1127d492086 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 9 Jan 2015 08:21:19 -0800
Subject: [PATCH] Fix pointer-to-integer conversion in w32 code

* w32fns.c (w32_msg_pump, Fw32_register_hot_key)
(Fw32_unregister_hot_key, Fw32_toggle_lock_key):
* w32inevt.c (handle_file_notifications):
* w32menu.c (add_menu_item, w32_menu_display_help):
* w32notify.c (Fw32notify_add_watch, Fw32notify_rm_watch)
(w32_get_watch_object):
* w32term.c (queue_notifications):
Use make_pointer_integer and XINTPTR rather than XIL and XLI.
---
 src/ChangeLog   | 10 ++++++++++
 src/w32fns.c    | 10 +++++-----
 src/w32inevt.c  |  4 +++-
 src/w32menu.c   |  6 ++++--
 src/w32notify.c |  6 +++---
 src/w32term.c   |  5 +++--
 6 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index c11ba11..22e690c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,15 @@
 2015-01-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Fix pointer-to-integer conversion in w32 code
+	* w32fns.c (w32_msg_pump, Fw32_register_hot_key)
+	(Fw32_unregister_hot_key, Fw32_toggle_lock_key):
+	* w32inevt.c (handle_file_notifications):
+	* w32menu.c (add_menu_item, w32_menu_display_help):
+	* w32notify.c (Fw32notify_add_watch, Fw32notify_rm_watch)
+	(w32_get_watch_object):
+	* w32term.c (queue_notifications):
+	Use make_pointer_integer and XINTPTR rather than XIL and XLI.
+
 	Refactor pointer-to-integer conversion
 	* gfilenotify.c (monitor_to_lisp, lisp_to_monitor):
 	Rename and move to lisp.h.  All uses changed.
diff --git a/src/w32fns.c b/src/w32fns.c
index ced3d87..c6cdf96 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -2540,7 +2540,7 @@ w32_msg_pump (deferred_msg * msg_buf)
                  thread-safe.  The next line is okay because the cons
                  cell is never made into garbage and is not relocated by
                  GC.  */
-	      XSETCAR (XIL ((EMACS_INT) msg.lParam), Qnil);
+	      XSETCAR (make_pointer_integer (msg.lParam), Qnil);
 	      if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0))
 		emacs_abort ();
 	      break;
@@ -2548,7 +2548,7 @@ w32_msg_pump (deferred_msg * msg_buf)
 	      {
 		int vk_code = (int) msg.wParam;
 		int cur_state = (GetKeyState (vk_code) & 1);
-		Lisp_Object new_state = XIL ((EMACS_INT) msg.lParam);
+		Lisp_Object new_state = make_pointer_integer (msg.lParam);
 
 		/* NB: This code must be thread-safe.  It is safe to
                    call NILP because symbols are not relocated by GC,
@@ -7235,7 +7235,7 @@ The return value is the hotkey-id if registered, otherwise nil.  */)
       /* Notify input thread about new hot-key definition, so that it
 	 takes effect without needing to switch focus.  */
       PostThreadMessage (dwWindowsThreadId, WM_EMACS_REGISTER_HOT_KEY,
-			 (WPARAM) XLI (key), 0);
+			 XINTPTR (key), 0);
     }
 
   return key;
@@ -7258,7 +7258,7 @@ DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key,
       /* Notify input thread about hot-key definition being removed, so
 	 that it takes effect without needing focus switch.  */
       if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_UNREGISTER_HOT_KEY,
-			     (WPARAM) XINT (XCAR (item)), (LPARAM) XLI (item)))
+			     (WPARAM) XINT (XCAR (item)), XINTPTR (item)))
 	{
 	  MSG msg;
 	  GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE);
@@ -7331,7 +7331,7 @@ is set to off if the low bit of NEW-STATE is zero, otherwise on.  */)
     return make_number (w32_console_toggle_lock_key (vk_code, new_state));
 
   if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_TOGGLE_LOCK_KEY,
-			 (WPARAM) vk_code, (LPARAM) XLI (new_state)))
+			 (WPARAM) vk_code, XINTPTR (new_state)))
     {
       MSG msg;
       GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE);
diff --git a/src/w32inevt.c b/src/w32inevt.c
index daf4a5c..ef2ec35 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -655,9 +655,11 @@ handle_file_notifications (struct input_event *hold_quit)
 	      Lisp_Object fname
 		= code_convert_string_norecord (utf_16_fn, cs, 0);
 	      Lisp_Object action = lispy_file_action (fni->Action);
+	      Lisp_Object descriptor
+		= make_pointer_integer (notifications_desc);
 
 	      inev.kind = FILE_NOTIFY_EVENT;
-	      inev.code = (ptrdiff_t)XINT (XIL ((EMACS_INT)notifications_desc));
+	      inev.code = XINT (descriptor);
 	      inev.timestamp = GetTickCount ();
 	      inev.modifiers = 0;
 	      inev.frame_or_window = callback;
diff --git a/src/w32menu.c b/src/w32menu.c
index 7a946d2..3ec6b54 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -1412,7 +1412,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
 		 be ULONG_PTR, which is correct for 32-bit and 64-bit
 		 Windows alike.  MSVC headers get it right; hopefully,
 		 MinGW headers will, too.  */
-	      info.dwItemData = (ULONG_PTR) XLI (wv->help);
+	      info.dwItemData = XINTPTR (wv->help);
 	    }
 	  if (wv->button_type == BUTTON_TYPE_RADIO)
 	    {
@@ -1488,7 +1488,9 @@ w32_menu_display_help (HWND owner, HMENU menu, UINT item, UINT flags)
 	  info.fMask = MIIM_DATA;
 	  get_menu_item_info (menu, item, FALSE, &info);
 
-	  help = info.dwItemData ? XIL (info.dwItemData) : Qnil;
+	  help = (info.dwItemData
+		  ? make_pointer_integer (info.dwItemData)
+		  : Qnil);
 	}
 
       /* Store the help echo in the keyboard buffer as the X toolkit
diff --git a/src/w32notify.c b/src/w32notify.c
index a0d555b..27d0aa1 100644
--- a/src/w32notify.c
+++ b/src/w32notify.c
@@ -580,7 +580,7 @@ generate notifications correctly, though.  */)
 	report_file_error ("Cannot watch file", Fcons (file, Qnil));
     }
   /* Store watch object in watch list. */
-  watch_descriptor = XIL ((EMACS_INT)dirwatch);
+  watch_descriptor = make_pointer_integer (dirwatch);
   watch_object = Fcons (watch_descriptor, callback);
   watch_list = Fcons (watch_object, watch_list);
 
@@ -605,7 +605,7 @@ WATCH-DESCRIPTOR should be an object returned by `w32notify-add-watch'.  */)
   if (!NILP (watch_object))
     {
       watch_list = Fdelete (watch_object, watch_list);
-      dirwatch = (struct notification *)XLI (watch_descriptor);
+      dirwatch = XINTPTR (watch_descriptor);
       if (w32_valid_pointer_p (dirwatch, sizeof(struct notification)))
 	status = remove_watch (dirwatch);
     }
@@ -620,7 +620,7 @@ WATCH-DESCRIPTOR should be an object returned by `w32notify-add-watch'.  */)
 Lisp_Object
 w32_get_watch_object (void *desc)
 {
-  Lisp_Object descriptor = XIL ((EMACS_INT)desc);
+  Lisp_Object descriptor = make_pointer_integer (desc);
 
   /* This is called from the input queue handling code, inside a
      critical section, so we cannot possibly QUIT if watch_list is not
diff --git a/src/w32term.c b/src/w32term.c
index 8a53a58..7ac3120 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -3245,10 +3245,11 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f,
 	      Lisp_Object fname
 		= code_convert_string_norecord (utf_16_fn, cs, 0);
 	      Lisp_Object action = lispy_file_action (fni->Action);
+	      Lisp_Object descriptor
+		= make_pointer_integer (notifications_desc);
 
 	      event->kind = FILE_NOTIFY_EVENT;
-	      event->code
-		= (ptrdiff_t)XINT (XIL ((EMACS_INT)notifications_desc));
+	      event->code = XINT (descriptor);
 	      event->timestamp = msg->msg.time;
 	      event->modifiers = 0;
 	      event->frame_or_window = callback;
-- 
2.1.0


  reply	other threads:[~2015-01-09 16:33 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
2015-01-08 13:28                             ` Eli Zaretskii
2015-01-09 16:33                               ` Paul Eggert [this message]
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=54B002F1.4030305@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=15880@debbugs.gnu.org \
    --cc=eliz@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).