From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bruno Haible Newsgroups: gmane.emacs.bugs Subject: bug#57129: 29.0.50; Improve behavior of conditionals in Eshell Date: Tue, 16 Aug 2022 21:59:10 +0200 Message-ID: <2135151.C4sosBPzcN__382.61770257435$1660680020$gmane$org@nimes> References: <1871347.6tgchFWduM@nimes> <838rnofgad.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2470919.4XsnlVU6TS" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39265"; mail-complaints-to="usenet@ciao.gmane.io" Cc: jporterbugs@gmail.com, larsi@gnus.org, eggert@cs.ucla.edu, bug-gnulib@gnu.org, 57129@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 16 22:00:12 2022 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 1oO2jT-0009zN-Tr for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Aug 2022 22:00:12 +0200 Original-Received: from localhost ([::1]:53498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO2jS-0004Ba-Tv for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Aug 2022 16:00:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO2jL-0004BD-AU for bug-gnu-emacs@gnu.org; Tue, 16 Aug 2022 16:00:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58689) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO2jL-0007ga-00 for bug-gnu-emacs@gnu.org; Tue, 16 Aug 2022 16:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oO2jK-0008Dh-Rb for bug-gnu-emacs@gnu.org; Tue, 16 Aug 2022 16:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Bruno Haible Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Aug 2022 20:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57129 X-GNU-PR-Package: emacs Original-Received: via spool by 57129-submit@debbugs.gnu.org id=B57129.166067995631516 (code B ref 57129); Tue, 16 Aug 2022 20:00:02 +0000 Original-Received: (at 57129) by debbugs.gnu.org; 16 Aug 2022 19:59:16 +0000 Original-Received: from localhost ([127.0.0.1]:48438 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oO2ia-0008CF-2V for submit@debbugs.gnu.org; Tue, 16 Aug 2022 15:59:16 -0400 Original-Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.54]:40943) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oO2iX-0008C6-PJ for 57129@debbugs.gnu.org; Tue, 16 Aug 2022 15:59:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1660679950; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=MqIf/K6WFWBXw9SmvP1Tk1nL/nip8h/gJtfRkQ0eLt4=; b=G6Cbgmw+J3lYBywD7l600y2vLcVOcwhNBaM3tvVhttV4jTWrqzanKZTLsy83v9XR94 7+H4njmynDHXdRQqbuCL8eqkeE8Wvga40/KVXcQIG3nLmOEysTe5VSPtHQYOwJqzTAGl aBReu/iRpMx9HlqAiEyhvyeQdqjx9/WBKh/YrwUSJEWAp10i51VXqTV7J1pEWfboXVbV A7ykz6mQatJ/Jx4VqVf3NM5SBo5ENeCJZ1WqKbORqrbRBDpyTJMSUYsh8B/LKCM6E9h8 PHb9Sz7FBek35x+1I+iNGw9hUTVGv6AnFfHa3WfNxSDH5KrD6T6+Z9SPDDc+EmITaubu 0Atw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zG6tLj91pCR2L7hM6+Odi8PRCuZoP2/ZC83xg==" X-RZG-CLASS-ID: mo00 Original-Received: from nimes.localnet by smtp.strato.de (RZmta 47.47.0 AUTH) with ESMTPSA id g97246y7GJxAmr9 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 16 Aug 2022 21:59:10 +0200 (CEST) In-Reply-To: <838rnofgad.fsf@gnu.org> 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:240000 Archived-At: This is a multi-part message in MIME format. --nextPart2470919.4XsnlVU6TS Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Eli Zaretskii wrote: > Looking at your test program, I see that you generate the seconds file > name without deleting the first one. When a file by the first > generated name already exists, gen_tempname will indeed generate a > different name. But in the scenario I described, Emacs creates one > temporary file, uses it, then deletes it, and only after that creates > another file. I'm adding this scenario to the unit test. Still, the unit test succeeds when run once on: Linux, FreeBSD, NetBSD, OpenBSD, macOS, Solaris, Cygwin, native Windows. Since this contradicts what you debugged on mingw, I ran the test 10000 times on native Windows. Result: - on 32-bit mingw, no failure. - on 64-bit mingw, around 30 failures (or around 10 failures with Paul's newest patch). That is, a probability of ca. 0.3% of getting the same file name as on the previous call. Bruno --nextPart2470919.4XsnlVU6TS Content-Disposition: attachment; filename="0001-tempname-Add-more-tests.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-tempname-Add-more-tests.patch" >From aa52cadc36fb1af0509dc3a4bce4ce73197ece68 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 16 Aug 2022 21:50:11 +0200 Subject: [PATCH] tempname: Add more tests. Based on scenario described by Eli Zaretskii in . * tests/test-tempname.c (main): Add another test. * modules/tempname-tests (Status): Mark the test as unportable. --- ChangeLog | 8 ++++++ modules/tempname-tests | 3 ++ tests/test-tempname.c | 65 ++++++++++++++++++++++++++++++------------ 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb96281591..de113ce081 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2022-08-16 Bruno Haible + + tempname: Add more tests. + Based on scenario described by Eli Zaretskii in + . + * tests/test-tempname.c (main): Add another test. + * modules/tempname-tests (Status): Mark the test as unportable. + 2022-08-16 Paul Eggert tempname: generate better names for MinGW Emacs diff --git a/modules/tempname-tests b/modules/tempname-tests index 384f98707b..adccd0d8e9 100644 --- a/modules/tempname-tests +++ b/modules/tempname-tests @@ -2,6 +2,9 @@ Files: tests/test-tempname.c tests/macros.h +Status: +unportable-test + Depends-on: unlink diff --git a/tests/test-tempname.c b/tests/test-tempname.c index d463eec2b4..4a0ca65f2c 100644 --- a/tests/test-tempname.c +++ b/tests/test-tempname.c @@ -34,24 +34,53 @@ main () char filename1[18 + 1]; char filename2[18 + 1]; - strcpy (filename1, templ18); - int fd1 = gen_tempname (filename1, strlen (".xyz"), 0, GT_FILE); - ASSERT (fd1 >= 0); - - strcpy (filename2, templ18); - int fd2 = gen_tempname (filename2, strlen (".xyz"), 0, GT_FILE); - ASSERT (fd2 >= 0); - - /* With 6 'X' and a good pseudo-random number generator behind the scenes, - the probability of getting the same file name twice in a row should be - 1/62^6 < 1/10^10. */ - ASSERT (strcmp (filename1, filename2) != 0); - - /* Clean up. */ - close (fd1); - close (fd2); - unlink (filename1); - unlink (filename2); + /* Case 1: The first file still exists while gen_tempname is called a second + time. */ + { + strcpy (filename1, templ18); + int fd1 = gen_tempname (filename1, strlen (".xyz"), 0, GT_FILE); + ASSERT (fd1 >= 0); + + strcpy (filename2, templ18); + int fd2 = gen_tempname (filename2, strlen (".xyz"), 0, GT_FILE); + ASSERT (fd2 >= 0); + + /* gen_tempname arranges (via O_EXCL) to not return the name of an existing + file. */ + ASSERT (strcmp (filename1, filename2) != 0); + + /* Clean up. */ + close (fd1); + close (fd2); + unlink (filename1); + unlink (filename2); + } + + /* Case 2: The first file is deleted before gen_tempname is called a second + time. */ + { + strcpy (filename1, templ18); + int fd1 = gen_tempname (filename1, strlen (".xyz"), 0, GT_FILE); + ASSERT (fd1 >= 0); + + /* Clean up. */ + close (fd1); + unlink (filename1); + + strcpy (filename2, templ18); + int fd2 = gen_tempname (filename2, strlen (".xyz"), 0, GT_FILE); + ASSERT (fd2 >= 0); + + /* With 6 'X' and a good pseudo-random number generator behind the scenes, + the probability of getting the same file name twice in a row should be + 1/62^6 < 1/10^10. + But on 64-bit native Windows, this probability is ca. 0.1% to 0.3%. */ + ASSERT (strcmp (filename1, filename2) != 0); + + /* Clean up. */ + close (fd2); + unlink (filename2); + } return 0; } -- 2.34.1 --nextPart2470919.4XsnlVU6TS--