Skip to content

_SwiftSyntaxCShims: rename Swift getter #2983

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
Mar 8, 2025
Merged

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Mar 5, 2025

_errno is a C reserved identifier. Windows uses this reserved namespace and results in a collision. Rename the getter to namespace it and avoid the collision.

@compnerd
Copy link
Member Author

compnerd commented Mar 5, 2025

@swift-ci please test

@bnbarham bnbarham requested a review from rintaro March 5, 2025 17:59
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Why is _errno a reserved C identifier? As far as I know only identifiers with two underscores and a lowercase letter or a single underscore followed by an uppercase letter are reserved.

Also, if we change this, I think we should also prefix _stdout etc in swiftsyntax_stdio.h for consistency.

@compnerd
Copy link
Member Author

compnerd commented Mar 5, 2025

I can change _stdout et al as well.

_ symbols are always reserved: https://en.cppreference.com/w/c/language/identifier

All external identifiers that begin with an underscore.

The same applies to C++. However, C++ additionally reserves any identifier with __ in the name (as opposed to C where it is just a leader).

@compnerd
Copy link
Member Author

compnerd commented Mar 5, 2025

@swift-ci please test

@ahoppen
Copy link
Member

ahoppen commented Mar 5, 2025

Hmm, interesting. I didn’t know about the external identifiers rule, assuming that external means external linkage here, the spec doesn’t seem to be clear on that.

But then we shouldn’t prefix the symbol with an underscore at all, ie. change it to swift_syntax_errno instead of _swift_syntax_errno, which is technically still reserved, right?

@compnerd
Copy link
Member Author

compnerd commented Mar 5, 2025

Yeah, anything with external linkage (though I think that there would be a conflict since _errno is defined. You should however be able to use it within a function as a variable name.

I can strip the _ on these decls.

`_errno` is a C reserved identifier. Windows uses this reserved
namespace and results in a collision. Rename the getter to namespace it
and avoid the collision.

Rename STDIO constants to maintain parity.
@compnerd
Copy link
Member Author

compnerd commented Mar 5, 2025

@swift-ci please test

@ahoppen
Copy link
Member

ahoppen commented Mar 5, 2025

@swift-ci Please test

@compnerd
Copy link
Member Author

compnerd commented Mar 6, 2025

@swift-ci please test Windows platform

@compnerd compnerd merged commit cb5e497 into swiftlang:main Mar 8, 2025
3 checks passed
@compnerd compnerd deleted the errno branch March 8, 2025 00:44
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.

3 participants