+2022-08-26 Keith Marshall <keith@users.osdn.me>
+
+ Do not expose private declarations in <search.h>
+
+ * include/search.h [_SEARCH_PRIVATE]: Do not consider.
+ (struct node, node_t, __MINGW_NONNULL): Relocate [re]definitions...
+ * mingwex/tsearch.h: ...to this new (private) header file.
+
+ * mingwex/tdelete.c mingwex/tfind.c mingwex/tsearch.c
+ * mingwex/twalk.c: Include "tsearch.h" in each, in place of
+ <search.h>; (the latter will be indirectly included by the former).
+ (_SEARCH_PRIVATE): Remove definition; it is no longer required.
+
2022-08-15 Keith Marshall <keith@users.osdn.me>
Correct project name references in mingwrt manpages.
* $Id$
*
* Written by Danny Smith <dannysmith@users.sourceforge.net>
- * Copyright (C) 2003, 2004, 2007, 2016, 2018, MinGW.org Project.
+ * Copyright (C) 2003, 2004, 2007, 2016, 2018, 2022, MinGW.OSDN Project.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
typedef
enum { preorder, postorder, endorder, leaf } VISIT;
-#ifdef _SEARCH_PRIVATE
-/* For private use within the respective tree function implementations,
- * we define a structured representation of a tree node.
- *
- * FIXME: this really doesn't belong here! Users should NEVER enable
- * this feature test; they should not be given this opportunity.
- */
-typedef
-struct node
-{ const void *key;
- struct node *llink, *rlink;
-} node_t;
-
-/* Suppress non-null argument annotations, when building the tsearch(),
- * tfind(), tdelete(), and twalk() implementations, to ensure that GCC
- * does not optimize away internal argument validation checks.
- */
-#undef __MINGW_ATTRIB_NONNULL
-#define __MINGW_ATTRIB_NONNULL(ARG_INDEX) /* NOTHING */
-
-#endif /* _SEARCH_PRIVATE */
-
__cdecl void *tdelete
(const void *__restrict__, void **__restrict__, __search_comparator)
__MINGW_ATTRIB_NONNULL(2) __MINGW_ATTRIB_NONNULL(3);
* Totally public domain.
*
*/
-#define _SEARCH_PRIVATE
-#include <search.h>
#include <stdlib.h>
+#include "tsearch.h"
__CRT_ALIAS void *__tdelete
(const void *key, node_t **rootp, int (*compar)(const void *, const void *))
{
/* Delete node with specified "key", from tree referred to by "rootp".
*
- * NOTE: node_t is defined as a structured data type, for internal use
- * when _SEARCH_PRIVATE is enabled; for public consumption, it becomes
- * an alias for "void", (assuming _SEARCH_PRIVATE is NOT enabled).
+ * NOTE: node_t is defined as a structured data type, in "tsearch.h",
+ * for private use within this implementation; for public consumption,
+ * it becomes an alias for "void".
*/
int cmp;
node_t *p, *q, *r;
* Totally public domain.
*
*/
-#define _SEARCH_PRIVATE
#include <stdlib.h>
-#include <search.h>
+#include "tsearch.h"
__CRT_ALIAS void *__tfind
(const void *key, node_t *const *rootp, int (*compar)(const void *, const void *))
* return NULL if not found, (or if either "rootp" or "compar" is not
* a valid pointer).
*
- * NOTE: node_t is defined as a structured data type, for internal use
- * when _SEARCH_PRIVATE is enabled; for public consumption, it becomes
- * an alias for "void", (assuming _SEARCH_PRIVATE is NOT enabled).
+ * NOTE: node_t is defined as a structured data type, in "tsearch.h",
+ * for private use within this implementation; for public consumption,
+ * it becomes an alias for "void".
*/
if( (rootp == NULL) || (compar == NULL) )
return NULL;
* Totally public domain.
*
*/
-#define _SEARCH_PRIVATE
-#include <search.h>
#include <stdlib.h>
+#include "tsearch.h"
__CRT_ALIAS void *__tsearch
(const void *key, node_t **rootp, int (*compar)(const void *, const void *))
/* Find node identified by "key", within the tree referred to by "rootp",
* or insert such datum node, if not already present.
*
- * NOTE: node_t is defined as a structured data type, for internal use
- * when _SEARCH_PRIVATE is enabled; for public consumption, it becomes
- * an alias for "void", (assuming _SEARCH_PRIVATE is NOT enabled).
+ * NOTE: node_t is defined as a structured data type, in "tsearch.h",
+ * for private use within this implementation; for public consumption,
+ * it becomes an alias for "void".
*/
node_t *q;
--- /dev/null
+/*
+ * tsearch.h
+ *
+ * A private wrapper, around <search.h>, to facilitate implementation of
+ * the POSIX.1 tsearch(), tfind(), tdelete(), and twalk() functions.
+ *
+ *
+ * $Id$
+ *
+ * Written Keith Marshall <keith@users.osdn.me>
+ * Copyright (C) 2022, MinGW.OSDN Project.
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice, this permission notice, and the following
+ * disclaimer shall be included in all copies or substantial portions of
+ * the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * All MinGW headers must include <_mingw.h>; ensure that it has been
+ * included early, because we need...
+ */
+#include <_mingw.h>
+
+/* ...to suppress its non-null argument annotations, BEFORE including
+ * the public <search.h>, to ensure that GCC does not optimize away any
+ * internal argument validation checks, when compiling the tsearch(),
+ * tfind(), tdelete(), and twalk() implementations.
+ */
+#undef __MINGW_ATTRIB_NONNULL
+#define __MINGW_ATTRIB_NONNULL(ARG_INDEX) /* NOTHING */
+
+#include <search.h>
+
+/* In addition to the public API declarations from <search.h>, each of
+ * the tsearch(), tfind(), tdelete(), and twalk() implementations needs
+ * this privately defined representation of a binary tree node.
+ */
+typedef
+struct node
+{ const void *key;
+ struct node *llink, *rlink;
+} node_t;
+
+/* $RCSfile$: end of file */
* Totally public domain.
*
*/
-#define _SEARCH_PRIVATE
-#include <search.h>
#include <stdlib.h>
+#include "tsearch.h"
static __MINGW_ATTRIB_NONNULL(1) __MINGW_ATTRIB_NONNULL(2)
void trecurse (const node_t *, void (*)(const void *, VISIT, int), int);
* in turn, as appropriate in each phase of traversal.
*/
if( (root != NULL) && (action != NULL) )
- trecurse (root, action, 0);
+ trecurse ((const node_t *)(root), action, 0);
}