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=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 EB4CF1F5AE for ; Sat, 12 Jun 2021 00:26:15 +0000 (UTC) Received: from localhost ([::1]:57770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrTb-0008Gj-32 for normalperson@yhbt.net; Fri, 11 Jun 2021 20:26:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrrTW-0008G3-0G for bug-gnulib@gnu.org; Fri, 11 Jun 2021 20:26:11 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:38996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrrTS-0003iC-Tq for bug-gnulib@gnu.org; Fri, 11 Jun 2021 20:26:09 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 06AA916011B for ; Fri, 11 Jun 2021 17:26:06 -0700 (PDT) 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 QI2uuvGvf7CZ; Fri, 11 Jun 2021 17:26:03 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E495C16011A; Fri, 11 Jun 2021 17:26:03 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu 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 xdKCSmsH1pSX; Fri, 11 Jun 2021 17:26:03 -0700 (PDT) Received: from day.example.com (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id BDD64160095; Fri, 11 Jun 2021 17:26:03 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH 01/13] ialloc: new module Date: Fri, 11 Jun 2021 17:25:41 -0700 Message-Id: <20210612002553.1105537-1-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * lib/ialloc.c, lib/ialloc.h, modules/ialloc: New files. --- ChangeLog | 3 ++ lib/ialloc.c | 3 ++ lib/ialloc.h | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ modules/ialloc | 29 ++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 lib/ialloc.c create mode 100644 lib/ialloc.h create mode 100644 modules/ialloc diff --git a/ChangeLog b/ChangeLog index 304599f81..dd9aa5015 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-06-11 Paul Eggert =20 + ialloc: new module + * lib/ialloc.c, lib/ialloc.h, modules/ialloc: New files. + exclude: improve wide-character hashing * lib/exclude.c (string_hasher_ci): Take the modulo at the end rather than each time a wide character is retrieved; this should diff --git a/lib/ialloc.c b/lib/ialloc.c new file mode 100644 index 000000000..9eff29035 --- /dev/null +++ b/lib/ialloc.c @@ -0,0 +1,3 @@ +#include +#define IALLOC_INLINE _GL_EXTERN_INLINE +#include "ialloc.h" diff --git a/lib/ialloc.h b/lib/ialloc.h new file mode 100644 index 000000000..e243c928c --- /dev/null +++ b/lib/ialloc.h @@ -0,0 +1,94 @@ +/* ialloc.h -- malloc with idx_t rather than size_t + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see = . */ + +#ifndef IALLOC_H_ +#define IALLOC_H_ + +#include "idx.h" + +#include +#include +#include + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef IALLOC_INLINE +# define IALLOC_INLINE _GL_INLINE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +IALLOC_INLINE void * _GL_ATTRIBUTE_COLD +_gl_alloc_nomem (void) +{ + errno =3D ENOMEM; + return NULL; +} + +IALLOC_INLINE void * +imalloc (idx_t s) +{ + return s <=3D SIZE_MAX ? malloc (s) : _gl_alloc_nomem (); +} + +IALLOC_INLINE void * +irealloc (void *p, idx_t s) +{ + /* Work around GNU realloc glitch by treating a zero size as if it + were 1, so that returning NULL is equivalent to failing. */ + return s <=3D SIZE_MAX ? realloc (p, s | !s) : _gl_alloc_nomem (); +} + +IALLOC_INLINE void * +icalloc (idx_t n, idx_t s) +{ + if (SIZE_MAX < n) + { + if (s !=3D 0) + return _gl_alloc_nomem (); + n =3D 0; + } + if (SIZE_MAX < s) + { + if (n !=3D 0) + return _gl_alloc_nomem (); + s =3D 0; + } + return calloc (n, s); +} + +IALLOC_INLINE void * +ireallocarray (void *p, idx_t n, idx_t s) +{ + /* Work around GNU reallocarray glitch by treating a zero size as if + it were 1, so that returning NULL is equivalent to failing. */ + if (n =3D=3D 0 || s =3D=3D 0) + n =3D s =3D 1; + return (n <=3D SIZE_MAX && s <=3D SIZE_MAX + ? reallocarray (p, n, s) + : _gl_alloc_nomem ()); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/modules/ialloc b/modules/ialloc new file mode 100644 index 000000000..3bf377a62 --- /dev/null +++ b/modules/ialloc @@ -0,0 +1,29 @@ +Description: +Memory allocation using idx_t instead of size_t + +Files: +lib/ialloc.c +lib/ialloc.h + +Depends-on: +calloc-gnu +extern-inline +idx +malloc-gnu +realloc-gnu +reallocarray +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES +=3D ialloc.c + +Include: +"ialloc.h" + +License: +LGPL + +Maintainer: +all --=20 2.30.2