Skip to content

Commit 3008727

Browse files
committed
gh-123797: Check for runtime availability of ptsname_r on macos
1 parent 033510e commit 3008727

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Lib/test/test_posix.py

+7
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,13 @@ def test_stat(self):
21402140
with self.assertRaisesRegex(NotImplementedError, "dir_fd unavailable"):
21412141
os.stat("file", dir_fd=0)
21422142

2143+
def test_ptsname_r(self):
2144+
self._verify_available("HAVE_PTSNAME_R")
2145+
if self.mac_ver >= (10, 13, 4):
2146+
self.assertIn("HAVE_PTSNAME_R", posix._have_functions)
2147+
else:
2148+
self.assertNotIn("HAVE_PTSNAME_R", posix._have_functions)
2149+
21432150
def test_access(self):
21442151
self._verify_available("HAVE_FACCESSAT")
21452152
if self.mac_ver >= (10, 10):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check for runtime availability of ``ptsname_r`` function on macos.

Modules/posixmodule.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
# define HAVE_PWRITEV_RUNTIME __builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
126126
# define HAVE_MKFIFOAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
127127
# define HAVE_MKNODAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
128+
# define HAVE_PTSNAME_R_RUNTIME __builtin_available(macOS 10.13.4, iOS 11.3, tvOS 11.3, watchOS 4.3, *)
128129

129130
# define HAVE_POSIX_SPAWN_SETSID_RUNTIME __builtin_available(macOS 10.15, *)
130131

@@ -206,6 +207,10 @@
206207
# define HAVE_MKNODAT_RUNTIME (mknodat != NULL)
207208
# endif
208209

210+
# ifdef HAVE_PTSNAME_R
211+
# define HAVE_PTSNAME_R_RUNTIME (ptsname_r != NULL)
212+
# endif
213+
209214
#endif
210215

211216
#ifdef HAVE_FUTIMESAT
@@ -231,6 +236,7 @@
231236
# define HAVE_PWRITEV_RUNTIME 1
232237
# define HAVE_MKFIFOAT_RUNTIME 1
233238
# define HAVE_MKNODAT_RUNTIME 1
239+
# define HAVE_PTSNAME_R_RUNTIME 1
234240
#endif
235241

236242

@@ -8656,7 +8662,12 @@ os_ptsname_impl(PyObject *module, int fd)
86568662
int ret;
86578663
char name[MAXPATHLEN+1];
86588664

8659-
ret = ptsname_r(fd, name, sizeof(name));
8665+
if (HAVE_PTSNAME_R_RUNTIME) {
8666+
ret = ptsname_r(fd, name, sizeof(name));
8667+
}
8668+
else {
8669+
ret = -1;
8670+
}
86608671
if (ret != 0) {
86618672
errno = ret;
86628673
return posix_error();
@@ -17751,6 +17762,9 @@ PROBE(probe_futimens, HAVE_FUTIMENS_RUNTIME)
1775117762
PROBE(probe_utimensat, HAVE_UTIMENSAT_RUNTIME)
1775217763
#endif
1775317764

17765+
#ifdef HAVE_PTSNAME_R
17766+
PROBE(probe_ptsname_r, HAVE_PTSNAME_R_RUNTIME)
17767+
#endif
1775417768

1775517769

1775617770

@@ -17891,6 +17905,10 @@ static const struct have_function {
1789117905
{ "HAVE_UTIMENSAT", probe_utimensat },
1789217906
#endif
1789317907

17908+
#ifdef HAVE_PTSNAME_R
17909+
{ "HAVE_PTSNAME_R", probe_ptsname_r },
17910+
#endif
17911+
1789417912
#ifdef MS_WINDOWS
1789517913
{ "MS_WINDOWS", NULL },
1789617914
#endif

0 commit comments

Comments
 (0)