Skip to content

asprintf exists on linux #3021

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

Merged
merged 1 commit into from
Jul 8, 2022
Merged

asprintf exists on linux #3021

merged 1 commit into from
Jul 8, 2022

Conversation

soloturn
Copy link
Contributor

asprintf exists on linux for quite a while, 2015 at least. do use it.

fixes https://bugs.swift.org/browse/SR-14935

asprintf exists on linux for quite a while, 2015 at least. do use it.
@spevans
Copy link
Contributor

spevans commented Jul 27, 2021

@swift-ci test

@AZero13
Copy link
Contributor

AZero13 commented Oct 14, 2021

@spevans any updates?

@soloturn
Copy link
Contributor Author

@gottesmm ?

@etcwilde
Copy link
Member

etcwilde commented Jun 29, 2022

As per the discussion in #4610, __USE_GNU includes asprintf as a C extension and Android's Bionic C library also implements asprintf, so having it defined for these two platforms results in duplicate declarations or duplicate definitions.

So long as -D_GNU_SOURCE is defined, this should build correctly.
The macro is set in CoreFoundation/build.py: https://github.com/apple/swift-corelibs-foundation/blob/cd988935ddf500cab069effe7ccd73aa5cf42fd1/CoreFoundation/build.py#L16-L18
And in CoreFoundation/CMakeLists.txt: https://github.com/apple/swift-corelibs-foundation/blob/cd988935ddf500cab069effe7ccd73aa5cf42fd1/CoreFoundation/CMakeLists.txt#L72-L75

@etcwilde
Copy link
Member

@swift-ci please test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to verify that _GNU_SOURCE is being defined. I suspect that this might come back to hurt us a bit as not all libc implementation may provide this extension. Perhaps a comment at these sites makes sense to indicate that we are relying on the fact that we only support glibc (and bionic) and that they provide asprintf (at least under some flags).

@drodriguez
Copy link
Contributor

We do for Android in https://github.com/apple/swift/blob/0053526c5d15532ef38fcf72006a9e16840b92a0/lib/ClangImporter/ClangImporter.cpp#L682-L688 . There's a comment for why it is not enabled in Linux, so if you need it for every Linux, maybe it needs to be done manually before any #include that end up in glibc.

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with merging this. We should probably add something like || (TARGET_OS_LINUX && !defined(_GNU_SOURCE)) just to completely cover the bases, but that can come in a subsequent patch.

@etcwilde etcwilde merged commit 0b5e0ea into swiftlang:main Jul 8, 2022
@etcwilde
Copy link
Member

etcwilde commented Jul 8, 2022

Thanks for the contribution @soloturn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants