From 497b5c900e1a4746c214af7be6242d0bc456cdc7 Mon Sep 17 00:00:00 2001 From: Helmut Eller 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 #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