GNU bug report logs - #34404
26.1; Finalizer in hash table run early?

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Braun Gábor <braungb88@HIDDEN>; dated Sat, 9 Feb 2019 18:04:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 9 Feb 2019 18:03:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 09 13:03:10 2019
Received: from localhost ([127.0.0.1]:41488 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gsWy5-00088F-EN
	for submit <at> debbugs.gnu.org; Sat, 09 Feb 2019 13:03:10 -0500
Received: from eggs.gnu.org ([209.51.188.92]:58208)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <braungb88@HIDDEN>) id 1gsSrc-0001ZE-S9
 for submit <at> debbugs.gnu.org; Sat, 09 Feb 2019 08:40:13 -0500
Received: from lists.gnu.org ([209.51.188.17]:48101)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <braungb88@HIDDEN>) id 1gsSrX-0000pH-K9
 for submit <at> debbugs.gnu.org; Sat, 09 Feb 2019 08:40:07 -0500
Received: from eggs.gnu.org ([209.51.188.92]:44357)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <braungb88@HIDDEN>) id 1gsSrW-0004ka-0v
 for bug-gnu-emacs@HIDDEN; Sat, 09 Feb 2019 08:40:07 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: *
X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50,
 FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,URIBL_BLOCKED autolearn=disabled
 version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <braungb88@HIDDEN>) id 1gsSrU-0000nn-Et
 for bug-gnu-emacs@HIDDEN; Sat, 09 Feb 2019 08:40:05 -0500
Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:55310)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <braungb88@HIDDEN>) id 1gsSrT-0000lV-Ju
 for bug-gnu-emacs@HIDDEN; Sat, 09 Feb 2019 08:40:03 -0500
Received: by mail-wm1-x344.google.com with SMTP id r17so8399846wmh.5
 for <bug-gnu-emacs@HIDDEN>; Sat, 09 Feb 2019 05:40:02 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=pTPxVEKavesNddiqKP4Vk5Z9IrqxD7hkjoANpPl21Jo=;
 b=Jq0nAbaGB3Pzc+1FRWcxD3NJhipQTEGPyIbXdG6iUnR/9oqXqPzLgqkcSpi2rrWVJM
 tRzz3t0QaC0m/knPHppO8A/Ug0S8cyQl+ajCh6mcny2VqQ5zTgjyZKZscIXaoj3WSqnq
 a09cfCP8/ZxGbVFk/WM7P1nkTsKJXZwsqaVduGfZhk3B7RNjoSEL4JekwW9FHR+gwISq
 RFpaeUaRz7FqzFsayAXoFOSY+4MW5tdxim48VnoAbLRzF4HEY+KyQpVb/oO31hJci4gW
 gvBtVzQu+0Hr0qjbwRELsz9weGaB0cylG/72K/4+JrmOSlxq/hgwGmeVPdXo+ERmc9j6
 yG7w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=pTPxVEKavesNddiqKP4Vk5Z9IrqxD7hkjoANpPl21Jo=;
 b=RJ62JUJRT+tkdez73rgwimnoUSFOK6FUC5xZCnvZVaQWJ9syMIwbhkQQqTEksl6taS
 4mRH8U2RrFQdl/g5lOfWU4T3dSz5BbCkkgkp+AB7O0NnHu0Azq6PIqF14+OF4OHHXI9C
 5Z77lcC3+cGRNi5DK+4wyJH+v/XPM00ncN+3lio3kb0Gs6x7MvVXZJ2ybTt6pXdA48d8
 CsrwQq7eVStvnZYgXTPiiPnC/q9Ldt20qr/9zExlBD6ajUQrSmSEct9yxYLYO5dSfuZQ
 cbaNNA1yTJjGVyiomX6avTk1tP7XmaszaGJziYlrbGqI5oDdPyV1RqzHzLV+dj3kn5IF
 9ayg==
X-Gm-Message-State: AHQUAuZnS0BcmvrG1IbfOODYzJ1jWeTPvp4X9RyY9pM5tCIw9FvuttUM
 kUmCd3kW8LOqaKa4wFINgUGjFws3
X-Google-Smtp-Source: AHgI3IZtyQN1I9pGZK4yIkjkO6VGzK666zaLu2hC34v1MmmELxU8loIOPXFaaFDDCDj6oj+h8tXVkw==
X-Received: by 2002:adf:fd0a:: with SMTP id e10mr21612793wrr.190.1549719600301; 
 Sat, 09 Feb 2019 05:40:00 -0800 (PST)
Received: from gabor.localnet (254C439A.nat.pool.telekom.hu. [37.76.67.154])
 by smtp.gmail.com with ESMTPSA id v13sm13849714wra.54.2019.02.09.05.39.58
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Sat, 09 Feb 2019 05:39:59 -0800 (PST)
From: Braun =?ISO-8859-1?Q?G=E1bor?= <braungb88@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 26.1; Finalizer in hash table run early?
Date: Sat, 09 Feb 2019 14:39:57 +0100
Message-ID: <6151161.jHdu2dTOOM@gabor>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2a00:1450:4864:20::344
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Spam-Score: 1.2 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  Hi, The following test is reported as failed in the *ert*
 buffer but I think it should pass. File test.el ;; -*- lexical-binding: t;
 -*- (require 'ert) 
 Content analysis details:   (1.2 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 0.0 URIBL_BLOCKED          ADMINISTRATOR NOTICE: The query to URIBL was
 blocked.  See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block
 for more information. [URIs: x.org]
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (braungb88[at]gmail.com)
 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends
 in digit (braungb88[at]gmail.com)
 1.0 SPF_SOFTFAIL           SPF: sender does not match SPF record (softfail)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sat, 09 Feb 2019 13:03:08 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.2 (/)

Hi,

The following test is reported as failed in the *ert* buffer
but I think it should pass.

=2D------------ File test.el ------------------
;; -*- lexical-binding: t; -*-
(require 'ert)

(ert-deftest finalizer-in-weak-hash-table ()
  "Test finalizers in weak hash tables"
  (skip-unless (fboundp 'make-finalizer))
  (let ((finalizer-run nil))
    (let ((table (make-hash-table :weakness 'key)))
      (let ((key (make-symbol "key")))
        ;; Without wrapper (ignore ...) the test passes, why?
        (ignore
         (puthash
          key
          (make-finalizer (lambda () (setq finalizer-run t)))
          table))
        (garbage-collect)
        ;; With just one (garbage-collect), the test passes.
        (garbage-collect)
        (message "Finalizer: %s" (gethash key table))
        (should-not finalizer-run)
        ;; Prevent optimizing out early.
        (message "Finalizer: %s" (gethash key table)))
      (garbage-collect)
      ;;(garbage-collect)
      (should finalizer-run))))
=2D---------------------------------------------------------------

Start emacs with the command line:

emacs -Q -l test.el --eval '(ert t)'

In buffer *ert* press "m" with the cursor on the single test.
The following buffers are shown:

=2D------------- buffer *ert* ------------------------------------
Selector: t
Passed:  0
=46ailed:  1 (1 unexpected)
Skipped: 0
Total:   1/1

Started at:   2019-02-09 13:53:14+0100
=46inished.
=46inished at:  2019-02-09 13:53:15+0100

=46

=46 finalizer-in-weak-hash-table
    Test finalizers in weak hash tables
    (ert-test-failed
     ((should-not finalizer-run)
      :form finalizer-run :value t))


=2D---------------------------------------------------------------


=2D----------------- buffer *ERT Messages* -----------------------
Messages for test =E2=80=98finalizer-in-weak-hash-table=E2=80=99:
=46inalizer: #<finalizer used>
=2D---------------------------------------------------------------

Discussion:

The finalizer since its creation is always reachable in the inner-most=20
(let...)
via (gethash key table), so it shouldn't be run until the last
(message...) there, which accesses the finalizer this way.
However, both the message made in buffer *ERT Messages* as well as the=20
failed
form in buffer *ert* indicates that the finalizer has been run; that is
the only way the local variable finalizer-run can have a value t.

(The (message...) after the failed test (should-not...) is there to rule
out the destruction of local variables key and table early as a form of
optimization, which would justify running the finalizer before the=20
test.)

As some of the comments in the test indicate,
small changes cause the test to pass:
like omitting the wrapper (ignore...) around (puthash...)
or just one (garbage-collection) before (should-not...) causes the test
to pass.

System information:

In GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.2)
 of 2018-12-26, modified by Debian built on x86-ubc-01
Windowing system distributor 'The X.Org Foundation', version=20
11.0.12003000
System Description:	Debian GNU/Linux buster/sid

Recent messages:
=46or information about GNU Emacs and the GNU system, type C-h C-a.
=46inalizer: #<finalizer used>
Ran 1 tests, 0 results were as expected, 1 unexpected
Making completion list...

Configured using:
 'configure --build x86_64-linux-gnu --prefix=3D/usr
 --sharedstatedir=3D/var/lib --libexecdir=3D/usr/lib
 --localstatedir=3D/var/lib --infodir=3D/usr/share/info
 --mandir=3D/usr/share/man --enable-libsystemd --with-pop=3Dyes
 --enable-locallisppath=3D/etc/emacs:/usr/local/share/emacs/26.1/site-
lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/
usr/share/emacs/site-lisp
 --with-sound=3Dalsa --without-gconf --with-mailutils --build
 x86_64-linux-gnu --prefix=3D/usr --sharedstatedir=3D/var/lib
 --libexecdir=3D/usr/lib --localstatedir=3D/var/lib
 --infodir=3D/usr/share/info --mandir=3D/usr/share/man --enable-libsystemd
 --with-pop=3Dyes
 --enable-locallisppath=3D/etc/emacs:/usr/local/share/emacs/26.1/site-
lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/
usr/share/emacs/site-lisp
 --with-sound=3Dalsa --without-gconf --with-mailutils --with-x=3Dyes
 --with-x-toolkit=3Dgtk3 --with-toolkit-scroll-bars 'CFLAGS=3D-g -O2
 -fdebug-prefix-map=3D/build/emacs-3ThesY/emacs-26.1+1=3D. -fstack-
protector-strong
 -Wformat -Werror=3Dformat-security -Wall' 'CPPFLAGS=3D-Wdate-time
 -D_FORTIFY_SOURCE=3D2' LDFLAGS=3D-Wl,-z,relro'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 THREADS LIBSYSTEMD LCMS2

Important settings:
  value of $LANG: hu_HU.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ERT-View

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

=46eatures:
(shadow sort mail-extr emacsbug message rmc puny seq byte-opt bytecomp
byte-compile cconv dired dired-loaddefs format-spec rfc822 mml mml-sec
password-cache epa derived epg epg-config gnus-util rmail rmail-loaddefs
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils cl-seq thingatpt cl-extra help-mode cl-macs gv ert pp
find-func ewoc easymenu debug cl-loaddefs cl-lib elec-pair time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 107828 8705)
 (symbols 48 21253 1)
 (miscs 40 63 154)
 (strings 32 30662 1206)
 (string-bytes 1 809252)
 (vectors 16 16338)
 (vector-slots 8 511222 11260)
 (floats 8 60 178)
 (intervals 56 366 8)
 (buffers 992 14))


Best wishes,

     G=C3=A1bor Braun







Acknowledgement sent to Braun Gábor <braungb88@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#34404; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.