[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GNULIB_POSIXCHECK, remove, and gl_oset
From: |
Bruno Haible |
Subject: |
Re: GNULIB_POSIXCHECK, remove, and gl_oset |
Date: |
Mon, 28 Sep 2009 23:26:10 +0200 |
User-agent: |
KMail/1.9.9 |
Hi Eric,
> I tried compiling m4 with -DGNULIB_POSIXCHECK, to see if I was missing any
> useful modules. To my surprise, gl_oset.h failed to compile:
>
> In file included from ../../lib/gl_avltree_oset.h:21,
> from ../../src/output.c:27:
> ../../lib/gl_oset.h:236:76: macro "remove" passed 2 arguments, but takes just
> 1
>
> POSIX states that:
> Any function declared in a header may also be implemented as a macro defined
> in
> the header, so a function should not be declared explicitly if its header is
> included. Any macro definition of a function can be suppressed locally by
> enclosing the name of the function in parentheses, because the name is then
> not
> followed by the <left-parenthesis> that indicates expansion of a macro
> function
> name.
>
> In other words, it is legal for a system to #define remove(x), and so any use
> of the name remove as a user identifier must be tolerant of the existence of
> such a function-like macro.
Agreed.
> I see two options - either rewrite gl_oset.h to call
> vtable->(remove)(set,elt),
This is not an option, because it leads to an error as well:
gl_oset.h: In function ‘gl_oset_remove_inline’:
gl_oset.h:236: error: expected identifier before ‘(’ token
> or rewrite gl_oset.h and clients to use a different vtable member function
> pointer name that does not clash with the standardized name remove. Which
> would you prefer?
There is not much choice. I'm applying this:
2009-09-28 Bruno Haible <address@hidden>
Avoid identifier clash with POSIX function 'remove' defined as a macro.
* lib/gl_list.h (struct gl_list_implementation): Rename field 'remove'
to 'remove_elt'.
(gl_list_remove): Update.
* lib/gl_list.c (gl_list_remove): Update.
* lib/gl_oset.h (struct gl_oset_implementation): Rename field 'remove'
to 'remove_elt'.
(gl_oset_remove): Update.
* lib/gl_list.c (gl_oset_remove): Update.
Reported by Eric Blake.
--- lib/gl_list.c.orig 2009-09-28 23:24:21.000000000 +0200
+++ lib/gl_list.c 2009-09-28 23:19:47.000000000 +0200
@@ -1,5 +1,5 @@
/* Abstract sequential list data type.
- Copyright (C) 2006-2008 Free Software Foundation, Inc.
+ Copyright (C) 2006-2009 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 2006.
This program is free software: you can redistribute it and/or modify
@@ -197,7 +197,7 @@
gl_list_remove (gl_list_t list, const void *elt)
{
return ((const struct gl_list_impl_base *) list)->vtable
- ->remove (list, elt);
+ ->remove_elt (list, elt);
}
void
--- lib/gl_list.h.orig 2009-09-28 23:24:21.000000000 +0200
+++ lib/gl_list.h 2009-09-28 23:19:47.000000000 +0200
@@ -1,5 +1,5 @@
/* Abstract sequential list data type.
- Copyright (C) 2006-2008 Free Software Foundation, Inc.
+ Copyright (C) 2006-2009 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 2006.
This program is free software: you can redistribute it and/or modify
@@ -405,7 +405,7 @@
const void *elt);
bool (*remove_node) (gl_list_t list, gl_list_node_t node);
bool (*remove_at) (gl_list_t list, size_t position);
- bool (*remove) (gl_list_t list, const void *elt);
+ bool (*remove_elt) (gl_list_t list, const void *elt);
void (*list_free) (gl_list_t list);
/* gl_list_iterator_t functions. */
gl_list_iterator_t (*iterator) (gl_list_t list);
@@ -650,7 +650,7 @@
gl_list_remove (gl_list_t list, const void *elt)
{
return ((const struct gl_list_impl_base *) list)->vtable
- ->remove (list, elt);
+ ->remove_elt (list, elt);
}
# define gl_list_free gl_list_free_inline
--- lib/gl_oset.c.orig 2009-09-28 23:24:21.000000000 +0200
+++ lib/gl_oset.c 2009-09-28 23:21:28.000000000 +0200
@@ -1,5 +1,5 @@
/* Abstract ordered set data type.
- Copyright (C) 2006-2007 Free Software Foundation, Inc.
+ Copyright (C) 2006-2007, 2009 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 2006.
This program is free software: you can redistribute it and/or modify
@@ -64,7 +64,8 @@
bool
gl_oset_remove (gl_oset_t set, const void *elt)
{
- return ((const struct gl_oset_impl_base *) set)->vtable->remove (set, elt);
+ return ((const struct gl_oset_impl_base *) set)->vtable
+ ->remove_elt (set, elt);
}
void
--- lib/gl_oset.h.orig 2009-09-28 23:24:21.000000000 +0200
+++ lib/gl_oset.h 2009-09-28 23:24:19.000000000 +0200
@@ -1,5 +1,5 @@
/* Abstract ordered set data type.
- Copyright (C) 2006-2007 Free Software Foundation, Inc.
+ Copyright (C) 2006-2007, 2009 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 2006.
This program is free software: you can redistribute it and/or modify
@@ -168,7 +168,7 @@
gl_setelement_threshold_fn threshold_fn,
const void *threshold, const void **eltp);
bool (*add) (gl_oset_t set, const void *elt);
- bool (*remove) (gl_oset_t set, const void *elt);
+ bool (*remove_elt) (gl_oset_t set, const void *elt);
void (*oset_free) (gl_oset_t set);
/* gl_oset_iterator_t functions. */
gl_oset_iterator_t (*iterator) (gl_oset_t set);
@@ -233,7 +233,8 @@
static inline bool
gl_oset_remove (gl_oset_t set, const void *elt)
{
- return ((const struct gl_oset_impl_base *) set)->vtable->remove (set, elt);
+ return ((const struct gl_oset_impl_base *) set)->vtable
+ ->remove_elt (set, elt);
}
# define gl_oset_free gl_oset_free_inline