From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Bignum speedup patch causes crash at startup Date: Tue, 4 Sep 2018 09:40:47 -0700 Organization: UCLA Computer Science Department Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------42FE9E16899454CA1B838F5D" X-Trace: blaine.gmane.org 1536079147 16314 195.159.176.226 (4 Sep 2018 16:39:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Sep 2018 16:39:07 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 To: Andy Moreton , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 04 18:39:03 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxELy-0003zb-WD for ged-emacs-devel@m.gmane.org; Tue, 04 Sep 2018 18:38:59 +0200 Original-Received: from localhost ([::1]:51773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxEO5-0004y9-5Z for ged-emacs-devel@m.gmane.org; Tue, 04 Sep 2018 12:41:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxENu-0004wc-A9 for emacs-devel@gnu.org; Tue, 04 Sep 2018 12:40:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxENn-0006eV-D2 for emacs-devel@gnu.org; Tue, 04 Sep 2018 12:40:56 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:37806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxENn-0006c4-2H for emacs-devel@gnu.org; Tue, 04 Sep 2018 12:40:51 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 91800160FBE; Tue, 4 Sep 2018 09:40:49 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id rjo9xQpEgMm6; Tue, 4 Sep 2018 09:40:48 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 503CA16116C; Tue, 4 Sep 2018 09:40:48 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ikPwGYYKE2UO; Tue, 4 Sep 2018 09:40:48 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 282EA160FBE; Tue, 4 Sep 2018 09:40:48 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:229244 Archived-At: This is a multi-part message in MIME format. --------------42FE9E16899454CA1B838F5D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Andy Moreton wrote: > The recent changes in commit fe042e9d ("Speed up (+ 2 2) by a factor of > 10") cause an immediate crash in 64bit emacs on Windows. Thanks for reporting it. Please try the attached patch, which I installed on master. > A patch that is this invasive should have been posted for comment and > review before it was committed. My feeling was that it was limited to bignum calculations, a reasonably compact area conceptually where we don't have many reviewers, unfortunately. Also, my judgment was that the effort to split this patch into pieces would have been more trouble overall than it would have been worth. Obviously this is a judgment call. I do regularly post for comment patches that I think might run into trouble on the MS-Windows side. I didn't think this one would cause trouble. Evidently I was wrong, sorry; these things happen. --------------42FE9E16899454CA1B838F5D Content-Type: text/x-patch; name="0001-Fix-bignum-initialization.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-bignum-initialization.patch" >From 1d84e6523250ab6d14f40fba3922c56d7a40416f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 4 Sep 2018 09:30:57 -0700 Subject: [PATCH] Fix bignum initialization Problem reported by Andy Moreton in: https://lists.gnu.org/r/emacs-devel/2018-09/msg00072.html and crystal-ball diagnosis by Eli Zaretskii in: https://lists.gnu.org/r/emacs-devel/2018-09/msg00075.html * src/alloc.c (xrealloc_for_gmp, xfree_for_gmp): Move to bignum.c. (init_alloc): Move bignum initialization to init_bignum. * src/bignum.c (init_bignum): Rename from init_bignum_once. All users changed. * src/emacs.c (main): Call init_bignum after init_alloc, instead of calling init_bignum_once after init_bignum. --- src/alloc.c | 16 ---------------- src/bignum.c | 18 +++++++++++++++++- src/bignum.h | 2 +- src/emacs.c | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 1eab82d1c2..28ca7804ee 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -7126,18 +7126,6 @@ range_error (void) xsignal0 (Qrange_error); } -static void * -xrealloc_for_gmp (void *ptr, size_t ignore, size_t size) -{ - return xrealloc (ptr, size); -} - -static void -xfree_for_gmp (void *ptr, size_t ignore) -{ - xfree (ptr); -} - /* Initialization. */ void @@ -7171,10 +7159,6 @@ init_alloc_once (void) void init_alloc (void) { - eassert (mp_bits_per_limb == GMP_NUMB_BITS); - integer_width = 1 << 16; - mp_set_memory_functions (xmalloc, xrealloc_for_gmp, xfree_for_gmp); - Vgc_elapsed = make_float (0.0); gcs_done = 0; diff --git a/src/bignum.c b/src/bignum.c index 2ce7412d06..35894f5647 100644 --- a/src/bignum.c +++ b/src/bignum.c @@ -34,9 +34,25 @@ along with GNU Emacs. If not, see . */ mpz_t mpz[4]; +static void * +xrealloc_for_gmp (void *ptr, size_t ignore, size_t size) +{ + return xrealloc (ptr, size); +} + +static void +xfree_for_gmp (void *ptr, size_t ignore) +{ + xfree (ptr); +} + void -init_bignum_once (void) +init_bignum (void) { + eassert (mp_bits_per_limb == GMP_NUMB_BITS); + integer_width = 1 << 16; + mp_set_memory_functions (xmalloc, xrealloc_for_gmp, xfree_for_gmp); + for (int i = 0; i < ARRAYELTS (mpz); i++) mpz_init (mpz[i]); } diff --git a/src/bignum.h b/src/bignum.h index 07622a37af..0e38c615ee 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -43,7 +43,7 @@ struct Lisp_Bignum extern mpz_t mpz[4]; -extern void init_bignum_once (void); +extern void init_bignum (void); extern Lisp_Object make_integer_mpz (void); extern void mpz_set_intmax_slow (mpz_t, intmax_t) ARG_NONNULL ((1)); diff --git a/src/emacs.c b/src/emacs.c index 5b399eca64..b1c96d1828 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1209,7 +1209,6 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem if (!initialized) { init_alloc_once (); - init_bignum_once (); init_threads_once (); init_obarray (); init_eval_once (); @@ -1257,6 +1256,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem } init_alloc (); + init_bignum (); init_threads (); if (do_initial_setlocale) -- 2.17.1 --------------42FE9E16899454CA1B838F5D--