bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xmalloc calling undeclared xalloc_die function


From: Florian Weimer
Subject: Re: xmalloc calling undeclared xalloc_die function
Date: Thu, 05 Jan 2023 18:16:41 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

* Bruno Haible:

> 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.

Thanks, this was helpful.  Submitted a patch:

  Define the GNULIB_XALLOC_DIE macro
  <https://github.com/kjn/lbzip2/pull/33>

Florian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]