I would like to propose a patch to PolyML (attached) that uses subsecond
time fields in stat structures, when they are available. I think the patch
is fairly straightforward.
When I changed configure.ac by adding the AC_CHECK_MEMBERS macro, autoconf
started whining at me about AC_CANONICAL_HOST being obsolete. Then it
turned out that its replacement, AC_CANONICAL_TARGET, must appear before
AM_INIT_AUTOMAKE, hence the slight rearrangement of macro calls there.
Ignore that part if you like AC_CANONICAL_HOST.
I am not sure of the best place to put the STAT_SECS and STAT_USECS macros.
They seemed to me to be somewhat related to other definitions in
io_internal.h, but perhaps there is a better place to put them.
Anyway, this is more a proof of concept than a finished product. Feel free
to mangle it to your heart's content. I won't be offended. :-)
Regards,
--
Jerry James
http://www.jamezone.org/
Index: polyml/config.h.in
===================================================================
--- polyml/config.h.in (revision 1911)
+++ polyml/config.h.in (working copy)
@@ -365,6 +365,21 @@
/* Define to 1 if `sun_len' is a member of `struct sockaddr_un'. */
#undef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
+/* Define to 1 if `st_atim' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIM
+
+/* Define to 1 if `st_atimensec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIMENSEC
+
+/* Define to 1 if `st_atimespec' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIMESPEC
+
+/* Define to 1 if `st_atime_n' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_ATIME_N
+
+/* Define to 1 if `st_uatime' is a member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_UATIME
+
/* Define to 1 if `ss' is a member of `struct __darwin_mcontext32'. */
#undef HAVE_STRUCT___DARWIN_MCONTEXT32_SS
Index: polyml/configure.ac
===================================================================
--- polyml/configure.ac (revision 1911)
+++ polyml/configure.ac (working copy)
@@ -2,8 +2,9 @@
# Process this file with autoconf to produce a configure script.
AC_INIT([Poly/ML],[5.5.1],[polyml AT polyml DOT org],[polyml])
+AC_PREREQ([2.69])
+AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE
-AC_PREREQ(2.65)
# libtoolize recommends this line.
AC_CONFIG_MACRO_DIR([m4])
@@ -27,7 +28,6 @@
test "${CCASFLAGS+set}" = set || CCASFLAGS=""
fi
-AC_CANONICAL_HOST
# Set the OS flag. This should not really be required but is still used in
# a few places for OS-specific quirks that can't be handled by more specific tests.
# Check also for mingw in which case we want to build native Windows.
@@ -316,6 +316,8 @@
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
+AC_CHECK_MEMBERS([struct stat.st_atim, struct stat.st_atimespec,
+ struct stat.st_atimensec, struct stat.st_atime_n, struct stat.st_uatime])
# Mac OS X, at any rate, needs signal.h to be included first.
AC_CHECK_TYPES([ucontext_t], , , [#include "signal.h"
#include "ucontext.h"])
Index: polyml/libpolyml/basicio.cpp
===================================================================
--- polyml/libpolyml/basicio.cpp (revision 1911)
+++ polyml/libpolyml/basicio.cpp (working copy)
@@ -1355,7 +1355,8 @@
if (proper_stat(string_buffer, &fbuff) != 0)
raise_syscall(taskData, "stat failed", errno);
/* Convert to microseconds. */
- return Make_arb_from_pair_scaled(taskData, fbuff.st_mtime, 0, 1000000);
+ return Make_arb_from_pair_scaled(taskData, STAT_SECS(&fbuff,m),
+ STAT_USECS(&fbuff,m), 1000000);
}
#endif
}
Index: polyml/libpolyml/io_internal.h
===================================================================
--- polyml/libpolyml/io_internal.h (revision 1911)
+++ polyml/libpolyml/io_internal.h (working copy)
@@ -115,4 +115,25 @@
extern PIOSTRUCT basic_io_vector;
extern bool emfileFlag;
+
+#if defined(HAVE_STRUCT_STAT_ST_ATIM)
+# define STAT_SECS(stat,kind) (stat)->st_##kind##tim.tv_sec
+# define STAT_USECS(stat,kind) (((stat)->st_##kind##tim.tv_nsec + 500) / 1000)
+#elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC)
+# define STAT_SECS(stat,kind) (stat)->st_##kind##time
+# define STAT_USECS(stat,kind) (((stat)->st_##kind##timensec + 500) / 1000)
+#elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
+# define STAT_SECS(stat,kind) (stat)->st_##kind##timespec.tv_sec
+# define STAT_USECS(stat,kind) (((stat)->st_##kind##timespec.tv_nsec + 500) / 1000)
+#elif defined(HAVE_STRUCT_STAT_ST_ATIME_N)
+# define STAT_SECS(stat,kind) (stat)->st_##kind##time
+# define STAT_USECS(stat,kind) (((stat)->st_##kind##time_n + 500) / 1000)
+#elif defined(HAVE_STRUCT_STAT_ST_UATIME)
+# define STAT_SECS(stat,kind) (stat)->st_##kind##time
+# define STAT_USECS(stat,kind) (stat)->st_u##kind##time
+#else
+# define STAT_SECS(stat,kind) (stat)->st_##kind##time
+# define STAT_USECS(stat,kind) 0
#endif
+
+#endif
Index: polyml/libpolyml/unix_specific.cpp
===================================================================
--- polyml/libpolyml/unix_specific.cpp (revision 1911)
+++ polyml/libpolyml/unix_specific.cpp (working copy)
@@ -1383,11 +1383,12 @@
uidHandle = Make_arbitrary_precision(taskData, buf->st_uid);
gidHandle = Make_arbitrary_precision(taskData, buf->st_gid);
sizeHandle = Make_arbitrary_precision(taskData, buf->st_size);
- /* TODO: The only really standard time fields give the seconds part. There
- are various extensions which would give us microseconds or nanoseconds. */
- atimeHandle = Make_arb_from_pair_scaled(taskData, buf->st_atime, 0, 1000000);
- mtimeHandle = Make_arb_from_pair_scaled(taskData, buf->st_mtime, 0, 1000000);
- ctimeHandle = Make_arb_from_pair_scaled(taskData, buf->st_ctime, 0, 1000000);
+ atimeHandle = Make_arb_from_pair_scaled(taskData, STAT_SECS(buf,a),
+ STAT_USECS(buf,a), 1000000);
+ mtimeHandle = Make_arb_from_pair_scaled(taskData, STAT_SECS(buf,m),
+ STAT_USECS(buf,m), 1000000);
+ ctimeHandle = Make_arb_from_pair_scaled(taskData, STAT_SECS(buf,c),
+ STAT_USECS(buf,c), 1000000);
result = ALLOC(11);
DEREFHANDLE(result)->Set(0, DEREFWORDHANDLE(modeHandle));
DEREFHANDLE(result)->Set(1, DEREFWORDHANDLE(kindHandle));
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml