-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-123797: Check for runtime availability of ptsname_r
on macos
#123806
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Check for runtime availability of ``ptsname_r`` function on macos. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,7 @@ | |
# define HAVE_PWRITEV_RUNTIME __builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) | ||
# define HAVE_MKFIFOAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) | ||
# define HAVE_MKNODAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) | ||
# define HAVE_PTSNAME_R_RUNTIME __builtin_available(macOS 10.13.4, iOS 11.3, tvOS 11.3, watchOS 4.3, *) | ||
|
||
# define HAVE_POSIX_SPAWN_SETSID_RUNTIME __builtin_available(macOS 10.15, *) | ||
|
||
|
@@ -206,6 +207,10 @@ | |
# define HAVE_MKNODAT_RUNTIME (mknodat != NULL) | ||
# endif | ||
|
||
# ifdef HAVE_PTSNAME_R | ||
# define HAVE_PTSNAME_R_RUNTIME (ptsname_r != NULL) | ||
# endif | ||
|
||
#endif | ||
|
||
#ifdef HAVE_FUTIMESAT | ||
|
@@ -231,6 +236,7 @@ | |
# define HAVE_PWRITEV_RUNTIME 1 | ||
# define HAVE_MKFIFOAT_RUNTIME 1 | ||
# define HAVE_MKNODAT_RUNTIME 1 | ||
# define HAVE_PTSNAME_R_RUNTIME 1 | ||
#endif | ||
|
||
|
||
|
@@ -8635,6 +8641,18 @@ os_unlockpt_impl(PyObject *module, int fd) | |
#endif /* HAVE_UNLOCKPT */ | ||
|
||
#if defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R) | ||
static PyObject * | ||
from_ptsname(int fd) | ||
{ | ||
char *name = ptsname(fd); | ||
/* POSIX manpage: Upon failure, ptsname() shall return a null pointer and may set errno. | ||
*MAY* set errno? Hmm... */ | ||
if (name == NULL) { | ||
return posix_error(); | ||
} | ||
sobolevn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return PyUnicode_DecodeFSDefault(name); | ||
} | ||
|
||
/*[clinic input] | ||
os.ptsname | ||
|
||
|
@@ -8656,22 +8674,28 @@ os_ptsname_impl(PyObject *module, int fd) | |
int ret; | ||
char name[MAXPATHLEN+1]; | ||
|
||
ret = ptsname_r(fd, name, sizeof(name)); | ||
if (HAVE_PTSNAME_R_RUNTIME) { | ||
ret = ptsname_r(fd, name, sizeof(name)); | ||
} | ||
else { | ||
#if defined(HAVE_PTSNAME) | ||
// fallback to `ptsname` if `ptsname_r` is not available in runtime. | ||
sobolevn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return from_ptsname(fd); | ||
#else | ||
// unknown error: | ||
// both ptsname_r and ptsname are not available for some reason. | ||
ret = -1; | ||
sobolevn marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a "cannot happen" case: ptsname is available on all versions of macOS where configure detects ptsname_r. I'd either drop drop the guard for the block above or replace this bit by an (And regardless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks for the review! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is there a macOS or iOS platform where ptsname() and ptsname_r() are not available? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ptsname_r() is available on macOS 10.13.4 and iOS 11.3 (and later), ptsname() has been available from the start. Or at least, there are no availability annotations in Apple's headers which is a good indication that the API was available from the start. |
||
#endif /* HAVE_PTSNAME */ | ||
} | ||
if (ret != 0) { | ||
errno = ret; | ||
return posix_error(); | ||
} | ||
#else | ||
char *name; | ||
|
||
name = ptsname(fd); | ||
/* POSIX manpage: Upon failure, ptsname() shall return a null pointer and may set errno. | ||
*MAY* set errno? Hmm... */ | ||
if (name == NULL) | ||
return posix_error(); | ||
#endif /* HAVE_PTSNAME_R */ | ||
|
||
return PyUnicode_DecodeFSDefault(name); | ||
#else | ||
return from_ptsname(fd); | ||
#endif /* HAVE_PTSNAME_R */ | ||
} | ||
#endif /* defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R) */ | ||
|
||
|
@@ -17751,6 +17775,9 @@ PROBE(probe_futimens, HAVE_FUTIMENS_RUNTIME) | |
PROBE(probe_utimensat, HAVE_UTIMENSAT_RUNTIME) | ||
#endif | ||
|
||
#ifdef HAVE_PTSNAME_R | ||
PROBE(probe_ptsname_r, HAVE_PTSNAME_R_RUNTIME) | ||
#endif | ||
|
||
|
||
|
||
|
@@ -17891,6 +17918,10 @@ static const struct have_function { | |
{ "HAVE_UTIMENSAT", probe_utimensat }, | ||
#endif | ||
|
||
#ifdef HAVE_PTSNAME_R | ||
{ "HAVE_PTSNAME_R", probe_ptsname_r }, | ||
#endif | ||
|
||
#ifdef MS_WINDOWS | ||
{ "MS_WINDOWS", NULL }, | ||
#endif | ||
|
Uh oh!
There was an error while loading. Please reload this page.