summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2001-07-11 22:27:39 (GMT)
committerThomas Wouters <thomas@python.org>2001-07-11 22:27:39 (GMT)
commitcac2498815dc526a5888fa534386c0f778667ad6 (patch)
treee7308899d8b4893ee7643f5a014cb9d8c6c9c772
parentd11f5f3eb51180c7cf55cb61ef5848fbafa03925 (diff)
downloadcpython-cac2498815dc526a5888fa534386c0f778667ad6.zip
cpython-cac2498815dc526a5888fa534386c0f778667ad6.tar.gz
cpython-cac2498815dc526a5888fa534386c0f778667ad6.tar.bz2
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 that isn't worth putting in 2.1.1.
-rw-r--r--Modules/posixmodule.c12
-rw-r--r--acconfig.h3
-rw-r--r--config.h.in6
-rwxr-xr-xconfigure55
-rw-r--r--configure.in19
5 files changed, 86 insertions, 9 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 1fbf1b8..1733d87 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1067,6 +1067,12 @@ posix_mkdir(PyObject *self, PyObject *args)
#ifdef HAVE_NICE
+#if defined(HAVE_BROKEN_NICE) && defined(HAVE_SYS_RESOURCE_H)
+#if defined(HAVE_GETPRIORITY) && !defined(PRIO_PROCESS)
+#include <sys/resource.h>
+#endif
+#endif
+
static char posix_nice__doc__[] =
"nice(inc) -> new_priority\n\
Decrease the priority of process and return new priority.";
@@ -1081,8 +1087,8 @@ posix_nice(PyObject *self, PyObject *args)
/* There are two flavours of 'nice': one that returns the new
priority (as required by almost all standards out there) and the
- Linux one, which returns '0' on success and advices the use of
- getpriority() to get the new priority.
+ Linux/FreeBSD/BSDI one, which returns '0' on success and advices
+ the use of getpriority() to get the new priority.
If we are of the nice family that returns the new priority, we
need to clear errno before the call, and check if errno is filled
@@ -1091,7 +1097,7 @@ posix_nice(PyObject *self, PyObject *args)
errno = 0;
value = nice(increment);
-#ifdef HAVE_GETPRIORITY
+#if defined(HAVE_BROKEN_NICE) && defined(HAVE_GETPRIORITY)
if (value == 0)
value = getpriority(PRIO_PROCESS, 0);
#endif
diff --git a/acconfig.h b/acconfig.h
index 549f46a..a54e055 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -95,6 +95,9 @@
/* Define if the compiler provides a wchar.h header file. */
#undef HAVE_WCHAR_H
+/* Define if nice() returns success/failure instead of the new priority. */
+#undef HAVE_BROKEN_NICE
+
/* Define if malloc(0) returns a NULL pointer */
#undef MALLOC_ZERO_RETURNS_NULL
diff --git a/config.h.in b/config.h.in
index 67ee996..5868314 100644
--- a/config.h.in
+++ b/config.h.in
@@ -154,6 +154,9 @@
/* Define if the compiler provides a wchar.h header file. */
#undef HAVE_WCHAR_H
+/* Define if nice() returns success/failure instead of the new priority. */
+#undef HAVE_BROKEN_NICE
+
/* Define if malloc(0) returns a NULL pointer */
#undef MALLOC_ZERO_RETURNS_NULL
@@ -605,6 +608,9 @@
/* Define if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
+/* Define if you have the <sys/resource.h> header file. */
+#undef HAVE_SYS_RESOURCE_H
+
/* Define if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
diff --git a/configure b/configure
index 4f7b8f5..54b6d39 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
-# From configure.in Revision: 1.215.2.2
+# From configure.in Revision: 1.215.2.3
# Guess values for system-dependent variables and create Makefiles.
# Generated automatically using autoconf version 2.13
@@ -1817,7 +1817,7 @@ signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
sys/audioio.h sys/file.h sys/lock.h sys/modem.h db_185.h db.h \
sys/param.h sys/select.h sys/socket.h sys/time.h sys/times.h \
sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
-ndbm.h db1/ndbm.h gdbm/ndbm.h
+ndbm.h db1/ndbm.h gdbm/ndbm.h sys/resource.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
@@ -6215,6 +6215,51 @@ else
fi
+echo $ac_n "checking for broken nice()""... $ac_c" 1>&6
+echo "configure:6220: checking for broken nice()" >&5
+if eval "test \"`echo '$''{'ac_cv_broken_nice'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+
+if test "$cross_compiling" = yes; then
+ { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+else
+ cat > conftest.$ac_ext <<EOF
+#line 6229 "configure"
+#include "confdefs.h"
+
+int main()
+{
+ int val1 = nice(1);
+ if (val1 != -1 && val1 == nice(2))
+ exit(0);
+ exit(1);
+}
+
+EOF
+if { (eval echo configure:6241: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+then
+ ac_cv_broken_nice=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -fr conftest*
+ ac_cv_broken_nice=no
+fi
+rm -fr conftest*
+fi
+
+fi
+
+echo "$ac_t""$ac_cv_broken_nice" 1>&6
+if test "$ac_cv_broken_nice" = yes
+then
+ cat >> confdefs.h <<\EOF
+#define HAVE_BROKEN_NICE 1
+EOF
+
+fi
+
# THIS MUST BE LAST, IT CAN BREAK OTHER TESTS!
# Add sys/socket.h to confdefs.h
cat >> confdefs.h <<\EOF
@@ -6223,12 +6268,12 @@ cat >> confdefs.h <<\EOF
#endif
EOF
echo $ac_n "checking for socklen_t""... $ac_c" 1>&6
-echo "configure:6227: checking for socklen_t" >&5
+echo "configure:6272: checking for socklen_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_socklen_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6232 "configure"
+#line 6277 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
@@ -6277,7 +6322,7 @@ done
SRCDIRS="Parser Grammar Objects Python Modules"
echo $ac_n "checking for build directories""... $ac_c" 1>&6
-echo "configure:6281: checking for build directories" >&5
+echo "configure:6326: checking for build directories" >&5
for dir in $SRCDIRS; do
if test ! -d $dir; then
mkdir $dir
diff --git a/configure.in b/configure.in
index 4867868..7e0ca73 100644
--- a/configure.in
+++ b/configure.in
@@ -384,7 +384,7 @@ signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
sys/audioio.h sys/file.h sys/lock.h sys/modem.h db_185.h db.h \
sys/param.h sys/select.h sys/socket.h sys/time.h sys/times.h \
sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
-ndbm.h db1/ndbm.h gdbm/ndbm.h)
+ndbm.h db1/ndbm.h gdbm/ndbm.h sys/resource.h)
AC_HEADER_DIRENT
# checks for typedefs
@@ -1334,6 +1334,23 @@ fi
AC_CHECK_LIB(readline, rl_completion_matches,
AC_DEFINE(HAVE_RL_COMPLETION_MATCHES), , -ltermcap)
+AC_MSG_CHECKING(for broken nice())
+AC_CACHE_VAL(ac_cv_broken_nice, [
+AC_TRY_RUN([
+int main()
+{
+ int val1 = nice(1);
+ if (val1 != -1 && val1 == nice(2))
+ exit(0);
+ exit(1);
+}
+],ac_cv_broken_nice=yes, ac_cv_broken_nice=no)])
+AC_MSG_RESULT($ac_cv_broken_nice)
+if test "$ac_cv_broken_nice" = yes
+then
+ AC_DEFINE(HAVE_BROKEN_NICE)
+fi
+
# THIS MUST BE LAST, IT CAN BREAK OTHER TESTS!
# Add sys/socket.h to confdefs.h
cat >> confdefs.h <<\EOF