Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix st_mtime has only second-level resolution #6285

Closed
vicuna opened this issue Jan 2, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Jan 2, 2014

Original bug ID: 6285
Reporter: gfxmonk
Assigned to: @diml
Status: closed (set by @xavierleroy on 2016-12-07T10:47:19Z)
Resolution: fixed
Priority: normal
Severity: feature
Platform: x86_64
OS: Linux
Version: 4.01.0
Fixed in version: 4.03.0+dev / +beta1
Category: standard library
Monitored by: @gasche @diml @hcarty

Bug description

stat.c (in the unix module) uses the old second-level precision data attributes of linux stat results:

https://github.com/ocaml/ocaml/blob/trunk/otherlibs/unix/stat.c#L46

It should use the newer, subsecond-precision attributes where available. Jane Street Core does this:

https://github.com/janestreet/core/blob/master/lib/unix_stubs.c#L426

Steps to reproduce

The following script always prints a whole number for mtime, despite other programs on the same machine/OS accessing sub-second resolution for mtime (e.g python):

#!/usr/bin/env ocamlscript
Ocaml.packs := ["unix"]

open Unix
open Printf

let () =
let this_file = Array.get Sys.argv 0 in
let stats = Unix.stat this_file in
printf "mtime: %f" stats.st_mtime

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 5, 2014

Comment author: @xavierleroy

I'm putting this as a feature wish, because it is.

Yes, it would be a nice touch to support subsecond resolution here. I am concerned about the three different ways to access the nanosecond parts: a solid configure-time test is needed here, because Jane Street's code seems to assume either Linux, MacOS X, or BSD, but nothing else.

I am also surprised at the "1000000000.0f" constant in their code. By forcing computation to single precision, rounding errors become much larger (up to 1.1 ns instead of 6e-8 ns for double precision). Not that it matters much, but as a floating-point nit-picker I had to point it out.

@vicuna

This comment has been minimized.

Copy link
Author

commented Mar 4, 2015

Comment author: @diml

We added a configure-time test for this in core a few month ago. I wrote a patch for OCaml:

#148

Without the single precision constant...

@vicuna

This comment has been minimized.

Copy link
Author

commented Mar 5, 2015

Comment author: @diml

Committed in trunk: 15877.

@vicuna

This comment has been minimized.

Copy link
Author

commented Mar 11, 2015

Comment author: @diml

Committed in 4.02: 15894

@vicuna vicuna closed this Dec 7, 2016

@vicuna vicuna added the stdlib label Mar 14, 2019

@vicuna vicuna added the feature-wish label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.