From 21c37987d9a1c2af389322f29e843c0bd206796b Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 16 Jan 2009 14:10:48 -0800 Subject: [PATCH] Bug 461841: Use configure-defined macros in #ifdefs for WinCE in js/src. r=crowder Perform the appropriate configure-time tests, and hard-code the answers for targets that don't support autoconf-style tests. Check for the io.h header, and the setbuf and isatty library functions. In js/src/xpconnect/shell/xpcshell.cpp, use configure-#defined preprocessor symbols to decide what to #include and use. The top-level configure script defines the preprocessor symbols used here. In js/src/prmjtime.cpp, use them to select the appropriate method for retrieving fine-grained time information for Windows and WinCE. The js/src/configure script defines the preprocessor symbols used here. (This should cover the issues addressed by patch.v2 in bug 461841, except for the stdint issue.) --- configure.in | 15 ++++++++++++++- js/src/configure.in | 20 ++++++++++++++++---- js/src/js-config.h.in | 4 ++++ js/src/jsstdint.h | 5 +++++ js/src/prmjtime.cpp | 32 ++++++++++++++++++++++++-------- js/src/prmjtime.h | 2 +- js/src/xpconnect/shell/xpcshell.cpp | 12 +++++++++--- 7 files changed, 73 insertions(+), 17 deletions(-) diff --git a/configure.in b/configure.in index 65ed942747..cb2988d0e6 100644 --- a/configure.in +++ b/configure.in @@ -655,6 +655,18 @@ if test -n "$_WIN32_MSVC"; then SKIP_PATH_CHECKS=1 SKIP_COMPILER_CHECKS=1 SKIP_LIBRARY_CHECKS=1 + + # Since we're skipping compiler and library checks, hard-code + # some facts here. + case "$target" in + *-wince) + ;; + *) + AC_DEFINE(HAVE_IO_H) + AC_DEFINE(HAVE_SETBUF) + AC_DEFINE(HAVE_ISATTY) + ;; + esac fi fi # COMPILE_ENVIRONMENT @@ -2955,6 +2967,7 @@ AC_CHECK_HEADERS(sys/bitypes.h memory.h unistd.h) AC_CHECK_HEADERS(gnu/libc-version.h nl_types.h) AC_CHECK_HEADERS(malloc.h) AC_CHECK_HEADERS(X11/XKBlib.h) +AC_CHECK_HEADERS(io.h) dnl These are all the places some variant of statfs can be hiding. AC_CHECK_HEADERS(sys/statvfs.h sys/statfs.h sys/vfs.h sys/mount.h) @@ -3353,7 +3366,7 @@ dnl Checks for library functions. dnl ======================================================== AC_PROG_GCC_TRADITIONAL AC_FUNC_MEMCMP -AC_CHECK_FUNCS(random strerror lchown fchmod snprintf statvfs memmove rint stat64 lstat64 truncate64 statvfs64) +AC_CHECK_FUNCS(random strerror lchown fchmod snprintf statvfs memmove rint stat64 lstat64 truncate64 statvfs64 setbuf isatty) AC_CHECK_FUNCS(flockfile getpagesize) AC_CHECK_FUNCS(localtime_r strtok_r) diff --git a/js/src/configure.in b/js/src/configure.in index b2bfef93f1..6184d44a3a 100644 --- a/js/src/configure.in +++ b/js/src/configure.in @@ -597,12 +597,24 @@ if test -n "$_WIN32_MSVC"; then # Since we're skipping compiler and library checks, hard-code # some facts here. + # Common to all MSVC environments: # Windows lacks , but has __int8, and so on. AC_DEFINE(JS_HAVE___INTN) - # Windows defines intptr_t and uintptr_t. - # VS2005: http://msdn.microsoft.com/en-us/library/323b6b3k(VS.80).aspx - # VS2008: http://msdn.microsoft.com/en-us/library/323b6b3k.aspx - AC_DEFINE(JS_STDDEF_H_HAS_INTPTR_T) + + case "$target" in + *-wince) + AC_DEFINE(HAVE_SYSTEMTIMETOFILETIME) + AC_DEFINE(JS_CRTDEFS_H_HAS_INTPTR_T) + ;; + *) + AC_DEFINE(HAVE_SYSTEMTIMETOFILETIME) + AC_DEFINE(HAVE_GETSYSTEMTIMEASFILETIME) + # Windows defines intptr_t and uintptr_t. + # VS2005: http://msdn.microsoft.com/en-us/library/323b6b3k(VS.80).aspx + # VS2008: http://msdn.microsoft.com/en-us/library/323b6b3k.aspx + AC_DEFINE(JS_STDDEF_H_HAS_INTPTR_T) + ;; + esac fi fi # COMPILE_ENVIRONMENT diff --git a/js/src/js-config.h.in b/js/src/js-config.h.in index c87761e549..fe6a2ad9c2 100644 --- a/js/src/js-config.h.in +++ b/js/src/js-config.h.in @@ -66,6 +66,10 @@ intptr_t and uintptr_t. */ #undef JS_STDDEF_H_HAS_INTPTR_T +/* Define to 1 if #including provides definitions for + intptr_t and uintptr_t. */ +#undef JS_CRTDEFS_H_HAS_INTPTR_T + /* The configure script defines these if it doesn't #define JS_HAVE_STDINT_H. */ #undef JS_INT8_TYPE diff --git a/js/src/jsstdint.h b/js/src/jsstdint.h index 941066c08f..1268927096 100644 --- a/js/src/jsstdint.h +++ b/js/src/jsstdint.h @@ -87,6 +87,11 @@ typedef unsigned __int64 uint64_t; /* Microsoft Visual C/C++ defines intptr_t and uintptr_t in . */ #if defined(JS_STDDEF_H_HAS_INTPTR_T) #include + +/* Windows Mobile defines intptr_t and uintptr_t in . Why not? */ +#elif defined(JS_CRTDEFS_H_HAS_INTPTR_T) +#include + #else #error "couldn't find definitions for intptr_t, uintptr_t" #endif diff --git a/js/src/prmjtime.cpp b/js/src/prmjtime.cpp index 303fdd08ff..923abc8fdc 100644 --- a/js/src/prmjtime.cpp +++ b/js/src/prmjtime.cpp @@ -153,7 +153,16 @@ PRMJ_ToExtendedTime(JSInt32 base_time) return exttime; } -#ifdef XP_WIN +#ifdef HAVE_SYSTEMTIMETOFILETIME + +static const JSInt64 win2un = JSLL_INIT(0x19DB1DE, 0xD53E8000); + +#define FILETIME2INT64(ft) (((JSInt64)ft.dwHighDateTime) << 32LL | (JSInt64)ft.dwLowDateTime) + +#endif + +#ifdef HAVE_GETSYSTEMTIMEASFILETIME + typedef struct CalibrationData { long double freq; /* The performance counter frequency */ @@ -171,12 +180,8 @@ typedef struct CalibrationData #endif } CalibrationData; -static const JSInt64 win2un = JSLL_INIT(0x19DB1DE, 0xD53E8000); - static CalibrationData calibration = { 0 }; -#define FILETIME2INT64(ft) (((JSInt64)ft.dwHighDateTime) << 32LL | (JSInt64)ft.dwLowDateTime) - static void NowCalibrate() { @@ -262,8 +267,7 @@ static PRCallOnceType calibrationOnce = { 0 }; #endif - -#endif /* XP_WIN */ +#endif /* HAVE_GETSYSTEMTIMEASFILETIME */ #if defined(XP_OS2) @@ -304,7 +308,7 @@ PRMJ_Now(void) return s; } -#elif defined(XP_WIN) +#elif defined(HAVE_GETSYSTEMTIMEASFILETIME) /* Win32 python-esque pseudo code @@ -506,6 +510,18 @@ PRMJ_Now(void) return returnedTime; } + +#elif defined (HAVE_SYSTEMTIMETOFILETIME) +JSInt64 +PRMJ_Now(void) +{ + FILETIME ft; + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st,&ft); + return (FILETIME2INT64(ft)-win2un)/10L; +} + #else #error "No implementation of PRMJ_Now was selected." #endif diff --git a/js/src/prmjtime.h b/js/src/prmjtime.h index e5539455a1..9005ef8235 100644 --- a/js/src/prmjtime.h +++ b/js/src/prmjtime.h @@ -78,7 +78,7 @@ extern JSInt64 PRMJ_Now(void); /* Release the resources associated with PRMJ_Now; don't call PRMJ_Now again */ -#if defined(JS_THREADSAFE) && defined(XP_WIN) +#if defined(JS_THREADSAFE) && defined(HAVE_GETSYSTEMTIMEASFILETIME) extern void PRMJ_NowShutdown(void); #else diff --git a/js/src/xpconnect/shell/xpcshell.cpp b/js/src/xpconnect/shell/xpcshell.cpp index 2bf88072e2..322755d1fd 100644 --- a/js/src/xpconnect/shell/xpcshell.cpp +++ b/js/src/xpconnect/shell/xpcshell.cpp @@ -77,9 +77,10 @@ // all this crap is needed to do the interactive shell stuff #include #include -#if defined(XP_WIN) || defined(XP_OS2) +#ifdef HAVE_IO_H #include /* for isatty() */ -#elif defined(XP_UNIX) || defined(XP_BEOS) +#endif +#ifdef HAVE_UNISTD_H #include /* for isatty() */ #endif @@ -715,7 +716,9 @@ ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file, if (forceTTY) { file = stdin; - } else if (!isatty(fileno(file))) { + } +#ifdef HAVE_ISATTY + else if (!isatty(fileno(file))) { /* * It's not interactive - just execute it. * @@ -746,6 +749,7 @@ ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file, return; } +#endif /* It's an interactive filehandle; drop into read-eval-print loop. */ lineno = 1; @@ -1407,9 +1411,11 @@ main(int argc, char **argv, char **envp) int result; nsresult rv; +#ifdef HAVE_SETBUF // unbuffer stdout so that output is in the correct order; note that stderr // is unbuffered by default setbuf(stdout, 0); +#endif gErrFile = stderr; gOutFile = stdout; -- 2.11.4.GIT