Bug 461841: Use configure-defined macros in #ifdefs for WinCE in js/src. r=crowder
authorJim Blandy <jimb@mozilla.org>
Fri, 16 Jan 2009 14:10:48 -0800
changeset 23834 7cf6db4b75c0daca9a188d839ca06dacbefbed49
parent 23833 d220fbb8ea6a58e7c304b29895c77d3a419ba20b
child 23836 58b777f8849a6e5454262a962c8f1fdb295c8593
push id4750
push userdougt@mozilla.com
push dateFri, 16 Jan 2009 22:19:49 +0000
treeherdermozilla-central@7cf6db4b75c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscrowder
bugs461841
milestone1.9.2a1pre
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
js/src/configure.in
js/src/js-config.h.in
js/src/jsstdint.h
js/src/prmjtime.cpp
js/src/prmjtime.h
js/src/xpconnect/shell/xpcshell.cpp
--- a/configure.in
+++ b/configure.in
@@ -650,16 +650,28 @@ fi
 
 AC_PROG_CPP
 AC_PROG_CXXCPP
 
 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
 
 AC_SUBST(MIDL_FLAGS)
 AC_SUBST(_MSC_VER)
 
 AC_SUBST(GNU_AS)
@@ -2950,16 +2962,17 @@ freebsd*)
     CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}"
     ;;
 esac
 AC_CHECK_HEADERS(sys/byteorder.h compat.h getopt.h)
 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)
 
 dnl Try for MMX support
 dnl NB - later gcc versions require -mmmx for this header to be successfully
 dnl included (or another option which implies it, such as -march=pentium-mmx)
 AC_CHECK_HEADERS(mmintrin.h)
@@ -3348,17 +3361,17 @@ if test "$result" = "no"; then
     AC_DEFINE(MMAP_MISSES_WRITES)
 fi
 
 
 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)
 
 dnl check for wcrtomb/mbrtowc
 dnl =======================================================================
 if test -z "$MACOS_DEPLOYMENT_TARGET" || test "$MACOS_DEPLOYMENT_TARGET" -ge "100300"; then
 AC_LANG_SAVE
 AC_LANG_CPLUSPLUS
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -592,22 +592,34 @@ AC_PROG_CXXCPP
 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.
 
+    # Common to all MSVC environments:
     # Windows lacks <stdint.h>, but has __int8, and so on.
     AC_DEFINE(JS_HAVE___INTN)
-    # Windows <stddef.h> 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 <stddef.h> 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
 
 if test "$cross_compiling"  = "yes"; then
     CROSS_COMPILE=1
 else
     CROSS_COMPILE=
--- a/js/src/js-config.h.in
+++ b/js/src/js-config.h.in
@@ -61,16 +61,20 @@
 /* Define to 1 if the public SpiderMonkey headers may assume that the
    N-byte __intN types are defined by the compiler.  */
 #undef JS_HAVE___INTN
 
 /* Define to 1 if #including <stddef.h> provides definitions for
    intptr_t and uintptr_t.  */
 #undef JS_STDDEF_H_HAS_INTPTR_T
 
+/* Define to 1 if #including <crtdefs.h> 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
 #undef JS_INT16_TYPE
 #undef JS_INT32_TYPE
 #undef JS_INT64_TYPE
 #undef JS_INTPTR_TYPE
 
--- a/js/src/jsstdint.h
+++ b/js/src/jsstdint.h
@@ -82,15 +82,20 @@ typedef unsigned __int64 uint64_t;
 
 #else
 #error "couldn't find exact-width integer types"
 #endif
 
 /* Microsoft Visual C/C++ defines intptr_t and uintptr_t in <stddef.h>.  */
 #if defined(JS_STDDEF_H_HAS_INTPTR_T)
 #include <stddef.h>
+
+/* Windows Mobile defines intptr_t and uintptr_t in <crtdefs.h>.  Why not?  */
+#elif defined(JS_CRTDEFS_H_HAS_INTPTR_T)
+#include <crtdefs.h>
+
 #else
 #error "couldn't find definitions for intptr_t, uintptr_t"
 #endif
 
 #endif /* JS_HAVE_STDINT_H */
 
 #endif /* jsstdint_h___ */
--- a/js/src/prmjtime.cpp
+++ b/js/src/prmjtime.cpp
@@ -148,17 +148,26 @@ PRMJ_ToExtendedTime(JSInt32 base_time)
     JSLL_ADD(g1970GMTMicroSeconds,g1970GMTMicroSeconds,low);
 
     JSLL_I2L(exttime,base_time);
     JSLL_ADD(exttime,exttime,g1970GMTMicroSeconds);
     JSLL_SUB(exttime,exttime,tmp);
     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 */
     long double offset;       /* The low res 'epoch' */
     long double timer_offset; /* The high res 'epoch' */
 
     /* The last high res time that we returned since recalibrating */
     JSInt64 last;
@@ -166,22 +175,18 @@ typedef struct CalibrationData
     JSBool calibrated;
 
 #ifdef JS_THREADSAFE
     CRITICAL_SECTION data_lock;
     CRITICAL_SECTION calibration_lock;
 #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()
 {
     FILETIME ft, ftStart;
     LARGE_INTEGER liFreq, now;
 
     if (calibration.freq == 0.0) {
         if(!QueryPerformanceFrequency(&liFreq)) {
@@ -257,18 +262,17 @@ static PRCallOnceType calibrationOnce = 
 
 #define MUTEX_LOCK(m)
 #define MUTEX_TRYLOCK(m) 1
 #define MUTEX_UNLOCK(m)
 #define MUTEX_SETSPINCOUNT(m, c)
 
 #endif
 
-
-#endif /* XP_WIN */
+#endif /* HAVE_GETSYSTEMTIMEASFILETIME */
 
 
 #if defined(XP_OS2)
 JSInt64
 PRMJ_Now(void)
 {
     JSInt64 s, us, ms2us, s2us;
     struct timeb b;
@@ -299,17 +303,17 @@ PRMJ_Now(void)
     JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
     JSLL_UI2L(s, tv.tv_sec);
     JSLL_UI2L(us, tv.tv_usec);
     JSLL_MUL(s, s, s2us);
     JSLL_ADD(s, s, us);
     return s;
 }
 
-#elif defined(XP_WIN)
+#elif defined(HAVE_GETSYSTEMTIMEASFILETIME)
 /*
 
 Win32 python-esque pseudo code
 Please see bug 363258 for why the win32 timing code is so complex.
 
 calibration mutex : Win32CriticalSection(spincount=0)
 data mutex : Win32CriticalSection(spincount=4096)
 
@@ -501,16 +505,28 @@ PRMJ_Now(void)
         } else {
             /* No high resolution timer is available, so fall back */
             returnedTime = (JSInt64)lowresTime;
         }
     } while (needsCalibration);
 
     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
 
 /* Get the DST timezone offset for the time passed in */
 JSInt64
 PRMJ_DSTOffset(JSInt64 local_time)
 {
--- a/js/src/prmjtime.h
+++ b/js/src/prmjtime.h
@@ -73,17 +73,17 @@ struct PRMJTime {
 #define PRMJ_USEC_PER_SEC       1000000L
 #define PRMJ_USEC_PER_MSEC      1000L
 
 /* Return the current local time in micro-seconds */
 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
 #define PRMJ_NowShutdown()
 #endif
 
 /* get the difference between this time zone and  gmt timezone in seconds */
 extern JSInt32
--- a/js/src/xpconnect/shell/xpcshell.cpp
+++ b/js/src/xpconnect/shell/xpcshell.cpp
@@ -72,19 +72,20 @@
 #ifndef XPCONNECT_STANDALONE
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
 #endif
 
 // all this crap is needed to do the interactive shell stuff
 #include <stdlib.h>
 #include <errno.h>
-#if defined(XP_WIN) || defined(XP_OS2)
+#ifdef HAVE_IO_H
 #include <io.h>     /* for isatty() */
-#elif defined(XP_UNIX) || defined(XP_BEOS)
+#endif
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>     /* for isatty() */
 #endif
 
 #include "nsIJSContextStack.h"
 
 /***************************************************************************/
 
 #ifdef JS_THREADSAFE
@@ -710,17 +711,19 @@ ProcessFile(JSContext *cx, JSObject *obj
     jsval result;
     int lineno, startline;
     JSBool ok, hitEOF;
     char *bufp, buffer[4096];
     JSString *str;
 
     if (forceTTY) {
         file = stdin;
-    } else if (!isatty(fileno(file))) {
+    }
+#ifdef HAVE_ISATTY
+    else if (!isatty(fileno(file))) {
         /*
          * It's not interactive - just execute it.
          *
          * Support the UNIX #! shell hack; gobble the first line if it starts
          * with '#'.  TODO - this isn't quite compatible with sharp variables,
          * as a legal js program (using sharp variables) might start with '#'.
          * But that would require multi-character lookahead.
          */
@@ -741,16 +744,17 @@ ProcessFile(JSContext *cx, JSObject *obj
             if (!compileOnly)
                 (void)JS_ExecuteScript(cx, obj, script, &result);
             JS_DestroyScript(cx, script);
         }
         DoEndRequest(cx);
 
         return;
     }
+#endif
 
     /* It's an interactive filehandle; drop into read-eval-print loop. */
     lineno = 1;
     hitEOF = JS_FALSE;
     do {
         bufp = buffer;
         *bufp = '\0';
 
@@ -1402,19 +1406,21 @@ main(int argc, char **argv, char **envp)
     InitAutoreleasePool();
 #endif
     JSRuntime *rt;
     JSContext *cx;
     JSObject *glob, *envobj;
     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;
     gInFile = stdin;
     {
         nsCOMPtr<nsIServiceManager> servMan;
         rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
         if (NS_FAILED(rv)) {