PATCH: Do not call xmalloc_failed in expandargv

Mark Mitchell
2005-09-27T14:51:43Z

This patch fixes the link error when compiling GDB. The cause of the
failure is that GDB's utils.c defines xmalloc, but not xmalloc_failed;
therefore, expandargv pulls in xmalloc.c to get xmalloc_failed, which
causes a duplicate symbol error for xmalloc. Arguably, GDB should
define xmalloc_failed, so as to completely replace the interface. (In
fact, GDB provides "nomem", which has almost the same signature.)
However, this patch to libiberty will be more robust if there are
other similar programs out there that, like GDB, replace only some of
the interface. We could also split xmalloc_failed into its own file,
so as to decouple it from xmalloc.

In any case, is this patch OK, to get GDB back to linking?

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-09-27 Mark Mitchell <mark@codesourcery.com>

* argv.c (expandargv): Do not use xmalloc_failed.

Index: argv.c
===================================================================
RCS file: /cvs/src/src/libiberty/argv.c,v
retrieving revision 1.14
diff -c -5 -p -r1.14 argv.c
*** argv.c 26 Sep 2005 21:02:59 -0000 1.14
--- argv.c 27 Sep 2005 14:45:31 -0000
*************** expandargv (argcp, argvp)
*** 363,375 ****
/* If *ARGVP is not already dynamically allocated, copy it. */
if (!argv_dynamic)
{
*argvp = dupargv (*argvp);
if (!*argvp)
! /* We do not know exactly many bytes dupargv tried to
! allocate, so make a guess. */
! xmalloc_failed (*argcp * 32);
}
/* Count the number of arguments. */
file_argc = 0;
while (file_argv[file_argc] && *file_argv[file_argc])
++file_argc;
--- 363,376 ----
/* If *ARGVP is not already dynamically allocated, copy it. */
if (!argv_dynamic)
{
*argvp = dupargv (*argvp);
if (!*argvp)
! {
! fprintf (stderr, "\n%sout of memory\n");
! xexit (1);
! }
}
/* Count the number of arguments. */
file_argc = 0;
while (file_argv[file_argc] && *file_argv[file_argc])
++file_argc;