[libc-commits] [libc] [libc] Combine the function prototype `int (*compar)(const void *, const void *)` (PR #134238)

Connector Switch via libc-commits libc-commits at lists.llvm.org
Thu Apr 3 05:10:28 PDT 2025


https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/134238

Closes #134118.

>From 0d5dd4da4181a54113b6beb2051cc7a26a0f3f2d Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Thu, 3 Apr 2025 20:09:20 +0800
Subject: [PATCH] add __search_compare_t

---
 libc/include/CMakeLists.txt                   | 20 +++++++++----------
 libc/include/llvm-libc-types/CMakeLists.txt   |  3 +--
 .../llvm-libc-types/__lsearchcompare_t.h      | 14 -------------
 ...searchcompare_t.h => __search_compare_t.h} | 10 +++++-----
 libc/include/search.yaml                      |  8 ++++----
 libc/include/stdlib.yaml                      |  6 +++---
 6 files changed, 23 insertions(+), 38 deletions(-)
 delete mode 100644 libc/include/llvm-libc-types/__lsearchcompare_t.h
 rename libc/include/llvm-libc-types/{__bsearchcompare_t.h => __search_compare_t.h} (53%)

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index d1e116ac547d7..e407de2f16959 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -240,13 +240,13 @@ add_header_macro(
   ../libc/include/search.yaml
   search.h
   DEPENDS
-    .llvm_libc_common_h
     .llvm-libc-types.ACTION
     .llvm-libc-types.ENTRY
-    .llvm-libc-types.struct_hsearch_data
-    .llvm-libc-types.size_t
     .llvm-libc-types.VISIT
-    .llvm-libc-types.__lsearchcompare_t
+    .llvm-libc-types.__search_compare_t
+    .llvm-libc-types.size_t
+    .llvm-libc-types.struct_hsearch_data
+    .llvm_libc_common_h
 )
 
 add_header_macro(
@@ -343,17 +343,17 @@ add_header_macro(
   ../libc/include/stdlib.yaml
   stdlib.h
   DEPENDS
-    .llvm_libc_common_h
     .llvm-libc-macros.stdlib_macros
+    .llvm-libc-types.__atexithandler_t
+    .llvm-libc-types.__qsortcompare_t
+    .llvm-libc-types.__qsortrcompare_t
+    .llvm-libc-types.__search_compare_t
     .llvm-libc-types.div_t
     .llvm-libc-types.ldiv_t
     .llvm-libc-types.lldiv_t
-    .llvm-libc-types.size_t
-    .llvm-libc-types.__bsearchcompare_t
-    .llvm-libc-types.__qsortcompare_t
-    .llvm-libc-types.__qsortrcompare_t
-    .llvm-libc-types.__atexithandler_t
     .llvm-libc-types.locale_t
+    .llvm-libc-types.size_t
+    .llvm_libc_common_h
 )
 
 add_header_macro(
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 66e8527701873..9ed39bcd05190 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -2,8 +2,7 @@ add_header(off64_t HDR off64_t.h)
 add_header(size_t HDR size_t.h)
 add_header(ssize_t HDR ssize_t.h)
 add_header(__atfork_callback_t HDR __atfork_callback_t.h)
-add_header(__bsearchcompare_t HDR __bsearchcompare_t.h)
-add_header(__lsearchcompare_t HDR __lsearchcompare_t.h)
+add_header(__search_compare_t HDR __search_compare_t.h)
 add_header(__call_once_func_t HDR __call_once_func_t.h)
 add_header(__dl_iterate_phdr_callback_t HDR __dl_iterate_phdr_callback_t.h DEPENDS .size_t)
 add_header(__exec_argv_t HDR __exec_argv_t.h)
diff --git a/libc/include/llvm-libc-types/__lsearchcompare_t.h b/libc/include/llvm-libc-types/__lsearchcompare_t.h
deleted file mode 100644
index 08dc2db274d0c..0000000000000
--- a/libc/include/llvm-libc-types/__lsearchcompare_t.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===-- Definition of type __lsearchcompare_t -----------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_TYPES___LSEARCHCOMPARE_T_H
-#define LLVM_LIBC_TYPES___LSEARCHCOMPARE_T_H
-
-typedef int (*__lsearchcompare_t)(const void *, const void *);
-
-#endif // LLVM_LIBC_TYPES___LSEARCHCOMPARE_T_H
diff --git a/libc/include/llvm-libc-types/__bsearchcompare_t.h b/libc/include/llvm-libc-types/__search_compare_t.h
similarity index 53%
rename from libc/include/llvm-libc-types/__bsearchcompare_t.h
rename to libc/include/llvm-libc-types/__search_compare_t.h
index 0b1987be1fdd6..7033fef49b49a 100644
--- a/libc/include/llvm-libc-types/__bsearchcompare_t.h
+++ b/libc/include/llvm-libc-types/__search_compare_t.h
@@ -1,4 +1,4 @@
-//===-- Definition of type __bsearchcompare_t -----------------------------===//
+//===-- Definition of type __search_compare_t -----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_TYPES___BSEARCHCOMPARE_T_H
-#define LLVM_LIBC_TYPES___BSEARCHCOMPARE_T_H
+#ifndef LLVM_LIBC_TYPES___SEARCH_COMPARE_T_H
+#define LLVM_LIBC_TYPES___SEARCH_COMPARE_T_H
 
-typedef int (*__bsearchcompare_t)(const void *, const void *);
+typedef int (*__search_compare_t)(const void *, const void *);
 
-#endif // LLVM_LIBC_TYPES___BSEARCHCOMPARE_T_H
+#endif // LLVM_LIBC_TYPES___SEARCH_COMPARE_T_H
diff --git a/libc/include/search.yaml b/libc/include/search.yaml
index e2e711cc93f4d..e5a48ef62daa7 100644
--- a/libc/include/search.yaml
+++ b/libc/include/search.yaml
@@ -2,11 +2,11 @@ header: search.h
 header_template: search.h.def
 macros: []
 types:
-  - type_name: struct_hsearch_data
-  - type_name: ENTRY
   - type_name: ACTION
+  - type_name: ENTRY
   - type_name: VISIT
   - type_name: __lsearchcompare_t
+  - type_name: struct_hsearch_data
 enums: []
 objects: []
 functions:
@@ -69,7 +69,7 @@ functions:
       - type: const void *
       - type: size_t *
       - type: size_t
-      - type: __lsearchcompare_t
+      - type: __search_compare_t
   - name: lsearch
     standards:
       - POSIX
@@ -79,4 +79,4 @@ functions:
       - type: void *
       - type: size_t *
       - type: size_t
-      - type: __lsearchcompare_t
+      - type: __search_compare_t
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index a6204ce3afee3..5690a942e2570 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -7,9 +7,9 @@ merge_yaml_files:
 macros: []
 types:
   - type_name: __atexithandler_t
-  - type_name: __qsortrcompare_t
   - type_name: __qsortcompare_t
-  - type_name: __bsearchcompare_t
+  - type_name: __qsortrcompare_t
+  - type_name: __search_compare_t
   - type_name: div_t
   - type_name: ldiv_t
   - type_name: lldiv_t
@@ -87,7 +87,7 @@ functions:
       - type: const void *
       - type: size_t
       - type: size_t
-      - type: __bsearchcompare_t
+      - type: __search_compare_t
   - name: div
     standards:
       - stdc



More information about the libc-commits mailing list