Mercurial > hg > octave-nkf > gnulib-hg
changeset 12937:dbc0820f9ddc
search: Avoid #define replacements in C++ mode.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 08 Mar 2010 01:16:01 +0100 |
parents | 9be4aca41cee |
children | baf17c6b8bd7 |
files | ChangeLog lib/search.in.h modules/search |
diffstat | 3 files changed, 108 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2010-03-07 Bruno Haible <bruno@clisp.org> + search: Avoid #define replacements in C++ mode. + * lib/search.in.h: Include c++defs.h. + (_gl_search_compar_fn, _gl_search_action_fn): New types. + (tsearch, tfind, tdelete, twalk): In C++, define a namespaced alias + symbol. + * modules/search (Depends-on): Add c++defs. + (Makefile.am): Update search.h rule. + math: Avoid #define replacements in C++ mode. * lib/math.in.h: Include c++defs.h. (frexp, acosl, asinl, atanl, ceilf, ceill, cosl, expl, floorf, floorl,
--- a/lib/search.in.h +++ b/lib/search.in.h @@ -29,30 +29,28 @@ #define _GL_SEARCH_H +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + /* The definition of _GL_ARG_NONNULL is copied here. */ /* The definition of _GL_WARN_ON_USE is copied here. */ -#ifdef __cplusplus -extern "C" { -#endif - - #if @GNULIB_TSEARCH@ # if @REPLACE_TSEARCH@ -# define tsearch rpl_tsearch -# define tfind rpl_tfind -# define tdelete rpl_tdelete -# define twalk rpl_twalk +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define tsearch rpl_tsearch +# define tfind rpl_tfind +# define tdelete rpl_tdelete +# define twalk rpl_twalk +# endif # endif -# if !@HAVE_TSEARCH@ || @REPLACE_TSEARCH@ /* See <http://www.opengroup.org/susv3xbd/search.h.html>, <http://www.opengroup.org/susv3xsh/tsearch.html> for details. */ -# if !@HAVE_TSEARCH@ +# if !@HAVE_TSEARCH@ typedef enum { preorder, @@ -61,27 +59,89 @@ leaf } VISIT; -# endif +# endif + +# ifdef __cplusplus +extern "C" { +# endif +typedef int (*_gl_search_compar_fn) (const void *, const void *); +typedef void (*_gl_search_action_fn) (const void *, VISIT, int); +# ifdef __cplusplus +} +# endif /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is returned. Otherwise, a new element equal to KEY is inserted in the tree and is returned. */ -extern void * tsearch (const void *key, void **vrootp, - int (*compar) (const void *, const void *)) - _GL_ARG_NONNULL ((1, 2, 3)); +# if @REPLACE_TSEARCH@ +_GL_FUNCDECL_RPL (tsearch, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar) + _GL_ARG_NONNULL ((1, 2, 3))); +_GL_CXXALIAS_RPL (tsearch, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar)); +# else +# if !@HAVE_TSEARCH@ +_GL_FUNCDECL_SYS (tsearch, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar) + _GL_ARG_NONNULL ((1, 2, 3))); +# endif +_GL_CXXALIAS_SYS (tsearch, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar)); +# endif +_GL_CXXALIASWARN (tsearch); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is returned. Otherwise, NULL is returned. */ -extern void * tfind (const void *key, void *const *vrootp, - int (*compar) (const void *, const void *)) - _GL_ARG_NONNULL ((1, 2, 3)); +# if @REPLACE_TSEARCH@ +_GL_FUNCDECL_RPL (tfind, void *, + (const void *key, void *const *vrootp, + _gl_search_compar_fn compar) + _GL_ARG_NONNULL ((1, 2, 3))); +_GL_CXXALIAS_RPL (tfind, void *, + (const void *key, void *const *vrootp, + _gl_search_compar_fn compar)); +# else +# if !@HAVE_TSEARCH@ +_GL_FUNCDECL_SYS (tfind, void *, + (const void *key, void *const *vrootp, + _gl_search_compar_fn compar) + _GL_ARG_NONNULL ((1, 2, 3))); +# endif +/* Need to cast, because on Cygwin 1.5.x systems, the second parameter is + void **vrootp. */ +_GL_CXXALIAS_SYS_CAST (tfind, void *, + (const void *key, void *const *vrootp, + _gl_search_compar_fn compar)); +# endif +_GL_CXXALIASWARN (tfind); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is removed from the tree, and its parent node is returned. Otherwise, NULL is returned. */ -extern void * tdelete (const void *key, void **vrootp, - int (*compar) (const void *, const void *)) - _GL_ARG_NONNULL ((1, 2, 3)); +# if @REPLACE_TSEARCH@ +_GL_FUNCDECL_RPL (tdelete, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar) + _GL_ARG_NONNULL ((1, 2, 3))); +_GL_CXXALIAS_RPL (tdelete, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar)); +# else +# if !@HAVE_TSEARCH@ +_GL_FUNCDECL_SYS (tdelete, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar) + _GL_ARG_NONNULL ((1, 2, 3))); +# endif +_GL_CXXALIAS_SYS (tdelete, void *, + (const void *key, void **vrootp, + _gl_search_compar_fn compar)); +# endif +_GL_CXXALIASWARN (tdelete); /* Perform a depth-first, left-to-right traversal of the tree VROOT. The ACTION function is called: @@ -94,11 +154,23 @@ pointer to the key, 2. an indicator which visit of the node this is, 3. the level of the node in the tree (0 for the root). */ -extern void twalk (const void *vroot, - void (*action) (const void *, VISIT, int)) - _GL_ARG_NONNULL ((2)); +# if @REPLACE_TSEARCH@ +_GL_FUNCDECL_RPL (twalk, void, + (const void *vroot, _gl_search_action_fn action) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (twalk, void, + (const void *vroot, _gl_search_action_fn action)); +# else +# if !@HAVE_TSEARCH@ +_GL_FUNCDECL_SYS (twalk, void, + (const void *vroot, _gl_search_action_fn action) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (twalk, void, + (const void *vroot, _gl_search_action_fn action)); +# endif +_GL_CXXALIASWARN (twalk); -# endif #elif defined GNULIB_POSIXCHECK # undef tsearch # if HAVE_RAW_DECL_TSEARCH @@ -123,9 +195,5 @@ #endif -#ifdef __cplusplus -} -#endif - #endif /* _GL_SEARCH_H */ #endif /* _GL_SEARCH_H */
--- a/modules/search +++ b/modules/search @@ -7,6 +7,7 @@ Depends-on: arg-nonnull +c++defs include_next warn-on-use @@ -18,7 +19,7 @@ # We need the following in order to create <search.h> when the system # doesn't have one that works with the given compiler. -search.h: search.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) +search.h: search.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''HAVE_SEARCH_H''@|$(HAVE_SEARCH_H)|g' \ @@ -28,6 +29,7 @@ -e 's|@''GNULIB_TSEARCH''@|$(GNULIB_TSEARCH)|g' \ -e 's|@''HAVE_TSEARCH''@|$(HAVE_TSEARCH)|g' \ -e 's|@''REPLACE_TSEARCH''@|$(REPLACE_TSEARCH)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/search.in.h; \