all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Helmut Eller <eller.helmut@gmail.com>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,  Emacs Devel <emacs-devel@gnu.org>
Subject: Re: MPS image cache
Date: Fri, 03 May 2024 17:02:20 +0200	[thread overview]
Message-ID: <87jzkb0whv.fsf@gmail.com> (raw)
In-Reply-To: <m21q6j5ee0.fsf@pro2.fritz.box> ("Gerd Möllmann"'s message of "Fri, 03 May 2024 13:22:15 +0200")

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

>> There is a bit of an issue with proper initialization of the structs
>> pointed to by those roots.  E.g. x_term_init uses xzalloc, puts pointers
>> into the struct, and only then stores the pointer to the struct in
>> x_display_list.  So what should be the root, the struct (registred
>> immediately after the call to xzalloc) or the global variable
>> x_display_list?
>
> Hm.

For my case, the troublesome field was xi_device_t.name.  I decided to
make x_display_info and xi_device_t amigous roots, because there is
usually only one x_display_info and dozen of xi_device_t.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-x_display_info-and-xi_device_t-amig-roots.patch --]
[-- Type: text/x-diff, Size: 4558 bytes --]

From 497b5c900e1a4746c214af7be6242d0bc456cdc7 Mon Sep 17 00:00:00 2001
From: Helmut Eller <eller.helmut@gmail.com>
Date: Fri, 3 May 2024 16:47:51 +0200
Subject: [PATCH] Make x_display_info and xi_device_t amig roots

* src/xterm.c (x_cache_xi_devices, xi_disable_devices): Use
  igc_xzalloc_ambig for xi_disable_t.
  (handle_one_xevent): For the XI_HierarchyChanged event
  igc_realloc_ambig if needed.
  (x_term_init): Use igc_xzalloc_ambig for dpyinfo.
* src/igc.h (igc_realloc_ambig): New.
* src/igc.c (igc_realloc_ambig): Not implemented yet;
  scetch of an implementation as comment.
---
 src/igc.c   | 24 ++++++++++++++++++++++--
 src/igc.h   |  1 +
 src/xterm.c | 29 +++++++++++++++++++++++++----
 3 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/src/igc.c b/src/igc.c
index 648f2bbc44d..6d553bc316d 100644
--- a/src/igc.c
+++ b/src/igc.c
@@ -1389,10 +1389,10 @@ fix_frame (mps_ss_t ss, struct frame *f)
 	struct font **font_ptr = &FRAME_FONT (f);
 	if (*font_ptr)
 	  IGC_FIX12_RAW (ss, font_ptr);
-	Lisp_Object *nle = &FRAME_DISPLAY_INFO(f)->name_list_element;
+	Lisp_Object *nle = &FRAME_DISPLAY_INFO (f)->name_list_element;
 	IGC_FIX12_OBJ (ss, nle);
       }
-#endif
+#endif // HAVE_WINDOW_SYSTEM
   }
   MPS_SCAN_END (ss);
   return MPS_RES_OK;
@@ -2157,6 +2157,26 @@ igc_xzalloc_ambig (size_t size)
   return p;
 }
 
+void *
+igc_realloc_ambig (void *block, size_t size)
+{
+#if 0 // non tested code:
+  struct igc_root_list *r = root_find (block);
+  igc_assert (r != NULL);
+  destroy_root (&r);
+
+  /* Can't make a root that has zero length. Want one to be able to
+     detect calling igc_free on something not having a root. */
+  size_t new_size = (size == 0 ? IGC_ALIGN_DFLT : size);
+  void *p = xrealloc (block, new_size);
+  void *end = (char *)p + new_size;
+  root_create_ambig (global_igc, p, end);
+  return p;
+#endif
+  emacs_abort ();
+}
+
+
 void
 igc_xfree (void *p)
 {
diff --git a/src/igc.h b/src/igc.h
index 84e4ff8f13a..b1d09700a78 100644
--- a/src/igc.h
+++ b/src/igc.h
@@ -51,6 +51,7 @@ #define EMACS_IGC_H
 
 struct Lisp_Buffer_Local_Value *igc_alloc_blv (void);
 void *igc_xzalloc_ambig (size_t size);
+void *igc_realloc_ambig (void *block, size_t size);
 void igc_xfree (void *p);
 Lisp_Object *igc_xalloc_lisp_objs_exact (size_t n);
 void *igc_xpalloc_ambig (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
diff --git a/src/xterm.c b/src/xterm.c
index 36f83a33244..c47c7b0534d 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -787,6 +787,9 @@ #define XtNinitialState "initialState"
 #ifdef HAVE_XKB
 #include <X11/XKBlib.h>
 #endif
+#ifdef HAVE_MPS
+#include "igc.h"
+#endif
 
 /* Although X11/Xlib.h commonly defines the types XErrorHandler and
    XIOErrorHandler, they are not in the Xlib spec, so for portability
@@ -5744,7 +5747,11 @@ x_cache_xi_devices (struct x_display_info *dpyinfo)
       return;
     }
 
+#ifdef HAVE_MPS
+  dpyinfo->devices = igc_xzalloc_ambig (sizeof *dpyinfo->devices * ndevices);
+#else
   dpyinfo->devices = xzalloc (sizeof *dpyinfo->devices * ndevices);
+#endif
 
   for (i = 0; i < ndevices; ++i)
     {
@@ -13774,7 +13781,11 @@ xi_disable_devices (struct x_display_info *dpyinfo,
     return;
 
   ndevices = 0;
+#ifdef HAVE_MPS
+  devices = igc_xzalloc_ambig (sizeof *devices * dpyinfo->num_devices);
+#else
   devices = xzalloc (sizeof *devices * dpyinfo->num_devices);
+#endif
 
   /* Loop through every device currently in DPYINFO, and copy it to
      DEVICES if it is not in TO_DISABLE.  Note that this function
@@ -24600,10 +24611,15 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 
 			  if (info && info->enabled)
 			    {
-			      dpyinfo->devices
-				= xrealloc (dpyinfo->devices,
-					    (sizeof *dpyinfo->devices
-					     * ++dpyinfo->num_devices));
+			      size_t new_size = (sizeof *dpyinfo->devices
+						 * ++dpyinfo->num_devices);
+#ifdef HAVE_MPS
+			      dpyinfo->devices =
+				igc_realloc_ambig (dpyinfo->devices, new_size);
+#else
+			      dpyinfo->devices =
+				xrealloc (dpyinfo->devices, new_size);
+#endif
 			      memset (dpyinfo->devices + dpyinfo->num_devices - 1,
 				      0, sizeof *dpyinfo->devices);
 			      device = &dpyinfo->devices[dpyinfo->num_devices - 1];
@@ -30676,7 +30692,12 @@ #define NUM_ARGV 10
 
   /* We have definitely succeeded.  Record the new connection.  */
 
+#ifdef HAVE_MPS
+  dpyinfo = igc_xzalloc_ambig (sizeof *dpyinfo);
+#else
   dpyinfo = xzalloc (sizeof *dpyinfo);
+#endif
+
   terminal = x_create_terminal (dpyinfo);
 
   if (!NILP (Vx_detect_server_trust))
-- 
2.39.2


  parent reply	other threads:[~2024-05-03 15:02 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03  8:53 MPS image cache Gerd Möllmann
2024-05-03 10:58 ` Helmut Eller
2024-05-03 11:05   ` Po Lu
2024-05-03 11:22   ` Gerd Möllmann
2024-05-03 11:43     ` Gerd Möllmann
2024-05-03 13:24       ` Gerd Möllmann
2024-05-03 17:02         ` Gerd Möllmann
2024-05-04  4:38           ` MPS: scroll-bars (was: MPS image cache) Helmut Eller
2024-05-04  5:22             ` MPS: scroll-bars Gerd Möllmann
2024-05-04  5:29               ` Gerd Möllmann
2024-05-04  5:50             ` Po Lu
2024-05-04  6:27               ` Helmut Eller
2024-05-04  6:45                 ` Gerd Möllmann
2024-05-04  7:05                   ` Helmut Eller
2024-05-04  7:13                     ` Gerd Möllmann
2024-05-04  7:48                       ` Gerd Möllmann
2024-05-04  7:09                   ` Gerd Möllmann
2024-05-04  8:47                     ` Eli Zaretskii
2024-05-04  9:13                       ` Gerd Möllmann
2024-05-04  9:29                         ` Eli Zaretskii
2024-05-04 10:04                           ` Gerd Möllmann
2024-05-04 13:59                             ` MPS: w32 threads Eli Zaretskii
2024-05-04 14:20                               ` Gerd Möllmann
2024-05-05  8:27                                 ` Eli Zaretskii
2024-05-05  9:16                                   ` Gerd Möllmann
2024-05-05 14:39                                     ` Eli Zaretskii
2024-05-05 15:23                                       ` Gerd Möllmann
2024-05-05 15:26                                         ` Gerd Möllmann
2024-05-04  8:29                 ` MPS: scroll-bars Po Lu
2024-05-05  4:52                   ` Gerd Möllmann
2024-05-05  7:53                     ` Helmut Eller
2024-05-05  8:01                       ` Gerd Möllmann
2024-05-05  8:08                         ` Helmut Eller
2024-05-05 16:43                       ` Eli Zaretskii
2024-05-05 18:02                         ` Helmut Eller
2024-05-05 18:09                           ` Eli Zaretskii
2024-05-06 15:05                             ` Eli Zaretskii
2024-05-06 15:53                               ` Gerd Möllmann
2024-05-06 18:25                                 ` Eli Zaretskii
2024-05-07  6:07                                   ` Helmut Eller
2024-05-07 12:56                                     ` Eli Zaretskii
2024-05-07 16:27                                       ` Helmut Eller
2024-05-03 14:59     ` MPS image cache Helmut Eller
2024-05-03 15:11       ` Gerd Möllmann
2024-05-05  6:45         ` Gerd Möllmann
2024-05-05  7:02           ` Gerd Möllmann
2024-05-05  9:00             ` Eli Zaretskii
2024-05-05  9:31               ` Gerd Möllmann
2024-05-05 10:24                 ` Eli Zaretskii
2024-05-05 10:36                   ` Gerd Möllmann
2024-05-05 11:01                     ` Eli Zaretskii
2024-05-05 12:55                       ` Gerd Möllmann
2024-05-05 14:07                         ` Eli Zaretskii
2024-05-05 14:32                           ` Gerd Möllmann
2024-05-05 15:49                             ` Eli Zaretskii
2024-05-05 16:19                               ` Gerd Möllmann
2024-05-05 17:45                               ` Gerd Möllmann
2024-05-05 18:04                                 ` Eli Zaretskii
2024-05-05 18:13                                   ` Eli Zaretskii
2024-05-05 18:35                                     ` Gerd Möllmann
2024-05-05 19:18                                       ` Eli Zaretskii
2024-05-05 19:57                                         ` Gerd Möllmann
2024-05-05  8:16           ` Helmut Eller
2024-05-05  8:42             ` Gerd Möllmann
2024-05-06 14:16               ` Helmut Eller
2024-05-06 14:28                 ` Gerd Möllmann
2024-05-03 15:02     ` Helmut Eller [this message]
2024-05-04 17:51       ` Gerd Möllmann
2024-05-03 11:04 ` Eli Zaretskii
2024-05-03 11:08   ` Gerd Möllmann

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

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

  git send-email \
    --in-reply-to=87jzkb0whv.fsf@gmail.com \
    --to=eller.helmut@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=gerd.moellmann@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.