From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 8101A1F461 for ; Mon, 9 Sep 2019 06:37:53 +0000 (UTC) Received: from localhost ([::1]:52418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7DJA-0000mB-8z for normalperson@yhbt.net; Mon, 09 Sep 2019 02:37:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7DJ5-0000ls-Mv for bug-gnulib@gnu.org; Mon, 09 Sep 2019 02:37:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7DJ4-0002Sm-DW for bug-gnulib@gnu.org; Mon, 09 Sep 2019 02:37:47 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:46484) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7DJ4-0002Sb-7X for bug-gnulib@gnu.org; Mon, 09 Sep 2019 02:37:46 -0400 Received: by mail-wr1-x435.google.com with SMTP id h7so12439964wrt.13 for ; Sun, 08 Sep 2019 23:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :cc:to; bh=WW4FOue5JpmwW0CmO4MKUaxRfQ8Fl3KnnLhB1sxAlvw=; b=Xi16D4ASXryJeg7xu2NJdR8mksRyRLlQBdCl5DYNzzi5oHVy5I18OLWjY/F/repNLd uPWLOm69lswrIlvC9oZSeApRStPjCYkFHj5RadlfZlycvH/VScXhPEF4SJv5V3Tg518X 8Y8qKv8/N0JuQkKmCBSBoAm6cP3oZ4GF4EoFP9qXB+BQ1YkaRMucXftpfyMsqqV0e4Od GcicEoZx/u4No64mhe/zjmcmda83+Ia0SqXmwyIJSzwZMB0n2wX6jRPQrgori3NM41Xh ZJ5kthgrCXXpiusm5troWFA1RPmBBWAuvZr7MWKynQHyFlIjI37vJXJip+Efo+zJvqUq /b9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:cc:to; bh=WW4FOue5JpmwW0CmO4MKUaxRfQ8Fl3KnnLhB1sxAlvw=; b=cGlhN5EBZgu4dC/Hqv4t/Jq3CCxgclcWHviruvCE7BP6bt1DK/hrp/Lli/CVX6IBCM mC05pQu36pOzFxtW1OIv7pvyd7mKfBjzEbla94b2oFaN2sINc0wOKlAxbhjk7S2vcwwX g8+04h35Mz8eHhKxUtO26gV/Ulb5oDXzevG3gwvO+GEpzk5MSMTOaTEeKJnh5j9L+E2L +bqElkZKWtw61UXkapfMnjQg+GBdDMeGsgRJEXXX2cqhWJ8JDf45P6gmSwWa7a19xKp+ JeYydgGZBWk6ydVlvijNkqQVb1uTWzxS7joy0+z2XwigcGZe/+052Vqnlv3lp3mrgQZB L85g== X-Gm-Message-State: APjAAAUQofTG+03f8g4a1ujYberPEovIYqQD1Wy9JQlDY4MkjsCyHDgl MHs40SOx2C8dlhaWkRdjALk= X-Google-Smtp-Source: APXvYqwOcB764cjr5VsG8sGb+q7zqnTJZOu1/+rxqv6S5PImRKoR+GeDIphnOxmVxIex5Z/2PXxYZA== X-Received: by 2002:adf:dc43:: with SMTP id m3mr17499634wrj.118.1568011065063; Sun, 08 Sep 2019 23:37:45 -0700 (PDT) Received: from [172.20.10.14] ([37.171.162.111]) by smtp.gmail.com with ESMTPSA id r28sm19070687wrr.94.2019.09.08.23.37.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Sep 2019 23:37:44 -0700 (PDT) From: Akim Demaille Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: hash: provide hash_xinitialize Message-Id: Date: Mon, 9 Sep 2019 08:37:40 +0200 To: Jim Meyering X-Mailer: Apple Mail (2.3445.104.11) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::435 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gnulib bugs Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hi Jim, Recently in Bison I had to check all my calls to hash_initialize for = memory exhaustion. Coreutils do it by hand for some of the calls, but = we could just as well provide a simple wrapper? commit 73f0aa2e58b1dabbe075ab6bf5644da36d7c72d2 Author: Akim Demaille Date: Mon Sep 9 08:31:33 2019 +0200 hash: provide hash_xinitialize. =20 Suggested by Egor Pugin = https://lists.gnu.org/archive/html/bison-patches/2019-09/msg00026.html =20 * modules/hash (Depends-on): Add xalloc. * lib/hash.h, lib/hash.c (hash_xinitialize): New. diff --git a/ChangeLog b/ChangeLog index 5c226ce43..ca12b170b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-09-09 Akim Demaille + + hash: provide hash_xinitialize. + Suggested by Egor Pugin + = https://lists.gnu.org/archive/html/bison-patches/2019-09/msg00026.html + * modules/hash (Depends-on): Add xalloc. + * lib/hash.h, lib/hash.c (hash_xinitialize): New. + 2019-09-06 Akim Demaille =20 bitset: style changes diff --git a/lib/hash.c b/lib/hash.c index 9e1f8e841..ca1d04044 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -27,6 +27,7 @@ #include "hash.h" =20 #include "bitrotate.h" +#include "xalloc.h" #include "xalloc-oversized.h" =20 #include @@ -645,6 +646,22 @@ hash_initialize (size_t candidate, const = Hash_tuning *tuning, return NULL; } =20 + +/* Same as hash_initialize, but invokes xalloc_die on memory + exhaustion. */ + +Hash_table * +hash_xinitialize (size_t candidate, const Hash_tuning *tuning, + Hash_hasher hasher, Hash_comparator comparator, + Hash_data_freer data_freer) +{ + Hash_table *res =3D + hash_initialize (candidate, tuning, hasher, comparator, = data_freer); + if (!res) + xalloc_die (); + return res; +} + /* Make all buckets empty, placing any chained entries on the free = list. Apply the user-specified function data_freer (if any) to the datas = of any affected entries. */ diff --git a/lib/hash.h b/lib/hash.h index a1a483a35..8f2e4591f 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -89,6 +89,9 @@ void hash_reset_tuning (Hash_tuning *); Hash_table *hash_initialize (size_t, const Hash_tuning *, Hash_hasher, Hash_comparator, Hash_data_freer) _GL_ATTRIBUTE_WUR; +Hash_table *hash_xinitialize (size_t, const Hash_tuning *, + Hash_hasher, Hash_comparator, + Hash_data_freer) _GL_ATTRIBUTE_WUR; void hash_clear (Hash_table *); void hash_free (Hash_table *); =20 diff --git a/modules/hash b/modules/hash index 42502e749..31303c1a8 100644 --- a/modules/hash +++ b/modules/hash @@ -9,6 +9,7 @@ Depends-on: bitrotate stdbool stdint +xalloc xalloc-oversized =20 configure.ac: