svaarala / duktape

Duktape - embeddable Javascript engine with a focus on portability and compact footprint
MIT License
5.96k stars 516 forks source link

Improvements to Windows date/time provider #1663

Open svaarala opened 7 years ago

svaarala commented 7 years ago
jbmonroe commented 6 years ago

What's the workaround for Windows 7 builds?

svaarala commented 6 years ago

@jbmonroe Could you clarify - does compilation fail for you (if so, what error)?

fatcerberus commented 6 years ago

This is just a guess but I'm thinking he's asking for a time provider that's this precise for Windows 7. GetSystemTimePreciseAsFileTime requires Windows 8+.

svaarala commented 6 years ago

There are various approaches before GetSystemTimePreciseAsFileTime() (for some background, see https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx) but AFAIK none of them are very simple.

It would be relatively simple to use e.g. QueryPerformanceCounter() and an arbitrary starting point to get high resolution (but low accuracy) Date timestamps. While accuracy is important, sometimes it's useful to have high resolution even when the absolute accuracy is not great; this is useful for example when doing timestamp comparisons.

But even in that approach one must deal with QPC quirks, see the above link.

svaarala commented 6 years ago

That said, if someone can point to a good, robust approach for pre-Windows 8, and would be willing to test it, I'd be happy to write up a pull that integrated it into the default Windows Date provider.

jbmonroe commented 6 years ago

Actually, I just need anything that will execute without popping up a dialog that says this or that thing can't be found in Runtime32.dll (or whatever it was). Even something with a pre-compile define that says "hey, this ain't for Windows 8" since there are constraints to what I can deploy.

fatcerberus commented 6 years ago

@jbmonroe You need to define _WIN32_WINNT appropriately sometime before windows.h gets included. Then everything should work itself out.

jbmonroe commented 6 years ago

Okay--that's definitely good news.

As for the part where I get a stack index error of 2.1 billion when trying to add a C function? I think I'll have to work that out on my own. :)

rlaveaux commented 6 years ago

On 28 Apr 2018, at 07:52, Sami Vaarala notifications@github.com wrote:

That said, if someone can point to a good, robust approach for pre-Windows 8, and would be willing to test it, I'd be happy to write up a pull that integrated it into the default Windows Date provider.

I have solved this by checking at runtime if GetSystemTimePreciseAsFileTime is available. If not, then the code falls back to GetSystemTime.

Here is a modified version:

if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS)

DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(void) { /* Variant of the basic algorithm using GetSystemTimePreciseAsFileTime()

Kind regards,,


Pluggers Software Scholekstersingel 48 2496 MP Den Haag The Netherlands

Email: rob.laveaux@pluggers.nl mailto:rob.laveaux@pluggers.nl Website: http://www.pluggers.nl http://www.pluggers.nl/