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
Closed

Unix st_mtime has only second-level resolution #6285

vicuna opened this issue Jan 2, 2014 · 4 comments

Comments

@vicuna
Copy link

vicuna 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
Copy link
Author

vicuna 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
Copy link
Author

vicuna 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
Copy link
Author

vicuna commented Mar 5, 2015

Comment author: @diml

Committed in trunk: 15877.

@vicuna
Copy link
Author

vicuna commented Mar 11, 2015

Comment author: @diml

Committed in 4.02: 15894

@vicuna vicuna closed this as completed Dec 7, 2016
@vicuna vicuna added the stdlib label Mar 14, 2019
@vicuna vicuna assigned ghost Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant