Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e38b2f1

Browse files
committed
Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Also note that it isn't just Linux nice() that is broken: at least FreeBSD and BSDI also have this problem. os.nice() should probably just be emulated using getpriority()/setpriority(), if they are available, but I'll get to that later.
1 parent 3230d5c commit e38b2f1

5 files changed

Lines changed: 86 additions & 9 deletions

File tree

Modules/posixmodule.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,12 @@ posix_mkdir(PyObject *self, PyObject *args)
11101110

11111111

11121112
#ifdef HAVE_NICE
1113+
#if defined(HAVE_BROKEN_NICE) && defined(HAVE_SYS_RESOURCE_H)
1114+
#if defined(HAVE_GETPRIORITY) && !defined(PRIO_PROCESS)
1115+
#include <sys/resource.h>
1116+
#endif
1117+
#endif
1118+
11131119
static char posix_nice__doc__[] =
11141120
"nice(inc) -> new_priority\n\
11151121
Decrease the priority of process and return new priority.";
@@ -1124,8 +1130,8 @@ posix_nice(PyObject *self, PyObject *args)
11241130

11251131
/* There are two flavours of 'nice': one that returns the new
11261132
priority (as required by almost all standards out there) and the
1127-
Linux one, which returns '0' on success and advices the use of
1128-
getpriority() to get the new priority.
1133+
Linux/FreeBSD/BSDI one, which returns '0' on success and advices
1134+
the use of getpriority() to get the new priority.
11291135
11301136
If we are of the nice family that returns the new priority, we
11311137
need to clear errno before the call, and check if errno is filled
@@ -1134,7 +1140,7 @@ posix_nice(PyObject *self, PyObject *args)
11341140

11351141
errno = 0;
11361142
value = nice(increment);
1137-
#ifdef HAVE_GETPRIORITY
1143+
#if defined(HAVE_BROKEN_NICE) && defined(HAVE_GETPRIORITY)
11381144
if (value == 0)
11391145
value = getpriority(PRIO_PROCESS, 0);
11401146
#endif

acconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116
/* Define as the size of the unicode type. */
117117
#undef Py_UNICODE_SIZE
118118

119+
/* Define if nice() returns success/failure instead of the new priority. */
120+
#undef HAVE_BROKEN_NICE
121+
119122
/* Define if malloc(0) returns a NULL pointer */
120123
#undef MALLOC_ZERO_RETURNS_NULL
121124

config.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@
175175
/* Define as the size of the unicode type. */
176176
#undef Py_UNICODE_SIZE
177177

178+
/* Define if nice() returns success/failure instead of the new priority. */
179+
#undef HAVE_BROKEN_NICE
180+
178181
/* Define if malloc(0) returns a NULL pointer */
179182
#undef MALLOC_ZERO_RETURNS_NULL
180183

@@ -641,6 +644,9 @@
641644
/* Define if you have the <sys/param.h> header file. */
642645
#undef HAVE_SYS_PARAM_H
643646

647+
/* Define if you have the <sys/resource.h> header file. */
648+
#undef HAVE_SYS_RESOURCE_H
649+
644650
/* Define if you have the <sys/select.h> header file. */
645651
#undef HAVE_SYS_SELECT_H
646652

configure

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22

3-
# From configure.in Revision: 1.225
3+
# From configure.in Revision: 1.226
44

55
# Guess values for system-dependent variables and create Makefiles.
66
# Generated automatically using autoconf version 2.13
@@ -2074,7 +2074,7 @@ signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
20742074
sys/audioio.h sys/file.h sys/lock.h sys/modem.h db_185.h db.h \
20752075
sys/param.h sys/select.h sys/socket.h sys/time.h sys/times.h \
20762076
sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
2077-
ndbm.h db1/ndbm.h gdbm/ndbm.h
2077+
ndbm.h db1/ndbm.h gdbm/ndbm.h sys/resource.h
20782078
do
20792079
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
20802080
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
@@ -6876,6 +6876,51 @@ else
68766876
fi
68776877

68786878

6879+
echo $ac_n "checking for broken nice()""... $ac_c" 1>&6
6880+
echo "configure:6881: checking for broken nice()" >&5
6881+
if eval "test \"`echo '$''{'ac_cv_broken_nice'+set}'`\" = set"; then
6882+
echo $ac_n "(cached) $ac_c" 1>&6
6883+
else
6884+
6885+
if test "$cross_compiling" = yes; then
6886+
{ echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
6887+
else
6888+
cat > conftest.$ac_ext <<EOF
6889+
#line 6890 "configure"
6890+
#include "confdefs.h"
6891+
6892+
int main()
6893+
{
6894+
int val1 = nice(1);
6895+
if (val1 != -1 && val1 == nice(2))
6896+
exit(0);
6897+
exit(1);
6898+
}
6899+
6900+
EOF
6901+
if { (eval echo configure:6902: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
6902+
then
6903+
ac_cv_broken_nice=yes
6904+
else
6905+
echo "configure: failed program was:" >&5
6906+
cat conftest.$ac_ext >&5
6907+
rm -fr conftest*
6908+
ac_cv_broken_nice=no
6909+
fi
6910+
rm -fr conftest*
6911+
fi
6912+
6913+
fi
6914+
6915+
echo "$ac_t""$ac_cv_broken_nice" 1>&6
6916+
if test "$ac_cv_broken_nice" = yes
6917+
then
6918+
cat >> confdefs.h <<\EOF
6919+
#define HAVE_BROKEN_NICE 1
6920+
EOF
6921+
6922+
fi
6923+
68796924
# THIS MUST BE LAST, IT CAN BREAK OTHER TESTS!
68806925
# Add sys/socket.h to confdefs.h
68816926
cat >> confdefs.h <<\EOF
@@ -6884,12 +6929,12 @@ cat >> confdefs.h <<\EOF
68846929
#endif
68856930
EOF
68866931
echo $ac_n "checking for socklen_t""... $ac_c" 1>&6
6887-
echo "configure:6888: checking for socklen_t" >&5
6932+
echo "configure:6933: checking for socklen_t" >&5
68886933
if eval "test \"`echo '$''{'ac_cv_type_socklen_t'+set}'`\" = set"; then
68896934
echo $ac_n "(cached) $ac_c" 1>&6
68906935
else
68916936
cat > conftest.$ac_ext <<EOF
6892-
#line 6893 "configure"
6937+
#line 6938 "configure"
68936938
#include "confdefs.h"
68946939
#include <sys/types.h>
68956940
#if STDC_HEADERS
@@ -6938,7 +6983,7 @@ done
69386983

69396984
SRCDIRS="Parser Grammar Objects Python Modules"
69406985
echo $ac_n "checking for build directories""... $ac_c" 1>&6
6941-
echo "configure:6942: checking for build directories" >&5
6986+
echo "configure:6987: checking for build directories" >&5
69426987
for dir in $SRCDIRS; do
69436988
if test ! -d $dir; then
69446989
mkdir $dir

configure.in

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
545545
sys/audioio.h sys/file.h sys/lock.h sys/modem.h db_185.h db.h \
546546
sys/param.h sys/select.h sys/socket.h sys/time.h sys/times.h \
547547
sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
548-
ndbm.h db1/ndbm.h gdbm/ndbm.h)
548+
ndbm.h db1/ndbm.h gdbm/ndbm.h sys/resource.h)
549549
AC_HEADER_DIRENT
550550

551551
# checks for typedefs
@@ -1671,6 +1671,23 @@ fi
16711671
AC_CHECK_LIB(readline, rl_completion_matches,
16721672
AC_DEFINE(HAVE_RL_COMPLETION_MATCHES), , -ltermcap)
16731673

1674+
AC_MSG_CHECKING(for broken nice())
1675+
AC_CACHE_VAL(ac_cv_broken_nice, [
1676+
AC_TRY_RUN([
1677+
int main()
1678+
{
1679+
int val1 = nice(1);
1680+
if (val1 != -1 && val1 == nice(2))
1681+
exit(0);
1682+
exit(1);
1683+
}
1684+
],ac_cv_broken_nice=yes, ac_cv_broken_nice=no)])
1685+
AC_MSG_RESULT($ac_cv_broken_nice)
1686+
if test "$ac_cv_broken_nice" = yes
1687+
then
1688+
AC_DEFINE(HAVE_BROKEN_NICE)
1689+
fi
1690+
16741691
# THIS MUST BE LAST, IT CAN BREAK OTHER TESTS!
16751692
# Add sys/socket.h to confdefs.h
16761693
cat >> confdefs.h <<\EOF

0 commit comments

Comments
 (0)