Skip to content

Commit

Permalink
pythongh-123797: Check for runtime availability of ptsname_r on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Sep 7, 2024
1 parent 033510e commit 6c0ec75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,13 @@ def test_stat(self):
with self.assertRaisesRegex(NotImplementedError, "dir_fd unavailable"):
os.stat("file", dir_fd=0)

def test_ptsname_r(self):
self._verify_available("HAVE_PTSNAME_R")
if self.mac_ver >= (10, 13, 4):
self.assertIn("HAVE_PTSNAME_R", posix._have_functions)
else:
self.assertNotIn("HAVE_PTSNAME_R", posix._have_functions)

def test_access(self):
self._verify_available("HAVE_FACCESSAT")
if self.mac_ver >= (10, 10):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check for runtime availability of ``ptsname_r`` function on macos.
20 changes: 19 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, *)

Expand Down Expand Up @@ -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
Expand All @@ -231,6 +236,7 @@
# define HAVE_PWRITEV_RUNTIME 1
# define HAVE_MKFIFOAT_RUNTIME 1
# define HAVE_MKNODAT_RUNTIME 1
# define HAVE_PTSNAME_R 1
#endif


Expand Down Expand Up @@ -8656,7 +8662,12 @@ 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 {
ret = -1;
}
if (ret != 0) {
errno = ret;
return posix_error();
Expand Down Expand Up @@ -17751,6 +17762,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



Expand Down Expand Up @@ -17891,6 +17905,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
Expand Down

0 comments on commit 6c0ec75

Please sign in to comment.