OSDN Git Service

Do not expose private declarations in <search.h>
authorKeith Marshall <keith@users.osdn.me>
Fri, 26 Aug 2022 20:50:12 +0000 (21:50 +0100)
committerKeith Marshall <keith@users.osdn.me>
Fri, 26 Aug 2022 20:50:12 +0000 (21:50 +0100)
mingwrt/ChangeLog
mingwrt/include/search.h
mingwrt/mingwex/tdelete.c
mingwrt/mingwex/tfind.c
mingwrt/mingwex/tsearch.c
mingwrt/mingwex/tsearch.h [new file with mode: 0644]
mingwrt/mingwex/twalk.c

index 60cde9f..737ab3b 100644 (file)
@@ -1,3 +1,16 @@
+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.
index 75feb19..879cdc7 100644 (file)
@@ -6,7 +6,7 @@
  * $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
@@ -91,28 +91,6 @@ enum { FIND, ENTER } ACTION;
 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);
index a4d0f92..8d492ce 100644 (file)
@@ -9,18 +9,17 @@
  * 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;
index fa33d86..27a7877 100644 (file)
@@ -9,9 +9,8 @@
  * 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 *))
@@ -20,9 +19,9 @@ __CRT_ALIAS void *__tfind
    * 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;
index 9cbba49..acd64ad 100644 (file)
@@ -9,9 +9,8 @@
  * 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 *))
@@ -19,9 +18,9 @@ __CRT_ALIAS void *__tsearch
   /* 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;
 
diff --git a/mingwrt/mingwex/tsearch.h b/mingwrt/mingwex/tsearch.h
new file mode 100644 (file)
index 0000000..5cc540d
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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 */
index 0c681e5..76b5024 100644 (file)
@@ -9,9 +9,8 @@
  * 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);
@@ -44,5 +43,5 @@ void twalk (const void *root, void (*action)(const void *, VISIT, 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);
 }