From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#42943: 28.0.50; Emacsclient crashes in ftcrfont_glyph_extents Date: Sat, 24 Oct 2020 17:48:26 +0300 Message-ID: <83d017he85.fsf@gnu.org> References: <877dtuta6z.fsf@tcd.ie> <87y2m82ix4.fsf@gnus.org> <87zh4emnzm.fsf@gnus.org> <87lffxlxm5.fsf@tcd.ie> <83lffvhmne.fsf@gnu.org> <83h7qjhfwr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20975"; mail-complaints-to="usenet@ciao.gmane.io" Cc: contovob@tcd.ie, larsi@gnus.org, 42943@debbugs.gnu.org To: rpluim@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 24 16:49:27 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWKrH-0005M3-TQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 24 Oct 2020 16:49:27 +0200 Original-Received: from localhost ([::1]:53494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kWKrG-0005tj-Va for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 24 Oct 2020 10:49:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kWKqs-0005s5-7k for bug-gnu-emacs@gnu.org; Sat, 24 Oct 2020 10:49:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kWKqr-0006Np-UX for bug-gnu-emacs@gnu.org; Sat, 24 Oct 2020 10:49:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kWKqr-0001D2-Ro for bug-gnu-emacs@gnu.org; Sat, 24 Oct 2020 10:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 24 Oct 2020 14:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42943 X-GNU-PR-Package: emacs Original-Received: via spool by 42943-submit@debbugs.gnu.org id=B42943.16035509304629 (code B ref 42943); Sat, 24 Oct 2020 14:49:01 +0000 Original-Received: (at 42943) by debbugs.gnu.org; 24 Oct 2020 14:48:50 +0000 Original-Received: from localhost ([127.0.0.1]:34249 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kWKqf-0001Cb-Rg for submit@debbugs.gnu.org; Sat, 24 Oct 2020 10:48:50 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39396) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kWKqb-0001CJ-Dr for 42943@debbugs.gnu.org; Sat, 24 Oct 2020 10:48:48 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:47612) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kWKqV-0006N5-3e; Sat, 24 Oct 2020 10:48:39 -0400 Original-Received: from [176.228.60.248] (port=2333 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kWKqU-0004a6-GB; Sat, 24 Oct 2020 10:48:38 -0400 In-Reply-To: <83h7qjhfwr.fsf@gnu.org> (message from Eli Zaretskii on Sat, 24 Oct 2020 17:12:04 +0300) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:191429 Archived-At: > Date: Sat, 24 Oct 2020 17:12:04 +0300 > From: Eli Zaretskii > Cc: contovob@tcd.ie, larsi@gnus.org, 42943@debbugs.gnu.org > > > s->font = XFONT_OBJECT (LGSTRING_FONT (lgstring)); <---- > > > > so itʼs the caching in the Lisp_Object for the composition thatʼs > > causing the problem. > > OK, so when we are about to release a font, we need to go over all the > LGSTRING objects in gstring_hash_table, and remove from that cache > every LGSTRING whose LGSTRING_FONT object holds the font we are about > to release. Here, does the below give good results? diff --git a/src/composite.c b/src/composite.c index 984e0d9..f1b4b97 100644 --- a/src/composite.c +++ b/src/composite.c @@ -679,6 +679,27 @@ composition_gstring_from_id (ptrdiff_t id) return HASH_VALUE (h, id); } +/* Remove from the composition hash table every lgstring that + references the given FONT_OBJECT. */ +void +composition_gstring_cache_clear_font (Lisp_Object font_object) +{ + struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); + + for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i) + { + Lisp_Object k = HASH_KEY (h, i); + + if (!EQ (k, Qunbound)) + { + Lisp_Object gstring = HASH_VALUE (h, i); + + if (EQ (LGSTRING_FONT (gstring), font_object)) + hash_remove_from_table (h, k); + } + } +} + DEFUN ("clear-composition-cache", Fclear_composition_cache, Sclear_composition_cache, 0, 0, 0, doc: /* Internal use only. diff --git a/src/composite.h b/src/composite.h index 239f1e5..0d7d1c7 100644 --- a/src/composite.h +++ b/src/composite.h @@ -331,6 +331,8 @@ #define LGLYPH_WADJUST(g) (VECTORP (LGLYPH_ADJUSTMENT (g)) \ extern ptrdiff_t composition_adjust_point (ptrdiff_t, ptrdiff_t); +extern void composition_gstring_cache_clear_font (Lisp_Object); + INLINE_HEADER_END #endif /* not EMACS_COMPOSITE_H */ diff --git a/src/font.c b/src/font.c index fe257f4..d74938e 100644 --- a/src/font.c +++ b/src/font.c @@ -2645,6 +2645,11 @@ font_clear_cache (struct frame *f, Lisp_Object cache, if (! NILP (AREF (val, FONT_TYPE_INDEX))) { eassert (font && driver == font->driver); + /* We are going to close the font, so make + sure we don't have any lgstrings lying + around in lgstring cache that reference + the font. */ + composition_gstring_cache_clear_font (val); driver->close_font (font); } }