unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattias.engdegard@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 65491@debbugs.gnu.org, Paul Eggert <eggert@cs.ucla.edu>,
	monnier@iro.umontreal.ca
Subject: bug#65491: [PATCH] Improve performance allocating vectors
Date: Tue, 19 Sep 2023 15:28:41 +0200	[thread overview]
Message-ID: <EB4BDF33-7998-4C21-AFE5-3D94AB86837D@gmail.com> (raw)
In-Reply-To: <95C2D44B-BA1B-47F5-8279-B3A3B8F7EB39@gmail.com>

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

> The conversion at the other end, TAG_PTR, suffers from the same potential problem but in reverse, which is perhaps less obvious to the casual C programmer but nevertheless a danger of the same kind, so we'd better do something about it as well. I'll be back with a proposed patch.

Here it is. Very straightforward: just flip a cast and remove unused definitions.


[-- Attachment #2: 0001-Don-t-use-pointer-arithmetic-for-pointer-tagging-bug.patch --]
[-- Type: application/octet-stream, Size: 2295 bytes --]

From 9072db6ca24df50dc8dc66cd50ef638b8aac8a1b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Mon, 18 Sep 2023 19:16:05 +0200
Subject: [PATCH] Don't use pointer arithmetic for pointer tagging (bug#65491)

This makes for safer code when tagging null pointers in particular,
since pointer arithmetic on NULL is undefined and therefore can be
assumed, by the compiler, not to occur.

* src/lisp.h (untagged_ptr): Remove.
(TAG_PTR): Cast to uintptr_t instead of untagged_ptr.
---
 src/lisp.h | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/lisp.h b/src/lisp.h
index de6746f1c07..f0eea0c1f28 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -920,20 +920,11 @@ #define DEFUN_ARGS_7	(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
 #define DEFUN_ARGS_8	(Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
 			 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
 
-/* untagged_ptr represents a pointer before tagging, and Lisp_Word_tag
-   contains a possibly-shifted tag to be added to an untagged_ptr to
-   convert it to a Lisp_Word.  */
+/* Lisp_Word_tag is big enough for a possibly-shifted tag, to be
+   added to a pointer value for conversion to a Lisp_Word.  */
 #if LISP_WORDS_ARE_POINTERS
-/* untagged_ptr is a pointer so that the compiler knows that TAG_PTR
-   yields a pointer.  It is char * so that adding a tag uses simple
-   machine addition.  */
-typedef char *untagged_ptr;
 typedef uintptr_t Lisp_Word_tag;
 #else
-/* untagged_ptr is an unsigned integer instead of a pointer, so that
-   it can be added to the possibly-wider Lisp_Word_tag type without
-   losing information.  */
-typedef uintptr_t untagged_ptr;
 typedef EMACS_UINT Lisp_Word_tag;
 #endif
 
@@ -943,7 +934,7 @@ #define LISP_WORD_TAG(tag) \
 
 /* An initializer for a Lisp_Object that contains TAG along with PTR.  */
 #define TAG_PTR(tag, ptr) \
-  LISP_INITIALLY ((Lisp_Word) ((untagged_ptr) (ptr) + LISP_WORD_TAG (tag)))
+  LISP_INITIALLY ((Lisp_Word) ((uintptr_t) (ptr) + LISP_WORD_TAG (tag)))
 
 /* LISPSYM_INITIALLY (Qfoo) is equivalent to Qfoo except it is
    designed for use as an initializer, even for a constant initializer.  */
-- 
2.32.0 (Apple Git-132)


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





  parent reply	other threads:[~2023-09-19 13:28 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24  9:59 bug#65491: [PATCH] Improve performance allocating vectors Ihor Radchenko
2023-08-26  7:14 ` Eli Zaretskii
2023-08-26  7:27   ` Ihor Radchenko
2023-08-26  7:31     ` Eli Zaretskii
2023-08-26  7:51       ` Ihor Radchenko
2023-08-26  8:07         ` Ihor Radchenko
2023-08-26  9:01         ` Eli Zaretskii
2023-08-26  7:47     ` Ihor Radchenko
2023-08-26 12:01 ` Mattias Engdegård
2023-08-26 14:54   ` Ihor Radchenko
2023-08-26 14:55   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-27  9:54     ` Mattias Engdegård
2023-09-16 14:58     ` Mattias Engdegård
2023-09-16 16:12       ` Eli Zaretskii
2023-09-16 16:17         ` Eli Zaretskii
2023-09-16 16:32           ` Mattias Engdegård
2023-09-16 16:54             ` Eli Zaretskii
2023-09-16 17:03               ` Mattias Engdegård
2023-09-16 17:11                 ` Eli Zaretskii
2023-09-17  3:02                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-17 17:02                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18  2:19                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18  2:27                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18  3:08                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18  4:10                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-16 16:54             ` Mattias Engdegård
2023-09-16 17:09               ` Eli Zaretskii
2023-09-16 17:22                 ` Mattias Engdegård
2023-09-16 18:19                   ` Eli Zaretskii
2023-09-16 19:04                     ` Mattias Engdegård
2023-09-16 19:46                 ` Paul Eggert
2023-09-17  5:18                   ` Eli Zaretskii
2023-09-17 15:22                     ` Paul Eggert
2023-09-17 16:15                       ` Eli Zaretskii
2023-09-17 16:37                         ` Paul Eggert
2023-09-17 16:44                           ` Eli Zaretskii
2023-09-18 16:10                             ` Mattias Engdegård
2023-09-18 17:13                               ` Eli Zaretskii
2023-09-19 13:28                               ` Mattias Engdegård [this message]
2023-09-19 14:04                                 ` Eli Zaretskii
2023-09-19 14:05                                   ` Mattias Engdegård
2023-09-25 16:06       ` Mattias Engdegård
2023-08-27 16:21 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-28 10:14   ` Ihor Radchenko
2023-08-28 16:32     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-28 12:47   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=EB4BDF33-7998-4C21-AFE5-3D94AB86837D@gmail.com \
    --to=mattias.engdegard@gmail.com \
    --cc=65491@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).