From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.bugs Subject: bug#40897: Negation of pixel-width :width expressions does not work Date: Mon, 27 Apr 2020 08:47:50 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0000000000004ad4da05a441c77d" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="12201"; mail-complaints-to="usenet@ciao.gmane.io" To: 40897@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 27 10:49:13 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 1jSzRw-00031Z-4N for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 Apr 2020 10:49:12 +0200 Original-Received: from localhost ([::1]:60292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSzRu-0003wi-Um for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 Apr 2020 04:49:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53994) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSzRm-0003vE-RM for bug-gnu-emacs@gnu.org; Mon, 27 Apr 2020 04:49:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSzRm-0000Kh-BM for bug-gnu-emacs@gnu.org; Mon, 27 Apr 2020 04:49:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSzRl-0000HF-Ue for bug-gnu-emacs@gnu.org; Mon, 27 Apr 2020 04:49:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jSzRl-0000gg-So for bug-gnu-emacs@gnu.org; Mon, 27 Apr 2020 04:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 Apr 2020 08:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40897 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15879773182610 (code B ref -1); Mon, 27 Apr 2020 08:49:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Apr 2020 08:48:38 +0000 Original-Received: from localhost ([127.0.0.1]:35649 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jSzRN-0000g1-Jl for submit@debbugs.gnu.org; Mon, 27 Apr 2020 04:48:37 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:36494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jSzRL-0000ft-Ia for submit@debbugs.gnu.org; Mon, 27 Apr 2020 04:48:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53850) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSzRK-0003qk-23 for bug-gnu-emacs@gnu.org; Mon, 27 Apr 2020 04:48:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSzRF-0005av-HI for bug-gnu-emacs@gnu.org; Mon, 27 Apr 2020 04:48:33 -0400 Original-Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]:39640) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSzRF-0005Zw-4D for bug-gnu-emacs@gnu.org; Mon, 27 Apr 2020 04:48:29 -0400 Original-Received: by mail-ot1-x32a.google.com with SMTP id m13so24840698otf.6 for ; Mon, 27 Apr 2020 01:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=5WxPetgRP8Iz7CTkEPdMzOIIKoXk4S2iCU5ugN9cjvc=; b=XrLzXJusbVH0I6jwXKREGXY0mt6672Vqdhox7bdlp3nnkL8nelHocCuLNXfj6YfZzv BN3KpYEh6QMgfSU8zn6IKLKpkl2dP4BtjYmn9z7fYokvKPlT//OQnpnm1sY+WADJX8/b H13R2MeDXTO/eOKlv6K+0ytRlxsqlM5hapCtfTXTUJGE/x2bqXCRC+ODFgmYCsrNEOT7 BBhAV9aJrghJIFjqApaIJJf3lr0NtoRNXzGcQtvyvOctecv8iHkLyc0Zc44P9ro4oqUC cyZ00/IqnPwS5ukdSz/keOGRY+T95OXIwoa2C/1ttsdzrSB1usdaO7K0h/XLah4dZdiN 3NLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=5WxPetgRP8Iz7CTkEPdMzOIIKoXk4S2iCU5ugN9cjvc=; b=VDvjq857J+RlebL+QbXnKrIPpKWR1Bg3dwqdN0kz5vZuhSCv8EhZ01uC1VqVpCK46G OJ7dQlNNIWZqKsedwcBIkkd5IDMbqs74OBXWMM3D9b9d0jG9s1mxZZ19dg5F6H5Oejgg bKbyK6hQE6fLVdSVh3qjH1bZ/YjVIneig/u4tY3z2ffzeVd8P1fgNL4DnEUifu1A4nai GZbFQKoHxgY90/1aTZOzd/4Xa3op1jdGX6AhYEGHEmDGjheXb1LOjRMW6muefs44SaYD WukaD49EXkD8ST6fRQhPi/v2rsJDjXGaAbSUVuTS1T0qjhAuUDSvDcEce6u0j+PXFhbt zIPQ== X-Gm-Message-State: AGi0PuZ0uD7QBgKhTk1Ggi+8PbODvwsAPXY6XmPYgSfDj35TQsQZWofz PAdCbue+BDMO1fxwp7cCe32Z0Wi9Qmsk0bFLeOrXrV7m3nA= X-Google-Smtp-Source: APiQypIUsMc+GLt3hEVNt+XJtHDz/fnHv6MpV97mckV/U1d71K2EteklaEE2mrXWuTtjl2GHui2iBe4DFt6GjJUjM3s= X-Received: by 2002:a05:6830:1059:: with SMTP id b25mr69552otp.292.1587977306938; Mon, 27 Apr 2020 01:48:26 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::32a; envelope-from=pipcet@gmail.com; helo=mail-ot1-x32a.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:179137 Archived-At: --0000000000004ad4da05a441c77d Content-Type: text/plain; charset="UTF-8" In looking over the xdisp.c code, I noticed that calc_pixel_width_or_height has at least three problems: 1. negation of width specifiers doesn't work 2. a circular list passed to (+) will hang Emacs 3. a circular list passed directly will crash Emacs (1) is a significant bug and should be fixed. (2) is easy to fix, and we should probably do so on the master branch. (3) is difficult to fix, but I'd like to fix all these, and undiscovered similar issues, by converting calc_pixel_width_or_height to using the Lisp interpreter. The underlying problem is we're writing yet another mini-interpreter for a limited Lisp-like language, in C. That means no quitting, no protection against stack overflows, and getting tricky semantics (such as the different behavior of (- A) and (- A B ...)) wrong. My proposal is to move the somewhat complex logic of calc_pixel_width_or_height to Lisp code, run when the display spec is actually evaluated (i.e. when "(when ...)" display specs run their Lisp code). This could be achieved by a method similar to the patch for bug#40845 in https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-04/msg01096.html. This would also resolve bug#40856 by allowing more complicated space calculations at a time when the font metrics are known. I'm attaching a patch, against master, for (1) only. I haven't tried to restore the previous "optimization" of avoiding (very cheap) calls to EQ for all but the first argument. Recipes: (1): (insert (propertize " " 'display '(space :width (+ 50 (- 50))))) Expected result: a zero-width space Actual result: a space of width 100 (2): (let ((l (cons 0 nil))) (setcdr l l) (insert (propertize " " 'display `(space :width (+ . ,l))))) Expected result: a quittable infinite loop Actual result: a non-quittable infinite loop (3): (let ((l (cons 0 nil))) (setcdr l l) (insert (propertize " " 'display `(space :width ,l)))) Expected result: a Lisp stack overflow error Actual result: a C stack overflow, Emacs crashes --0000000000004ad4da05a441c77d Content-Type: text/x-patch; charset="US-ASCII"; name="0001-Fix-pixel-width-evaluation-of-negated-specs.patch" Content-Disposition: attachment; filename="0001-Fix-pixel-width-evaluation-of-negated-specs.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_k9i8n4k40 RnJvbSBiNzQ5M2ZmOTM0NTUzYTJkMDA4Y2NlNGZiODg0NGQyNWZkMmRmOTk4IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBQaXAgQ2V0IDxwaXBjZXRAZ21haWwuY29tPgpEYXRlOiBNb24s IDI3IEFwciAyMDIwIDA4OjQxOjUyICswMDAwClN1YmplY3Q6IFtQQVRDSF0gRml4IHBpeGVsLXdp ZHRoIGV2YWx1YXRpb24gb2YgbmVnYXRlZCBzcGVjcwoKKiBzcmMveGRpc3AuYyAoY2FsY19waXhl bF93aWR0aF9vcl9oZWlnaHQpOiBGaXggZXZhbHVhdGlvbiBvZiAoLSBYKQpTUEVDLgotLS0KIHNy Yy94ZGlzcC5jIHwgMTAgKysrKystLS0tLQogMSBm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