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

Skip to content

Commit 37098cd

Browse files
committed
more granular configure checks for clock_* functions (closes #28081)
1 parent 54bb13b commit 37098cd

4 files changed

Lines changed: 91 additions & 4 deletions

File tree

Modules/timemodule.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ PyDoc_STRVAR(clock_gettime_doc,
160160
"clock_gettime(clk_id) -> floating point number\n\
161161
\n\
162162
Return the time of the specified clock clk_id.");
163+
#endif /* HAVE_CLOCK_GETTIME */
163164

165+
#ifdef HAVE_CLOCK_SETTIME
164166
static PyObject *
165167
time_clock_settime(PyObject *self, PyObject *args)
166168
{
@@ -191,7 +193,9 @@ PyDoc_STRVAR(clock_settime_doc,
191193
"clock_settime(clk_id, time)\n\
192194
\n\
193195
Set the time of the specified clock clk_id.");
196+
#endif /* HAVE_CLOCK_SETTIME */
194197

198+
#ifdef HAVE_CLOCK_GETRES
195199
static PyObject *
196200
time_clock_getres(PyObject *self, PyObject *args)
197201
{
@@ -215,7 +219,7 @@ PyDoc_STRVAR(clock_getres_doc,
215219
"clock_getres(clk_id) -> floating point number\n\
216220
\n\
217221
Return the resolution (precision) of the specified clock clk_id.");
218-
#endif /* HAVE_CLOCK_GETTIME */
222+
#endif /* HAVE_CLOCK_GETRES */
219223

220224
static PyObject *
221225
time_sleep(PyObject *self, PyObject *obj)
@@ -1287,7 +1291,11 @@ static PyMethodDef time_methods[] = {
12871291
#endif
12881292
#ifdef HAVE_CLOCK_GETTIME
12891293
{"clock_gettime", time_clock_gettime, METH_VARARGS, clock_gettime_doc},
1294+
#endif
1295+
#ifdef HAVE_CLOCK_SETTIME
12901296
{"clock_settime", time_clock_settime, METH_VARARGS, clock_settime_doc},
1297+
#endif
1298+
#ifdef HAVE_CLOCK_GETRES
12911299
{"clock_getres", time_clock_getres, METH_VARARGS, clock_getres_doc},
12921300
#endif
12931301
{"sleep", time_sleep, METH_O, sleep_doc},
@@ -1383,8 +1391,9 @@ PyInit_time(void)
13831391
/* Set, or reset, module variables like time.timezone */
13841392
PyInit_timezone(m);
13851393

1386-
#if defined(HAVE_CLOCK_GETTIME)
1394+
#ifdef CLOCK_REALTIME
13871395
PyModule_AddIntMacro(m, CLOCK_REALTIME);
1396+
#endif
13881397
#ifdef CLOCK_MONOTONIC
13891398
PyModule_AddIntMacro(m, CLOCK_MONOTONIC);
13901399
#endif
@@ -1400,7 +1409,6 @@ PyInit_time(void)
14001409
#ifdef CLOCK_THREAD_CPUTIME_ID
14011410
PyModule_AddIntMacro(m, CLOCK_THREAD_CPUTIME_ID);
14021411
#endif
1403-
#endif /* HAVE_CLOCK_GETTIME */
14041412

14051413
if (!initialized) {
14061414
if (PyStructSequence_InitType2(&StructTimeType,

configure

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ infodir
784784
docdir
785785
oldincludedir
786786
includedir
787+
runstatedir
787788
localstatedir
788789
sharedstatedir
789790
sysconfdir
@@ -894,6 +895,7 @@ datadir='${datarootdir}'
894895
sysconfdir='${prefix}/etc'
895896
sharedstatedir='${prefix}/com'
896897
localstatedir='${prefix}/var'
898+
runstatedir='${localstatedir}/run'
897899
includedir='${prefix}/include'
898900
oldincludedir='/usr/include'
899901
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1146,6 +1148,15 @@ do
11461148
| -silent | --silent | --silen | --sile | --sil)
11471149
silent=yes ;;
11481150

1151+
-runstatedir | --runstatedir | --runstatedi | --runstated \
1152+
| --runstate | --runstat | --runsta | --runst | --runs \
1153+
| --run | --ru | --r)
1154+
ac_prev=runstatedir ;;
1155+
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
1156+
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
1157+
| --run=* | --ru=* | --r=*)
1158+
runstatedir=$ac_optarg ;;
1159+
11491160
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
11501161
ac_prev=sbindir ;;
11511162
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1283,7 +1294,7 @@ fi
12831294
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
12841295
datadir sysconfdir sharedstatedir localstatedir includedir \
12851296
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
1286-
libdir localedir mandir
1297+
libdir localedir mandir runstatedir
12871298
do
12881299
eval ac_val=\$$ac_var
12891300
# Remove trailing slashes.
@@ -1436,6 +1447,7 @@ Fine tuning of the installation directories:
14361447
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
14371448
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
14381449
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
1450+
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
14391451
--libdir=DIR object code libraries [EPREFIX/lib]
14401452
--includedir=DIR C header files [PREFIX/include]
14411453
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -12571,6 +12583,64 @@ fi
1257112583
done
1257212584

1257312585

12586+
for ac_func in clock_settime
12587+
do :
12588+
ac_fn_c_check_func "$LINENO" "clock_settime" "ac_cv_func_clock_settime"
12589+
if test "x$ac_cv_func_clock_settime" = xyes; then :
12590+
cat >>confdefs.h <<_ACEOF
12591+
#define HAVE_CLOCK_SETTIME 1
12592+
_ACEOF
12593+
12594+
else
12595+
12596+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_settime in -lrt" >&5
12597+
$as_echo_n "checking for clock_settime in -lrt... " >&6; }
12598+
if ${ac_cv_lib_rt_clock_settime+:} false; then :
12599+
$as_echo_n "(cached) " >&6
12600+
else
12601+
ac_check_lib_save_LIBS=$LIBS
12602+
LIBS="-lrt $LIBS"
12603+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12604+
/* end confdefs.h. */
12605+
12606+
/* Override any GCC internal prototype to avoid an error.
12607+
Use char because int might match the return type of a GCC
12608+
builtin and then its argument prototype would still apply. */
12609+
#ifdef __cplusplus
12610+
extern "C"
12611+
#endif
12612+
char clock_settime ();
12613+
int
12614+
main ()
12615+
{
12616+
return clock_settime ();
12617+
;
12618+
return 0;
12619+
}
12620+
_ACEOF
12621+
if ac_fn_c_try_link "$LINENO"; then :
12622+
ac_cv_lib_rt_clock_settime=yes
12623+
else
12624+
ac_cv_lib_rt_clock_settime=no
12625+
fi
12626+
rm -f core conftest.err conftest.$ac_objext \
12627+
conftest$ac_exeext conftest.$ac_ext
12628+
LIBS=$ac_check_lib_save_LIBS
12629+
fi
12630+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_settime" >&5
12631+
$as_echo "$ac_cv_lib_rt_clock_settime" >&6; }
12632+
if test "x$ac_cv_lib_rt_clock_settime" = xyes; then :
12633+
12634+
$as_echo "#define HAVE_CLOCK_SETTIME 1" >>confdefs.h
12635+
12636+
12637+
fi
12638+
12639+
12640+
fi
12641+
done
12642+
12643+
1257412644
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for major" >&5
1257512645
$as_echo_n "checking for major... " >&6; }
1257612646
cat confdefs.h - <<_ACEOF >conftest.$ac_ext

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,6 +3734,12 @@ AC_CHECK_FUNCS(clock_getres, [], [
37343734
])
37353735
])
37363736

3737+
AC_CHECK_FUNCS(clock_settime, [], [
3738+
AC_CHECK_LIB(rt, clock_settime, [
3739+
AC_DEFINE(HAVE_CLOCK_SETTIME, 1)
3740+
])
3741+
])
3742+
37373743
AC_MSG_CHECKING(for major, minor, and makedev)
37383744
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
37393745
#if defined(MAJOR_IN_MKDEV)

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@
125125
/* Define to 1 if you have the `clock_gettime' function. */
126126
#undef HAVE_CLOCK_GETTIME
127127

128+
/* Define to 1 if you have the `clock_settime' function. */
129+
#undef HAVE_CLOCK_SETTIME
130+
128131
/* Define if the C compiler supports computed gotos. */
129132
#undef HAVE_COMPUTED_GOTOS
130133

0 commit comments

Comments
 (0)