Skip to content

Commit d823443

Browse files
bpo-35550: Fix incorrect Solaris define guards (GH-11275)
Python source code uses on several places ifdef sun or defined(sun) without the underscores, which is not standard compliant and shouldn't be used. Defines should check for __sun instead. Reference: http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_systemGH-Solaris https://bugs.python.org/issue35550 (cherry picked from commit 6f9bc72) Co-authored-by: Jakub Kulík <[email protected]>
1 parent e404299 commit d823443

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix incorrect Solaris #ifdef checks to look for __sun && __SVR4 instead of sun when compiling.

Modules/_posixsubprocess.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# define SYS_getdents64 __NR_getdents64
3131
#endif
3232

33-
#if defined(sun)
33+
#if defined(__sun) && defined(__SVR4)
3434
/* readdir64 is used to work around Solaris 9 bug 6395699. */
3535
# define readdir readdir64
3636
# define dirent dirent64

Modules/posixmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5926,7 +5926,7 @@ os_openpty_impl(PyObject *module)
59265926
#endif
59275927
#if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY)
59285928
PyOS_sighandler_t sig_saved;
5929-
#ifdef sun
5929+
#if defined(__sun) && defined(__SVR4)
59305930
extern char *ptsname(int fildes);
59315931
#endif
59325932
#endif

Modules/socketmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ if_indextoname(index) -- return the corresponding interface name\n\
265265
#endif
266266

267267
/* Solaris fails to define this variable at all. */
268-
#if defined(sun) && !defined(INET_ADDRSTRLEN)
268+
#if (defined(__sun) && defined(__SVR4)) && !defined(INET_ADDRSTRLEN)
269269
#define INET_ADDRSTRLEN 16
270270
#endif
271271

Modules/timemodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ time_strftime(PyObject *self, PyObject *args)
725725
return NULL;
726726
}
727727

728-
#if defined(_MSC_VER) || defined(sun) || defined(_AIX)
728+
#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX)
729729
if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) {
730730
PyErr_SetString(PyExc_ValueError,
731731
"strftime() requires year in [1; 9999]");
@@ -771,7 +771,7 @@ time_strftime(PyObject *self, PyObject *args)
771771
return NULL;
772772
}
773773
}
774-
#elif (defined(_AIX) || defined(sun)) && defined(HAVE_WCSFTIME)
774+
#elif (defined(_AIX) || (defined(__sun) && defined(__SVR4))) && defined(HAVE_WCSFTIME)
775775
for (outbuf = wcschr(fmt, '%');
776776
outbuf != NULL;
777777
outbuf = wcschr(outbuf+2, '%'))

Python/bootstrap_hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
116116
flags = blocking ? 0 : GRND_NONBLOCK;
117117
dest = buffer;
118118
while (0 < size) {
119-
#ifdef sun
119+
#if defined(__sun) && defined(__SVR4)
120120
/* Issue #26735: On Solaris, getrandom() is limited to returning up
121121
to 1024 bytes. Call it multiple times if more bytes are
122122
requested. */
@@ -266,7 +266,7 @@ py_getentropy(char *buffer, Py_ssize_t size, int raise)
266266
}
267267
return 1;
268268
}
269-
#endif /* defined(HAVE_GETENTROPY) && !defined(sun) */
269+
#endif /* defined(HAVE_GETENTROPY) && !(defined(__sun) && defined(__SVR4)) */
270270

271271

272272
static struct {

0 commit comments

Comments
 (0)