From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#71929: 30.0.60; crash in mark_image_cache Date: Sun, 07 Jul 2024 15:41:53 +0800 Message-ID: <875xth3aym.fsf@yahoo.com> References: <87jzi17uot.fsf@melete.silentflame.com> <87y16h6fm3.fsf@melete.silentflame.com> <86jzi1aeje.fsf@gnu.org> <86ikxlae3p.fsf@gnu.org> <87tth4ofvp.fsf@melete.silentflame.com> <86jzi073r8.fsf@gnu.org> <871q4849yc.fsf@yahoo.com> <86frso70i4.fsf@gnu.org> <87wmm02n9q.fsf@yahoo.com> <867ce06qnf.fsf@gnu.org> <87sewo2hk3.fsf@yahoo.com> <87cynrjl84.fsf@melete.silentflame.com> <87o77b2gsr.fsf@yahoo.com> <87tth1rkfy.fsf@melete.silentflame.com> <87plrprkb2.fsf@melete.silentflame.com> <87frsl3l0p.fsf@yahoo.com> <87plrpvm2y.fsf@melete.silentflame.com> <86a5it3cj2.fsf@gnu.org> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40467"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 71929@debbugs.gnu.org, Sean Whitton To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 07 09:43:23 2024 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 1sQMYN-000AKT-6L for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Jul 2024 09:43:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQMY0-0002Qg-Ba; Sun, 07 Jul 2024 03:43:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQMXy-0002QF-Dm for bug-gnu-emacs@gnu.org; Sun, 07 Jul 2024 03:42:58 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQMXy-0000T0-5Z for bug-gnu-emacs@gnu.org; Sun, 07 Jul 2024 03:42:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sQMY2-0001EU-0O for bug-gnu-emacs@gnu.org; Sun, 07 Jul 2024 03:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Jul 2024 07:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71929 X-GNU-PR-Package: emacs Original-Received: via spool by 71929-submit@debbugs.gnu.org id=B71929.17203381424690 (code B ref 71929); Sun, 07 Jul 2024 07:43:01 +0000 Original-Received: (at 71929) by debbugs.gnu.org; 7 Jul 2024 07:42:22 +0000 Original-Received: from localhost ([127.0.0.1]:47245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sQMXO-0001Da-8b for submit@debbugs.gnu.org; Sun, 07 Jul 2024 03:42:22 -0400 Original-Received: from sonic302-20.consmr.mail.ne1.yahoo.com ([66.163.186.146]:42007) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sQMXM-0001DI-Oe for 71929@debbugs.gnu.org; Sun, 07 Jul 2024 03:42:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1720338129; bh=hL7qh5uKHPqDthhx0qgr8cPARgjSvXF8OwKL37yD63A=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=dDV+NNnikexzreWj0CYbax2WSZm27RzYeCOCwsr9OtCv+75UdIe9/BJZsohF/0qC2amnt+z5q1AxsJ9qv6Ru/TbR9nYTDxL5L0NLx/A9GukMqKYhmun3f+1aUFcqpE53e0FgVvR8vKDlxZ3mH1imDNfpLvkafaBAhvIoXNGn2gkGx8sEQUK05CxsErczeKs50bVz1QYPmIZMQkg5KzhJwLH6IZG91CT66NOLG+nGk92qkack6ARfltBHvNLmGRK5s8/TO6bxSXL/ezOBGn3QXDCJxLdVWVV4Nk83CSxhZzgniuFif+uOei6uo6N8o9H3I8N0qx46STNoWsDMWGixAw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1720338129; bh=nxCkNdCi6lD4sFMxi5jEyLgml0DF9/x8u7pWeb9XvyL=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=SgdiF3GQGcB1g3xfiuPKBGKjicUs6gAQsTua+Pntx+k7NcMXD8T/B7ZzyEPipjLVhFzosQ3yzOmPdSx/AVkN4GPY0j3xyjxfQL1RrRneImoegORQv3Uv20v31YoGwuhIPdiHANLgBRvlPLPGhwsJ5+leAUjBNUmix0PuUJ0+bMifri6xX0df6CUsS93IEQdB77cZQMHD8WAl0GYlubIpF53gn8Ln9EX44Aw4PFXNa9qlz6vtc5vt1zmFU5iecPOh4Q6UGjFFGV1T8Fn8KQgiE/ZW1j/b/Pygx2EuKamWuhmZPLJmN5g4s/hTI8c5uXBI0AcVTP9XEf3gnOe051XeNw== X-YMail-OSG: 76pHJ6wVM1mgDIzfQx2MqQXbfG.9VebQB63irBuYjUFDwb42VEdZ2A8uwIpfxHp wHsrHG8BQIitJKgUo_2_dtxI8vw2W8PKjr.bicQrv0YQvrj83v_8i.vs7FgMSfKkUyy_pNv7hQ4u LN0wWWrkx6g5z0hbsOzoyFhGMUfid0aqUrhPkodakUp6e.Ti.BgxuIcszsAVOnkYySZGrYgDBlwW x0vwz1Py0WemBjBFdqdnIA3UguBHOpv3xU6plo4NfQohFXdJTlO4AStap8bok7OWZ5ktl_YZu_6l zRzSFZtS.Mi7JcD7QbTFkz02dgbGCrnynKU_rPBUFPFnwQZaKc4QQuPJEFYHWE1POFLJwPrnbXIC GIuGQLRGasqdfAXnUU6qn_8nFsLw.vv21_p7Syr7d18XaCZ7LvqVA7aoN3e3tJ6mt4sFRN7O4XRF TuXf6ZAnSvWcRGZGDrwrKewSo.Z0.YOKcflSbkvYJ22RdLyloKA9aRkG2RhyZFrG8ucBZcSpYqyx lChkb7DwvOiB2juVld4g9OflHFJ2s_PFTkBjHZbiHhHyB7_UXyo0q6B2RsFtW5jlFfRLY8deHMPT 532Qh45rTz3N86gBGvIYeYLwVERLVgi_X1rDjLjvDrnuC3H2raq6A5NCQU9mK6U4jLVF8gJZzOPS KTItkZQEcTS9QgoNfrUlqwLkNxxSnzP6QWf6FnG0haHFPIJtEg__fLIkDzDfidsvgSD5j_1PW0a6 B1jjlxk1SiMp8tyWqDjlqfQq8rwJBvrBIARENhc.KSn3Y37OYTjvujieKnC.bo5ioFktPDCn.Sme 5vC45slaCnUokMOvv9bCaIxAijy1pMOJ0LgH1DXQOR X-Sonic-MF: X-Sonic-ID: 6eacb9f7-12d7-4803-ae2f-3e07bca834d6 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Sun, 7 Jul 2024 07:42:09 +0000 Original-Received: by hermes--production-sg3-7b469d9f6-w9xm6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 7baf8149924fe8f3d0c675118afe2749; Sun, 07 Jul 2024 07:42:01 +0000 (UTC) In-Reply-To: <86a5it3cj2.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 07 Jul 2024 10:08:01 +0300") X-Mailer: WebService/1.1.22464 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:288548 Archived-At: Eli Zaretskii writes: > This is the initial frame of the daemon. It is not a GUI frame, and > so it should not have a valid image cache. I guess some change is > needed in verify_image_cache_refcount? Not quite: init_frame_faces is apparently called before the frame is entered into Vframe_list, so, likewise, the face cache's reference count should be verified before it is incremented. Sean, please retry with this patch substituted for the previous: diff --git a/src/frame.c b/src/frame.c index 7f4bf274ad9..9793b9f5cbe 100644 --- a/src/frame.c +++ b/src/frame.c @@ -4831,14 +4831,20 @@ gui_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) /* Clean F's image cache of images whose values are derived from the font width. */ clear_image_cache (f, Qauto); + verify_image_cache_refcount (FRAME_IMAGE_CACHE (f)); } else { + struct image_cache *old_cache = FRAME_IMAGE_CACHE (f); + /* Release the current image cache, and reuse or allocate a new image cache with IWIDTH. */ FRAME_IMAGE_CACHE (f)->refcount--; + FRAME_IMAGE_CACHE (f) = NULL; + verify_image_cache_refcount (old_cache); FRAME_IMAGE_CACHE (f) = share_image_cache (f); FRAME_IMAGE_CACHE (f)->refcount++; + verify_image_cache_refcount (FRAME_IMAGE_CACHE (f)); } } diff --git a/src/frame.h b/src/frame.h index 1d920d1a6bc..8a636c56643 100644 --- a/src/frame.h +++ b/src/frame.h @@ -1682,6 +1682,31 @@ IMAGE_OPT_FROM_ID (struct frame *f, int id) eassume (0 <= used); return 0 <= id && id < used ? FRAME_IMAGE_CACHE (f)->images[id] : NULL; } + +/* Abort if C is non-NULL and C's `refcount' field disagrees with the + number of frames holding references to the same. */ + +INLINE void +verify_image_cache_refcount (struct image_cache *c) +{ + int expected; + Lisp_Object tail, frame; + + if (c) + { + expected = 0; + + FOR_EACH_FRAME (tail, frame) + { + if (FRAME_IMAGE_CACHE (XFRAME (frame)) == c) + expected++; + } + + if (expected != c->refcount) + emacs_abort (); + } +} + #endif /*********************************************************************** diff --git a/src/image.c b/src/image.c index 2945447b962..9387c78408b 100644 --- a/src/image.c +++ b/src/image.c @@ -3625,6 +3625,7 @@ cache_image (struct frame *f, struct image *img) { c = FRAME_IMAGE_CACHE (f) = share_image_cache (f); c->refcount++; + verify_image_cache_refcount (c); } /* Find a free slot in c->images. */ diff --git a/src/xfaces.c b/src/xfaces.c index 188dd4778bc..ed4d404fbf3 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -678,7 +678,10 @@ init_frame_faces (struct frame *f) /* Make or share an image cache. */ if (FRAME_WINDOW_P (f)) { - FRAME_IMAGE_CACHE (f) = share_image_cache (f); + struct image_cache *c = share_image_cache (f); + + verify_image_cache_refcount (c); + FRAME_IMAGE_CACHE (f) = c; ++FRAME_IMAGE_CACHE (f)->refcount; } #endif /* HAVE_WINDOW_SYSTEM */ @@ -709,6 +712,7 @@ free_frame_faces (struct frame *f) struct image_cache *image_cache = FRAME_IMAGE_CACHE (f); if (image_cache) { + verify_image_cache_refcount (image_cache); --image_cache->refcount; if (image_cache->refcount == 0) free_image_cache (f);