* xmalloc calling undeclared xalloc_die function
@ 2022-12-09 11:49 Florian Weimer
2022-12-09 16:08 ` Bruno Haible
0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2022-12-09 11:49 UTC (permalink / raw)
To: bug-gnulib
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 */
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. So I'm wondering how this is supposed to work.
Thanks,
Florian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xmalloc calling undeclared xalloc_die function
2022-12-09 11:49 xmalloc calling undeclared xalloc_die function Florian Weimer
@ 2022-12-09 16:08 ` Bruno Haible
2023-01-05 17:16 ` Florian Weimer
0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2022-12-09 16:08 UTC (permalink / raw)
To: bug-gnulib; +Cc: Florian Weimer
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xmalloc calling undeclared xalloc_die function
2022-12-09 16:08 ` Bruno Haible
@ 2023-01-05 17:16 ` Florian Weimer
0 siblings, 0 replies; 3+ messages in thread
From: Florian Weimer @ 2023-01-05 17:16 UTC (permalink / raw)
To: Bruno Haible; +Cc: bug-gnulib
* 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-05 17:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09 11:49 xmalloc calling undeclared xalloc_die function Florian Weimer
2022-12-09 16:08 ` Bruno Haible
2023-01-05 17:16 ` Florian Weimer
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).