[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: proposed new module careadlinkat (renamed from breadlinkat)
From: |
Eric Blake |
Subject: |
Re: proposed new module careadlinkat (renamed from breadlinkat) |
Date: |
Fri, 08 Apr 2011 08:54:09 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.9 |
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 <address@hidden>
+
+ careadlink: fix compilation error on mingw
+ * lib/careadlinkat.c (standard_allocator): Avoid renaming fields
+ within struct allocator.
+
2011-04-06 Eric Blake <address@hidden>
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 address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- proposed new module careadlinkat (renamed from breadlinkat), Paul Eggert, 2011/04/01
- Re: proposed new module careadlinkat (renamed from breadlinkat), Ben Pfaff, 2011/04/01
- Re: proposed new module careadlinkat (renamed from breadlinkat),
Eric Blake <=
- Re: proposed new module careadlinkat (renamed from breadlinkat), Bruno Haible, 2011/04/09
- Re: proposed new module careadlinkat (renamed from breadlinkat), Bruno Haible, 2011/04/09
- Re: proposed new module careadlinkat (renamed from breadlinkat), Bruno Haible, 2011/04/09
- Re: proposed new module careadlinkat (renamed from breadlinkat), Bruno Haible, 2011/04/09
- Re: proposed new module careadlinkat (renamed from breadlinkat), Bruno Haible, 2011/04/09