On 03/31/2011 11:57 PM, Paul Eggert wrote:
> Following up on Bruno's comments, here's a revised proposed
> patch to gnulib, which I've tested with coreutils and with Emacs.
>
> +#ifndef _GL_ALLOCATOR_H
> +
> +#include <stddef.h>
> +
> +struct allocator
> +{
> + /* Call MALLOC to allocate memory, like 'malloc'. On failure MALLOC
> + should return NULL, though not necessarily set errno. When given
> + a zero size it may return NULL even if successful. */
> + void *(*malloc) (size_t);Problem. This is causing failures on mingw: ../../../gnulib/lib/careadlinkat.c: In function 'careadlinkat': ../../../gnulib/lib/careadlinkat.c:143:39: error: 'const struct allocator' has no member named 'malloc' ../../../gnulib/lib/careadlinkat.c:149:66: error: 'const struct allocator' has no member named 'realloc' ../../../gnulib/lib/careadlinkat.c:152:39: error: 'const struct allocator' has no member named 'realloc' ../../../gnulib/lib/careadlinkat.c:169:27: error: 'const struct allocator' has no member named 'malloc' make[4]: *** [careadlinkat.lo] Error 1 It stems from the fact that on mingw, malloc and realloc are not POSIX compliant, so they have been redefined to rpl_malloc and rpl_realloc by the replacement <stdlib.h> prior to the time that "allocator.h" is included. Then you undefine those macros, and subsequent code is trying to access different struct names: > + > +#include <config.h> > + > +#include "careadlinkat.h" > + > +#include "allocator.h" > + > +#include <errno.h> > +#include <limits.h> > +#include <stdlib.h> > +#include <string.h> > +#include <unistd.h> > + > +/* Use the system functions, not the gnulib overrides, because this > + module does not depend on GNU or POSIX semantics. */ > +#undef malloc > +#undef realloc I'm pushing this as the simplest patch, but you may want to instead consider renaming the field members to not shadow functions that might have been #defined into replacement names. diff --git i/ChangeLog w/ChangeLog index 922d211..2c887a6 100644 --- i/ChangeLog +++ w/ChangeLog @@ -1,3 +1,9 @@ +2011-04-08 Eric Blake <[email protected]> + + careadlink: fix compilation error on mingw + * lib/careadlinkat.c (standard_allocator): Avoid renaming fields + within struct allocator. + 2011-04-06 Eric Blake <[email protected]> binary-io: relicense under LGPLv2+ diff --git i/lib/careadlinkat.c w/lib/careadlinkat.c index 15ffe24..eb2e009 100644 --- i/lib/careadlinkat.c +++ w/lib/careadlinkat.c @@ -30,11 +30,6 @@ #include <string.h> #include <unistd.h> -/* Use the system functions, not the gnulib overrides, because this - module does not depend on GNU or POSIX semantics. */ -#undef malloc -#undef realloc - /* Define this independently so that stdint.h is not a prerequisite. */ #ifndef SIZE_MAX # define SIZE_MAX ((size_t) -1) @@ -57,10 +52,10 @@ careadlinkatcwd (int fd, char const *filename, char *buffer, } #endif -/* A standard allocator. For now, only careadlinkat needs this, but - perhaps it should be moved to the allocator module. */ -static struct allocator const standard_allocator = - { malloc, realloc, free, NULL }; +/* Forward declaration. We want to #undef malloc before initializing + this struct, but cannot do so until after all code that uses named + fields from "allocator.h" has been compiled. */ +static struct allocator const standard_allocator; /* Assuming the current directory is FD, get the symbolic link value of FILENAME as a null-terminated string and put it into a buffer. @@ -173,3 +168,14 @@ careadlinkat (int fd, char const *filename, errno = ENOMEM; return NULL; } + +/* Use the system functions, not the gnulib overrides, because this + module does not depend on GNU or POSIX semantics. See comments + above why this must occur here. */ +#undef malloc +#undef realloc + +/* A standard allocator. For now, only careadlinkat needs this, but + perhaps it should be moved to the allocator module. */ +static struct allocator const standard_allocator = + { malloc, realloc, free, NULL }; -- Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
