Skip to content

[Darwin] Get rid of trampoline hack for lgamma function. #1776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}")
POSIXError.swift
MachError.swift)
set(swift_platform_flags
SWIFT_COMPILE_FLAGS -Xfrontend -disable-objc-attr-requires-foundation-module
SWIFT_COMPILE_FLAGS
-Xfrontend -disable-objc-attr-requires-foundation-module
-Xcc -D_REENTRANT # Required to unveil lgamma_r used in tgmath.
API_NOTES_NON_OVERLAY)
else()
set(swift_platform_name swiftGlibc)
Expand Down
20 changes: 0 additions & 20 deletions stdlib/public/Platform/Misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,6 @@ _swift_Platform_fcntlPtr(int fd, int cmd, void* ptr) {
return fcntl(fd, cmd, ptr);
}

#if defined(__APPLE__)
#define _REENTRANT
#include <math.h>

extern float
_swift_Darwin_lgammaf_r(float x, int *psigngam) {
return lgammaf_r(x, psigngam);
}

extern double
_swift_Darwin_lgamma_r(double x, int *psigngam) {
return lgamma_r(x, psigngam);
}

extern long double
_swift_Darwin_lgammal_r(long double x, int *psigngam) {
return lgammal_r(x, psigngam);
}
#endif

#if defined(__FreeBSD__)
extern char **
_swift_FreeBSD_getEnv() {
Expand Down
20 changes: 0 additions & 20 deletions stdlib/public/Platform/tgmath.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -282,33 +282,13 @@ public func scalbn(x: ${T}, _ n: Int) -> ${T} {

% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
% for T, CT, f in AllFloatTypes():
#if os(Linux) || os(FreeBSD)
@_transparent
@warn_unused_result
public func lgamma(x: ${T}) -> (${T}, Int) {
var sign = CInt(0)
let value = lgamma${f}_r(${CT}(x), &sign)
return (${T}(value), Int(sign))
}
#else
% # On Darwin platform,
% # The real lgamma_r is not imported because it hides behind macro _REENTRANT.
@warn_unused_result
@_silgen_name("_swift_Darwin_lgamma${f}_r")
func _swift_Darwin_lgamma${f}_r(_: ${CT},
_: UnsafeMutablePointer<CInt>) -> ${CT}

@_transparent
@warn_unused_result
public func lgamma(x: ${T}) -> (${T}, Int) {
var sign = CInt(0)
let value = withUnsafeMutablePointer(&sign) {
(signp: UnsafeMutablePointer<CInt>) -> ${CT} in
return _swift_Darwin_lgamma${f}_r(${CT}(x), signp)
}
return (${T}(value), Int(sign))
}
#endif

% end

Expand Down