Skip to content

Commit f66bae4

Browse files
committed
Add rationale to include-signal.swift
1 parent 1be4265 commit f66bae4

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#ifndef TEST_INTEROP_C_LIBC_INPUTS_INCLUDE_SIGNAL_H
2+
#define TEST_INTEROP_C_LIBC_INPUTS_INCLUDE_SIGNAL_H
3+
14
#include <signal.h>
25

36
pid_t returnPidT();
7+
8+
#endif // TEST_INTEROP_C_LIBC_INPUTS_INCLUDE_SIGNAL_H
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
11
// RUN: %target-typecheck-verify-swift -I %S/Inputs
22

3-
import IncludeSignal
3+
// Some types such as pid_t that glibc defines are defined using the following
4+
// construct:
5+
//
6+
// #ifndef __pid_t_defined
7+
// typedef __pid_t pid_t;
8+
// #define __pid_t_defined
9+
// #endif
10+
//
11+
// glibc defines pid_t in this way in multiple header files, as required by
12+
// POSIX (e.g. signal.h, unistd.h, and sys/types.h). A number of other types
13+
// use the same construct (e.g. ssize_t, intptr_t, uid_t, gid_t).
14+
//
15+
// Because Swift does not set the -fmodules-local-submodule-visibility flag,
16+
// the __pid_t_defined macro can leak from the first submodule that defines it
17+
// into all submodules that follow.
18+
//
19+
// As a consequence, a C header file may fail to compile when imported into
20+
// Swift, even though it compiles cleanly outside Swift with the same system
21+
// headers.
22+
//
23+
// This is a regression test for a bug that was once present in SwiftGlibc
24+
// module layout. Originally SwiftGlibc defined one submodule per header, and
25+
// types such as pid_t were defined by the first module that encountered the
26+
// ifndef construct.
27+
//
28+
// See https://forums.swift.org/t/problems-with-swiftglibc-and-proposed-fix/37594
29+
// for further details.
30+
31+
import IncludeSignal

0 commit comments

Comments
 (0)