Skip to content

runtime: use the preferred spelling on Windows (NFCI) #78548

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
Jan 11, 2025

Conversation

compnerd
Copy link
Member

This changes the windows path to use the preferred _strdup over strdup to avoid the deprecation warning.

This changes the windows path to use the preferred `_strdup` over
`strdup` to avoid the deprecation warning.
@compnerd
Copy link
Member Author

@swift-ci please smoke test

@compnerd
Copy link
Member Author

@swift-ci please smoke test macOS platform

@compnerd compnerd merged commit 34b6842 into swiftlang:main Jan 11, 2025
3 checks passed
@compnerd compnerd deleted the spelling branch January 11, 2025 00:15
@al45tair
Copy link
Contributor

@compnerd Do you think it would be worthwhile doing

#ifdef _WIN32
#define strdup _strdup
#define open _open
#define close _close
// ... and so on ...
#endif

in a header somewhere rather than putting conditionals around uses of these functions?

@compnerd
Copy link
Member Author

@compnerd Do you think it would be worthwhile doing


#ifdef _WIN32

#define strdup _strdup

#define open _open

#define close _close

// ... and so on ...

#endif

in a header somewhere rather than putting conditionals around uses of these functions?

That can be tempting but they are not always identical. Furthermore, use of _open is a bad idea as it introduces a security issue as well as runtime deficiencies. We should use _wopen which takes a UCS-2/UTF-16 encoded path, which will break open. It's better to conditionalize the use sites IMO.

@al45tair
Copy link
Contributor

That can be tempting but they are not always identical.

In practice though many of them, and strdup()/_strdup() is an excellent example here, are identical, which isn't surprising because they were added to DOS compilers back in the day for exactly that reason. So we could do this at least for the ones that are actually identical, or near enough that nobody cares about the differences.

I take your point about _open() vs _wopen(). We could perhaps do

static inline int open(const char *name, ...) __attribute__((unavailable("open() is not a good idea on Windows; please use _wopen() instead"))) {
  return -1;
}

or similar to make it obvious what the problem is.

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