[libc-commits] [libc] [libc] Add proxy header for __sighandler_t type (PR #107354)

via libc-commits libc-commits at lists.llvm.org
Thu Sep 5 11:13:38 PDT 2024


https://github.com/wldfngrs updated https://github.com/llvm/llvm-project/pull/107354

>From f2aaab8287bb18f793c4f9c88212986d807feddd Mon Sep 17 00:00:00 2001
From: wldfngrs <wldfngrs at gmail.com>
Date: Wed, 4 Sep 2024 21:43:08 +0100
Subject: [PATCH 1/6] add proxy header for __sighandler_t type

---
 libc/src/signal/CMakeLists.txt | 2 +-
 libc/src/signal/signal.h       | 6 ++----
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/libc/src/signal/CMakeLists.txt b/libc/src/signal/CMakeLists.txt
index c70ab952b9950f..20f57d217c5f37 100644
--- a/libc/src/signal/CMakeLists.txt
+++ b/libc/src/signal/CMakeLists.txt
@@ -55,7 +55,7 @@ add_entrypoint_object(
   signal
   ALIAS
   DEPENDS
-    .${LIBC_TARGET_OS}.signal
+     libc.include.llvm-libc-types.__sighandler_t 
 )
 
 add_entrypoint_object(
diff --git a/libc/src/signal/signal.h b/libc/src/signal/signal.h
index 2037305f8c11e5..8bc04dd2c8faf9 100644
--- a/libc/src/signal/signal.h
+++ b/libc/src/signal/signal.h
@@ -10,13 +10,11 @@
 #define LLVM_LIBC_SRC_SIGNAL_SIGNAL_H
 
 #include "src/__support/macros/config.h"
-#include <signal.h>
+#include "include/llvm-libc-types/__sighandler_t.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-using sighandler_t = __sighandler_t;
-
-sighandler_t signal(int signum, sighandler_t handler);
+__sighandler_t signal(int signum, __sighandler_t handler);
 
 } // namespace LIBC_NAMESPACE_DECL
 

>From e8857837c71f438048ae36b0856749c7d07cb3e4 Mon Sep 17 00:00:00 2001
From: wldfngrs <wldfngrs at gmail.com>
Date: Thu, 5 Sep 2024 06:43:16 +0100
Subject: [PATCH 2/6] add proxy headers for __sighandler_t type

---
 libc/hdr/types/CMakeLists.txt        | 9 +++++++++
 libc/src/signal/CMakeLists.txt       | 2 +-
 libc/src/signal/linux/signal.cpp     | 4 +++-
 libc/test/src/signal/CMakeLists.txt  | 2 +-
 libc/test/src/signal/signal_test.cpp | 4 ++--
 5 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index f41576c07d99be..335f30db340214 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -171,3 +171,12 @@ add_proxy_header_library(
     libc.include.llvm-libc-types.locale_t
     libc.include.locale
 )
+
+add_proxy_header_library(
+  __sighandler_t
+  HDRS
+    __sighandler_t.h
+  FULL_BUILD_DEPENDS
+   libc.include.llvm-libc-types.__sighandler_t
+)
+
diff --git a/libc/src/signal/CMakeLists.txt b/libc/src/signal/CMakeLists.txt
index 20f57d217c5f37..462a3b95468f12 100644
--- a/libc/src/signal/CMakeLists.txt
+++ b/libc/src/signal/CMakeLists.txt
@@ -55,7 +55,7 @@ add_entrypoint_object(
   signal
   ALIAS
   DEPENDS
-     libc.include.llvm-libc-types.__sighandler_t 
+     .${LIBC_TARGET_OS}.signal
 )
 
 add_entrypoint_object(
diff --git a/libc/src/signal/linux/signal.cpp b/libc/src/signal/linux/signal.cpp
index 241258faf2e81d..c3b15491767e3f 100644
--- a/libc/src/signal/linux/signal.cpp
+++ b/libc/src/signal/linux/signal.cpp
@@ -8,13 +8,15 @@
 
 #include "src/signal/signal.h"
 #include "hdr/signal_macros.h"
+#include "include/llvm-libc-types/__sighandler_t.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include "src/signal/sigaction.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(sighandler_t, signal, (int signum, sighandler_t handler)) {
+LLVM_LIBC_FUNCTION(__sighandler_t, signal,
+                   (int signum, __sighandler_t handler)) {
   struct sigaction action, old;
   action.sa_handler = handler;
   action.sa_flags = SA_RESTART;
diff --git a/libc/test/src/signal/CMakeLists.txt b/libc/test/src/signal/CMakeLists.txt
index edbd5c19edab38..132798cb7fc663 100644
--- a/libc/test/src/signal/CMakeLists.txt
+++ b/libc/test/src/signal/CMakeLists.txt
@@ -74,7 +74,7 @@ add_libc_unittest(
   SRCS
     signal_test.cpp
   DEPENDS
-    libc.include.signal
+    libc.include.llvm-libc-types.__sighandler_t
     libc.src.errno.errno
     libc.src.signal.raise
     libc.src.signal.signal
diff --git a/libc/test/src/signal/signal_test.cpp b/libc/test/src/signal/signal_test.cpp
index 70e95a8c159a8b..329ff37ba3baca 100644
--- a/libc/test/src/signal/signal_test.cpp
+++ b/libc/test/src/signal/signal_test.cpp
@@ -13,14 +13,14 @@
 #include "test/UnitTest/ErrnoSetterMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <signal.h>
+#include "include/llvm-libc-types/__sighandler_t.h"
 
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
 
 TEST(LlvmLibcSignal, Invalid) {
   LIBC_NAMESPACE::libc_errno = 0;
-  LIBC_NAMESPACE::sighandler_t valid = +[](int) {};
+  __sighandler_t valid = +[](int) {};
   EXPECT_THAT((void *)LIBC_NAMESPACE::signal(0, valid),
               Fails(EINVAL, (void *)SIG_ERR));
   EXPECT_THAT((void *)LIBC_NAMESPACE::signal(65, valid),

>From e4aa6ac5260d11d540cd6d963cc7164157240ee2 Mon Sep 17 00:00:00 2001
From: wldfngrs <wldfngrs at gmail.com>
Date: Thu, 5 Sep 2024 07:02:05 +0100
Subject: [PATCH 3/6] fixed code format

---
 libc/src/signal/signal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/signal/signal.h b/libc/src/signal/signal.h
index 8bc04dd2c8faf9..23ce2c9c942077 100644
--- a/libc/src/signal/signal.h
+++ b/libc/src/signal/signal.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_SIGNAL_SIGNAL_H
 #define LLVM_LIBC_SRC_SIGNAL_SIGNAL_H
 
-#include "src/__support/macros/config.h"
 #include "include/llvm-libc-types/__sighandler_t.h"
+#include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 

>From 60060a9f5d758e3f4ad66db4d036033ccd30b68d Mon Sep 17 00:00:00 2001
From: wldfngrs <wldfngrs at gmail.com>
Date: Thu, 5 Sep 2024 18:23:16 +0100
Subject: [PATCH 4/6] switched header includes to the added proxy headers,
 modified CMakeLists.txt to reflect that

---
 libc/hdr/types/CMakeLists.txt        |  3 ++-
 libc/hdr/types/sighandler_t.h        | 23 +++++++++++++++++++++++
 libc/src/signal/CMakeLists.txt       |  2 +-
 libc/src/signal/linux/signal.cpp     |  2 +-
 libc/src/signal/signal.h             |  2 +-
 libc/test/src/signal/CMakeLists.txt  |  2 +-
 libc/test/src/signal/signal_test.cpp |  2 +-
 7 files changed, 30 insertions(+), 6 deletions(-)
 create mode 100644 libc/hdr/types/sighandler_t.h

diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 335f30db340214..fab81511216ae2 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -177,6 +177,7 @@ add_proxy_header_library(
   HDRS
     __sighandler_t.h
   FULL_BUILD_DEPENDS
-   libc.include.llvm-libc-types.__sighandler_t
+    libc.include.llvm-libc-types.__sighandler_t
+    libc.include.signal
 )
 
diff --git a/libc/hdr/types/sighandler_t.h b/libc/hdr/types/sighandler_t.h
new file mode 100644
index 00000000000000..9c229ae8fcd1f9
--- /dev/null
+++ b/libc/hdr/types/sighandler_t.h
@@ -0,0 +1,23 @@
+//===-- Definition of macros from __sighandler_t.h ------------------------===//
+//
+// 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_HDR_SIGHANDLER_T_H
+#define LLVM_LIBC_HDR_SIGHANDLER_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/__sighandler_t.h"
+
+#else // overlay mode
+
+#include <signal.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_SIGHANDLER_T_H
+
diff --git a/libc/src/signal/CMakeLists.txt b/libc/src/signal/CMakeLists.txt
index 462a3b95468f12..c70ab952b9950f 100644
--- a/libc/src/signal/CMakeLists.txt
+++ b/libc/src/signal/CMakeLists.txt
@@ -55,7 +55,7 @@ add_entrypoint_object(
   signal
   ALIAS
   DEPENDS
-     .${LIBC_TARGET_OS}.signal
+    .${LIBC_TARGET_OS}.signal
 )
 
 add_entrypoint_object(
diff --git a/libc/src/signal/linux/signal.cpp b/libc/src/signal/linux/signal.cpp
index c3b15491767e3f..ee7fb958fb648e 100644
--- a/libc/src/signal/linux/signal.cpp
+++ b/libc/src/signal/linux/signal.cpp
@@ -8,7 +8,7 @@
 
 #include "src/signal/signal.h"
 #include "hdr/signal_macros.h"
-#include "include/llvm-libc-types/__sighandler_t.h"
+#include "hdr/types/sighandler_t.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include "src/signal/sigaction.h"
diff --git a/libc/src/signal/signal.h b/libc/src/signal/signal.h
index 23ce2c9c942077..bf105c009130c9 100644
--- a/libc/src/signal/signal.h
+++ b/libc/src/signal/signal.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SIGNAL_SIGNAL_H
 #define LLVM_LIBC_SRC_SIGNAL_SIGNAL_H
 
-#include "include/llvm-libc-types/__sighandler_t.h"
+#include "hdr/types/sighandler_t.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/signal/CMakeLists.txt b/libc/test/src/signal/CMakeLists.txt
index 132798cb7fc663..f7923204eaf499 100644
--- a/libc/test/src/signal/CMakeLists.txt
+++ b/libc/test/src/signal/CMakeLists.txt
@@ -74,7 +74,7 @@ add_libc_unittest(
   SRCS
     signal_test.cpp
   DEPENDS
-    libc.include.llvm-libc-types.__sighandler_t
+    libc.hdr.types.sighandler_t
     libc.src.errno.errno
     libc.src.signal.raise
     libc.src.signal.signal
diff --git a/libc/test/src/signal/signal_test.cpp b/libc/test/src/signal/signal_test.cpp
index 329ff37ba3baca..d56df550190be1 100644
--- a/libc/test/src/signal/signal_test.cpp
+++ b/libc/test/src/signal/signal_test.cpp
@@ -13,7 +13,7 @@
 #include "test/UnitTest/ErrnoSetterMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include "include/llvm-libc-types/__sighandler_t.h"
+#include "hdr/types/sighandler_t.h"
 
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;

>From e342bc970addf4ec68fea0558d112f68a9594880 Mon Sep 17 00:00:00 2001
From: wldfngrs <wldfngrs at gmail.com>
Date: Thu, 5 Sep 2024 18:32:03 +0100
Subject: [PATCH 5/6] add sighandler_t.h file to libc/hdr/types directory

---
 libc/hdr/types/sighandler_t.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/hdr/types/sighandler_t.h b/libc/hdr/types/sighandler_t.h
index 9c229ae8fcd1f9..9416aabca4bec5 100644
--- a/libc/hdr/types/sighandler_t.h
+++ b/libc/hdr/types/sighandler_t.h
@@ -20,4 +20,3 @@
 #endif // LLVM_LIBC_FULL_BUILD
 
 #endif // LLVM_LIBC_HDR_TYPES_SIGHANDLER_T_H
-

>From ad7a499deb55494f5912430e77fac24589a20aff Mon Sep 17 00:00:00 2001
From: wldfngrs <wldfngrs at gmail.com>
Date: Thu, 5 Sep 2024 19:12:43 +0100
Subject: [PATCH 6/6] modified to use sighandler_t instead of __sighandler_t

---
 libc/hdr/types/sighandler_t.h        | 2 ++
 libc/src/signal/linux/signal.cpp     | 4 ++--
 libc/src/signal/signal.h             | 2 +-
 libc/test/src/signal/signal_test.cpp | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/libc/hdr/types/sighandler_t.h b/libc/hdr/types/sighandler_t.h
index 9416aabca4bec5..b18f8e856c5b6c 100644
--- a/libc/hdr/types/sighandler_t.h
+++ b/libc/hdr/types/sighandler_t.h
@@ -13,6 +13,8 @@
 
 #include "include/llvm-libc-types/__sighandler_t.h"
 
+using sighandler_t = __sighandler_t;
+
 #else // overlay mode
 
 #include <signal.h>
diff --git a/libc/src/signal/linux/signal.cpp b/libc/src/signal/linux/signal.cpp
index ee7fb958fb648e..261a8f9d8e0c29 100644
--- a/libc/src/signal/linux/signal.cpp
+++ b/libc/src/signal/linux/signal.cpp
@@ -15,8 +15,8 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(__sighandler_t, signal,
-                   (int signum, __sighandler_t handler)) {
+LLVM_LIBC_FUNCTION(sighandler_t, signal,
+                   (int signum, sighandler_t handler)) {
   struct sigaction action, old;
   action.sa_handler = handler;
   action.sa_flags = SA_RESTART;
diff --git a/libc/src/signal/signal.h b/libc/src/signal/signal.h
index bf105c009130c9..06e77e11bf0bd3 100644
--- a/libc/src/signal/signal.h
+++ b/libc/src/signal/signal.h
@@ -14,7 +14,7 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-__sighandler_t signal(int signum, __sighandler_t handler);
+sighandler_t signal(int signum, sighandler_t handler);
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/test/src/signal/signal_test.cpp b/libc/test/src/signal/signal_test.cpp
index d56df550190be1..4b57311eee2d86 100644
--- a/libc/test/src/signal/signal_test.cpp
+++ b/libc/test/src/signal/signal_test.cpp
@@ -20,7 +20,7 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
 
 TEST(LlvmLibcSignal, Invalid) {
   LIBC_NAMESPACE::libc_errno = 0;
-  __sighandler_t valid = +[](int) {};
+  sighandler_t valid = +[](int) {};
   EXPECT_THAT((void *)LIBC_NAMESPACE::signal(0, valid),
               Fails(EINVAL, (void *)SIG_ERR));
   EXPECT_THAT((void *)LIBC_NAMESPACE::signal(65, valid),



More information about the libc-commits mailing list