diff -r 58695845e159 Modules/resource.c --- a/Modules/resource.c Mon Sep 28 13:35:54 2015 -0700 +++ b/Modules/resource.c Tue Sep 29 00:26:53 2015 +0300 @@ -105,44 +105,49 @@ return result; } +#if defined(RLIM_T_IS_LONG_LONG) && defined(RLIM_T_IS_UNSIGNED) +# define PyLong_AsRlim PyLong_AsUnsignedLongLong +# define PyLong_FromRlim PyLong_FromUnsignedLongLong +# define RLIM_TYPE unsigned PY_LONG_LONG +# define RLIM_CONVERSION "KK" +#elif defined(RLIM_T_IS_LONG_LONG) && !defined(RLIM_T_IS_UNSIGNED) +# define PyLong_AsRlim PyLong_AsLongLong +# define PyLong_FromRlim PyLong_FromLongLong +# define RLIM_TYPE PY_LONG_LONG +# define RLIM_CONVERSION "LL" +#elif !defined(RLIM_T_IS_LONG_LONG) && defined(RLIM_T_IS_UNSIGNED) +# define PyLong_AsRlim PyLong_AsUnsignedLong +# define PyLong_FromRlim PyLong_FromUnsignedLong +# define RLIM_TYPE unsigned long +# define RLIM_CONVERSION "kk" +#else +# define PyLong_AsRlim PyLong_AsLong +# define PyLong_FromRlim PyLong_FromLong +# define RLIM_TYPE long +# define RLIM_CONVERSION "ll" +#endif static int py2rlimit(PyObject *curobj, PyObject *maxobj, struct rlimit *rl_out) { -#if !defined(HAVE_LARGEFILE_SUPPORT) - rl_out->rlim_cur = PyLong_AsLong(curobj); + rl_out->rlim_cur = PyLong_AsRlim(curobj); if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred()) return -1; - rl_out->rlim_max = PyLong_AsLong(maxobj); + rl_out->rlim_max = PyLong_AsRlim(maxobj); if (rl_out->rlim_max == (rlim_t)-1 && PyErr_Occurred()) return -1; -#else - /* The limits are probably bigger than a long */ - rl_out->rlim_cur = PyLong_AsLongLong(curobj); - if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred()) - return -1; - rl_out->rlim_max = PyLong_AsLongLong(maxobj); - if (rl_out->rlim_max == (rlim_t)-1 && PyErr_Occurred()) - return -1; -#endif rl_out->rlim_cur = rl_out->rlim_cur & RLIM_INFINITY; rl_out->rlim_max = rl_out->rlim_max & RLIM_INFINITY; return 0; - } static PyObject* rlimit2py(struct rlimit rl) { -#if defined(HAVE_LONG_LONG) - if (sizeof(rl.rlim_cur) > sizeof(long)) { - return Py_BuildValue("LL", - (PY_LONG_LONG) rl.rlim_cur, - (PY_LONG_LONG) rl.rlim_max); - } -#endif - return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max); + return Py_BuildValue(RLIM_CONVERSION, + (RLIM_TYPE) rl.rlim_cur, + (RLIM_TYPE) rl.rlim_max); } static PyObject * @@ -438,14 +443,7 @@ PyModule_AddIntMacro(m, RLIMIT_NPTS); #endif -#if defined(HAVE_LONG_LONG) - if (sizeof(RLIM_INFINITY) > sizeof(long)) { - v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY); - } else -#endif - { - v = PyLong_FromLong((long) RLIM_INFINITY); - } + v = PyLong_FromRlim((RLIM_TYPE) RLIM_INFINITY); if (v) { PyModule_AddObject(m, "RLIM_INFINITY", v); } diff -r 58695845e159 configure --- a/configure Mon Sep 28 13:35:54 2015 -0700 +++ b/configure Tue Sep 29 00:26:53 2015 +0300 @@ -16148,6 +16148,78 @@ fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if rlim_t is longer than a long" >&5 +$as_echo_n "checking if rlim_t is longer than a long... " >&6; } + +if test "$cross_compiling" = yes; then : + type_rlim_t_is_longer=yes +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +main(){ + struct rlimit r; + exit(sizeof(r.rlim_cur) <= sizeof(long)); +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + type_rlim_t_is_longer=yes +else + type_rlim_t_is_longer=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +if test "$type_rlim_t_is_longer" = "yes"; then + $as_echo "#define RLIM_T_IS_LONG_LONG 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if rlim_t is unsigned" >&5 +$as_echo_n "checking if rlim_t is unsigned... " >&6; } + +if test "$cross_compiling" = yes; then : + type_rlim_t_is_unsigned=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +main() +{ + struct rlimit r; + r.rlim_cur = -1; + exit(r.rlim_cur < 0); +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + type_rlim_t_is_unsigned=yes +else + type_rlim_t_is_unsigned=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +if test "$type_rlim_t_is_unsigned" = "yes"; then + $as_echo "#define RLIM_T_IS_UNSIGNED 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + # generate output files ac_config_files="$ac_config_files Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh" diff -r 58695845e159 configure.ac --- a/configure.ac Mon Sep 28 13:35:54 2015 -0700 +++ b/configure.ac Tue Sep 29 00:26:53 2015 +0300 @@ -5195,6 +5195,48 @@ [Define to 1 if the getrandom() function is available]) fi +AC_MSG_CHECKING([if rlim_t is longer than a long]) +AH_TEMPLATE([RLIM_T_IS_LONG_LONG], +[Define to 1 if rlim_t is long long]) +AC_TRY_RUN([ +#include +main(){ + struct rlimit r; + exit(sizeof(r.rlim_cur) <= sizeof(long)); +} +], +[type_rlim_t_is_longer=yes], +[type_rlim_t_is_longer=no], +[type_rlim_t_is_longer=yes]) +if test "$type_rlim_t_is_longer" = "yes"; then + AC_DEFINE(RLIM_T_IS_LONG_LONG) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +AC_MSG_CHECKING([if rlim_t is unsigned]) +AH_TEMPLATE([RLIM_T_IS_UNSIGNED], +[Define to 1 if rlim_t is unsigned]) +AC_TRY_RUN([ +#include +main() +{ + struct rlimit r; + r.rlim_cur = -1; + exit(r.rlim_cur < 0); +} +], +[type_rlim_t_is_unsigned=yes], +[type_rlim_t_is_unsigned=no], +[type_rlim_t_is_unsigned=no]) +if test "$type_rlim_t_is_unsigned" = "yes"; then + AC_DEFINE(RLIM_T_IS_UNSIGNED) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + + # generate output files AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh) AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix]) diff -r 58695845e159 pyconfig.h.in --- a/pyconfig.h.in Mon Sep 28 13:35:54 2015 -0700 +++ b/pyconfig.h.in Tue Sep 29 00:26:53 2015 +0300 @@ -1242,6 +1242,12 @@ /* assume C89 semantics that RETSIGTYPE is always void */ #undef RETSIGTYPE +/* Define to 1 if rlim_t is long long */ +#undef RLIM_T_IS_LONG_LONG + +/* Define to 1 if rlim_t is unsigned */ +#undef RLIM_T_IS_UNSIGNED + /* Define if setpgrp() must be called as setpgrp(0, 0). */ #undef SETPGRP_HAVE_ARG