From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#23386: Segfault when messing with font-backend Date: Sun, 10 Jul 2016 16:15:07 -0400 Message-ID: <87d1mlgshg.fsf@users.sourceforge.net> References: <83y47zxi81.fsf@gnu.org> <87d1mmiq35.fsf@users.sourceforge.net> <8760seinqh.fsf@users.sourceforge.net> <83lh19fug5.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1468181788 27296 80.91.229.3 (10 Jul 2016 20:16:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 10 Jul 2016 20:16:28 +0000 (UTC) Cc: 23386@debbugs.gnu.org, monnier@IRO.UMontreal.CA To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 10 22:16:17 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bML9D-0006Y4-Q1 for geb-bug-gnu-emacs@m.gmane.org; Sun, 10 Jul 2016 22:16:16 +0200 Original-Received: from localhost ([::1]:56772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bML9C-0003J1-Jf for geb-bug-gnu-emacs@m.gmane.org; Sun, 10 Jul 2016 16:16:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bML94-0003Iv-S7 for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2016 16:16:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bML90-0007gU-Jr for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2016 16:16:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33344) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bML90-0007gO-Fj for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2016 16:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bML90-00053b-1w for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2016 16:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Jul 2016 20:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23386 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 23386-submit@debbugs.gnu.org id=B23386.146818172119387 (code B ref 23386); Sun, 10 Jul 2016 20:16:02 +0000 Original-Received: (at 23386) by debbugs.gnu.org; 10 Jul 2016 20:15:21 +0000 Original-Received: from localhost ([127.0.0.1]:45681 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bML8K-00052d-IX for submit@debbugs.gnu.org; Sun, 10 Jul 2016 16:15:20 -0400 Original-Received: from mail-io0-f170.google.com ([209.85.223.170]:36465) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bML8F-00052N-M9 for 23386@debbugs.gnu.org; Sun, 10 Jul 2016 16:15:18 -0400 Original-Received: by mail-io0-f170.google.com with SMTP id s93so41488775ioi.3 for <23386@debbugs.gnu.org>; Sun, 10 Jul 2016 13:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=OMqw5P3ieadIPHvdwLBJH4N9rvsJDcuJJXrGoNGKNxA=; b=tp25Cfe0WlGvm4vlcRFrSXPxtZycjrkYDSPQZKB0klberj8mxyQQu0mv9wp3KIbc9d jW3nyJzmvQLppG+kkyRK2Sq9JYnPcSpwPJp5GyB+WwVKuhJ5h12lB4dYvhguqye2EHJx znpeiM1WixAVHzMSVpMzXESawOHZYW0K1VjtRGZUkOlz9ebwp1/sYVUCv+jIUR3lWwXZ 5Xuemwzg7NobW9EzrbE1b5U0IIzVySlWoibj+psooV0cYQEnd/kheNDTZj91RF0DuLu4 Jl5D6ZEqjQsSAgYJrTxJQtsz5DYK6/8MFatNRWA+8oCfbgnHS9DHtRrpTIarB3mVNd71 hnUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=OMqw5P3ieadIPHvdwLBJH4N9rvsJDcuJJXrGoNGKNxA=; b=Dz17ZDSBWkPSxM0X+ZjNdTWCvUwOWEq4pJNe8Oq8QNy+fUS/fy0qd2A2hhoNyVwmk8 bZbOjTQhL9tkz4rM1TF9+NSDRUZkFdPXnocwfPb7Bp8WtdfC/rPvINuZfvePH2SryN7x ADpIgYxmgibNhUHnCisGyxiEfOs8MMyUqYhi2kWILkKtX/QqSPKjmrOvo7x7/gZFNypA FKF4yENBoxB49lz2Fom/DYOamA1kOpvW0SEoASrSyCS08/UbNlO6JoHHgFDTz4SnLWCD d05I4hAE7AMVMxAlDYXReWePvN0fLwyj0GI1ickI7P3UarQDR3PU2kYXwvlyt5FXQrzR elQA== X-Gm-Message-State: ALyK8tIjCfU2SAR2LhlSW6vSt8CLfHRCmu2CCkIfVpMB777jtWjdrac9pEgSNvgqPsHmLg== X-Received: by 10.107.159.16 with SMTP id i16mr16233626ioe.29.1468181710094; Sun, 10 Jul 2016 13:15:10 -0700 (PDT) Original-Received: from zony (206-188-64-44.cpe.distributel.net. [206.188.64.44]) by smtp.googlemail.com with ESMTPSA id i13sm6091797ita.18.2016.07.10.13.15.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Jul 2016 13:15:09 -0700 (PDT) In-Reply-To: <83lh19fug5.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 10 Jul 2016 17:18:02 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.93 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:120819 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: npostavs@users.sourceforge.net >> Cc: 23386@debbugs.gnu.org, Eli Zaretskii >> Date: Sat, 09 Jul 2016 16:02:30 -0400 >> >> > Here is a patch that attempts to fix the issue by resetting the font >> > after the backend is changed. It does let Emacs successfully open the >> > frame with the new font (no funny box characters in the modeline), but >> > I'm not sure if it's the best way of marking the font object invalid. >> >> Definitely not the best way: it causes segfault on delete-frame. > > Backtrace from that segfault? Hmm, looks like I just tried to kill the font twice, adding a NULL check fixes it. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v2-0001-Don-t-segfault-on-font-backend-change-Bug-23386.patch Content-Description: patch v2 >From f405410bf424b0a24a0eac54d12eeed758af95e9 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 9 Jul 2016 14:20:53 -0400 Subject: [PATCH v2] Don't segfault on font backend change (Bug #23386) * src/font.c (font_finish_cache): Kill frame's font if it used the driver we just turned off. * src/frame.c (x_set_font_backend): Reset the frame's font if it's been killed. --- src/font.c | 7 +++++++ src/frame.c | 16 ++++++++++++++-- src/frame.h | 1 + src/xfns.c | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/font.c b/src/font.c index 2519599..21eb95a 100644 --- a/src/font.c +++ b/src/font.c @@ -2587,6 +2587,13 @@ font_finish_cache (struct frame *f, struct font_driver *driver) font_clear_cache (f, XCAR (val), driver); XSETCDR (cache, XCDR (val)); } + + if (FRAME_FONT (f) && FRAME_FONT (f)->driver == driver) + { + /* Don't leave the frame's font pointing to a closed driver. */ + store_frame_param(f, Qfont, Qnil); + FRAME_FONT (f) = NULL; + } } diff --git a/src/frame.c b/src/frame.c index 00f25f7..d7454d9 100644 --- a/src/frame.c +++ b/src/frame.c @@ -3677,6 +3677,8 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) void x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { + Lisp_Object frame; + if (! NILP (new_value) && !CONSP (new_value)) { @@ -3718,11 +3720,21 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu } store_frame_param (f, Qfont_backend, new_value); + XSETFRAME (frame, f); + + /* If closing the font driver killed the frame's font, we need to + get a new one. */ + if (!FRAME_FONT (f)) + x_default_font_parameter (f, Fframe_parameters (frame)); + if (!FRAME_FONT (f)) + { + delete_frame (frame, Qnoelisp); + error ("Invalid frame font"); + } + if (FRAME_FONT (f)) { - Lisp_Object frame; - XSETFRAME (frame, f); x_set_font (f, Fframe_parameter (frame, Qfont), Qnil); face_change = true; windows_or_buffers_changed = 18; diff --git a/src/frame.h b/src/frame.h index f0cdcd4..5b5349e 100644 --- a/src/frame.h +++ b/src/frame.h @@ -1356,6 +1356,7 @@ extern void x_set_scroll_bar_default_height (struct frame *); extern void x_set_offset (struct frame *, int, int, int); extern void x_wm_set_size_hint (struct frame *f, long flags, bool user_position); extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int); +extern void x_default_font_parameter (struct frame *f, Lisp_Object parms); extern void x_set_frame_parameters (struct frame *, Lisp_Object); extern void x_set_fullscreen (struct frame *, Lisp_Object, Lisp_Object); extern void x_set_line_spacing (struct frame *, Lisp_Object, Lisp_Object); diff --git a/src/xfns.c b/src/xfns.c index 7c1bb1c..1b9dd48 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -3071,7 +3071,7 @@ do_unwind_create_frame (Lisp_Object frame) unwind_create_frame (frame); } -static void +void x_default_font_parameter (struct frame *f, Lisp_Object parms) { struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); -- 2.8.0 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=bug-23386-patch-v1-backtrace.txt Content-Description: backtrace #0 0x000000000063f535 in font_finish_cache (f=0x1404710, driver=0xd0f800 ) at font.c:2591 #1 0x0000000000642ccd in font_update_drivers (f=0x1404710, new_drivers=0) at font.c:3539 #2 0x0000000000429e82 in delete_frame (frame=20989717, force=0) at frame.c:1662 #3 0x000000000042a647 in Fdelete_frame (frame=0, force=0) at frame.c:1839 #4 0x0000000000624959 in Ffuncall (nargs=1, args=0x7fffffffdda8) at eval.c:2696 #5 0x000000000061afa2 in Ffuncall_interactively (nargs=1, args=0x7fffffffdda8) at callint.c:252 #6 0x00000000006247eb in Ffuncall (nargs=2, args=0x7fffffffdda0) at eval.c:2673 #7 0x000000000061d4ae in Fcall_interactively (function=17232, record_flag=0, keys=14537909) at callint.c:840 #8 0x0000000000624994 in Ffuncall (nargs=4, args=0x7fffffffe098) at eval.c:2700 #9 0x000000000066f3df in exec_byte_code (bytestr=10946140, vector=10946173, maxdepth=54, args_template=4102, nargs=1, args=0x7fffffffe5f0) at bytecode.c:880 #10 0x0000000000625271 in funcall_lambda (fun=10946093, nargs=1, arg_vector=0x7fffffffe5e8) at eval.c:2855 #11 0x0000000000624ba8 in Ffuncall (nargs=2, args=0x7fffffffe5e0) at eval.c:2742 #12 0x00000000006242e6 in call1 (fn=14784, arg1=17232) at eval.c:2552 #13 0x00000000005789a1 in command_loop_1 () at keyboard.c:1479 #14 0x000000000062104a in internal_condition_case (bfun=0x578178 , handlers=19056, hfun=0x5777e6 ) at eval.c:1309 #15 0x0000000000577da5 in command_loop_2 (ignore=0) at keyboard.c:1107 #16 0x00000000006205dc in internal_catch (tag=45840, func=0x577d7c , arg=0) at eval.c:1074 #17 0x0000000000577d47 in command_loop () at keyboard.c:1086 #18 0x00000000005772be in recursive_edit_1 () at keyboard.c:692 #19 0x00000000005774ca in Frecursive_edit () at keyboard.c:763 #20 0x0000000000575262 in main (argc=2, argv=0x7fffffffea98) at emacs.c:1606 Lisp Backtrace: "delete-frame" (0xffffddb0) "funcall-interactively" (0xffffdda8) "call-interactively" (0xffffe0a0) "command-execute" (0xffffe5e8) --=-=-= Content-Type: text/plain > > I think one idea that could be useful is to trace the creation of > relevant objects when Emacs starts up, starting with the call to > font_update_drivers, and then compare that with what happens in this > case. That could delineate the missing parts and the differences > which could point the way to solving this cleanly. Yeah, I'm still having trouble seeing the forest for the trees. --=-=-=--