Home | History | Annotate | Download | only in patches
      1 diff --git a/AUTHORS b/AUTHORS
      2 index 3c0f928..e17d9bf 100644
      3 --- a/AUTHORS
      4 +++ b/AUTHORS
      5 @@ -8,5 +8,6 @@
      6  
      7  # Please keep the list sorted.
      8  
      9 +Brian Gunlogson <unixman83 (a] gmail.com>
     10  Google Inc.
     11  Stefano Rivera <stefano.rivera (a] gmail.com>
     12 diff --git a/CONTRIBUTORS b/CONTRIBUTORS
     13 index 7b44e04..7f6a93d 100644
     14 --- a/CONTRIBUTORS
     15 +++ b/CONTRIBUTORS
     16 @@ -26,6 +26,7 @@
     17  
     18  # Please keep the list sorted.
     19  
     20 +Brian Gunlogson <unixman83 (a] gmail.com>
     21  Dominic Battr <battre (a] chromium.org>
     22  John Millikin <jmillikin (a] gmail.com>
     23  Rob Pike <r (a] google.com>
     24 diff --git a/mswin/stdint.h b/mswin/stdint.h
     25 new file mode 100644
     26 index 0000000..d02608a
     27 --- /dev/null
     28 +++ b/mswin/stdint.h
     29 @@ -0,0 +1,247 @@
     30 +// ISO C9x  compliant stdint.h for Microsoft Visual Studio
     31 +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 
     32 +// 
     33 +//  Copyright (c) 2006-2008 Alexander Chemeris
     34 +// 
     35 +// Redistribution and use in source and binary forms, with or without
     36 +// modification, are permitted provided that the following conditions are met:
     37 +// 
     38 +//   1. Redistributions of source code must retain the above copyright notice,
     39 +//      this list of conditions and the following disclaimer.
     40 +// 
     41 +//   2. Redistributions in binary form must reproduce the above copyright
     42 +//      notice, this list of conditions and the following disclaimer in the
     43 +//      documentation and/or other materials provided with the distribution.
     44 +// 
     45 +//   3. The name of the author may be used to endorse or promote products
     46 +//      derived from this software without specific prior written permission.
     47 +// 
     48 +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     49 +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     50 +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     51 +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     52 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     53 +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     54 +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
     55 +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     56 +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     57 +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     58 +// 
     59 +///////////////////////////////////////////////////////////////////////////////
     60 +
     61 +#ifndef _MSC_VER // [
     62 +#error "Use this header only with Microsoft Visual C++ compilers!"
     63 +#endif // _MSC_VER ]
     64 +
     65 +#ifndef _MSC_STDINT_H_ // [
     66 +#define _MSC_STDINT_H_
     67 +
     68 +#if _MSC_VER > 1000
     69 +#pragma once
     70 +#endif
     71 +
     72 +#include <limits.h>
     73 +
     74 +// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
     75 +// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
     76 +// or compiler give many errors like this:
     77 +//   error C2733: second C linkage of overloaded function 'wmemchr' not allowed
     78 +#ifdef __cplusplus
     79 +extern "C" {
     80 +#endif
     81 +#  include <wchar.h>
     82 +#ifdef __cplusplus
     83 +}
     84 +#endif
     85 +
     86 +// Define _W64 macros to mark types changing their size, like intptr_t.
     87 +#ifndef _W64
     88 +#  if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
     89 +#     define _W64 __w64
     90 +#  else
     91 +#     define _W64
     92 +#  endif
     93 +#endif
     94 +
     95 +
     96 +// 7.18.1 Integer types
     97 +
     98 +// 7.18.1.1 Exact-width integer types
     99 +
    100 +// Visual Studio 6 and Embedded Visual C++ 4 doesn't
    101 +// realize that, e.g. char has the same size as __int8
    102 +// so we give up on __intX for them.
    103 +#if (_MSC_VER < 1300)
    104 +   typedef signed char       int8_t;
    105 +   typedef signed short      int16_t;
    106 +   typedef signed int        int32_t;
    107 +   typedef unsigned char     uint8_t;
    108 +   typedef unsigned short    uint16_t;
    109 +   typedef unsigned int      uint32_t;
    110 +#else
    111 +   typedef signed __int8     int8_t;
    112 +   typedef signed __int16    int16_t;
    113 +   typedef signed __int32    int32_t;
    114 +   typedef unsigned __int8   uint8_t;
    115 +   typedef unsigned __int16  uint16_t;
    116 +   typedef unsigned __int32  uint32_t;
    117 +#endif
    118 +typedef signed __int64       int64_t;
    119 +typedef unsigned __int64     uint64_t;
    120 +
    121 +
    122 +// 7.18.1.2 Minimum-width integer types
    123 +typedef int8_t    int_least8_t;
    124 +typedef int16_t   int_least16_t;
    125 +typedef int32_t   int_least32_t;
    126 +typedef int64_t   int_least64_t;
    127 +typedef uint8_t   uint_least8_t;
    128 +typedef uint16_t  uint_least16_t;
    129 +typedef uint32_t  uint_least32_t;
    130 +typedef uint64_t  uint_least64_t;
    131 +
    132 +// 7.18.1.3 Fastest minimum-width integer types
    133 +typedef int8_t    int_fast8_t;
    134 +typedef int16_t   int_fast16_t;
    135 +typedef int32_t   int_fast32_t;
    136 +typedef int64_t   int_fast64_t;
    137 +typedef uint8_t   uint_fast8_t;
    138 +typedef uint16_t  uint_fast16_t;
    139 +typedef uint32_t  uint_fast32_t;
    140 +typedef uint64_t  uint_fast64_t;
    141 +
    142 +// 7.18.1.4 Integer types capable of holding object pointers
    143 +#ifdef _WIN64 // [
    144 +   typedef signed __int64    intptr_t;
    145 +   typedef unsigned __int64  uintptr_t;
    146 +#else // _WIN64 ][
    147 +   typedef _W64 signed int   intptr_t;
    148 +   typedef _W64 unsigned int uintptr_t;
    149 +#endif // _WIN64 ]
    150 +
    151 +// 7.18.1.5 Greatest-width integer types
    152 +typedef int64_t   intmax_t;
    153 +typedef uint64_t  uintmax_t;
    154 +
    155 +
    156 +// 7.18.2 Limits of specified-width integer types
    157 +
    158 +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [   See footnote 220 at page 257 and footnote 221 at page 259
    159 +
    160 +// 7.18.2.1 Limits of exact-width integer types
    161 +#define INT8_MIN     ((int8_t)_I8_MIN)
    162 +#define INT8_MAX     _I8_MAX
    163 +#define INT16_MIN    ((int16_t)_I16_MIN)
    164 +#define INT16_MAX    _I16_MAX
    165 +#define INT32_MIN    ((int32_t)_I32_MIN)
    166 +#define INT32_MAX    _I32_MAX
    167 +#define INT64_MIN    ((int64_t)_I64_MIN)
    168 +#define INT64_MAX    _I64_MAX
    169 +#define UINT8_MAX    _UI8_MAX
    170 +#define UINT16_MAX   _UI16_MAX
    171 +#define UINT32_MAX   _UI32_MAX
    172 +#define UINT64_MAX   _UI64_MAX
    173 +
    174 +// 7.18.2.2 Limits of minimum-width integer types
    175 +#define INT_LEAST8_MIN    INT8_MIN
    176 +#define INT_LEAST8_MAX    INT8_MAX
    177 +#define INT_LEAST16_MIN   INT16_MIN
    178 +#define INT_LEAST16_MAX   INT16_MAX
    179 +#define INT_LEAST32_MIN   INT32_MIN
    180 +#define INT_LEAST32_MAX   INT32_MAX
    181 +#define INT_LEAST64_MIN   INT64_MIN
    182 +#define INT_LEAST64_MAX   INT64_MAX
    183 +#define UINT_LEAST8_MAX   UINT8_MAX
    184 +#define UINT_LEAST16_MAX  UINT16_MAX
    185 +#define UINT_LEAST32_MAX  UINT32_MAX
    186 +#define UINT_LEAST64_MAX  UINT64_MAX
    187 +
    188 +// 7.18.2.3 Limits of fastest minimum-width integer types
    189 +#define INT_FAST8_MIN    INT8_MIN
    190 +#define INT_FAST8_MAX    INT8_MAX
    191 +#define INT_FAST16_MIN   INT16_MIN
    192 +#define INT_FAST16_MAX   INT16_MAX
    193 +#define INT_FAST32_MIN   INT32_MIN
    194 +#define INT_FAST32_MAX   INT32_MAX
    195 +#define INT_FAST64_MIN   INT64_MIN
    196 +#define INT_FAST64_MAX   INT64_MAX
    197 +#define UINT_FAST8_MAX   UINT8_MAX
    198 +#define UINT_FAST16_MAX  UINT16_MAX
    199 +#define UINT_FAST32_MAX  UINT32_MAX
    200 +#define UINT_FAST64_MAX  UINT64_MAX
    201 +
    202 +// 7.18.2.4 Limits of integer types capable of holding object pointers
    203 +#ifdef _WIN64 // [
    204 +#  define INTPTR_MIN   INT64_MIN
    205 +#  define INTPTR_MAX   INT64_MAX
    206 +#  define UINTPTR_MAX  UINT64_MAX
    207 +#else // _WIN64 ][
    208 +#  define INTPTR_MIN   INT32_MIN
    209 +#  define INTPTR_MAX   INT32_MAX
    210 +#  define UINTPTR_MAX  UINT32_MAX
    211 +#endif // _WIN64 ]
    212 +
    213 +// 7.18.2.5 Limits of greatest-width integer types
    214 +#define INTMAX_MIN   INT64_MIN
    215 +#define INTMAX_MAX   INT64_MAX
    216 +#define UINTMAX_MAX  UINT64_MAX
    217 +
    218 +// 7.18.3 Limits of other integer types
    219 +
    220 +#ifdef _WIN64 // [
    221 +#  define PTRDIFF_MIN  _I64_MIN
    222 +#  define PTRDIFF_MAX  _I64_MAX
    223 +#else  // _WIN64 ][
    224 +#  define PTRDIFF_MIN  _I32_MIN
    225 +#  define PTRDIFF_MAX  _I32_MAX
    226 +#endif  // _WIN64 ]
    227 +
    228 +#define SIG_ATOMIC_MIN  INT_MIN
    229 +#define SIG_ATOMIC_MAX  INT_MAX
    230 +
    231 +#ifndef SIZE_MAX // [
    232 +#  ifdef _WIN64 // [
    233 +#     define SIZE_MAX  _UI64_MAX
    234 +#  else // _WIN64 ][
    235 +#     define SIZE_MAX  _UI32_MAX
    236 +#  endif // _WIN64 ]
    237 +#endif // SIZE_MAX ]
    238 +
    239 +// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
    240 +#ifndef WCHAR_MIN // [
    241 +#  define WCHAR_MIN  0
    242 +#endif  // WCHAR_MIN ]
    243 +#ifndef WCHAR_MAX // [
    244 +#  define WCHAR_MAX  _UI16_MAX
    245 +#endif  // WCHAR_MAX ]
    246 +
    247 +#define WINT_MIN  0
    248 +#define WINT_MAX  _UI16_MAX
    249 +
    250 +#endif // __STDC_LIMIT_MACROS ]
    251 +
    252 +
    253 +// 7.18.4 Limits of other integer types
    254 +
    255 +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [   See footnote 224 at page 260
    256 +
    257 +// 7.18.4.1 Macros for minimum-width integer constants
    258 +
    259 +#define INT8_C(val)  val##i8
    260 +#define INT16_C(val) val##i16
    261 +#define INT32_C(val) val##i32
    262 +#define INT64_C(val) val##i64
    263 +
    264 +#define UINT8_C(val)  val##ui8
    265 +#define UINT16_C(val) val##ui16
    266 +#define UINT32_C(val) val##ui32
    267 +#define UINT64_C(val) val##ui64
    268 +
    269 +// 7.18.4.2 Macros for greatest-width integer constants
    270 +#define INTMAX_C   INT64_C
    271 +#define UINTMAX_C  UINT64_C
    272 +
    273 +#endif // __STDC_CONSTANT_MACROS ]
    274 +
    275 +
    276 +#endif // _MSC_STDINT_H_ ]
    277 diff --git a/re2/compile.cc b/re2/compile.cc
    278 index 9cddb71..adb45fd 100644
    279 --- a/re2/compile.cc
    280 +++ b/re2/compile.cc
    281 @@ -502,7 +502,7 @@ int Compiler::RuneByteSuffix(uint8 lo, uint8 hi, bool foldcase, int next) {
    282      return UncachedRuneByteSuffix(lo, hi, foldcase, next);
    283    }
    284  
    285 -  uint64 key = ((uint64)next << 17) | (lo<<9) | (hi<<1) | foldcase;
    286 +  uint64 key = ((uint64)next << 17) | (lo<<9) | (hi<<1) | (foldcase ? 1ULL : 0ULL);
    287    map<uint64, int>::iterator it = rune_cache_.find(key);
    288    if (it != rune_cache_.end())
    289      return it->second;
    290 diff --git a/re2/prefilter_tree.cc b/re2/prefilter_tree.cc
    291 index d8bc37a..cdcf77e 100644
    292 --- a/re2/prefilter_tree.cc
    293 +++ b/re2/prefilter_tree.cc
    294 @@ -8,6 +8,11 @@
    295  #include "re2/prefilter_tree.h"
    296  #include "re2/re2.h"
    297  
    298 +#ifdef WIN32
    299 +#include <stdio.h>
    300 +#define snprintf _snprintf
    301 +#endif
    302 +
    303  DEFINE_int32(filtered_re2_min_atom_len,
    304               3,
    305               "Strings less than this length are not stored as atoms");
    306 diff --git a/re2/re2.cc b/re2/re2.cc
    307 index 8d1d468..0da886d 100644
    308 --- a/re2/re2.cc
    309 +++ b/re2/re2.cc
    310 @@ -11,7 +11,13 @@
    311  
    312  #include <stdio.h>
    313  #include <string>
    314 +#ifdef WIN32
    315 +#define strtoll _strtoi64
    316 +#define strtoull _strtoui64
    317 +#define strtof strtod
    318 +#else
    319  #include <pthread.h>
    320 +#endif
    321  #include <errno.h>
    322  #include "util/util.h"
    323  #include "util/flags.h"
    324 @@ -31,10 +37,22 @@ const VariadicFunction2<bool, const StringPiece&, const RE2&, RE2::Arg, RE2::Par
    325  const VariadicFunction2<bool, StringPiece*, const RE2&, RE2::Arg, RE2::ConsumeN> RE2::Consume;
    326  const VariadicFunction2<bool, StringPiece*, const RE2&, RE2::Arg, RE2::FindAndConsumeN> RE2::FindAndConsume;
    327  
    328 -// This will trigger LNK2005 error in MSVC.
    329 -#ifndef COMPILER_MSVC
    330 -const int RE2::Options::kDefaultMaxMem;  // initialized in re2.h
    331 -#endif  // COMPILER_MSVC
    332 +#define kDefaultMaxMem (8<<20)
    333 +
    334 +RE2::Options::Options()
    335 +  :  encoding_(EncodingUTF8),
    336 +     posix_syntax_(false),
    337 +     longest_match_(false),
    338 +     log_errors_(true),
    339 +     max_mem_(kDefaultMaxMem),
    340 +     literal_(false),
    341 +     never_nl_(false),
    342 +     never_capture_(false),
    343 +     case_sensitive_(true),
    344 +     perl_classes_(false),
    345 +     word_boundary_(false),
    346 +     one_line_(false) {
    347 +}
    348  
    349  RE2::Options::Options(RE2::CannedOptions opt)
    350    : encoding_(opt == RE2::Latin1 ? EncodingLatin1 : EncodingUTF8),
    351 diff --git a/re2/re2.h b/re2/re2.h
    352 index 272028b..c509853 100644
    353 --- a/re2/re2.h
    354 +++ b/re2/re2.h
    355 @@ -552,28 +552,16 @@ class RE2 {
    356      // If this happens too often, RE2 falls back on the NFA implementation.
    357  
    358      // For now, make the default budget something close to Code Search.
    359 +#ifndef WIN32
    360      static const int kDefaultMaxMem = 8<<20;
    361 +#endif
    362  
    363      enum Encoding {
    364        EncodingUTF8 = 1,
    365        EncodingLatin1
    366      };
    367  
    368 -    Options() :
    369 -      encoding_(EncodingUTF8),
    370 -      posix_syntax_(false),
    371 -      longest_match_(false),
    372 -      log_errors_(true),
    373 -      max_mem_(kDefaultMaxMem),
    374 -      literal_(false),
    375 -      never_nl_(false),
    376 -      never_capture_(false),
    377 -      case_sensitive_(true),
    378 -      perl_classes_(false),
    379 -      word_boundary_(false),
    380 -      one_line_(false) {
    381 -    }
    382 -    
    383 +    Options();
    384      /*implicit*/ Options(CannedOptions);
    385  
    386      Encoding encoding() const { return encoding_; }
    387 diff --git a/re2/stringpiece.h b/re2/stringpiece.h
    388 index ab9297c..38a5150 100644
    389 --- a/re2/stringpiece.h
    390 +++ b/re2/stringpiece.h
    391 @@ -23,6 +23,9 @@
    392  #include <cstddef>
    393  #include <iosfwd>
    394  #include <string>
    395 +#ifdef WIN32
    396 +#include <algorithm>
    397 +#endif
    398  
    399  namespace re2 {
    400  
    401 diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc
    402 index b99cacf..911e868 100644
    403 --- a/re2/testing/re2_test.cc
    404 +++ b/re2/testing/re2_test.cc
    405 @@ -6,7 +6,9 @@
    406  // TODO: Test extractions for PartialMatch/Consume
    407  
    408  #include <sys/types.h>
    409 +#ifndef WIN32
    410  #include <sys/mman.h>
    411 +#endif
    412  #include <sys/stat.h>
    413  #include <errno.h>
    414  #include <vector>
    415 @@ -14,6 +16,11 @@
    416  #include "re2/re2.h"
    417  #include "re2/regexp.h"
    418  
    419 +#ifdef WIN32
    420 +#include <stdio.h>
    421 +#define snprintf _snprintf
    422 +#endif
    423 +
    424  DECLARE_bool(logtostderr);
    425  
    426  namespace re2 {
    427 @@ -657,6 +664,7 @@ TEST(RE2, FullMatchTypedNullArg) {
    428    CHECK(!RE2::FullMatch("hello", "(.*)", (float*)NULL));
    429  }
    430  
    431 +#ifndef WIN32
    432  // Check that numeric parsing code does not read past the end of
    433  // the number being parsed.
    434  TEST(RE2, NULTerminated) {
    435 @@ -678,6 +686,7 @@ TEST(RE2, NULTerminated) {
    436    CHECK(RE2::FullMatch(StringPiece(v + pagesize - 1, 1), "(.*)", &x));
    437    CHECK_EQ(x, 1);
    438  }
    439 +#endif
    440  
    441  TEST(RE2, FullMatchTypeTests) {
    442    // Type tests
    443 diff --git a/util/logging.h b/util/logging.h
    444 index 4443f7c..d0a2d87 100644
    445 --- a/util/logging.h
    446 +++ b/util/logging.h
    447 @@ -7,8 +7,13 @@
    448  #ifndef RE2_UTIL_LOGGING_H__
    449  #define RE2_UTIL_LOGGING_H__
    450  
    451 +#ifndef WIN32
    452  #include <unistd.h>  /* for write */
    453 +#endif
    454  #include <sstream>
    455 +#ifdef WIN32
    456 +#include <io.h>
    457 +#endif
    458  
    459  // Debug-only checking.
    460  #define DCHECK(condition) assert(condition)
    461 diff --git a/util/mutex.h b/util/mutex.h
    462 index 9787bfb..e321fae 100644
    463 --- a/util/mutex.h
    464 +++ b/util/mutex.h
    465 @@ -12,8 +12,10 @@
    466  
    467  namespace re2 {
    468  
    469 +#ifndef WIN32
    470  #define HAVE_PTHREAD 1
    471  #define HAVE_RWLOCK 1
    472 +#endif
    473  
    474  #if defined(NO_THREADS)
    475    typedef int MutexType;      // to keep a lock-count
    476 @@ -32,7 +34,9 @@ namespace re2 {
    477  # include <pthread.h>
    478    typedef pthread_mutex_t MutexType;
    479  #elif defined(WIN32)
    480 -# define WIN32_LEAN_AND_MEAN  // We only need minimal includes
    481 +# ifndef WIN32_LEAN_AND_MEAN
    482 +#  define WIN32_LEAN_AND_MEAN  // We only need minimal includes
    483 +# endif
    484  # ifdef GMUTEX_TRYLOCK
    485    // We need Windows NT or later for TryEnterCriticalSection().  If you
    486    // don't need that functionality, you can remove these _WIN32_WINNT
    487 diff --git a/util/pcre.cc b/util/pcre.cc
    488 index 5e67e1f..1602133 100644
    489 --- a/util/pcre.cc
    490 +++ b/util/pcre.cc
    491 @@ -11,6 +11,11 @@
    492  #include "util/flags.h"
    493  #include "util/pcre.h"
    494  
    495 +#ifdef WIN32
    496 +#define strtoll _strtoi64
    497 +#define strtoull _strtoui64
    498 +#endif
    499 +
    500  #define PCREPORT(level) LOG(level)
    501  
    502  // Default PCRE limits.
    503 diff --git a/util/pcre.h b/util/pcre.h
    504 index 4dda95d..771ac91 100644
    505 --- a/util/pcre.h
    506 +++ b/util/pcre.h
    507 @@ -180,9 +180,15 @@ struct pcre_extra { int flags, match_limit, match_limit_recursion; };
    508  #define PCRE_ERROR_MATCHLIMIT 2
    509  #define PCRE_ERROR_RECURSIONLIMIT 3
    510  #define PCRE_INFO_CAPTURECOUNT 0
    511 +#ifndef WIN32
    512  #define pcre_compile(a,b,c,d,e) ({ (void)(a); (void)(b); *(c)=""; *(d)=0; (void)(e); ((pcre*)0); })
    513  #define pcre_exec(a, b, c, d, e, f, g, h) ({ (void)(a); (void)(b); (void)(c); (void)(d); (void)(e); (void)(f); (void)(g); (void)(h); 0; })
    514  #define pcre_fullinfo(a, b, c, d) ({ (void)(a); (void)(b); (void)(c); *(d) = 0; 0; })
    515 +#else
    516 +#define pcre_compile(a,b,c,d,e) NULL
    517 +#define pcre_exec(a, b, c, d, e, f, g, h) NULL
    518 +#define pcre_fullinfo(a, b, c, d) NULL
    519 +#endif
    520  }  // namespace re2
    521  #endif
    522  
    523 diff --git a/util/stringprintf.cc b/util/stringprintf.cc
    524 index c908181..d4691d1 100644
    525 --- a/util/stringprintf.cc
    526 +++ b/util/stringprintf.cc
    527 @@ -4,6 +4,10 @@
    528  
    529  #include "util/util.h"
    530  
    531 +#ifndef va_copy
    532 +#define va_copy(d,s) ((d) = (s)) //KLUGE: for MS compilers
    533 +#endif
    534 +
    535  namespace re2 { 
    536  
    537  static void StringAppendV(string* dst, const char* format, va_list ap) {
    538 diff --git a/util/test.cc b/util/test.cc
    539 index 0644829..2fe1bfa 100644
    540 --- a/util/test.cc
    541 +++ b/util/test.cc
    542 @@ -3,7 +3,9 @@
    543  // license that can be found in the LICENSE file.
    544  
    545  #include <stdio.h>
    546 +#ifndef WIN32
    547  #include <sys/resource.h>
    548 +#endif
    549  #include "util/test.h"
    550  
    551  DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
    552 @@ -23,9 +25,13 @@ void RegisterTest(void (*fn)(void), const char *name) {
    553  
    554  namespace re2 {
    555  int64 VirtualProcessSize() {
    556 +#ifndef WIN32
    557    struct rusage ru;
    558    getrusage(RUSAGE_SELF, &ru);
    559    return (int64)ru.ru_maxrss*1024;
    560 +#else
    561 +  return 0;
    562 +#endif
    563  }
    564  }  // namespace re2
    565  
    566 diff --git a/util/util.h b/util/util.h
    567 index c46ab1b..17ef824 100644
    568 --- a/util/util.h
    569 +++ b/util/util.h
    570 @@ -12,7 +12,9 @@
    571  #include <stddef.h>         // For size_t
    572  #include <assert.h>
    573  #include <stdarg.h>
    574 +#ifndef WIN32
    575  #include <sys/time.h>
    576 +#endif
    577  #include <time.h>
    578  #include <ctype.h>	// For isdigit, isalpha.
    579  
    580 @@ -51,7 +53,11 @@ using std::tr1::unordered_set;
    581  #else
    582  
    583  #include <unordered_set>
    584 +#ifdef WIN32
    585 +using std::tr1::unordered_set;
    586 +#else
    587  using std::unordered_set;
    588 +#endif
    589  
    590  #endif
    591  
    592 diff --git a/util/valgrind.h b/util/valgrind.h
    593 index ca10b1a..d097b0c 100644
    594 --- a/util/valgrind.h
    595 +++ b/util/valgrind.h
    596 @@ -4064,6 +4064,7 @@ typedef
    597  #endif /* PLAT_ppc64_aix5 */
    598  
    599  
    600 +#ifndef WIN32
    601  /* ------------------------------------------------------------------ */
    602  /* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS.               */
    603  /*                                                                    */
    604 @@ -4170,7 +4171,7 @@ typedef
    605                                 VG_USERREQ__DISCARD_TRANSLATIONS,  \
    606                                 _qzz_addr, _qzz_len, 0, 0, 0);     \
    607     }
    608 -
    609 +#endif
    610  
    611  /* These requests are for getting Valgrind itself to print something.
    612     Possibly with a backtrace.  This is a really ugly hack.  The return value
    613