bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Florian Weimer <fweimer@redhat.com>
Subject: Re: xmalloc calling undeclared xalloc_die function
Date: Fri, 09 Dec 2022 17:08:35 +0100	[thread overview]
Message-ID: <2518769.sP1CNn8AQk@nimes> (raw)
In-Reply-To: <87cz8slruc.fsf@oldenburg.str.redhat.com>

Florian Weimer wrote:
> lib/xmalloc.c contains this function definition, unconditionally:
> 
>   static void * _GL_ATTRIBUTE_PURE
>   nonnull (void *p)
>   {
>     if (!p)
>       xalloc_die ();
>     return p;
>   }
> 
> But the declaration of xalloc_die in lib/xalloc.h is conditional:
> 
>   #if GNULIB_XALLOC_DIE
>   
>   /* This function is always triggered when memory is exhausted.
>      It must be defined by the application, either explicitly
>      or by using gnulib's xalloc-die module.  This is the
>      function to call when one wants the program to die because of a
>      memory allocation failure.  */
>   /*extern*/ _Noreturn void xalloc_die (void);
>   
>   #endif /* GNULIB_XALLOC_DIE */

It's conditional on the C macro GNULIB_XALLOC_DIE, which is defined by
the module 'xalloc-die' (file modules/xalloc-die, line 15).

This conditional was added through
  <https://lists.gnu.org/archive/html/bug-gnulib/2020-10/msg00140.html>
1) to avoid link errors with a compiler that does not eliminate unused
   inline functions,
2) to trigger a compilation error instead of a link error or runtime error
   when a packages requerts 'xalloc-die' without 'xalloc' or vice versa
   but then actually uses both.

> I have a package (lbzip2 <https://github.com/kjn/lbzip2/>) which
> supplies its own definition of xalloc_die, and fails to build due to an
> undeclared function.

This package calls gnulib-tool like this:

  gnulib-tool --avoid=xalloc-die --add-import pthread utimens warnings \
      timespec-add timespec-sub dtotimespec stat-time lstat malloc-gnu \
      fprintf-posix inttypes xalloc largefile gitlog-to-changelog

This means, the module 'xalloc-die' is not included, thus xalloc.h does
not provide the declaration of xalloc_die().

There are at least three possible fixes:

  * Rather than '--avoid=xalloc-die', the package could override parts
    of the 'xalloc-die' module, as described in
    <https://www.gnu.org/software/gnulib/manual/html_node/Extending-Gnulib.html>.

  * The package could define the C macro GNULIB_XALLOC_DIE.

  * The package could declare xalloc_die().

I would probably pick the second one.

Bruno





  reply	other threads:[~2022-12-09 16:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09 11:49 xmalloc calling undeclared xalloc_die function Florian Weimer
2022-12-09 16:08 ` Bruno Haible [this message]
2023-01-05 17:16   ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2518769.sP1CNn8AQk@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=fweimer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).