Skip to content

Commit 0b67b0d

Browse files
yarshureclaude
andcommitted
CI: fix pthread_t() init in Thread.swift for FreeBSD
pthread_t is OpaquePointer on FreeBSD (no default initializer). Use unsafeBitCast(0 as UInt) as a placeholder — _subprocess_pthread_create takes _Nonnull ptr so the variable must stay non-optional; pthread_create overwrites it before any read. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent de025de commit 0b67b0d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ jobs:
105105
sed -i '' 's/Glibc\.stdout!/Glibc.stdout/g; s/Glibc\.stderr!/Glibc.stderr/g' "$LOGGING" && \
106106
echo "Patched $LOGGING"
107107
fi
108-
# swift-subprocess Thread.swift: MutexType/ConditionType need optional on FreeBSD
108+
# swift-subprocess Thread.swift: two FreeBSD fixes —
109+
# 1) MutexType/ConditionType need optional typealiases (opaque pthread types)
110+
# 2) pthread_t() has no default init on FreeBSD; use unsafeBitCast placeholder
111+
# (_subprocess_pthread_create takes _Nonnull ptr so must stay non-optional)
109112
SUBTHREAD=$(find .build/checkouts -path "*/swift-subprocess*/Thread.swift" 2>/dev/null | head -1)
110113
if [ -n "$SUBTHREAD" ]; then
111114
grep -qF "pthread_mutex_t?" "$SUBTHREAD" || {
@@ -114,7 +117,18 @@ jobs:
114117
/^private typealias ConditionType = pthread_cond_t$/{print $0 "\n#endif"; next}1' \
115118
"$SUBTHREAD" > /tmp/_th.swift
116119
mv /tmp/_th.swift "$SUBTHREAD"
117-
echo "Patched $SUBTHREAD"
120+
echo "Patched $SUBTHREAD (typealiases)"
121+
}
122+
grep -qF 'unsafeBitCast(0 as UInt' "$SUBTHREAD" || {
123+
awk '/^ var thread = pthread_t\(\)$/{
124+
print "#if os(FreeBSD) || os(OpenBSD)"
125+
print " var thread: pthread_t = unsafeBitCast(0 as UInt, to: pthread_t.self)"
126+
print "#else"
127+
print $0
128+
print "#endif"
129+
next}1' "$SUBTHREAD" > /tmp/_th.swift
130+
mv /tmp/_th.swift "$SUBTHREAD"
131+
echo "Patched $SUBTHREAD (pthread_t init)"
118132
}
119133
fi
120134
swift build 2>&1

0 commit comments

Comments
 (0)