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

via libc-commits libc-commits at lists.llvm.org
Wed Sep 4 23:02:30 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/3] 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/3] 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/3] 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 {
 



More information about the libc-commits mailing list