From dfc29df08b2af201dbec3d91d22328b7dfad5921 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sun, 6 Aug 2017 00:39:26 +0300 Subject: [PATCH] Remove 'thr' argument from ecma/mono time calls --- config/header-snippets/date_provider.h.in | 8 ++++---- src-input/duk_api_internal.h | 1 + src-input/duk_api_time.c | 5 +++++ src-input/duk_bi_date_unix.c | 12 ++++++++---- src-input/duk_bi_date_windows.c | 8 ++------ src-input/duk_bi_protos.h | 8 ++++---- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/config/header-snippets/date_provider.h.in b/config/header-snippets/date_provider.h.in index 445a7d7a..19d9e9f1 100644 --- a/config/header-snippets/date_provider.h.in +++ b/config/header-snippets/date_provider.h.in @@ -11,13 +11,13 @@ #if defined(DUK_USE_DATE_GET_NOW) /* External provider already defined. */ #elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) -#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday((ctx)) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday() #elif defined(DUK_USE_DATE_NOW_TIME) -#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time((ctx)) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time() #elif defined(DUK_USE_DATE_NOW_WINDOWS) -#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows((ctx)) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows() #elif defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) -#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows_subms((ctx)) +#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows_subms() #else #error no provider for DUK_USE_DATE_GET_NOW() #endif diff --git a/src-input/duk_api_internal.h b/src-input/duk_api_internal.h index 9468dcf1..051c39ee 100644 --- a/src-input/duk_api_internal.h +++ b/src-input/duk_api_internal.h @@ -338,6 +338,7 @@ DUK_INTERNAL_DECL duk_int_t duk_pcall_method_flags(duk_hthread *thr, duk_idx_t n (thr)->valstack_bottom - 1) DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time(duk_hthread *thr); +DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time_nofrac(duk_hthread *thr); DUK_INTERNAL_DECL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr); #endif /* DUK_API_INTERNAL_H_INCLUDED */ diff --git a/src-input/duk_api_time.c b/src-input/duk_api_time.c index c46e3087..8d75a3ce 100644 --- a/src-input/duk_api_time.c +++ b/src-input/duk_api_time.c @@ -8,6 +8,7 @@ DUK_INTERNAL duk_double_t duk_time_get_ecmascript_time(duk_hthread *thr) { /* Ecmascript time, with millisecond fractions. Exposed via * duk_get_now() for example. */ + DUK_UNREF(thr); return (duk_double_t) DUK_USE_DATE_GET_NOW(thr); } @@ -15,10 +16,12 @@ DUK_INTERNAL duk_double_t duk_time_get_ecmascript_time_nofrac(duk_hthread *thr) /* Ecmascript time without millisecond fractions. Exposed via * the Date built-in which doesn't allow fractions. */ + DUK_UNREF(thr); return (duk_double_t) DUK_FLOOR(DUK_USE_DATE_GET_NOW(thr)); } DUK_INTERNAL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr) { + DUK_UNREF(thr); #if defined(DUK_USE_GET_MONOTONIC_TIME) return (duk_double_t) DUK_USE_GET_MONOTONIC_TIME(thr); #else @@ -28,6 +31,7 @@ DUK_INTERNAL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr) { DUK_EXTERNAL duk_double_t duk_get_now(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); + DUK_UNREF(thr); /* This API intentionally allows millisecond fractions. */ return duk_time_get_ecmascript_time(thr); @@ -36,6 +40,7 @@ DUK_EXTERNAL duk_double_t duk_get_now(duk_hthread *thr) { #if 0 /* XXX: worth exposing? */ DUK_EXTERNAL duk_double_t duk_get_monotonic_time(duk_hthread *thr) { DUK_ASSERT_API_ENTRY(thr); + DUK_UNREF(thr); return duk_time_get_monotonic_time(thr); } diff --git a/src-input/duk_bi_date_unix.c b/src-input/duk_bi_date_unix.c index bac6561f..4c4bcace 100644 --- a/src-input/duk_bi_date_unix.c +++ b/src-input/duk_bi_date_unix.c @@ -16,12 +16,13 @@ #if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) /* Get current Ecmascript time (= UNIX/Posix time, but in milliseconds). */ -DUK_INTERNAL duk_double_t duk_bi_date_get_now_gettimeofday(duk_hthread *thr) { +DUK_INTERNAL duk_double_t duk_bi_date_get_now_gettimeofday(void) { struct timeval tv; duk_double_t d; if (gettimeofday(&tv, NULL) != 0) { - DUK_ERROR_INTERNAL(thr); + DUK_D(DUK_DPRINT("gettimeofday() failed")); + return 0.0; } /* As of Duktape 2.2.0 allow fractions. */ @@ -34,11 +35,14 @@ DUK_INTERNAL duk_double_t duk_bi_date_get_now_gettimeofday(duk_hthread *thr) { #if defined(DUK_USE_DATE_NOW_TIME) /* Not a very good provider: only full seconds are available. */ -DUK_INTERNAL duk_double_t duk_bi_date_get_now_time(duk_hthread *thr) { +DUK_INTERNAL duk_double_t duk_bi_date_get_now_time(void) { time_t t; - DUK_UNREF(thr); t = time(NULL); + if (t == (time_t) -1) { + DUK_D(DUK_DPRINT("time() failed")); + return 0; + } return ((duk_double_t) t) * 1000.0; } #endif /* DUK_USE_DATE_NOW_TIME */ diff --git a/src-input/duk_bi_date_windows.c b/src-input/duk_bi_date_windows.c index b236363b..25ab711a 100644 --- a/src-input/duk_bi_date_windows.c +++ b/src-input/duk_bi_date_windows.c @@ -42,15 +42,13 @@ DUK_LOCAL void duk__set_systime_jan1970(SYSTEMTIME *st) { #endif /* defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS) */ #if defined(DUK_USE_DATE_NOW_WINDOWS) -DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(duk_hthread *thr) { +DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(void) { /* Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970: * http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx */ SYSTEMTIME st1, st2; ULARGE_INTEGER tmp1, tmp2; - DUK_UNREF(thr); - GetSystemTime(&st1); duk__convert_systime_to_ularge((const SYSTEMTIME *) &st1, &tmp1); @@ -66,7 +64,7 @@ DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows(duk_hthread *thr) { #endif /* DUK_USE_DATE_NOW_WINDOWS */ #if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) -DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(duk_hthread *thr) { +DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(void) { /* Variant of the basic algorithm using GetSystemTimePreciseAsFileTime() * for more accuracy. */ @@ -74,8 +72,6 @@ DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(duk_hthread *thr) { SYSTEMTIME st2; ULARGE_INTEGER tmp1, tmp2; - DUK_UNREF(thr); - GetSystemTimePreciseAsFileTime(&ft1); duk__convert_filetime_to_ularge((const FILETIME *) &ft1, &tmp1); diff --git a/src-input/duk_bi_protos.h b/src-input/duk_bi_protos.h index 082448ce..73c3fcb0 100644 --- a/src-input/duk_bi_protos.h +++ b/src-input/duk_bi_protos.h @@ -23,16 +23,16 @@ DUK_INTERNAL_DECL duk_bool_t duk_bi_date_year_in_valid_range(duk_double_t year); DUK_INTERNAL_DECL duk_bool_t duk_bi_date_timeval_in_leeway_range(duk_double_t x); /* Built-in providers */ #if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY) -DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_gettimeofday(duk_hthread *thr); +DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_gettimeofday(void); #endif #if defined(DUK_USE_DATE_NOW_TIME) -DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_time(duk_hthread *thr); +DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_time(void); #endif #if defined(DUK_USE_DATE_NOW_WINDOWS) -DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows(duk_hthread *thr); +DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows(void); #endif #if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) -DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows_subms(duk_hthread *thr); +DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows_subms(void); #endif #if defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) || defined(DUK_USE_DATE_TZO_GMTIME) DUK_INTERNAL_DECL duk_int_t duk_bi_date_get_local_tzoffset_gmtime(duk_double_t d);