From c8de268e1b636ec9c53d6934d04e8164d0c596c1 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 21 Feb 2012 12:59:52 +0000 Subject: Camera tracing: search area was always centered to marker's position when tracking --- extern/libmv/libmv-capi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extern') diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp index 1835c53b53f..dbfdfdacafe 100644 --- a/extern/libmv/libmv-capi.cpp +++ b/extern/libmv/libmv-capi.cpp @@ -296,7 +296,7 @@ int libmv_regionTrackerTrack(libmv_RegionTracker *libmv_tracker, const float *im double sx2 = *x2, sy2 = *y2; int result = region_tracker->Track(old_patch, new_patch, x1, y1, x2, y2); - if (!result) { + if (!result { saveImage("old_patch", old_patch, x1, y1); saveImage("new_patch", new_patch, sx2, sy2); } -- cgit v1.2.3 From 6a5b34bdb55c430622ec88afc9bbd79ffe85d502 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 21 Feb 2012 13:00:58 +0000 Subject: Somehow typo was made just before commit in previous patch. --- extern/libmv/libmv-capi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extern') diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp index dbfdfdacafe..1835c53b53f 100644 --- a/extern/libmv/libmv-capi.cpp +++ b/extern/libmv/libmv-capi.cpp @@ -296,7 +296,7 @@ int libmv_regionTrackerTrack(libmv_RegionTracker *libmv_tracker, const float *im double sx2 = *x2, sy2 = *y2; int result = region_tracker->Track(old_patch, new_patch, x1, y1, x2, y2); - if (!result { + if (!result) { saveImage("old_patch", old_patch, x1, y1); saveImage("new_patch", new_patch, sx2, sy2); } -- cgit v1.2.3 From edb04d1461536f214f8afa46cce6b34cdc770afc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 24 Feb 2012 09:53:29 +0000 Subject: bmesh docs now written in sphinx doc generator. * http://www.blender.org/documentation/blender_python_api_2_62_0/bmesh.types.html * http://www.blender.org/documentation/blender_python_api_2_62_0/bmesh.utils.html --- extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp | 2 +- extern/recastnavigation/Recast/Source/RecastLayers.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'extern') diff --git a/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp b/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp index bf59cd89dda..8da8e2c1e1e 100644 --- a/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp +++ b/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp @@ -566,7 +566,7 @@ float dtStatNavMesh::findDistanceToWall(dtStatPolyRef centerRef, const float* ce hitPos[2] = vj[2] + (vi[2] - vj[2])*tseg; } - // Check to see if teh circle expands to one of the neighbours and expand. + // Check to see if the circle expands to one of the neighbours and expand. for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++) { // Skip solid edges. diff --git a/extern/recastnavigation/Recast/Source/RecastLayers.cpp b/extern/recastnavigation/Recast/Source/RecastLayers.cpp index 617cf45fe66..2d9658b2bed 100644 --- a/extern/recastnavigation/Recast/Source/RecastLayers.cpp +++ b/extern/recastnavigation/Recast/Source/RecastLayers.cpp @@ -368,7 +368,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, rcLayerRegion& rj = regs[j]; if (!rj.base) continue; - // Skip if teh regions are not close to each other. + // Skip if the regions are not close to each other. if (!overlapRange(ri.ymin,ri.ymax+mergeHeight, rj.ymin,rj.ymax+mergeHeight)) continue; // Skip if the height range would become too large. -- cgit v1.2.3 From 6ca7d8293228e821695a3149e8fb91b0d305daeb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 25 Feb 2012 16:04:03 +0000 Subject: code cleanup: white space, spelling & ';;' end of lines. --- extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'extern') diff --git a/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp b/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp index 126529e9779..3922c864eba 100644 --- a/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp +++ b/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp @@ -70,7 +70,7 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3, const float cp = vcross2(p1, p2, p3); if (fabsf(cp) > EPS) - { + { const float p1Sq = vdot2(p1,p1); const float p2Sq = vdot2(p2,p2); const float p3Sq = vdot2(p3,p3); @@ -78,7 +78,7 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3, c[2] = (p1Sq*(p3[0]-p2[0]) + p2Sq*(p1[0]-p3[0]) + p3Sq*(p2[0]-p1[0])) / (2*cp); r = vdist2(c, p1); return true; - } + } c[0] = p1[0]; c[2] = p1[2]; -- cgit v1.2.3 From dd40560230102fb5a6ba185b491e86c56d84bfae Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 Feb 2012 05:26:15 +0000 Subject: patch [#30331] Support clang-3.0 from Yasuhiro Fujii (y-fujii) added the diff to libmv/patches so it can be applied upstream. --- extern/libmv/patches/clang-3.diff | 49 +++++++++++++++++++++++++++ extern/libmv/patches/series | 1 + extern/libmv/third_party/glog/src/logging.cc | 17 ++++++---- extern/libmv/third_party/glog/src/utilities.h | 2 +- 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 extern/libmv/patches/clang-3.diff (limited to 'extern') diff --git a/extern/libmv/patches/clang-3.diff b/extern/libmv/patches/clang-3.diff new file mode 100644 index 00000000000..9e73490827d --- /dev/null +++ b/extern/libmv/patches/clang-3.diff @@ -0,0 +1,49 @@ +Index: third_party/glog/src/utilities.h +=================================================================== +--- third_party/glog/src/utilities.h (revision 44501) ++++ third_party/glog/src/utilities.h (working copy) +@@ -105,7 +105,7 @@ + # undef STACKTRACE_H + #elif defined(HAVE_LIB_UNWIND) + # define STACKTRACE_H "stacktrace_libunwind-inl.h" +-#elif !defined(NO_FRAME_POINTER) ++#elif !defined(NO_FRAME_POINTER) && !defined(__clang__) + # if defined(__i386__) && __GNUC__ >= 2 + # define STACKTRACE_H "stacktrace_x86-inl.h" + # elif defined(__x86_64__) && __GNUC__ >= 2 +Index: third_party/glog/src/logging.cc +=================================================================== +--- third_party/glog/src/logging.cc (revision 44501) ++++ third_party/glog/src/logging.cc (working copy) +@@ -1231,6 +1231,14 @@ + #endif + } + ++#if defined(HAVE___ATTRIBUTE__) ++typedef void (*fail_func_t)() __attribute__((noreturn)); ++static void logging_fail() __attribute__((noreturn)); ++#else ++typedef void (*fail_func_t)(); ++static void logging_fail(); ++#endif ++ + static void logging_fail() { + // #if defined(_DEBUG) && defined(_MSC_VER) + // doesn't work for my laptop (sergey) +@@ -1243,14 +1251,9 @@ + #endif + } + +-#ifdef HAVE___ATTRIBUTE__ +-GOOGLE_GLOG_DLL_DECL +-void (*g_logging_fail_func)() __attribute__((noreturn)) = &logging_fail; +-#else +-GOOGLE_GLOG_DLL_DECL void (*g_logging_fail_func)() = &logging_fail; +-#endif ++GOOGLE_GLOG_DLL_DECL fail_func_t g_logging_fail_func = &logging_fail; + +-void InstallFailureFunction(void (*fail_func)()) { ++void InstallFailureFunction(fail_func_t fail_func) { + g_logging_fail_func = fail_func; + } + diff --git a/extern/libmv/patches/series b/extern/libmv/patches/series index ca671122a61..2b2e69bd849 100644 --- a/extern/libmv/patches/series +++ b/extern/libmv/patches/series @@ -1,2 +1,3 @@ v3d_verbosity.patch bundle_tweaks.patch +clang-3.diff diff --git a/extern/libmv/third_party/glog/src/logging.cc b/extern/libmv/third_party/glog/src/logging.cc index 1bb3867aa10..f7488b3e04c 100644 --- a/extern/libmv/third_party/glog/src/logging.cc +++ b/extern/libmv/third_party/glog/src/logging.cc @@ -1231,6 +1231,14 @@ void LogMessage::RecordCrashReason( #endif } +#if defined(HAVE___ATTRIBUTE__) +typedef void (*fail_func_t)() __attribute__((noreturn)); +static void logging_fail() __attribute__((noreturn)); +#else +typedef void (*fail_func_t)(); +static void logging_fail(); +#endif + static void logging_fail() { // #if defined(_DEBUG) && defined(_MSC_VER) // doesn't work for my laptop (sergey) @@ -1243,14 +1251,9 @@ static void logging_fail() { #endif } -#ifdef HAVE___ATTRIBUTE__ -GOOGLE_GLOG_DLL_DECL -void (*g_logging_fail_func)() __attribute__((noreturn)) = &logging_fail; -#else -GOOGLE_GLOG_DLL_DECL void (*g_logging_fail_func)() = &logging_fail; -#endif +GOOGLE_GLOG_DLL_DECL fail_func_t g_logging_fail_func = &logging_fail; -void InstallFailureFunction(void (*fail_func)()) { +void InstallFailureFunction(fail_func_t fail_func) { g_logging_fail_func = fail_func; } diff --git a/extern/libmv/third_party/glog/src/utilities.h b/extern/libmv/third_party/glog/src/utilities.h index bbb0eb0746c..6d7262e84ae 100644 --- a/extern/libmv/third_party/glog/src/utilities.h +++ b/extern/libmv/third_party/glog/src/utilities.h @@ -105,7 +105,7 @@ # undef STACKTRACE_H #elif defined(HAVE_LIB_UNWIND) # define STACKTRACE_H "stacktrace_libunwind-inl.h" -#elif !defined(NO_FRAME_POINTER) +#elif !defined(NO_FRAME_POINTER) && !defined(__clang__) # if defined(__i386__) && __GNUC__ >= 2 # define STACKTRACE_H "stacktrace_x86-inl.h" # elif defined(__x86_64__) && __GNUC__ >= 2 -- cgit v1.2.3 From 729ddf51b7b8e5b8d5a91aa63940196dbfca9604 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 Feb 2012 05:50:02 +0000 Subject: revert r44503, (left patch file in for now), this gives an error with gcc: extern/libmv/third_party/glog/src/utilities.cc:318: error: undefined reference to 'google::InstallFailureFunction(void (*)())' --- extern/libmv/third_party/glog/src/logging.cc | 17 +++++++---------- extern/libmv/third_party/glog/src/utilities.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'extern') diff --git a/extern/libmv/third_party/glog/src/logging.cc b/extern/libmv/third_party/glog/src/logging.cc index f7488b3e04c..1bb3867aa10 100644 --- a/extern/libmv/third_party/glog/src/logging.cc +++ b/extern/libmv/third_party/glog/src/logging.cc @@ -1231,14 +1231,6 @@ void LogMessage::RecordCrashReason( #endif } -#if defined(HAVE___ATTRIBUTE__) -typedef void (*fail_func_t)() __attribute__((noreturn)); -static void logging_fail() __attribute__((noreturn)); -#else -typedef void (*fail_func_t)(); -static void logging_fail(); -#endif - static void logging_fail() { // #if defined(_DEBUG) && defined(_MSC_VER) // doesn't work for my laptop (sergey) @@ -1251,9 +1243,14 @@ static void logging_fail() { #endif } -GOOGLE_GLOG_DLL_DECL fail_func_t g_logging_fail_func = &logging_fail; +#ifdef HAVE___ATTRIBUTE__ +GOOGLE_GLOG_DLL_DECL +void (*g_logging_fail_func)() __attribute__((noreturn)) = &logging_fail; +#else +GOOGLE_GLOG_DLL_DECL void (*g_logging_fail_func)() = &logging_fail; +#endif -void InstallFailureFunction(fail_func_t fail_func) { +void InstallFailureFunction(void (*fail_func)()) { g_logging_fail_func = fail_func; } diff --git a/extern/libmv/third_party/glog/src/utilities.h b/extern/libmv/third_party/glog/src/utilities.h index 6d7262e84ae..bbb0eb0746c 100644 --- a/extern/libmv/third_party/glog/src/utilities.h +++ b/extern/libmv/third_party/glog/src/utilities.h @@ -105,7 +105,7 @@ # undef STACKTRACE_H #elif defined(HAVE_LIB_UNWIND) # define STACKTRACE_H "stacktrace_libunwind-inl.h" -#elif !defined(NO_FRAME_POINTER) && !defined(__clang__) +#elif !defined(NO_FRAME_POINTER) # if defined(__i386__) && __GNUC__ >= 2 # define STACKTRACE_H "stacktrace_x86-inl.h" # elif defined(__x86_64__) && __GNUC__ >= 2 -- cgit v1.2.3 From 7f34653f59ad3f7bed75eb9a36aa6ed928eef181 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 10 Mar 2012 22:00:55 +0000 Subject: style cleanup: + some warning fixes, also remove unused metaelem extern. --- extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'extern') diff --git a/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp b/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp index 8da8e2c1e1e..a02211816a2 100644 --- a/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp +++ b/extern/recastnavigation/Detour/Source/DetourStatNavMesh.cpp @@ -465,7 +465,7 @@ int dtStatNavMesh::raycast(dtStatPolyRef centerRef, const float* startPos, const if (!m_header) return 0; if (!centerRef) return 0; - dtStatPolyRef prevRef = centerRef; + /* dtStatPolyRef prevRef = centerRef; */ /* UNUSED */ dtStatPolyRef curRef = centerRef; t = 0; @@ -506,7 +506,7 @@ int dtStatNavMesh::raycast(dtStatPolyRef centerRef, const float* startPos, const } // No hit, advance to neighbour polygon. - prevRef = curRef; + /* prevRef = curRef; */ /* UNUSED */ curRef = nextRef; } -- cgit v1.2.3 From 2382afa968afa338bbbc3f2e615c847e5ddbc770 Mon Sep 17 00:00:00 2001 From: Jens Verwiebe Date: Sun, 11 Mar 2012 11:23:30 +0000 Subject: OSX/libmv: added a ahck to fix compiling with 10.6.sdk, unwind.h related --- extern/libmv/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 73c2baa0207..db788059800 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -37,6 +37,9 @@ set(INC set(INC_SYS ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} + if(APPLE) # this is a momentary hack to find unwind.h in 10.6.sdk + ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + endif() ) set(SRC -- cgit v1.2.3 From fa169fdcb69ef3310b747c9433eddbc4b0435a95 Mon Sep 17 00:00:00 2001 From: Jens Verwiebe Date: Sun, 11 Mar 2012 12:15:39 +0000 Subject: OSX/libmv: restrict the unwind.h workaround to 10.6.sdk only --- extern/libmv/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index db788059800..3bd021209df 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -37,7 +37,7 @@ set(INC set(INC_SYS ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} - if(APPLE) # this is a momentary hack to find unwind.h in 10.6.sdk + if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") # this is a momentary hack to find unwind.h in 10.6.sdk ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include endif() ) -- cgit v1.2.3 From 42b3463030b07ba3a87574c173e759e3bb15353b Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sun, 11 Mar 2012 19:52:25 +0000 Subject: Bundle new upstream version of libmv from own branch This version of libmv includes new gflags and glog libraries which makes it possible to compile libmv with clang compiler. Also remove code from CMakeLists which was disabling libmv if using clang. Tested on linux with gcc-4.6 and clang-3.0, windows cmake+msvc and scons+mingw. Could be some issues with other platforms/build system which shall be simple to resolve. --- extern/libmv/CMakeLists.txt | 6 +- extern/libmv/ChangeLog | 75 ++- extern/libmv/files.txt | 10 +- extern/libmv/libmv-capi.cpp | 1 + extern/libmv/libmv/logging/logging.h | 2 +- extern/libmv/libmv/simple_pipeline/pipeline.cc | 19 + extern/libmv/patches/bundle_tweaks.patch | 152 ------ extern/libmv/patches/clang-3.diff | 49 -- extern/libmv/patches/series | 2 - extern/libmv/third_party/gflags/AUTHORS | 2 + extern/libmv/third_party/gflags/COPYING | 28 + extern/libmv/third_party/gflags/ChangeLog | 195 +++++++ extern/libmv/third_party/gflags/NEWS | 158 ++++++ extern/libmv/third_party/gflags/README.libmv | 2 +- extern/libmv/third_party/gflags/config.h | 19 +- extern/libmv/third_party/gflags/gflags.cc | 285 +++++----- extern/libmv/third_party/gflags/gflags.h | 589 --------------------- extern/libmv/third_party/gflags/gflags/gflags.h | 568 ++++++++++++++++++++ .../third_party/gflags/gflags/gflags_completions.h | 130 +++++ .../third_party/gflags/gflags/gflags_declare.h | 112 ++++ .../libmv/third_party/gflags/gflags_completions.cc | 109 ++-- .../libmv/third_party/gflags/gflags_completions.h | 121 ----- .../libmv/third_party/gflags/gflags_reporting.cc | 81 +-- extern/libmv/third_party/gflags/mutex.h | 13 +- extern/libmv/third_party/gflags/util.h | 339 ++++++++++++ extern/libmv/third_party/glog/ChangeLog | 10 + extern/libmv/third_party/glog/README.libmv | 50 +- .../third_party/glog/src/base/commandlineflags.h | 4 +- .../libmv/third_party/glog/src/base/googleinit.h | 2 +- extern/libmv/third_party/glog/src/config_freebsd.h | 11 +- extern/libmv/third_party/glog/src/config_linux.h | 30 +- extern/libmv/third_party/glog/src/config_mac.h | 12 +- extern/libmv/third_party/glog/src/demangle.cc | 378 +++++++------ .../libmv/third_party/glog/src/glog/log_severity.h | 10 +- extern/libmv/third_party/glog/src/glog/logging.h | 96 ++-- .../libmv/third_party/glog/src/glog/raw_logging.h | 12 +- extern/libmv/third_party/glog/src/logging.cc | 83 ++- extern/libmv/third_party/glog/src/raw_logging.cc | 2 +- extern/libmv/third_party/glog/src/signalhandler.cc | 10 +- .../glog/src/stacktrace_libunwind-inl.h | 2 +- .../third_party/glog/src/stacktrace_x86_64-inl.h | 4 - extern/libmv/third_party/glog/src/symbolize.cc | 8 +- extern/libmv/third_party/glog/src/symbolize.h | 2 +- extern/libmv/third_party/glog/src/utilities.cc | 27 +- extern/libmv/third_party/glog/src/utilities.h | 4 + extern/libmv/third_party/glog/src/vlog_is_on.cc | 6 +- .../glog/src/windows/glog/log_severity.h | 10 +- .../third_party/glog/src/windows/glog/logging.h | 95 ++-- .../glog/src/windows/glog/raw_logging.h | 12 +- extern/libmv/third_party/glog/src/windows/port.h | 18 +- .../third_party/glog/src/windows/preprocess.sh | 0 51 files changed, 2415 insertions(+), 1550 deletions(-) delete mode 100644 extern/libmv/patches/bundle_tweaks.patch delete mode 100644 extern/libmv/patches/clang-3.diff create mode 100644 extern/libmv/third_party/gflags/AUTHORS create mode 100644 extern/libmv/third_party/gflags/COPYING create mode 100644 extern/libmv/third_party/gflags/ChangeLog create mode 100644 extern/libmv/third_party/gflags/NEWS delete mode 100644 extern/libmv/third_party/gflags/gflags.h create mode 100644 extern/libmv/third_party/gflags/gflags/gflags.h create mode 100644 extern/libmv/third_party/gflags/gflags/gflags_completions.h create mode 100644 extern/libmv/third_party/gflags/gflags/gflags_declare.h delete mode 100644 extern/libmv/third_party/gflags/gflags_completions.h create mode 100644 extern/libmv/third_party/gflags/util.h mode change 100755 => 100644 extern/libmv/third_party/glog/src/windows/preprocess.sh (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 3bd021209df..c16d842dd65 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -132,9 +132,11 @@ set(SRC third_party/fast/fast.h third_party/gflags/config.h - third_party/gflags/gflags_completions.h - third_party/gflags/gflags.h + third_party/gflags/gflags/gflags_completions.h + third_party/gflags/gflags/gflags_declare.h + third_party/gflags/gflags/gflags.h third_party/gflags/mutex.h + third_party/gflags/util.h third_party/ldl/Include/ldl.h third_party/msinttypes/inttypes.h third_party/msinttypes/stdint.h diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index f49a07de350..68c3431314a 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,3 +1,60 @@ +commit bf0c3423ba41b90638e89a56500aeaeb120fbaf1 +Author: Sergey I. Sharybin +Date: Sun Mar 11 20:34:15 2012 +0600 + + Replace "third_party/glog/src/glog/logging.h" with + + It was needed because of how build systems is setup in Blender but think + this will be helpful change for other applications too because it makes + it's easier to move libraries around and even use libraries installed + on the operation system. + +commit 3e2673282f313c5bd19720f26d769f5d240a0563 +Author: Sergey I. Sharybin +Date: Sun Mar 11 19:27:41 2012 +0600 + + Upgrade gflags and glog libraries - stage 2 (final) + + Changes to upstream code which are needed to make libmv compile smooth on all platforms + + * Replace with "third_party/gflags/gflags/gflags.h" which is easier + to setup things in libmv and also helps with setting up building libmv into + external applications. + * Replace "glog/logging.h" and "glog/logging.h" with and + which is needed on Windows platform because otherwise files like logging.cc will be using + relative path which points to headers used by linux instead of headers need to be used + on Windows. + * Replace _asm int 3 with __debugbreak(). Such assembler code is obsolete and doesn't work + with 64bit versions of MSVC compilers. + * Do not use stacktrace for MinGW and FreeBSD because it leads into issues accessing + some specific data on this platforms. + * Define HAVE_LIB_GFLAGS for Windows builds. + * Do not define __declspec(dllimport) for MinGW platforms. + * Setup proper includes and datatypes for int32, uint32, int64 and uint64 for MinGW + * Do not define va_copy for MinGW platforms (it's already defined there). + * Patch localtime_r to be working fine with MinGW, disable strerror_r for MinGW because + of lack of needed functions. + +commit 8ed07abfa49d1e0511752021c972e0715e5a1383 +Author: Sergey I. Sharybin +Date: Sun Mar 11 19:06:33 2012 +0600 + + Upgrade gflags and glog libraries - stage 1 + + This commit copies sources from latest original release of gflags and glog + over currently bundled versions of this libraries without any modifications. + + This revision can't b compiled, all needed changes to make new libraries working + fine will be done with next commit to make it clear which changes were necessary + for easier bundling further newer version and extract patches and put them to + gflags/glog upstream repo. + + Such upgrade of libraries is needed to make it able to compile libmv + with clang compilers. Currently used versions: + + - gflags is version 2.0 + - glog is version 0.3.2 + commit 75b9af405964ff2c7d3f0a44500e27e63b37c91b Author: Sergey Sharybin Date: Fri Feb 17 23:29:11 2012 +0600 @@ -429,21 +486,3 @@ Author: Matthias Fauconneau Date: Thu Aug 18 23:14:17 2011 +0200 Fix affine iteration. - -commit 4e8e0aa6018e3eb2fbebdad7f1cbd6c909d26e79 -Author: Matthias Fauconneau -Date: Thu Aug 18 23:03:26 2011 +0200 - - Handle rotations. - -commit 3ce41cf3c1b5c136a61d8f4c63ccae3cafbdb8da -Author: Matthias Fauconneau -Date: Thu Aug 18 22:24:47 2011 +0200 - - Slow brute-force affine diamond search implementation. - -commit 1c4acd03e030c1c50dc6fc36c419c72ea69a0713 -Author: Matthias Fauconneau -Date: Thu Aug 18 20:51:43 2011 +0200 - - Fix detect.cc. diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt index 96dfd89828e..028af579d11 100644 --- a/extern/libmv/files.txt +++ b/extern/libmv/files.txt @@ -78,14 +78,20 @@ third_party/fast/LICENSE third_party/fast/nonmax.c third_party/fast/README third_party/fast/README.libmv +third_party/gflags/AUTHORS +third_party/gflags/ChangeLog third_party/gflags/config.h +third_party/gflags/COPYING third_party/gflags/gflags.cc third_party/gflags/gflags_completions.cc -third_party/gflags/gflags_completions.h -third_party/gflags/gflags.h +third_party/gflags/gflags/gflags_completions.h +third_party/gflags/gflags/gflags_declare.h +third_party/gflags/gflags/gflags.h third_party/gflags/gflags_reporting.cc third_party/gflags/mutex.h +third_party/gflags/NEWS third_party/gflags/README.libmv +third_party/gflags/util.h third_party/glog/AUTHORS third_party/glog/ChangeLog third_party/glog/COPYING diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp index 1835c53b53f..465bf519dbd 100644 --- a/extern/libmv/libmv-capi.cpp +++ b/extern/libmv/libmv-capi.cpp @@ -30,6 +30,7 @@ #include "libmv-capi.h" +#include "third_party/gflags/gflags/gflags.h" #include "glog/logging.h" #include "libmv/logging/logging.h" diff --git a/extern/libmv/libmv/logging/logging.h b/extern/libmv/libmv/logging/logging.h index af86c4baa42..776d9d52f7a 100644 --- a/extern/libmv/libmv/logging/logging.h +++ b/extern/libmv/libmv/logging/logging.h @@ -21,7 +21,7 @@ #ifndef LIBMV_LOGGING_LOGGING_H #define LIBMV_LOGGING_LOGGING_H -#include "glog/logging.h" +#include #define LG LOG(INFO) #define V0 LOG(INFO) diff --git a/extern/libmv/libmv/simple_pipeline/pipeline.cc b/extern/libmv/libmv/simple_pipeline/pipeline.cc index 2e4e5a6491d..2459d059114 100644 --- a/extern/libmv/libmv/simple_pipeline/pipeline.cc +++ b/extern/libmv/libmv/simple_pipeline/pipeline.cc @@ -280,6 +280,25 @@ double InternalReprojectionError(const Tracks &image_tracks, double ex = reprojected_marker.x - markers[i].x; double ey = reprojected_marker.y - markers[i].y; + const int N = 100; + char line[N]; + snprintf(line, N, + "image %-3d track %-3d " + "x %7.1f y %7.1f " + "rx %7.1f ry %7.1f " + "ex %7.1f ey %7.1f" + " e %7.1f", + markers[i].image, + markers[i].track, + markers[i].x, + markers[i].y, + reprojected_marker.x, + reprojected_marker.y, + ex, + ey, + sqrt(ex*ex + ey*ey)); + LG << line; + total_error += sqrt(ex*ex + ey*ey); } LG << "Skipped " << num_skipped << " markers."; diff --git a/extern/libmv/patches/bundle_tweaks.patch b/extern/libmv/patches/bundle_tweaks.patch deleted file mode 100644 index aebc257f7f9..00000000000 --- a/extern/libmv/patches/bundle_tweaks.patch +++ /dev/null @@ -1,152 +0,0 @@ -diff --git a/src/libmv/logging/logging.h b/src/libmv/logging/logging.h -index 067da52..af86c4b 100644 ---- a/src/libmv/logging/logging.h -+++ b/src/libmv/logging/logging.h -@@ -21,7 +21,7 @@ - #ifndef LIBMV_LOGGING_LOGGING_H - #define LIBMV_LOGGING_LOGGING_H - --#include "third_party/glog/src/glog/logging.h" -+#include "glog/logging.h" - - #define LG LOG(INFO) - #define V0 LOG(INFO) -diff --git a/src/libmv/simple_pipeline/pipeline.cc b/src/libmv/simple_pipeline/pipeline.cc -index 2459d05..2e4e5a6 100644 ---- a/src/libmv/simple_pipeline/pipeline.cc -+++ b/src/libmv/simple_pipeline/pipeline.cc -@@ -280,25 +280,6 @@ double InternalReprojectionError(const Tracks &image_tracks, - double ex = reprojected_marker.x - markers[i].x; - double ey = reprojected_marker.y - markers[i].y; - -- const int N = 100; -- char line[N]; -- snprintf(line, N, -- "image %-3d track %-3d " -- "x %7.1f y %7.1f " -- "rx %7.1f ry %7.1f " -- "ex %7.1f ey %7.1f" -- " e %7.1f", -- markers[i].image, -- markers[i].track, -- markers[i].x, -- markers[i].y, -- reprojected_marker.x, -- reprojected_marker.y, -- ex, -- ey, -- sqrt(ex*ex + ey*ey)); -- LG << line; -- - total_error += sqrt(ex*ex + ey*ey); - } - LG << "Skipped " << num_skipped << " markers."; -diff --git a/src/third_party/glog/src/glog/logging.h b/src/third_party/glog/src/glog/logging.h -index 57615ef..a58d478 100644 ---- a/src/third_party/glog/src/glog/logging.h -+++ b/src/third_party/glog/src/glog/logging.h -@@ -33,6 +33,7 @@ - // Pretty much everybody needs to #include this file so that they can - // log various happenings. - // -+ - #ifndef _LOGGING_H_ - #define _LOGGING_H_ - -diff --git a/src/third_party/glog/src/logging.cc b/src/third_party/glog/src/logging.cc -index 868898f..1bb3867 100644 ---- a/src/third_party/glog/src/logging.cc -+++ b/src/third_party/glog/src/logging.cc -@@ -58,8 +58,8 @@ - #include // for errno - #include - #include "base/commandlineflags.h" // to get the program name --#include "glog/logging.h" --#include "glog/raw_logging.h" -+#include -+#include - #include "base/googleinit.h" - - #ifdef HAVE_STACKTRACE -@@ -1232,7 +1232,9 @@ void LogMessage::RecordCrashReason( - } - - static void logging_fail() { --#if defined(_DEBUG) && defined(_MSC_VER) -+// #if defined(_DEBUG) && defined(_MSC_VER) -+// doesn't work for my laptop (sergey) -+#if 0 - // When debugging on windows, avoid the obnoxious dialog and make - // it possible to continue past a LOG(FATAL) in the debugger - _asm int 3 -diff --git a/src/third_party/glog/src/raw_logging.cc b/src/third_party/glog/src/raw_logging.cc -index 50c6a71..b179a1e 100644 ---- a/src/third_party/glog/src/raw_logging.cc -+++ b/src/third_party/glog/src/raw_logging.cc -@@ -42,8 +42,8 @@ - #include // for open() - #include - #include "config.h" --#include "glog/logging.h" // To pick up flag settings etc. --#include "glog/raw_logging.h" -+#include // To pick up flag settings etc. -+#include - #include "base/commandlineflags.h" - - #ifdef HAVE_STACKTRACE -diff --git a/src/third_party/glog/src/utilities.h b/src/third_party/glog/src/utilities.h -index c4ae256..5c841a0 100644 ---- a/src/third_party/glog/src/utilities.h -+++ b/src/third_party/glog/src/utilities.h -@@ -79,7 +79,7 @@ - #endif - - #include "config.h" --#include "glog/logging.h" -+#include - - // There are three different ways we can try to get the stack trace: - // -diff --git a/src/third_party/glog/src/vlog_is_on.cc b/src/third_party/glog/src/vlog_is_on.cc -index ee0e412..ed88514 100644 ---- a/src/third_party/glog/src/vlog_is_on.cc -+++ b/src/third_party/glog/src/vlog_is_on.cc -@@ -40,8 +40,8 @@ - #include - #include - #include "base/commandlineflags.h" --#include "glog/logging.h" --#include "glog/raw_logging.h" -+#include -+#include - #include "base/googleinit.h" - - // glog doesn't have annotation -diff --git a/src/third_party/glog/src/windows/config.h b/src/third_party/glog/src/windows/config.h -index 114762e..682a1b9 100755 ---- a/src/third_party/glog/src/windows/config.h -+++ b/src/third_party/glog/src/windows/config.h -@@ -19,7 +19,7 @@ - #undef HAVE_LIBUNWIND_H - - /* define if you have google gflags library */ --#undef HAVE_LIB_GFLAGS -+#define HAVE_LIB_GFLAGS 1 - - /* define if you have libunwind */ - #undef HAVE_LIB_UNWIND -diff --git a/src/third_party/glog/src/windows/glog/logging.h b/src/third_party/glog/src/windows/glog/logging.h -index 4257375..2f41681 100755 ---- a/src/third_party/glog/src/windows/glog/logging.h -+++ b/src/third_party/glog/src/windows/glog/logging.h -@@ -82,8 +82,8 @@ - #include // a third place for uint16_t or u_int16_t - #endif - --#if 0 --#include -+#if 1 -+#include "third_party/gflags/gflags.h" - #endif - - #ifdef __MINGW32__ diff --git a/extern/libmv/patches/clang-3.diff b/extern/libmv/patches/clang-3.diff deleted file mode 100644 index 9e73490827d..00000000000 --- a/extern/libmv/patches/clang-3.diff +++ /dev/null @@ -1,49 +0,0 @@ -Index: third_party/glog/src/utilities.h -=================================================================== ---- third_party/glog/src/utilities.h (revision 44501) -+++ third_party/glog/src/utilities.h (working copy) -@@ -105,7 +105,7 @@ - # undef STACKTRACE_H - #elif defined(HAVE_LIB_UNWIND) - # define STACKTRACE_H "stacktrace_libunwind-inl.h" --#elif !defined(NO_FRAME_POINTER) -+#elif !defined(NO_FRAME_POINTER) && !defined(__clang__) - # if defined(__i386__) && __GNUC__ >= 2 - # define STACKTRACE_H "stacktrace_x86-inl.h" - # elif defined(__x86_64__) && __GNUC__ >= 2 -Index: third_party/glog/src/logging.cc -=================================================================== ---- third_party/glog/src/logging.cc (revision 44501) -+++ third_party/glog/src/logging.cc (working copy) -@@ -1231,6 +1231,14 @@ - #endif - } - -+#if defined(HAVE___ATTRIBUTE__) -+typedef void (*fail_func_t)() __attribute__((noreturn)); -+static void logging_fail() __attribute__((noreturn)); -+#else -+typedef void (*fail_func_t)(); -+static void logging_fail(); -+#endif -+ - static void logging_fail() { - // #if defined(_DEBUG) && defined(_MSC_VER) - // doesn't work for my laptop (sergey) -@@ -1243,14 +1251,9 @@ - #endif - } - --#ifdef HAVE___ATTRIBUTE__ --GOOGLE_GLOG_DLL_DECL --void (*g_logging_fail_func)() __attribute__((noreturn)) = &logging_fail; --#else --GOOGLE_GLOG_DLL_DECL void (*g_logging_fail_func)() = &logging_fail; --#endif -+GOOGLE_GLOG_DLL_DECL fail_func_t g_logging_fail_func = &logging_fail; - --void InstallFailureFunction(void (*fail_func)()) { -+void InstallFailureFunction(fail_func_t fail_func) { - g_logging_fail_func = fail_func; - } - diff --git a/extern/libmv/patches/series b/extern/libmv/patches/series index 2b2e69bd849..1db7983fdd0 100644 --- a/extern/libmv/patches/series +++ b/extern/libmv/patches/series @@ -1,3 +1 @@ v3d_verbosity.patch -bundle_tweaks.patch -clang-3.diff diff --git a/extern/libmv/third_party/gflags/AUTHORS b/extern/libmv/third_party/gflags/AUTHORS new file mode 100644 index 00000000000..887918bd00e --- /dev/null +++ b/extern/libmv/third_party/gflags/AUTHORS @@ -0,0 +1,2 @@ +google-gflags@googlegroups.com + diff --git a/extern/libmv/third_party/gflags/COPYING b/extern/libmv/third_party/gflags/COPYING new file mode 100644 index 00000000000..d15b0c24134 --- /dev/null +++ b/extern/libmv/third_party/gflags/COPYING @@ -0,0 +1,28 @@ +Copyright (c) 2006, Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/extern/libmv/third_party/gflags/ChangeLog b/extern/libmv/third_party/gflags/ChangeLog new file mode 100644 index 00000000000..f9ef9350984 --- /dev/null +++ b/extern/libmv/third_party/gflags/ChangeLog @@ -0,0 +1,195 @@ +Wed Jan 25 15:09:14 2012 Google Inc. + + * gflags: version 2.0 + * Changed the 'official' gflags email in setup.py/etc + * Renamed google-gflags.sln to gflags.sln + * Changed copyright text to reflect Google's relinquished ownership + +Tue Dec 20 19:48:57 2011 Google Inc. + + * google-gflags: version 1.7 + * Add CommandLineFlagInfo::flag_ptr pointing to current storage (musji) + * PORTING: flush after writing to stderr, needed on cygwin + * PORTING: Clean up the GFLAGS_DLL_DECL stuff better + * Fix a bug in StringPrintf() that affected large strings (csilvers) + * Die at configure-time when g++ isn't installed + +Fri Jul 29 19:05:21 2011 Google Inc. + + * google-gflags: version 1.6 + * BUGFIX: Fix a bug where we were leaving out a required $(top_srcdir) + * Fix definition of clstring (jyrki) + * Split up flag declares into its own file (jyrki) + * Add --version support (csilvers) + * Update the README for gflags with static libs + * Update acx_pthread.m4 for nostdlib + * Change ReparseCommandLineFlags to return void (csilvers) + * Some doc typofixes and example augmentation (various) + +Mon Jan 24 16:11:35 2011 Google Inc. + + * google-gflags: version 1.5 + * Better reporting of current vs default value (handler) + * Add API for cleaning up of memory at program-exit (jmarantz) + * Fix macros to work inside namespaces (csilvers) + * Use our own string typedef in case string is redefined (csilvers) + * Updated to autoconf 2.65 + +Wed Oct 13 17:40:12 2010 Google Inc. + + * google-gflags: version 1.4 + * Add a check to prevent passing 0 to DEFINE_string (jorg) + * Reduce compile (.o) size (jyrki) + * Some small changes to quiet debug compiles (alexk) + * PORTING: better support static linking on windows (csilvers) + * DOCUMENTATION: change default values, use validators, etc. + * Update the NEWS file to be non-empty + * Add pkg-config (.pc) files for libgflags and libgflags_nothreads + +Mon Jan 4 18:09:30 2010 Google Inc. + + * google-gflags: version 1.3 + * PORTABILITY: can now build and run tests under MSVC (csilvers) + * Remove the python gflags code, which is now its own package (tansell) + * Clarify that "last flag wins" in the docs (csilvers) + * Comment danger of using GetAllFlags in validators (wojtekm) + * PORTABILITY: Some fixes necessary for c++0x (mboerger) + * Makefile fix: $(srcdir) -> $(top_srcdir) in one place (csilvres) + * INSTALL: autotools to autoconf v2.64 + automake v1.11 (csilvers) + +Thu Sep 10 12:53:04 2009 Google Inc. + + * google-gflags: version 1.2 + * PORTABILITY: can now build and run tests under mingw (csilvers) + * Using a string arg for a bool flag is a compile-time error (rbayardo) + * Add --helpxml to gflags.py (salcianu) + * Protect against a hypothetical global d'tor mutex problem (csilvers) + * BUGFIX: can now define a flag after 'using namespace google' (hamaji) + +Tue Apr 14 12:35:25 2009 Google Inc. + + * google-gflags: version 1.1 + * Add both foo and nofoo for boolean flags, with --undefok (andychu) + * Better document how validators work (wojtekm) + * Improve binary-detection for bash-completion (mtamsky) + * Python: Add a concept of "key flags", used with --help (salcianu) + * Python: Robustify flag_values (salcianu) + * Python: Add a new DEFINE_bool alias (keir, andrewliu) + * Python: Do module introspection based on module name (dsturtevant) + * Fix autoconf a bit better, especially on windows and solaris (ajenjo) + * BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo) + * BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo) + * PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers) + * PORTABILITY: Update deb.sh for more recenty debuilds (csilvers) + * PORTABILITY: #include more headers to satify new gcc's (csilvers) + * INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers) + +Fri Oct 3 15:16:46 2008 Google Inc. + + * google-gflags: version 1.0 + * Add a missing newline to an error string (bcmills) + * (otherwise exactly the same as gflags 1.0rc2) + +Thu Sep 18 12:58:05 2008 Google Inc. + + * google-gflags: version 1.0rc2 + * Report current flag values in --helpxml (hdn) + * Fix compilation troubles with gcc 4.3.3 (simonb) + * BUG FIX: I was missing a std:: in DECLARE_string (csilvers) + * BUG FIX: Clarify in docs how to specify --bool flags (csilvers) + * BUG FIX: Fix --helpshort for source files not in a subdir (csilvers) + * BUG FIX: Fix python unittest for 64-bit builds (bcmills) + +Tue Aug 19 16:15:48 2008 + + * google-gflags: version 1.0rc1 + * Move #include files from google/ to gflags/ (csilvers) + * Small optimizations to reduce binary (library) size (jyrki) + * BUGFIX: forgot a std:: in one of the .h files (csilvers) + * Speed up locking by making sure calls are inlined (ajenjo) + * 64-BIT COMPATIBILITY: Use %PRId64 instead of %lld (csilvers) + * PORTABILITY: fix Makefile to work with Cygwin (ajenjo) + * PORTABILITY: fix code to compile under Visual Studio (ajenjo) + * PORTABILITY: fix code to compile under Solaris 10 with CC (csilvers) + +Mon Jul 21 23:01:38 2008 Google Inc. + + * google-gflags: version 0.9 + * Add the ability to validate a command-line flag (csilvers) + * Add completion support for commandline flags in bash (daven) + * Add -W compile flags to Makefile, when using gcc (csilvers) + * Allow helpstring to be NULL (cristianoc) + * Improved documentation of classes in the .cc file (csilvers) + * Fix python bug with AppendFlagValues + shortnames (jjtswan) + * Use bool instead of int for boolean flags in gflags.py (bcmills) + * Simplify the way we declare flags, now more foolproof (csilvers) + * Better error messages when bool flags collide (colohan) + * Only evaluate DEFINE_foo macro args once (csilvers) + +Wed Mar 26 15:20:18 2008 Google Inc. + + * google-gflags: version 0.8 + * Export DescribeOneFlag() in the API + * Add support for automatic line wrapping at 80 cols for gflags.py + * Bugfix: do not treat an isolated "-" the same as an isolated "--" + * Update rpm spec to point to Google Code rather than sourceforge (!) + * Improve documentation (including documenting thread-safety) + * Improve #include hygiene + * Improve testing + +Thu Oct 18 11:33:20 2007 Google Inc. + + * google-gflags: version 0.7 + * Deal even more correctly with libpthread not linked in (csilvers) + * Add STRIP_LOG, an improved DO_NOT_SHOW_COMMANDLINE_HELP (sioffe) + * Be more accurate printing default flag values in --help (dsturtevant) + * Reduce .o file size a bit by using shorter namespace names (jeff) + * Use relative install path, so 'setup.py --home' works (csilvers) + * Notice when a boolean flag has a non-boolean default (bnmouli) + * Broaden --helpshort to match foo-main.cc and foo_main.cc (hendrie) + * Fix "no modules match" message for --helpshort, etc (hendrie) + +Wed Aug 15 07:35:51 2007 Google Inc. + + * google-gflags: version 0.6 + * Deal correctly with case that libpthread is not linked in (csilvers) + * Update Makefile/tests so we pass "make distcheck" (csilvers) + * Document and test that last assignment to a flag wins (wan) + +Tue Jun 12 15:23:42 2007 Google Inc. + + * google-gflags: version 0.5 + * Include all m4 macros in the distribution (csilvers) + * Python: Fix broken data_files field in setup.py (sidlon) + * Python: better string serliaizing and unparsing (abo, csimmons) + * Fix checks for NaN and inf to work with Mac OS X (csilvers) + +Thu Apr 19 15:15:07 2007 Google Inc. + + * google-gflags: version 0.4 + * Remove is_default from GetCommandLineFlagInfo (csilvers) + * Portability fixes: includes, strtoll, gcc4.3 errors (csilvers) + * A few doc typo cleanups (csilvers) + +Wed Mar 28 12:15:56 2007 Google Inc. + + * google-gflags: version 0.3 + * python portability fix: use popen instead of subprocess (csilvers) + * Add is_default to CommandLineFlagInfo (pchien) + * Make docs a bit prettier (csilvers) + * Actually include the python files in the distribution! :-/ (csilvers) + +Mon Jan 22 15:33:06 2007 Google Inc. + + * google-gflags: version 0.2 + * added support for python commandlineflags, as well as c++ + * gflags2man, a script to turn flags into a man page (dchristian) + +Wed Dec 13 12:37:19 2006 Google Inc. + + * google-gflags: initial release: + The gflags package contains a library that implements commandline + flags processing. As such it's a replacement for getopt(). It + has increased flexibility, including built-in support for C++ + types like string, and the ability to define flags in the source + file in which they're used. diff --git a/extern/libmv/third_party/gflags/NEWS b/extern/libmv/third_party/gflags/NEWS new file mode 100644 index 00000000000..ffc0127d91e --- /dev/null +++ b/extern/libmv/third_party/gflags/NEWS @@ -0,0 +1,158 @@ +== 25 January 2012 == + +I've just released gflags 2.0. + +The `google-gflags` project has been renamed to `gflags`. I +(csilvers) am stepping down as maintainer, to be replaced by Andreas +Schuh. Welcome to the team, Andreas! I've seen the energy you have +around gflags and the ideas you have for the project going forward, +and look forward to having you on the team. + +I bumped the major version number up to 2 to reflect the new community +ownership of the project. All the +[http://gflags.googlecode.com/svn/tags/gflags-2.0/ChangeLog changes] +are related to the renaming. There are no functional changes from +gflags 1.7. In particular, I've kept the code in the namespace +`google`, though in a future version it should be renamed to `gflags`. +I've also kept the `/usr/local/include/google/` subdirectory as +synonym of `/usr/local/include/gflags/`, though the former name has +been obsolete for some time now. + + +=== 18 January 2011 === + +The `google-gflags` Google Code page has been renamed to +`gflags`, in preparation for the project being renamed to +`gflags`. In the coming weeks, I'll be stepping down as +maintainer for the gflags project, and as part of that Google is +relinquishing ownership of the project; it will now be entirely +community run. The name change reflects that shift. + + +=== 20 December 2011 === + +I've just released gflags 1.7. This is a minor release; the major +change is that `CommandLineFlagInfo` now exports the address in memory +where the flag is located. There has also been a bugfix involving +very long --help strings, and some other minor +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.7/ChangeLog changes]. + +=== 29 July 2011 === + +I've just released gflags 1.6. The major new feature in this release +is support for setting version info, so that --version does something +useful. + +One minor change has required bumping the library number: +`ReparseCommandlineFlags` now returns `void` instead of `int` (the int +return value was always meaningless). Though I doubt anyone ever used +this (meaningless) return value, technically it's a change to the ABI +that requires a version bump. A bit sad. + +There's also a procedural change with this release: I've changed the +internal tools used to integrate Google-supplied patches for gflags +into the opensource release. These new tools should result in more +frequent updates with better change descriptions. They will also +result in future `ChangeLog` entries being much more verbose (for better +or for worse). + +See the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.6/ChangeLog ChangeLog] +for a full list of changes for this release. + +=== 24 January 2011 === + +I've just released gflags 1.5. This release has only minor changes +from 1.4, including some slightly better reporting in --help, and +an new memory-cleanup function that can help when running gflags-using +libraries under valgrind. The major change is to fix up the macros +(`DEFINE_bool` and the like) to work more reliably inside namespaces. + +If you have not had a problem with these macros, and don't need any of +the other changes described, there is no need to upgrade. See the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.5/ChangeLog ChangeLog] +for a full list of changes for this release. + +=== 11 October 2010 === + +I've just released gflags 1.4. This release has only minor changes +from 1.3, including some documentation tweaks and some work to make +the library smaller. If 1.3 is working well for you, there's no +particular reason to upgrade. + +=== 4 January 2010 === + +I've just released gflags 1.3. gflags now compiles under MSVC, and +all tests pass. I *really* never thought non-unix-y Windows folks +would want gflags, but at least some of them do. + +The major news, though, is that I've separated out the python package +into its own library, [http://code.google.com/p/python-gflags python-gflags]. +If you're interested in the Python version of gflags, that's the place to +get it now. + +=== 10 September 2009 == + +I've just released gflags 1.2. The major change from gflags 1.1 is it +now compiles under MinGW (as well as cygwin), and all tests pass. I +never thought Windows folks would want unix-style command-line flags, +since they're so different from the Windows style, but I guess I was +wrong! + +The other changes are minor, such as support for --htmlxml in the +python version of gflags. + +=== 15 April 2009 === + +I've just released gflags 1.1. It has only minor changes fdrom gflags +1.0 (see the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.1/ChangeLog ChangeLog] +for details). The major change is that I moved to a new +system for creating .deb and .rpm files. This allows me to create +x86_64 deb and rpm files. + +In the process of moving to this new system, I noticed an +inconsistency: the tar.gz and .rpm files created libraries named +libgflags.so, but the deb file created libgoogle-gflags.so. I have +fixed the deb file to create libraries like the others. I'm no expert +in debian packaging, but I believe this has caused the package name to +change as well. Please let me know (at +[mailto:google-gflags@googlegroups.com +google-gflags@googlegroups.com]) if this causes problems for you -- +especially if you know of a fix! I would be happy to change the deb +packages to add symlinks from the old library name to the new +(libgoogle-gflags.so -> libgflags.so), but that is beyond my knowledge +of how to make .debs. + +If you've tried to install a .rpm or .deb and it doesn't work for you, +let me know. I'm excited to finally have 64-bit package files, but +there may still be some wrinkles in the new system to iron out. + +===1 October 2008=== + +gflags 1.0rc2 was out for a few weeks without any issues, so gflags +1.0 is now released. This is much like gflags 0.9. The major change +is that the .h files have been moved from `/usr/include/google` to +`/usr/include/gflags`. While I have backwards-compatibility +forwarding headeds in place, please rewrite existing code to say +{{{ + #include +}}} +instead of +{{{ + #include +}}} + +I've kept the default namespace to google. You can still change with +with the appropriate flag to the configure script (`./configure +--help` to see the flags). If you have feedback as to whether the +default namespace should change to gflags, which would be a +non-backwards-compatible change, send mail to +`google-gflags@googlegroups.com`! + +Version 1.0 also has some neat new features, like support for bash +commandline-completion of help flags. See the +[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.0rc2/ChangeLog +ChangeLog] for more details. + +If I don't hear any bad news for a few weeks, I'll release 1.0-final. diff --git a/extern/libmv/third_party/gflags/README.libmv b/extern/libmv/third_party/gflags/README.libmv index f2bdef6563e..673099ce618 100644 --- a/extern/libmv/third_party/gflags/README.libmv +++ b/extern/libmv/third_party/gflags/README.libmv @@ -1,7 +1,7 @@ Project: Google Flags URL: http://code.google.com/p/google-gflags/ License: New BSD -Upstream version: 1.5 +Upstream version: 2.0 Local modifications: - Flattened the tree and only included files needed for libmv. This involved diff --git a/extern/libmv/third_party/gflags/config.h b/extern/libmv/third_party/gflags/config.h index ca2c1276c44..03ed03ca99b 100644 --- a/extern/libmv/third_party/gflags/config.h +++ b/extern/libmv/third_party/gflags/config.h @@ -15,7 +15,7 @@ #define HAVE_DLFCN_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_FNMATCH_H +/* #ubdef HAVE_FNMATCH_H 1 */ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 @@ -29,12 +29,6 @@ /* Define if you have POSIX threads libraries and header files. */ #define HAVE_PTHREAD 1 -/* Define to 1 if you have the `putenv' function. */ -#define HAVE_PUTENV 1 - -/* Define to 1 if you have the `setenv' function. */ -#define HAVE_SETENV 1 - /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 @@ -73,22 +67,19 @@ #define PACKAGE "gflags" /* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "opensource@google.com" +#define PACKAGE_BUGREPORT "google-gflags@googlegroups.com" /* Define to the full name of this package. */ #define PACKAGE_NAME "gflags" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "gflags 1.5" +#define PACKAGE_STRING "gflags 2.0" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "gflags" -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.5" +#define PACKAGE_VERSION "2.0" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -101,7 +92,7 @@ #define STL_NAMESPACE std /* Version number of package */ -#define VERSION "1.5" +#define VERSION "2.0" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } diff --git a/extern/libmv/third_party/gflags/gflags.cc b/extern/libmv/third_party/gflags/gflags.cc index 34fe95dac59..4ba2b6f393c 100644 --- a/extern/libmv/third_party/gflags/gflags.cc +++ b/extern/libmv/third_party/gflags/gflags.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006, Google Inc. +// Copyright (c) 1999, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -28,7 +28,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // --- -// Author: Ray Sidney // Revamped and reorganized by Craig Silverstein // // This file contains the implementation of all our command line flags @@ -88,76 +87,35 @@ // other hand, hooks into CommandLineFlagParser. Other API functions // are, similarly, mostly hooks into the functionality described above. -#include "config.h" // This comes first to ensure we define __STDC_FORMAT_MACROS in time. -#ifdef HAVE_INTTYPES_H -#ifndef __STDC_FORMAT_MACROS +#include "config.h" +#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS) # define __STDC_FORMAT_MACROS 1 // gcc requires this to get PRId64, etc. #endif -#include -#endif // HAVE_INTTYPES_H -#include // for snprintf + +#include "gflags/gflags.h" +#include #include #include -#include +#ifdef HAVE_FNMATCH_H +# include +#endif #include // For va_list and related operations +#include #include -#include -#ifdef HAVE_FNMATCH_H -#include -#endif // HAVE_FNMATCH_H -#include + +#include #include -#include +#include #include // for pair<> -#include -#include "gflags.h" +#include #include "mutex.h" +#include "util.h" #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' #endif -// Work properly if either strtoll or strtoq is on this system -#ifdef HAVE_STRTOLL -# define strtoint64 strtoll -# define strtouint64 strtoull -#elif HAVE_STRTOQ -# define strtoint64 strtoq -# define strtouint64 strtouq -#else -// Neither strtoll nor strtoq are defined. I hope strtol works! -# define strtoint64 strtol -# define strtouint64 strtoul -#endif - -// If we have inttypes.h, it will have defined PRId32/etc for us. If -// not, take our best guess. -#ifndef PRId32 -# define PRId32 "d" -#endif -#ifndef PRId64 -# define PRId64 "lld" -#endif -#ifndef PRIu64 -# define PRIu64 "llu" -#endif - -// Windows is missing random bits like strcasecmp, strtoll, strtoull, and -// snprintf in the usual locations. Put them somewhere sensible. -// -// TODO(keir): Get the upstream Windows port and use that instead. -#ifdef _MSC_VER -# define snprintf _snprintf -# undef strtoint64 -# define strtoint64 _strtoi64 -# undef strtouint64 -# define strtouint64 _strtoui64 -# define strcasecmp _stricmp -#endif - -typedef signed char int8; -typedef unsigned char uint8; // Special flags, type 1: the 'recursive' flags. They set another flag's val. DEFINE_string(flagfile, "", @@ -183,20 +141,21 @@ using std::sort; using std::string; using std::vector; +// This is used by the unittest to test error-exit code +void GFLAGS_DLL_DECL (*gflags_exitfunc)(int) = &exit; // from stdlib.h + + // The help message indicating that the commandline flag has been // 'stripped'. It will not show up when doing "-help" and its // variants. The flag is stripped if STRIP_FLAG_HELP is set to 1 -// before including gflags/gflags.h. +// before including base/gflags.h -// This is used by this file, and also in commandlineflags_reporting.cc +// This is used by this file, and also in gflags_reporting.cc const char kStrippedFlagHelp[] = "\001\002\003\004 (unknown) \004\003\002\001"; -// This is used by the unittest to test error-exit code -void GFLAGS_DLL_DECL (*commandlineflags_exitfunc)(int) = &exit; // from stdlib.h - namespace { -// There are also 'reporting' flags, in commandlineflags_reporting.cc. +// There are also 'reporting' flags, in gflags_reporting.cc. static const char kError[] = "ERROR: "; @@ -218,12 +177,14 @@ enum DieWhenReporting { DIE, DO_NOT_DIE }; // Report Error and exit if requested. static void ReportError(DieWhenReporting should_die, const char* format, ...) { + char error_message[255]; va_list ap; va_start(ap, format); - vfprintf(stderr, format, ap); + vsnprintf(error_message, sizeof(error_message), format, ap); va_end(ap); - if (should_die == DIE) - commandlineflags_exitfunc(1); // almost certainly exit() + fprintf(stderr, "%s", error_message); + fflush(stderr); // should be unnecessary, but cygwin's rxvt buffers stderr + if (should_die == DIE) gflags_exitfunc(1); } @@ -317,6 +278,7 @@ bool FlagValue::ParseFrom(const char* value) { if (type_ == FV_BOOL) { const char* kTrue[] = { "1", "t", "true", "y", "yes" }; const char* kFalse[] = { "0", "f", "false", "n", "no" }; + COMPILE_ASSERT(sizeof(kTrue) == sizeof(kFalse), true_false_equal); for (size_t i = 0; i < sizeof(kTrue)/sizeof(*kTrue); ++i) { if (strcasecmp(value, kTrue[i]) == 0) { SET_VALUE_AS(bool, true); @@ -346,7 +308,7 @@ bool FlagValue::ParseFrom(const char* value) { switch (type_) { case FV_INT32: { - const int64 r = strtoint64(value, &end, base); + const int64 r = strto64(value, &end, base); if (errno || end != value + strlen(value)) return false; // bad parse if (static_cast(r) != r) // worked, but number out of range return false; @@ -354,7 +316,7 @@ bool FlagValue::ParseFrom(const char* value) { return true; } case FV_INT64: { - const int64 r = strtoint64(value, &end, base); + const int64 r = strto64(value, &end, base); if (errno || end != value + strlen(value)) return false; // bad parse SET_VALUE_AS(int64, r); return true; @@ -362,7 +324,7 @@ bool FlagValue::ParseFrom(const char* value) { case FV_UINT64: { while (*value == ' ') value++; if (*value == '-') return false; // negative number - const uint64 r = strtouint64(value, &end, base); + const uint64 r = strtou64(value, &end, base); if (errno || end != value + strlen(value)) return false; // bad parse SET_VALUE_AS(uint64, r); return true; @@ -531,6 +493,7 @@ class CommandLineFlag { string default_value() const { return defvalue_->ToString(); } const char* type_name() const { return defvalue_->TypeName(); } ValidateFnProto validate_function() const { return validate_fn_proto_; } + const void* flag_ptr() const { return current_->value_buffer_; } void FillCommandLineFlagInfo(struct CommandLineFlagInfo* result); @@ -583,7 +546,6 @@ const char* CommandLineFlag::CleanFileName() const { // search full path backwards. // Stop going backwards at kRootDir; and skip by the first slash. static const char kRootDir[] = ""; // can set this to root directory, - // e.g. "myproject" if (sizeof(kRootDir)-1 == 0) // no prefix to strip return filename(); @@ -592,8 +554,7 @@ const char* CommandLineFlag::CleanFileName() const { while ( clean_name > filename() ) { if (*clean_name == PATH_SEPARATOR) { if (strncmp(clean_name, kRootDir, sizeof(kRootDir)-1) == 0) { - // ".../myproject/base/logging.cc" ==> "base/logging.cc" - clean_name += sizeof(kRootDir)-1; // past "/myproject/" + clean_name += sizeof(kRootDir)-1; // past root-dir break; } } @@ -614,6 +575,7 @@ void CommandLineFlag::FillCommandLineFlagInfo( UpdateModifiedBit(); result->is_default = !modified_; result->has_validator_fn = validate_function() != NULL; + result->flag_ptr = flag_ptr(); } void CommandLineFlag::UpdateModifiedBit() { @@ -634,6 +596,7 @@ void CommandLineFlag::CopyFrom(const CommandLineFlag& src) { } bool CommandLineFlag::Validate(const FlagValue& value) const { + if (validate_function() == NULL) return true; else @@ -657,10 +620,14 @@ struct StringCmp { // Used by the FlagRegistry map class to compare char*'s } }; + class FlagRegistry { public: - FlagRegistry() { } + FlagRegistry() { + } ~FlagRegistry() { + // Not using STLDeleteElements as that resides in util and this + // class is base. for (FlagMap::iterator p = flags_.begin(), e = flags_.end(); p != e; ++p) { CommandLineFlag* flag = p->second; delete flag; @@ -672,12 +639,12 @@ class FlagRegistry { global_registry_ = NULL; } - void Lock() { lock_.Lock(); } - void Unlock() { lock_.Unlock(); } - // Store a flag in this registry. Takes ownership of the given pointer. void RegisterFlag(CommandLineFlag* flag); + void Lock() { lock_.Lock(); } + void Unlock() { lock_.Unlock(); } + // Returns the flag object for the specified name, or NULL if not found. CommandLineFlag* FindFlagLocked(const char* name); @@ -718,26 +685,26 @@ class FlagRegistry { typedef map FlagPtrMap; FlagPtrMap flags_by_ptr_; + static FlagRegistry* global_registry_; // a singleton registry + Mutex lock_; + static Mutex global_registry_lock_; - static FlagRegistry* global_registry_; // a singleton registry - static Mutex global_registry_lock_; // guards creation of global_registry_ + static void InitGlobalRegistry(); // Disallow FlagRegistry(const FlagRegistry&); FlagRegistry& operator=(const FlagRegistry&); }; -FlagRegistry* FlagRegistry::global_registry_ = NULL; -Mutex FlagRegistry::global_registry_lock_(Mutex::LINKER_INITIALIZED); +class FlagRegistryLock { + public: + explicit FlagRegistryLock(FlagRegistry* fr) : fr_(fr) { fr_->Lock(); } + ~FlagRegistryLock() { fr_->Unlock(); } + private: + FlagRegistry *const fr_; +}; -FlagRegistry* FlagRegistry::GlobalRegistry() { - MutexLock acquire_lock(&global_registry_lock_); - if (!global_registry_) { - global_registry_ = new FlagRegistry; - } - return global_registry_; -} void FlagRegistry::RegisterFlag(CommandLineFlag* flag) { Lock(); @@ -807,22 +774,22 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg, // In that case, we want to return flag 'x'. if (!(flag_name[0] == 'n' && flag_name[1] == 'o')) { // flag-name is not 'nox', so we're not in the exception case. - *error_message = (string(kError) + - "unknown command line flag '" + *key + "'\n"); + *error_message = StringPrintf("%sunknown command line flag '%s'\n", + kError, key->c_str()); return NULL; } flag = FindFlagLocked(flag_name+2); if (flag == NULL) { // No flag named 'x' exists, so we're not in the exception case. - *error_message = (string(kError) + - "unknown command line flag '" + *key + "'\n"); + *error_message = StringPrintf("%sunknown command line flag '%s'\n", + kError, key->c_str()); return NULL; } if (strcmp(flag->type_name(), "bool") != 0) { // 'x' exists but is not boolean, so we're not in the exception case. - *error_message = (string(kError) + - "boolean value (" + *key + ") specified for " + - flag->type_name() + " command line flag\n"); + *error_message = StringPrintf( + "%sboolean value (%s) specified for %s command line flag\n", + kError, key->c_str(), flag->type_name()); return NULL; } // We're in the exception case! @@ -845,25 +812,27 @@ bool TryParseLocked(const CommandLineFlag* flag, FlagValue* flag_value, FlagValue* tentative_value = flag_value->New(); if (!tentative_value->ParseFrom(value)) { if (msg) { - *msg += (string(kError) + "illegal value '" + value + - + "' specified for " + flag->type_name() + " flag '" - + flag->name() + "'\n"); + StringAppendF(msg, + "%sillegal value '%s' specified for %s flag '%s'\n", + kError, value, + flag->type_name(), flag->name()); } delete tentative_value; return false; } else if (!flag->Validate(*tentative_value)) { if (msg) { - *msg += (string(kError) + "failed validation of new value " - + "'" + tentative_value->ToString() + "' for flag '" + - + flag->name() + "'\n"); + StringAppendF(msg, + "%sfailed validation of new value '%s' for flag '%s'\n", + kError, tentative_value->ToString().c_str(), + flag->name()); } delete tentative_value; return false; } else { flag_value->CopyFrom(*tentative_value); if (msg) { - *msg += (string(flag->name()) + " set to " + flag_value->ToString() - + "\n"); + StringAppendF(msg, "%s set to %s\n", + flag->name(), flag_value->ToString().c_str()); } delete tentative_value; return true; @@ -890,7 +859,8 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag, return false; flag->modified_ = true; } else { - *msg = string(flag->name()) + " set to " + flag->current_value(); + *msg = StringPrintf("%s set to %s", + flag->name(), flag->current_value().c_str()); } break; } @@ -914,13 +884,17 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag, return true; } -class FlagRegistryLock { - public: - explicit FlagRegistryLock(FlagRegistry* fr) : fr_(fr) { fr_->Lock(); } - ~FlagRegistryLock() { fr_->Unlock(); } - private: - FlagRegistry *const fr_; -}; +// Get the singleton FlagRegistry object +FlagRegistry* FlagRegistry::global_registry_ = NULL; +Mutex FlagRegistry::global_registry_lock_(Mutex::LINKER_INITIALIZED); + +FlagRegistry* FlagRegistry::GlobalRegistry() { + MutexLock acquire_lock(&global_registry_lock_); + if (!global_registry_) { + global_registry_ = new FlagRegistry; + } + return global_registry_; +} // -------------------------------------------------------------------- // CommandLineFlagParser @@ -1002,12 +976,12 @@ class CommandLineFlagParser { static void ParseFlagList(const char* value, vector* flags) { for (const char *p = value; p && *p; value = p) { p = strchr(value, ','); - int len; + size_t len; if (p) { - len = static_cast(p - value); + len = p - value; p++; } else { - len = static_cast(strlen(value)); + len = strlen(value); } if (len == 0) @@ -1023,7 +997,7 @@ static void ParseFlagList(const char* value, vector* flags) { // can do all the I/O in one place and not worry about it everywhere. // Plus, it's convenient to have the whole file contents at hand. // Adds a newline at the end of the file. -#define PFATAL(s) do { perror(s); commandlineflags_exitfunc(1); } while (0) +#define PFATAL(s) do { perror(s); gflags_exitfunc(1); } while (0) static string ReadFileIntoString(const char* filename) { const int kBufSize = 8092; @@ -1112,9 +1086,9 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv, && strcmp(flag->type_name(), "string") == 0 && (strstr(flag->help(), "true") || strstr(flag->help(), "false"))) { - fprintf(stderr, "Did you really mean to set flag '%s'" - " to the value '%s'?\n", - flag->name(), value); + LOG(WARNING) << "Did you really mean to set flag '" + << flag->name() << "' to the value '" + << value << "'?"; } } } @@ -1165,9 +1139,10 @@ string CommandLineFlagParser::ProcessFromenvLocked(const string& flagval, const char* flagname = flaglist[i].c_str(); CommandLineFlag* flag = registry_->FindFlagLocked(flagname); if (flag == NULL) { - error_flags_[flagname] = (string(kError) + "unknown command line flag" - + " '" + flagname + "'" - + " (via --fromenv or --tryfromenv)\n"); + error_flags_[flagname] = + StringPrintf("%sunknown command line flag '%s' " + "(via --fromenv or --tryfromenv)\n", + kError, flagname); undefined_names_[flagname] = ""; continue; } @@ -1185,8 +1160,9 @@ string CommandLineFlagParser::ProcessFromenvLocked(const string& flagval, // Avoid infinite recursion. if ((strcmp(envval, "fromenv") == 0) || (strcmp(envval, "tryfromenv") == 0)) { - error_flags_[flagname] = (string(kError) + "infinite recursion on " + - "environment flag '" + envval + "'\n"); + error_flags_[flagname] = + StringPrintf("%sinfinite recursion on environment flag '%s'\n", + kError, envval); continue; } @@ -1289,7 +1265,7 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked( while (*flagfile_contents && isspace(*flagfile_contents)) ++flagfile_contents; line_end = strchr(flagfile_contents, '\n'); - size_t len = line_end ? static_cast(line_end - flagfile_contents) + size_t len = line_end ? line_end - flagfile_contents : strlen(flagfile_contents); string line(flagfile_contents, len); @@ -1340,17 +1316,17 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked( space = word + strlen(word); const string glob(word, space - word); // We try matching both against the full argv0 and basename(argv0) + if (glob == ProgramInvocationName() // small optimization + || glob == ProgramInvocationShortName() #ifdef HAVE_FNMATCH_H - if (fnmatch(glob.c_str(), - ProgramInvocationName(), - FNM_PATHNAME) == 0 || - fnmatch(glob.c_str(), - ProgramInvocationShortName(), - FNM_PATHNAME) == 0) { -#else // !HAVE_FNMATCH_H - if ((glob == ProgramInvocationName()) || - (glob == ProgramInvocationShortName())) { -#endif // HAVE_FNMATCH_H + || fnmatch(glob.c_str(), + ProgramInvocationName(), + FNM_PATHNAME) == 0 + || fnmatch(glob.c_str(), + ProgramInvocationShortName(), + FNM_PATHNAME) == 0 +#endif + ) { flags_are_relevant = true; } } @@ -1391,14 +1367,14 @@ bool AddFlagValidator(const void* flag_ptr, ValidateFnProto validate_fn_proto) { // This is the CommandLineFlag whose current_->value_buffer_ == flag CommandLineFlag* flag = registry->FindFlagViaPtrLocked(flag_ptr); if (!flag) { - // WARNING << "Ignoring RegisterValidateFunction() for flag pointer " - // << flag_ptr << ": no flag found at that address"; + LOG(WARNING) << "Ignoring RegisterValidateFunction() for flag pointer " + << flag_ptr << ": no flag found at that address"; return false; } else if (validate_fn_proto == flag->validate_function()) { return true; // ok to register the same function over and over again } else if (validate_fn_proto != NULL && flag->validate_function() != NULL) { - // WARNING << "Ignoring RegisterValidateFunction() for flag '" - // << flag->name() << "': validate-fn already registered"; + LOG(WARNING) << "Ignoring RegisterValidateFunction() for flag '" + << flag->name() << "': validate-fn already registered"; return false; } else { flag->validate_fn_proto_ = validate_fn_proto; @@ -1548,6 +1524,24 @@ const char* ProgramUsage() { return "Warning: SetUsageMessage() never called"; } +// -------------------------------------------------------------------- +// SetVersionString() +// VersionString() +// -------------------------------------------------------------------- + +static const char* version_string = NULL; + +void SetVersionString(const string& version) { + if (version_string != NULL) + ReportError(DIE, "ERROR: SetVersionString() called twice\n"); + version_string = strdup(version.c_str()); // small memory leak +} + +const char* VersionString() { + return version_string ? version_string : ""; +} + + // -------------------------------------------------------------------- // GetCommandLineOption() // GetCommandLineFlagInfo() @@ -1601,7 +1595,7 @@ CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name) { CommandLineFlagInfo info; if (!GetCommandLineFlagInfo(name, &info)) { fprintf(stderr, "FATAL ERROR: flag name '%s' doesn't exist\n", name); - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); // almost certainly gflags_exitfunc() } return info; } @@ -1616,10 +1610,7 @@ string SetCommandLineOptionWithMode(const char* name, const char* value, CommandLineFlagParser parser(registry); result = parser.ProcessSingleOptionLocked(flag, value, set_mode); if (!result.empty()) { // in the error case, we've already logged - // You could consider logging this change, if you wanted to know it: - //fprintf(stderr, "%sFLAGS_%s\n", - // (set_mode == SET_FLAGS_DEFAULT ? "default value of " : ""), - // result); + // Could consider logging this change } } // The API of this function is that we return empty string on error @@ -1765,7 +1756,7 @@ bool ReadFlagsFromString(const string& flagfilecontents, if (parser.ReportErrors()) { // Error. Restore all global flags to their previous values. if (errors_are_fatal) - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); saved_states.RestoreToRegistry(); return false; } @@ -1917,7 +1908,7 @@ static uint32 ParseCommandLineFlagsInternal(int* argc, char*** argv, parser.ValidateAllFlags(); if (parser.ReportErrors()) // may cause us to exit on illegal flags - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); return r; } @@ -1947,7 +1938,7 @@ void AllowCommandLineReparsing() { allow_command_line_reparsing = true; } -uint32 ReparseCommandLineNonHelpFlags() { +void ReparseCommandLineNonHelpFlags() { // We make a copy of argc and argv to pass in const vector& argvs = GetArgvs(); int tmp_argc = static_cast(argvs.size()); @@ -1955,13 +1946,11 @@ uint32 ReparseCommandLineNonHelpFlags() { for (int i = 0; i < tmp_argc; ++i) tmp_argv[i] = strdup(argvs[i].c_str()); // TODO(csilvers): don't dup - const int retval = ParseCommandLineNonHelpFlags(&tmp_argc, &tmp_argv, false); + ParseCommandLineNonHelpFlags(&tmp_argc, &tmp_argv, false); for (int i = 0; i < tmp_argc; ++i) free(tmp_argv[i]); delete[] tmp_argv; - - return retval; } void ShutDownCommandLineFlags() { diff --git a/extern/libmv/third_party/gflags/gflags.h b/extern/libmv/third_party/gflags/gflags.h deleted file mode 100644 index cefbd62ae51..00000000000 --- a/extern/libmv/third_party/gflags/gflags.h +++ /dev/null @@ -1,589 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// --- -// Author: Ray Sidney -// Revamped and reorganized by Craig Silverstein -// -// This is the file that should be included by any file which declares -// or defines a command line flag or wants to parse command line flags -// or print a program usage message (which will include information about -// flags). Executive summary, in the form of an example foo.cc file: -// -// #include "foo.h" // foo.h has a line "DECLARE_int32(start);" -// #include "validators.h" // hypothetical file defining ValidateIsFile() -// -// DEFINE_int32(end, 1000, "The last record to read"); -// -// DEFINE_string(filename, "my_file.txt", "The file to read"); -// // Crash if the specified file does not exist. -// static bool dummy = RegisterFlagValidator(&FLAGS_filename, -// &ValidateIsFile); -// -// DECLARE_bool(verbose); // some other file has a DEFINE_bool(verbose, ...) -// -// void MyFunc() { -// if (FLAGS_verbose) printf("Records %d-%d\n", FLAGS_start, FLAGS_end); -// } -// -// Then, at the command-line: -// ./foo --noverbose --start=5 --end=100 -// -// For more details, see -// doc/gflags.html -// -// --- A note about thread-safety: -// -// We describe many functions in this routine as being thread-hostile, -// thread-compatible, or thread-safe. Here are the meanings we use: -// -// thread-safe: it is safe for multiple threads to call this routine -// (or, when referring to a class, methods of this class) -// concurrently. -// thread-hostile: it is not safe for multiple threads to call this -// routine (or methods of this class) concurrently. In gflags, -// most thread-hostile routines are intended to be called early in, -// or even before, main() -- that is, before threads are spawned. -// thread-compatible: it is safe for multiple threads to read from -// this variable (when applied to variables), or to call const -// methods of this class (when applied to classes), as long as no -// other thread is writing to the variable or calling non-const -// methods of this class. - -#ifndef GOOGLE_GFLAGS_H_ -#define GOOGLE_GFLAGS_H_ - -#include -#include - -// We care a lot about number of bits things take up. Unfortunately, -// systems define their bit-specific ints in a lot of different ways. -// We use our own way, and have a typedef to get there. -// Note: these commands below may look like "#if 1" or "#if 0", but -// that's because they were constructed that way at ./configure time. -// Look at gflags.h.in to see how they're calculated (based on your config). -#if 1 -#include // the normal place uint16_t is defined -#endif -#if 1 -#include // the normal place u_int16_t is defined -#endif -#if 1 -#include // a third place for uint16_t or u_int16_t -#endif - -namespace google { - -#if 1 // the C99 format -typedef int32_t int32; -typedef uint32_t uint32; -typedef int64_t int64; -typedef uint64_t uint64; -#elif 1 // the BSD format -typedef int32_t int32; -typedef u_int32_t uint32; -typedef int64_t int64; -typedef u_int64_t uint64; -#elif 0 // the windows (vc7) format -typedef __int32 int32; -typedef unsigned __int32 uint32; -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else -#error Do not know how to define a 32-bit integer quantity on your system -#endif - -// -------------------------------------------------------------------- -// To actually define a flag in a file, use DEFINE_bool, -// DEFINE_string, etc. at the bottom of this file. You may also find -// it useful to register a validator with the flag. This ensures that -// when the flag is parsed from the commandline, or is later set via -// SetCommandLineOption, we call the validation function. It is _not_ -// called when you assign the value to the flag directly using the = operator. -// -// The validation function should return true if the flag value is valid, and -// false otherwise. If the function returns false for the new setting of the -// flag, the flag will retain its current value. If it returns false for the -// default value, ParseCommandLineFlags() will die. -// -// This function is safe to call at global construct time (as in the -// example below). -// -// Example use: -// static bool ValidatePort(const char* flagname, int32 value) { -// if (value > 0 && value < 32768) // value is ok -// return true; -// printf("Invalid value for --%s: %d\n", flagname, (int)value); -// return false; -// } -// DEFINE_int32(port, 0, "What port to listen on"); -// static bool dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort); - -// Returns true if successfully registered, false if not (because the -// first argument doesn't point to a command-line flag, or because a -// validator is already registered for this flag). -bool RegisterFlagValidator(const bool* flag, - bool (*validate_fn)(const char*, bool)); -bool RegisterFlagValidator(const int32* flag, - bool (*validate_fn)(const char*, int32)); -bool RegisterFlagValidator(const int64* flag, - bool (*validate_fn)(const char*, int64)); -bool RegisterFlagValidator(const uint64* flag, - bool (*validate_fn)(const char*, uint64)); -bool RegisterFlagValidator(const double* flag, - bool (*validate_fn)(const char*, double)); -bool RegisterFlagValidator(const std::string* flag, - bool (*validate_fn)(const char*, const std::string&)); - - -// -------------------------------------------------------------------- -// These methods are the best way to get access to info about the -// list of commandline flags. Note that these routines are pretty slow. -// GetAllFlags: mostly-complete info about the list, sorted by file. -// ShowUsageWithFlags: pretty-prints the list to stdout (what --help does) -// ShowUsageWithFlagsRestrict: limit to filenames with restrict as a substr -// -// In addition to accessing flags, you can also access argv[0] (the program -// name) and argv (the entire commandline), which we sock away a copy of. -// These variables are static, so you should only set them once. - -struct CommandLineFlagInfo { - std::string name; // the name of the flag - std::string type; // the type of the flag: int32, etc - std::string description; // the "help text" associated with the flag - std::string current_value; // the current value, as a string - std::string default_value; // the default value, as a string - std::string filename; // 'cleaned' version of filename holding the flag - bool has_validator_fn; // true if RegisterFlagValidator called on flag - bool is_default; // true if the flag has the default value and - // has not been set explicitly from the cmdline - // or via SetCommandLineOption -}; - -// Using this inside of a validator is a recipe for a deadlock. -// TODO(wojtekm) Fix locking when validators are running, to make it safe to -// call validators during ParseAllFlags. -// Also make sure then to uncomment the corresponding unit test in -// commandlineflags_unittest.sh -extern void GetAllFlags(std::vector* OUTPUT); -// These two are actually defined in commandlineflags_reporting.cc. -extern void ShowUsageWithFlags(const char *argv0); // what --help does -extern void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict); - -// Create a descriptive string for a flag. -// Goes to some trouble to make pretty line breaks. -extern std::string DescribeOneFlag(const CommandLineFlagInfo& flag); - -// Thread-hostile; meant to be called before any threads are spawned. -extern void SetArgv(int argc, const char** argv); -// The following functions are thread-safe as long as SetArgv() is -// only called before any threads start. -extern const std::vector& GetArgvs(); // all of argv as a vector -extern const char* GetArgv(); // all of argv as a string -extern const char* GetArgv0(); // only argv0 -extern uint32 GetArgvSum(); // simple checksum of argv -extern const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set -extern const char* ProgramInvocationShortName(); // basename(argv0) -// ProgramUsage() is thread-safe as long as SetUsageMessage() is only -// called before any threads start. -extern const char* ProgramUsage(); // string set by SetUsageMessage() - - -// -------------------------------------------------------------------- -// Normally you access commandline flags by just saying "if (FLAGS_foo)" -// or whatever, and set them by calling "FLAGS_foo = bar" (or, more -// commonly, via the DEFINE_foo macro). But if you need a bit more -// control, we have programmatic ways to get/set the flags as well. -// These programmatic ways to access flags are thread-safe, but direct -// access is only thread-compatible. - -// Return true iff the flagname was found. -// OUTPUT is set to the flag's value, or unchanged if we return false. -extern bool GetCommandLineOption(const char* name, std::string* OUTPUT); - -// Return true iff the flagname was found. OUTPUT is set to the flag's -// CommandLineFlagInfo or unchanged if we return false. -extern bool GetCommandLineFlagInfo(const char* name, - CommandLineFlagInfo* OUTPUT); - -// Return the CommandLineFlagInfo of the flagname. exit() if name not found. -// Example usage, to check if a flag's value is currently the default value: -// if (GetCommandLineFlagInfoOrDie("foo").is_default) ... -extern CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name); - -enum FlagSettingMode { - // update the flag's value (can call this multiple times). - SET_FLAGS_VALUE, - // update the flag's value, but *only if* it has not yet been updated - // with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef". - SET_FLAG_IF_DEFAULT, - // set the flag's default value to this. If the flag has not yet updated - // yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef") - // change the flag's current value to the new default value as well. - SET_FLAGS_DEFAULT -}; - -// Set a particular flag ("command line option"). Returns a string -// describing the new value that the option has been set to. The -// return value API is not well-specified, so basically just depend on -// it to be empty if the setting failed for some reason -- the name is -// not a valid flag name, or the value is not a valid value -- and -// non-empty else. - -// SetCommandLineOption uses set_mode == SET_FLAGS_VALUE (the common case) -extern std::string SetCommandLineOption(const char* name, const char* value); -extern std::string SetCommandLineOptionWithMode(const char* name, const char* value, - FlagSettingMode set_mode); - - -// -------------------------------------------------------------------- -// Saves the states (value, default value, whether the user has set -// the flag, registered validators, etc) of all flags, and restores -// them when the FlagSaver is destroyed. This is very useful in -// tests, say, when you want to let your tests change the flags, but -// make sure that they get reverted to the original states when your -// test is complete. -// -// Example usage: -// void TestFoo() { -// FlagSaver s1; -// FLAG_foo = false; -// FLAG_bar = "some value"; -// -// // test happens here. You can return at any time -// // without worrying about restoring the FLAG values. -// } -// -// Note: This class is marked with __attribute__((unused)) because all the -// work is done in the constructor and destructor, so in the standard -// usage example above, the compiler would complain that it's an -// unused variable. -// -// This class is thread-safe. - -class FlagSaver { - public: - FlagSaver(); - ~FlagSaver(); - - private: - class FlagSaverImpl* impl_; // we use pimpl here to keep API steady - - FlagSaver(const FlagSaver&); // no copying! - void operator=(const FlagSaver&); -} -#ifndef _MSC_VER -__attribute__ ((unused)) -#endif -; - -// -------------------------------------------------------------------- -// Some deprecated or hopefully-soon-to-be-deprecated functions. - -// This is often used for logging. TODO(csilvers): figure out a better way -extern std::string CommandlineFlagsIntoString(); -// Usually where this is used, a FlagSaver should be used instead. -extern bool ReadFlagsFromString(const std::string& flagfilecontents, - const char* prog_name, - bool errors_are_fatal); // uses SET_FLAGS_VALUE - -// These let you manually implement --flagfile functionality. -// DEPRECATED. -extern bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name); -extern bool SaveCommandFlags(); // actually defined in google.cc ! -extern bool ReadFromFlagsFile(const std::string& filename, const char* prog_name, - bool errors_are_fatal); // uses SET_FLAGS_VALUE - - -// -------------------------------------------------------------------- -// Useful routines for initializing flags from the environment. -// In each case, if 'varname' does not exist in the environment -// return defval. If 'varname' does exist but is not valid -// (e.g., not a number for an int32 flag), abort with an error. -// Otherwise, return the value. NOTE: for booleans, for true use -// 't' or 'T' or 'true' or '1', for false 'f' or 'F' or 'false' or '0'. - -extern bool BoolFromEnv(const char *varname, bool defval); -extern int32 Int32FromEnv(const char *varname, int32 defval); -extern int64 Int64FromEnv(const char *varname, int64 defval); -extern uint64 Uint64FromEnv(const char *varname, uint64 defval); -extern double DoubleFromEnv(const char *varname, double defval); -extern const char *StringFromEnv(const char *varname, const char *defval); - - -// -------------------------------------------------------------------- -// The next two functions parse commandlineflags from main(): - -// Set the "usage" message for this program. For example: -// string usage("This program does nothing. Sample usage:\n"); -// usage += argv[0] + " "; -// SetUsageMessage(usage); -// Do not include commandline flags in the usage: we do that for you! -// Thread-hostile; meant to be called before any threads are spawned. -extern void SetUsageMessage(const std::string& usage); - -// Looks for flags in argv and parses them. Rearranges argv to put -// flags first, or removes them entirely if remove_flags is true. -// If a flag is defined more than once in the command line or flag -// file, the last definition is used. Returns the index (into argv) -// of the first non-flag argument. -// See top-of-file for more details on this function. -#ifndef SWIG // In swig, use ParseCommandLineFlagsScript() instead. -extern uint32 ParseCommandLineFlags(int *argc, char*** argv, - bool remove_flags); -#endif - - -// Calls to ParseCommandLineNonHelpFlags and then to -// HandleCommandLineHelpFlags can be used instead of a call to -// ParseCommandLineFlags during initialization, in order to allow for -// changing default values for some FLAGS (via -// e.g. SetCommandLineOptionWithMode calls) between the time of -// command line parsing and the time of dumping help information for -// the flags as a result of command line parsing. If a flag is -// defined more than once in the command line or flag file, the last -// definition is used. Returns the index (into argv) of the first -// non-flag argument. (If remove_flags is true, will always return 1.) -extern uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv, - bool remove_flags); -// This is actually defined in commandlineflags_reporting.cc. -// This function is misnamed (it also handles --version, etc.), but -// it's too late to change that now. :-( -extern void HandleCommandLineHelpFlags(); // in commandlineflags_reporting.cc - -// Allow command line reparsing. Disables the error normally -// generated when an unknown flag is found, since it may be found in a -// later parse. Thread-hostile; meant to be called before any threads -// are spawned. -extern void AllowCommandLineReparsing(); - -// Reparse the flags that have not yet been recognized. Only flags -// registered since the last parse will be recognized. Any flag value -// must be provided as part of the argument using "=", not as a -// separate command line argument that follows the flag argument. -// Intended for handling flags from dynamically loaded libraries, -// since their flags are not registered until they are loaded. -// Returns the index (into the original argv) of the first non-flag -// argument. (If remove_flags is true, will always return 1.) -extern uint32 ReparseCommandLineNonHelpFlags(); - -// Clean up memory allocated by flags. This is only needed to reduce -// the quantity of "potentially leaked" reports emitted by memory -// debugging tools such as valgrind. It is not required for normal -// operation, or for the perftools heap-checker. It must only be called -// when the process is about to exit, and all threads that might -// access flags are quiescent. Referencing flags after this is called -// will have unexpected consequences. This is not safe to run when -// multiple threads might be running: the function is thread-hostile. -extern void ShutDownCommandLineFlags(); - - -// -------------------------------------------------------------------- -// Now come the command line flag declaration/definition macros that -// will actually be used. They're kind of hairy. A major reason -// for this is initialization: we want people to be able to access -// variables in global constructors and have that not crash, even if -// their global constructor runs before the global constructor here. -// (Obviously, we can't guarantee the flags will have the correct -// default value in that case, but at least accessing them is safe.) -// The only way to do that is have flags point to a static buffer. -// So we make one, using a union to ensure proper alignment, and -// then use placement-new to actually set up the flag with the -// correct default value. In the same vein, we have to worry about -// flag access in global destructors, so FlagRegisterer has to be -// careful never to destroy the flag-values it constructs. -// -// Note that when we define a flag variable FLAGS_, we also -// preemptively define a junk variable, FLAGS_no. This is to -// cause a link-time error if someone tries to define 2 flags with -// names like "logging" and "nologging". We do this because a bool -// flag FLAG can be set from the command line to true with a "-FLAG" -// argument, and to false with a "-noFLAG" argument, and so this can -// potentially avert confusion. -// -// We also put flags into their own namespace. It is purposefully -// named in an opaque way that people should have trouble typing -// directly. The idea is that DEFINE puts the flag in the weird -// namespace, and DECLARE imports the flag from there into the current -// namespace. The net result is to force people to use DECLARE to get -// access to a flag, rather than saying "extern bool FLAGS_whatever;" -// or some such instead. We want this so we can put extra -// functionality (like sanity-checking) in DECLARE if we want, and -// make sure it is picked up everywhere. -// -// We also put the type of the variable in the namespace, so that -// people can't DECLARE_int32 something that they DEFINE_bool'd -// elsewhere. - -class FlagRegisterer { - public: - FlagRegisterer(const char* name, const char* type, - const char* help, const char* filename, - void* current_storage, void* defvalue_storage); -}; - -extern bool FlagsTypeWarn(const char *name); - -// If your application #defines STRIP_FLAG_HELP to a non-zero value -// before #including this file, we remove the help message from the -// binary file. This can reduce the size of the resulting binary -// somewhat, and may also be useful for security reasons. - -extern const char kStrippedFlagHelp[]; - -} - -#ifndef SWIG // In swig, ignore the main flag declarations - -#if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0 -// Need this construct to avoid the 'defined but not used' warning. -#define MAYBE_STRIPPED_HELP(txt) (false ? (txt) : ::google::kStrippedFlagHelp) -#else -#define MAYBE_STRIPPED_HELP(txt) txt -#endif - -// Each command-line flag has two variables associated with it: one -// with the current value, and one with the default value. However, -// we have a third variable, which is where value is assigned; it's a -// constant. This guarantees that FLAG_##value is initialized at -// static initialization time (e.g. before program-start) rather than -// than global construction time (which is after program-start but -// before main), at least when 'value' is a compile-time constant. We -// use a small trick for the "default value" variable, and call it -// FLAGS_no. This serves the second purpose of assuring a -// compile error if someone tries to define a flag named no -// which is illegal (--foo and --nofoo both affect the "foo" flag). -#define DEFINE_VARIABLE(type, shorttype, name, value, help) \ - namespace fL##shorttype { \ - static const type FLAGS_nono##name = value; \ - type FLAGS_##name = FLAGS_nono##name; \ - type FLAGS_no##name = FLAGS_nono##name; \ - static ::google::FlagRegisterer o_##name( \ - #name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \ - &FLAGS_##name, &FLAGS_no##name); \ - } \ - using fL##shorttype::FLAGS_##name - -#define DECLARE_VARIABLE(type, shorttype, name) \ - namespace fL##shorttype { \ - extern type FLAGS_##name; \ - } \ - using fL##shorttype::FLAGS_##name - -// For DEFINE_bool, we want to do the extra check that the passed-in -// value is actually a bool, and not a string or something that can be -// coerced to a bool. These declarations (no definition needed!) will -// help us do that, and never evaluate From, which is important. -// We'll use 'sizeof(IsBool(val))' to distinguish. This code requires -// that the compiler have different sizes for bool & double. Since -// this is not guaranteed by the standard, we check it with a -// compile-time assert (msg[-1] will give a compile-time error). -namespace fLB { -struct CompileAssert {}; -typedef CompileAssert expected_sizeof_double_neq_sizeof_bool[ - (sizeof(double) != sizeof(bool)) ? 1 : -1]; -template double IsBoolFlag(const From& from); -bool IsBoolFlag(bool from); -} // namespace fLB - -#define DECLARE_bool(name) DECLARE_VARIABLE(bool, B, name) -#define DEFINE_bool(name, val, txt) \ - namespace fLB { \ - typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \ - (sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \ - } \ - DEFINE_VARIABLE(bool, B, name, val, txt) - -#define DECLARE_int32(name) DECLARE_VARIABLE(::google::int32, I, name) -#define DEFINE_int32(name,val,txt) DEFINE_VARIABLE(::google::int32, I, name, val, txt) - -#define DECLARE_int64(name) DECLARE_VARIABLE(::google::int64, I64, name) -#define DEFINE_int64(name,val,txt) DEFINE_VARIABLE(::google::int64, I64, name, val, txt) - -#define DECLARE_uint64(name) DECLARE_VARIABLE(::google::uint64, U64, name) -#define DEFINE_uint64(name,val,txt) DEFINE_VARIABLE(::google::uint64, U64, name, val, txt) - -#define DECLARE_double(name) DECLARE_VARIABLE(double, D, name) -#define DEFINE_double(name, val, txt) DEFINE_VARIABLE(double, D, name, val, txt) - -// Strings are trickier, because they're not a POD, so we can't -// construct them at static-initialization time (instead they get -// constructed at global-constructor time, which is much later). To -// try to avoid crashes in that case, we use a char buffer to store -// the string, which we can static-initialize, and then placement-new -// into it later. It's not perfect, but the best we can do. - -namespace fLS { -// The meaning of "string" might be different between now and when the -// macros below get invoked (e.g., if someone is experimenting with -// other string implementations that get defined after this file is -// included). Save the current meaning now and use it in the macros. -typedef std::string clstring; - -inline clstring* dont_pass0toDEFINE_string(char *stringspot, - const char *value) { - return new(stringspot) clstring(value); -} -inline clstring* dont_pass0toDEFINE_string(char *stringspot, - const clstring &value) { - return new(stringspot) clstring(value); -} -inline clstring* dont_pass0toDEFINE_string(char *stringspot, - int value); -} // namespace fLS - -#define DECLARE_string(name) namespace fLS { extern ::fLS::clstring& FLAGS_##name; } \ - using fLS::FLAGS_##name - -// We need to define a var named FLAGS_no##name so people don't define -// --string and --nostring. And we need a temporary place to put val -// so we don't have to evaluate it twice. Two great needs that go -// great together! -// The weird 'using' + 'extern' inside the fLS namespace is to work around -// an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See -// http://code.google.com/p/google-gflags/issues/detail?id=20 -#define DEFINE_string(name, val, txt) \ - namespace fLS { \ - using ::fLS::clstring; \ - static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \ - clstring* const FLAGS_no##name = ::fLS:: \ - dont_pass0toDEFINE_string(s_##name[0].s, \ - val); \ - static ::google::FlagRegisterer o_##name( \ - #name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \ - s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \ - extern clstring& FLAGS_##name; \ - using fLS::FLAGS_##name; \ - clstring& FLAGS_##name = *FLAGS_no##name; \ - } \ - using fLS::FLAGS_##name - -#endif // SWIG - -#endif // GOOGLE_GFLAGS_H_ diff --git a/extern/libmv/third_party/gflags/gflags/gflags.h b/extern/libmv/third_party/gflags/gflags/gflags.h new file mode 100644 index 00000000000..e69812c8c38 --- /dev/null +++ b/extern/libmv/third_party/gflags/gflags/gflags.h @@ -0,0 +1,568 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// --- +// Revamped and reorganized by Craig Silverstein +// +// This is the file that should be included by any file which declares +// or defines a command line flag or wants to parse command line flags +// or print a program usage message (which will include information about +// flags). Executive summary, in the form of an example foo.cc file: +// +// #include "foo.h" // foo.h has a line "DECLARE_int32(start);" +// #include "validators.h" // hypothetical file defining ValidateIsFile() +// +// DEFINE_int32(end, 1000, "The last record to read"); +// +// DEFINE_string(filename, "my_file.txt", "The file to read"); +// // Crash if the specified file does not exist. +// static bool dummy = RegisterFlagValidator(&FLAGS_filename, +// &ValidateIsFile); +// +// DECLARE_bool(verbose); // some other file has a DEFINE_bool(verbose, ...) +// +// void MyFunc() { +// if (FLAGS_verbose) printf("Records %d-%d\n", FLAGS_start, FLAGS_end); +// } +// +// Then, at the command-line: +// ./foo --noverbose --start=5 --end=100 +// +// For more details, see +// doc/gflags.html +// +// --- A note about thread-safety: +// +// We describe many functions in this routine as being thread-hostile, +// thread-compatible, or thread-safe. Here are the meanings we use: +// +// thread-safe: it is safe for multiple threads to call this routine +// (or, when referring to a class, methods of this class) +// concurrently. +// thread-hostile: it is not safe for multiple threads to call this +// routine (or methods of this class) concurrently. In gflags, +// most thread-hostile routines are intended to be called early in, +// or even before, main() -- that is, before threads are spawned. +// thread-compatible: it is safe for multiple threads to read from +// this variable (when applied to variables), or to call const +// methods of this class (when applied to classes), as long as no +// other thread is writing to the variable or calling non-const +// methods of this class. + +#ifndef BASE_COMMANDLINEFLAGS_H_ +#define BASE_COMMANDLINEFLAGS_H_ + +#include +#include +#include "gflags_declare.h" // IWYU pragma: export +namespace google { + +// +// NOTE: all functions below MUST have an explicit 'extern' before +// them. Our automated opensourcing tools use this as a signal to do +// appropriate munging for windows, which needs to add GFLAGS_DLL_DECL. +// +#define GFLAGS_DLL_DECL /* rewritten to be non-empty in windows dir */ +#define GFLAGS_DLL_DEFINE_FLAG /* rewritten to be non-empty in windows dir */ + + +// -------------------------------------------------------------------- +// To actually define a flag in a file, use DEFINE_bool, +// DEFINE_string, etc. at the bottom of this file. You may also find +// it useful to register a validator with the flag. This ensures that +// when the flag is parsed from the commandline, or is later set via +// SetCommandLineOption, we call the validation function. It is _not_ +// called when you assign the value to the flag directly using the = operator. +// +// The validation function should return true if the flag value is valid, and +// false otherwise. If the function returns false for the new setting of the +// flag, the flag will retain its current value. If it returns false for the +// default value, ParseCommandLineFlags() will die. +// +// This function is safe to call at global construct time (as in the +// example below). +// +// Example use: +// static bool ValidatePort(const char* flagname, int32 value) { +// if (value > 0 && value < 32768) // value is ok +// return true; +// printf("Invalid value for --%s: %d\n", flagname, (int)value); +// return false; +// } +// DEFINE_int32(port, 0, "What port to listen on"); +// static bool dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort); + +// Returns true if successfully registered, false if not (because the +// first argument doesn't point to a command-line flag, or because a +// validator is already registered for this flag). +extern bool RegisterFlagValidator(const bool* flag, + bool (*validate_fn)(const char*, bool)); +extern bool RegisterFlagValidator(const int32* flag, + bool (*validate_fn)(const char*, int32)); +extern bool RegisterFlagValidator(const int64* flag, + bool (*validate_fn)(const char*, int64)); +extern bool RegisterFlagValidator(const uint64* flag, + bool (*validate_fn)(const char*, uint64)); +extern bool RegisterFlagValidator(const double* flag, + bool (*validate_fn)(const char*, double)); +extern bool RegisterFlagValidator(const std::string* flag, + bool (*validate_fn)(const char*, + const std::string&)); + + +// -------------------------------------------------------------------- +// These methods are the best way to get access to info about the +// list of commandline flags. Note that these routines are pretty slow. +// GetAllFlags: mostly-complete info about the list, sorted by file. +// ShowUsageWithFlags: pretty-prints the list to stdout (what --help does) +// ShowUsageWithFlagsRestrict: limit to filenames with restrict as a substr +// +// In addition to accessing flags, you can also access argv[0] (the program +// name) and argv (the entire commandline), which we sock away a copy of. +// These variables are static, so you should only set them once. + +struct GFLAGS_DLL_DECL CommandLineFlagInfo { + std::string name; // the name of the flag + std::string type; // the type of the flag: int32, etc + std::string description; // the "help text" associated with the flag + std::string current_value; // the current value, as a string + std::string default_value; // the default value, as a string + std::string filename; // 'cleaned' version of filename holding the flag + bool has_validator_fn; // true if RegisterFlagValidator called on this flag + bool is_default; // true if the flag has the default value and + // has not been set explicitly from the cmdline + // or via SetCommandLineOption + const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo) +}; + +// Using this inside of a validator is a recipe for a deadlock. +// TODO(user) Fix locking when validators are running, to make it safe to +// call validators during ParseAllFlags. +// Also make sure then to uncomment the corresponding unit test in +// gflags_unittest.sh +extern void GetAllFlags(std::vector* OUTPUT); +// These two are actually defined in gflags_reporting.cc. +extern void ShowUsageWithFlags(const char *argv0); // what --help does +extern void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict); + +// Create a descriptive string for a flag. +// Goes to some trouble to make pretty line breaks. +extern std::string DescribeOneFlag(const CommandLineFlagInfo& flag); + +// Thread-hostile; meant to be called before any threads are spawned. +extern void SetArgv(int argc, const char** argv); + +// The following functions are thread-safe as long as SetArgv() is +// only called before any threads start. +extern const std::vector& GetArgvs(); +extern const char* GetArgv(); // all of argv as a string +extern const char* GetArgv0(); // only argv0 +extern uint32 GetArgvSum(); // simple checksum of argv +extern const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set +extern const char* ProgramInvocationShortName(); // basename(argv0) + +// ProgramUsage() is thread-safe as long as SetUsageMessage() is only +// called before any threads start. +extern const char* ProgramUsage(); // string set by SetUsageMessage() + +// VersionString() is thread-safe as long as SetVersionString() is only +// called before any threads start. +extern const char* VersionString(); // string set by SetVersionString() + + + +// -------------------------------------------------------------------- +// Normally you access commandline flags by just saying "if (FLAGS_foo)" +// or whatever, and set them by calling "FLAGS_foo = bar" (or, more +// commonly, via the DEFINE_foo macro). But if you need a bit more +// control, we have programmatic ways to get/set the flags as well. +// These programmatic ways to access flags are thread-safe, but direct +// access is only thread-compatible. + +// Return true iff the flagname was found. +// OUTPUT is set to the flag's value, or unchanged if we return false. +extern bool GetCommandLineOption(const char* name, std::string* OUTPUT); + +// Return true iff the flagname was found. OUTPUT is set to the flag's +// CommandLineFlagInfo or unchanged if we return false. +extern bool GetCommandLineFlagInfo(const char* name, + CommandLineFlagInfo* OUTPUT); + +// Return the CommandLineFlagInfo of the flagname. exit() if name not found. +// Example usage, to check if a flag's value is currently the default value: +// if (GetCommandLineFlagInfoOrDie("foo").is_default) ... +extern CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name); + +enum GFLAGS_DLL_DECL FlagSettingMode { + // update the flag's value (can call this multiple times). + SET_FLAGS_VALUE, + // update the flag's value, but *only if* it has not yet been updated + // with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef". + SET_FLAG_IF_DEFAULT, + // set the flag's default value to this. If the flag has not yet updated + // yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef") + // change the flag's current value to the new default value as well. + SET_FLAGS_DEFAULT +}; + +// Set a particular flag ("command line option"). Returns a string +// describing the new value that the option has been set to. The +// return value API is not well-specified, so basically just depend on +// it to be empty if the setting failed for some reason -- the name is +// not a valid flag name, or the value is not a valid value -- and +// non-empty else. + +// SetCommandLineOption uses set_mode == SET_FLAGS_VALUE (the common case) +extern std::string SetCommandLineOption(const char* name, const char* value); +extern std::string SetCommandLineOptionWithMode(const char* name, const char* value, + FlagSettingMode set_mode); + + +// -------------------------------------------------------------------- +// Saves the states (value, default value, whether the user has set +// the flag, registered validators, etc) of all flags, and restores +// them when the FlagSaver is destroyed. This is very useful in +// tests, say, when you want to let your tests change the flags, but +// make sure that they get reverted to the original states when your +// test is complete. +// +// Example usage: +// void TestFoo() { +// FlagSaver s1; +// FLAG_foo = false; +// FLAG_bar = "some value"; +// +// // test happens here. You can return at any time +// // without worrying about restoring the FLAG values. +// } +// +// Note: This class is marked with ATTRIBUTE_UNUSED because all the +// work is done in the constructor and destructor, so in the standard +// usage example above, the compiler would complain that it's an +// unused variable. +// +// This class is thread-safe. However, its destructor writes to +// exactly the set of flags that have changed value during its +// lifetime, so concurrent _direct_ access to those flags +// (i.e. FLAGS_foo instead of {Get,Set}CommandLineOption()) is unsafe. + +class GFLAGS_DLL_DECL FlagSaver { + public: + FlagSaver(); + ~FlagSaver(); + + private: + class FlagSaverImpl* impl_; // we use pimpl here to keep API steady + + FlagSaver(const FlagSaver&); // no copying! + void operator=(const FlagSaver&); +} +#ifndef _MSC_VER +__attribute__ ((unused)) +#endif +; + +// -------------------------------------------------------------------- +// Some deprecated or hopefully-soon-to-be-deprecated functions. + +// This is often used for logging. TODO(csilvers): figure out a better way +extern std::string CommandlineFlagsIntoString(); +// Usually where this is used, a FlagSaver should be used instead. +extern bool ReadFlagsFromString(const std::string& flagfilecontents, + const char* prog_name, + bool errors_are_fatal); // uses SET_FLAGS_VALUE + +// These let you manually implement --flagfile functionality. +// DEPRECATED. +extern bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name); +extern bool ReadFromFlagsFile(const std::string& filename, const char* prog_name, + bool errors_are_fatal); // uses SET_FLAGS_VALUE + + +// -------------------------------------------------------------------- +// Useful routines for initializing flags from the environment. +// In each case, if 'varname' does not exist in the environment +// return defval. If 'varname' does exist but is not valid +// (e.g., not a number for an int32 flag), abort with an error. +// Otherwise, return the value. NOTE: for booleans, for true use +// 't' or 'T' or 'true' or '1', for false 'f' or 'F' or 'false' or '0'. + +extern bool BoolFromEnv(const char *varname, bool defval); +extern int32 Int32FromEnv(const char *varname, int32 defval); +extern int64 Int64FromEnv(const char *varname, int64 defval); +extern uint64 Uint64FromEnv(const char *varname, uint64 defval); +extern double DoubleFromEnv(const char *varname, double defval); +extern const char *StringFromEnv(const char *varname, const char *defval); + + +// -------------------------------------------------------------------- +// The next two functions parse gflags from main(): + +// Set the "usage" message for this program. For example: +// string usage("This program does nothing. Sample usage:\n"); +// usage += argv[0] + " "; +// SetUsageMessage(usage); +// Do not include commandline flags in the usage: we do that for you! +// Thread-hostile; meant to be called before any threads are spawned. +extern void SetUsageMessage(const std::string& usage); + +// Sets the version string, which is emitted with --version. +// For instance: SetVersionString("1.3"); +// Thread-hostile; meant to be called before any threads are spawned. +extern void SetVersionString(const std::string& version); + + +// Looks for flags in argv and parses them. Rearranges argv to put +// flags first, or removes them entirely if remove_flags is true. +// If a flag is defined more than once in the command line or flag +// file, the last definition is used. Returns the index (into argv) +// of the first non-flag argument. +// See top-of-file for more details on this function. +#ifndef SWIG // In swig, use ParseCommandLineFlagsScript() instead. +extern uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags); +#endif + + +// Calls to ParseCommandLineNonHelpFlags and then to +// HandleCommandLineHelpFlags can be used instead of a call to +// ParseCommandLineFlags during initialization, in order to allow for +// changing default values for some FLAGS (via +// e.g. SetCommandLineOptionWithMode calls) between the time of +// command line parsing and the time of dumping help information for +// the flags as a result of command line parsing. If a flag is +// defined more than once in the command line or flag file, the last +// definition is used. Returns the index (into argv) of the first +// non-flag argument. (If remove_flags is true, will always return 1.) +extern uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv, + bool remove_flags); +// This is actually defined in gflags_reporting.cc. +// This function is misnamed (it also handles --version, etc.), but +// it's too late to change that now. :-( +extern void HandleCommandLineHelpFlags(); // in gflags_reporting.cc + +// Allow command line reparsing. Disables the error normally +// generated when an unknown flag is found, since it may be found in a +// later parse. Thread-hostile; meant to be called before any threads +// are spawned. +extern void AllowCommandLineReparsing(); + +// Reparse the flags that have not yet been recognized. Only flags +// registered since the last parse will be recognized. Any flag value +// must be provided as part of the argument using "=", not as a +// separate command line argument that follows the flag argument. +// Intended for handling flags from dynamically loaded libraries, +// since their flags are not registered until they are loaded. +extern void ReparseCommandLineNonHelpFlags(); + +// Clean up memory allocated by flags. This is only needed to reduce +// the quantity of "potentially leaked" reports emitted by memory +// debugging tools such as valgrind. It is not required for normal +// operation, or for the google perftools heap-checker. It must only +// be called when the process is about to exit, and all threads that +// might access flags are quiescent. Referencing flags after this is +// called will have unexpected consequences. This is not safe to run +// when multiple threads might be running: the function is +// thread-hostile. +extern void ShutDownCommandLineFlags(); + + +// -------------------------------------------------------------------- +// Now come the command line flag declaration/definition macros that +// will actually be used. They're kind of hairy. A major reason +// for this is initialization: we want people to be able to access +// variables in global constructors and have that not crash, even if +// their global constructor runs before the global constructor here. +// (Obviously, we can't guarantee the flags will have the correct +// default value in that case, but at least accessing them is safe.) +// The only way to do that is have flags point to a static buffer. +// So we make one, using a union to ensure proper alignment, and +// then use placement-new to actually set up the flag with the +// correct default value. In the same vein, we have to worry about +// flag access in global destructors, so FlagRegisterer has to be +// careful never to destroy the flag-values it constructs. +// +// Note that when we define a flag variable FLAGS_, we also +// preemptively define a junk variable, FLAGS_no. This is to +// cause a link-time error if someone tries to define 2 flags with +// names like "logging" and "nologging". We do this because a bool +// flag FLAG can be set from the command line to true with a "-FLAG" +// argument, and to false with a "-noFLAG" argument, and so this can +// potentially avert confusion. +// +// We also put flags into their own namespace. It is purposefully +// named in an opaque way that people should have trouble typing +// directly. The idea is that DEFINE puts the flag in the weird +// namespace, and DECLARE imports the flag from there into the current +// namespace. The net result is to force people to use DECLARE to get +// access to a flag, rather than saying "extern bool FLAGS_whatever;" +// or some such instead. We want this so we can put extra +// functionality (like sanity-checking) in DECLARE if we want, and +// make sure it is picked up everywhere. +// +// We also put the type of the variable in the namespace, so that +// people can't DECLARE_int32 something that they DEFINE_bool'd +// elsewhere. + +class GFLAGS_DLL_DECL FlagRegisterer { + public: + FlagRegisterer(const char* name, const char* type, + const char* help, const char* filename, + void* current_storage, void* defvalue_storage); +}; + +// If your application #defines STRIP_FLAG_HELP to a non-zero value +// before #including this file, we remove the help message from the +// binary file. This can reduce the size of the resulting binary +// somewhat, and may also be useful for security reasons. + +extern const char kStrippedFlagHelp[]; + +} + +#ifndef SWIG // In swig, ignore the main flag declarations + +#if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0 +// Need this construct to avoid the 'defined but not used' warning. +#define MAYBE_STRIPPED_HELP(txt) \ + (false ? (txt) : ::google::kStrippedFlagHelp) +#else +#define MAYBE_STRIPPED_HELP(txt) txt +#endif + +// Each command-line flag has two variables associated with it: one +// with the current value, and one with the default value. However, +// we have a third variable, which is where value is assigned; it's a +// constant. This guarantees that FLAG_##value is initialized at +// static initialization time (e.g. before program-start) rather than +// than global construction time (which is after program-start but +// before main), at least when 'value' is a compile-time constant. We +// use a small trick for the "default value" variable, and call it +// FLAGS_no. This serves the second purpose of assuring a +// compile error if someone tries to define a flag named no +// which is illegal (--foo and --nofoo both affect the "foo" flag). +#define DEFINE_VARIABLE(type, shorttype, name, value, help) \ + namespace fL##shorttype { \ + static const type FLAGS_nono##name = value; \ + /* We always want to export defined variables, dll or no */ \ + GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \ + type FLAGS_no##name = FLAGS_nono##name; \ + static ::google::FlagRegisterer o_##name( \ + #name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \ + &FLAGS_##name, &FLAGS_no##name); \ + } \ + using fL##shorttype::FLAGS_##name + +// For DEFINE_bool, we want to do the extra check that the passed-in +// value is actually a bool, and not a string or something that can be +// coerced to a bool. These declarations (no definition needed!) will +// help us do that, and never evaluate From, which is important. +// We'll use 'sizeof(IsBool(val))' to distinguish. This code requires +// that the compiler have different sizes for bool & double. Since +// this is not guaranteed by the standard, we check it with a +// COMPILE_ASSERT. +namespace fLB { +struct CompileAssert {}; +typedef CompileAssert expected_sizeof_double_neq_sizeof_bool[ + (sizeof(double) != sizeof(bool)) ? 1 : -1]; +template double GFLAGS_DLL_DECL IsBoolFlag(const From& from); +GFLAGS_DLL_DECL bool IsBoolFlag(bool from); +} // namespace fLB + +// Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros +// are in a separate include, gflags_declare.h, for reducing +// the physical transitive size for DECLARE use. +#define DEFINE_bool(name, val, txt) \ + namespace fLB { \ + typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \ + (sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \ + } \ + DEFINE_VARIABLE(bool, B, name, val, txt) + +#define DEFINE_int32(name, val, txt) \ + DEFINE_VARIABLE(::google::int32, I, \ + name, val, txt) + +#define DEFINE_int64(name, val, txt) \ + DEFINE_VARIABLE(::google::int64, I64, \ + name, val, txt) + +#define DEFINE_uint64(name,val, txt) \ + DEFINE_VARIABLE(::google::uint64, U64, \ + name, val, txt) + +#define DEFINE_double(name, val, txt) \ + DEFINE_VARIABLE(double, D, name, val, txt) + +// Strings are trickier, because they're not a POD, so we can't +// construct them at static-initialization time (instead they get +// constructed at global-constructor time, which is much later). To +// try to avoid crashes in that case, we use a char buffer to store +// the string, which we can static-initialize, and then placement-new +// into it later. It's not perfect, but the best we can do. + +namespace fLS { + +inline clstring* dont_pass0toDEFINE_string(char *stringspot, + const char *value) { + return new(stringspot) clstring(value); +} +inline clstring* dont_pass0toDEFINE_string(char *stringspot, + const clstring &value) { + return new(stringspot) clstring(value); +} +inline clstring* dont_pass0toDEFINE_string(char *stringspot, + int value); +} // namespace fLS + +// We need to define a var named FLAGS_no##name so people don't define +// --string and --nostring. And we need a temporary place to put val +// so we don't have to evaluate it twice. Two great needs that go +// great together! +// The weird 'using' + 'extern' inside the fLS namespace is to work around +// an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See +// http://code.google.com/p/google-gflags/issues/detail?id=20 +#define DEFINE_string(name, val, txt) \ + namespace fLS { \ + using ::fLS::clstring; \ + static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \ + clstring* const FLAGS_no##name = ::fLS:: \ + dont_pass0toDEFINE_string(s_##name[0].s, \ + val); \ + static ::google::FlagRegisterer o_##name( \ + #name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \ + s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \ + extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \ + using fLS::FLAGS_##name; \ + clstring& FLAGS_##name = *FLAGS_no##name; \ + } \ + using fLS::FLAGS_##name + +#endif // SWIG + +#endif // BASE_COMMANDLINEFLAGS_H_ diff --git a/extern/libmv/third_party/gflags/gflags/gflags_completions.h b/extern/libmv/third_party/gflags/gflags/gflags_completions.h new file mode 100644 index 00000000000..37f5b0ec2cf --- /dev/null +++ b/extern/libmv/third_party/gflags/gflags/gflags_completions.h @@ -0,0 +1,130 @@ +// Copyright (c) 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --- + +// +// Implement helpful bash-style command line flag completions +// +// ** Functional API: +// HandleCommandLineCompletions() should be called early during +// program startup, but after command line flag code has been +// initialized, such as the beginning of HandleCommandLineHelpFlags(). +// It checks the value of the flag --tab_completion_word. If this +// flag is empty, nothing happens here. If it contains a string, +// however, then HandleCommandLineCompletions() will hijack the +// process, attempting to identify the intention behind this +// completion. Regardless of the outcome of this deduction, the +// process will be terminated, similar to --helpshort flag +// handling. +// +// ** Overview of Bash completions: +// Bash can be told to programatically determine completions for the +// current 'cursor word'. It does this by (in this case) invoking a +// command with some additional arguments identifying the command +// being executed, the word being completed, and the previous word +// (if any). Bash then expects a sequence of output lines to be +// printed to stdout. If these lines all contain a common prefix +// longer than the cursor word, bash will replace the cursor word +// with that common prefix, and display nothing. If there isn't such +// a common prefix, bash will display the lines in pages using 'more'. +// +// ** Strategy taken for command line completions: +// If we can deduce either the exact flag intended, or a common flag +// prefix, we'll output exactly that. Otherwise, if information +// must be displayed to the user, we'll take the opportunity to add +// some helpful information beyond just the flag name (specifically, +// we'll include the default flag value and as much of the flag's +// description as can fit on a single terminal line width, as specified +// by the flag --tab_completion_columns). Furthermore, we'll try to +// make bash order the output such that the most useful or relevent +// flags are the most likely to be shown at the top. +// +// ** Additional features: +// To assist in finding that one really useful flag, substring matching +// was implemented. Before pressing a to get completion for the +// current word, you can append one or more '?' to the flag to do +// substring matching. Here's the semantics: +// --foo Show me all flags with names prefixed by 'foo' +// --foo? Show me all flags with 'foo' somewhere in the name +// --foo?? Same as prior case, but also search in module +// definition path for 'foo' +// --foo??? Same as prior case, but also search in flag +// descriptions for 'foo' +// Finally, we'll trim the output to a relatively small number of +// flags to keep bash quiet about the verbosity of output. If one +// really wanted to see all possible matches, appending a '+' to the +// search word will force the exhaustive list of matches to be printed. +// +// ** How to have bash accept completions from a binary: +// Bash requires that it be informed about each command that programmatic +// completion should be enabled for. Example addition to a .bashrc +// file would be (your path to gflags_completions.sh file may differ): + +/* +$ complete -o bashdefault -o default -o nospace -C \ + '/home/build/eng/bash/bash_completions.sh --tab_completion_columns $COLUMNS' \ + time env binary_name another_binary [...] +*/ + +// This would allow the following to work: +// $ /path/to/binary_name --vmodule +// Or: +// $ ./bin/path/another_binary --gfs_u +// (etc) +// +// Sadly, it appears that bash gives no easy way to force this behavior for +// all commands. That's where the "time" in the above example comes in. +// If you haven't specifically added a command to the list of completion +// supported commands, you can still get completions by prefixing the +// entire command with "env". +// $ env /some/brand/new/binary --vmod +// Assuming that "binary" is a newly compiled binary, this should still +// produce the expected completion output. + + +#ifndef BASE_COMMANDLINEFLAGS_COMPLETIONS_H_ +#define BASE_COMMANDLINEFLAGS_COMPLETIONS_H_ + +// Annoying stuff for windows -- makes sure clients can import these functions +// +// NOTE: all functions below MUST have an explicit 'extern' before +// them. Our automated opensourcing tools use this as a signal to do +// appropriate munging for windows, which needs to add GFLAGS_DLL_DECL. +// +#define GFLAGS_DLL_DECL /* rewritten to be non-empty in windows dir */ + + +namespace google { + +extern void HandleCommandLineCompletions(void); + +} + +#endif // BASE_COMMANDLINEFLAGS_COMPLETIONS_H_ diff --git a/extern/libmv/third_party/gflags/gflags/gflags_declare.h b/extern/libmv/third_party/gflags/gflags/gflags_declare.h new file mode 100644 index 00000000000..e3013826d53 --- /dev/null +++ b/extern/libmv/third_party/gflags/gflags/gflags_declare.h @@ -0,0 +1,112 @@ +// Copyright (c) 1999, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// --- +// +// Revamped and reorganized by Craig Silverstein +// +// This is the file that should be included by any file which declares +// command line flag. + +#ifndef BASE_COMMANDLINEFLAGS_DECLARE_H_ +#define BASE_COMMANDLINEFLAGS_DECLARE_H_ + +#include +#if 1 +#include // the normal place uint16_t is defined +#endif +#if 1 +#include // the normal place u_int16_t is defined +#endif +#if 1 +#include // a third place for uint16_t or u_int16_t +#endif + +namespace google { +#if 1 // the C99 format +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; +#elif 1 // the BSD format +typedef int32_t int32; +typedef u_int32_t uint32; +typedef int64_t int64; +typedef u_int64_t uint64; +#elif 0 // the windows (vc7) format +typedef __int32 int32; +typedef unsigned __int32 uint32; +typedef __int64 int64; +typedef unsigned __int64 uint64; +#else +#error Do not know how to define a 32-bit integer quantity on your system +#endif +} + + +#define GFLAGS_DLL_DECLARE_FLAG /* rewritten to be non-empty in windows dir */ + +namespace fLS { + +// The meaning of "string" might be different between now and when the +// macros below get invoked (e.g., if someone is experimenting with +// other string implementations that get defined after this file is +// included). Save the current meaning now and use it in the macros. +typedef std::string clstring; + +} + +#define DECLARE_VARIABLE(type, shorttype, name) \ + /* We always want to import declared variables, dll or no */ \ + namespace fL##shorttype { extern GFLAGS_DLL_DECLARE_FLAG type FLAGS_##name; } \ + using fL##shorttype::FLAGS_##name + +#define DECLARE_bool(name) \ + DECLARE_VARIABLE(bool, B, name) + +#define DECLARE_int32(name) \ + DECLARE_VARIABLE(::google::int32, I, name) + +#define DECLARE_int64(name) \ + DECLARE_VARIABLE(::google::int64, I64, name) + +#define DECLARE_uint64(name) \ + DECLARE_VARIABLE(::google::uint64, U64, name) + +#define DECLARE_double(name) \ + DECLARE_VARIABLE(double, D, name) + +#define DECLARE_string(name) \ + namespace fLS { \ + using ::fLS::clstring; \ + extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \ + } \ + using fLS::FLAGS_##name + +#endif // BASE_COMMANDLINEFLAGS_DECLARE_H_ diff --git a/extern/libmv/third_party/gflags/gflags_completions.cc b/extern/libmv/third_party/gflags/gflags_completions.cc index a129611d8a1..75e9236ef63 100644 --- a/extern/libmv/third_party/gflags/gflags_completions.cc +++ b/extern/libmv/third_party/gflags/gflags_completions.cc @@ -28,8 +28,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // --- -// Author: Dave Nicponski -// + // Bash-style command line flag completion for C++ binaries // // This module implements bash-style completions. It achieves this @@ -58,7 +57,12 @@ #include #include -#include "gflags.h" +#include "gflags/gflags.h" +#include "util.h" + +using std::set; +using std::string; +using std::vector; #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' @@ -74,11 +78,6 @@ DEFINE_int32(tab_completion_columns, 80, _START_GOOGLE_NAMESPACE_ namespace { - -using std::set; -using std::string; -using std::vector; - // Function prototypes and Type forward declarations. Code may be // more easily understood if it is roughly ordered according to // control flow, rather than by C's "declare before use" ordering @@ -210,12 +209,12 @@ static void PrintFlagCompletionInfo(void) { &canonical_token, &options); - //VLOG(1) << "Identified canonical_token: '" << canonical_token << "'"; + DVLOG(1) << "Identified canonical_token: '" << canonical_token << "'"; vector all_flags; set matching_flags; GetAllFlags(&all_flags); - //VLOG(2) << "Found " << all_flags.size() << " flags overall"; + DVLOG(2) << "Found " << all_flags.size() << " flags overall"; string longest_common_prefix; FindMatchingFlags( @@ -224,28 +223,28 @@ static void PrintFlagCompletionInfo(void) { canonical_token, &matching_flags, &longest_common_prefix); - //VLOG(1) << "Identified " << matching_flags.size() << " matching flags"; - //VLOG(1) << "Identified " << longest_common_prefix - // << " as longest common prefix."; + DVLOG(1) << "Identified " << matching_flags.size() << " matching flags"; + DVLOG(1) << "Identified " << longest_common_prefix + << " as longest common prefix."; if (longest_common_prefix.size() > canonical_token.size()) { // There's actually a shared common prefix to all matching flags, // so may as well output that and quit quickly. - //VLOG(1) << "The common prefix '" << longest_common_prefix - // << "' was longer than the token '" << canonical_token - // << "'. Returning just this prefix for completion."; + DVLOG(1) << "The common prefix '" << longest_common_prefix + << "' was longer than the token '" << canonical_token + << "'. Returning just this prefix for completion."; fprintf(stdout, "--%s", longest_common_prefix.c_str()); return; } if (matching_flags.empty()) { - //VLOG(1) << "There were no matching flags, returning nothing."; + VLOG(1) << "There were no matching flags, returning nothing."; return; } string module; string package_dir; TryFindModuleAndPackageDir(all_flags, &module, &package_dir); - //VLOG(1) << "Identified module: '" << module << "'"; - //VLOG(1) << "Identified package_dir: '" << package_dir << "'"; + DVLOG(1) << "Identified module: '" << module << "'"; + DVLOG(1) << "Identified package_dir: '" << package_dir << "'"; NotableFlags notable_flags; CategorizeAllMatchingFlags( @@ -254,12 +253,12 @@ static void PrintFlagCompletionInfo(void) { module, package_dir, ¬able_flags); - //VLOG(2) << "Categorized matching flags:"; - //VLOG(2) << " perfect_match: " << notable_flags.perfect_match_flag.size(); - //VLOG(2) << " module: " << notable_flags.module_flags.size(); - //VLOG(2) << " package: " << notable_flags.package_flags.size(); - //VLOG(2) << " most common: " << notable_flags.most_common_flags.size(); - //VLOG(2) << " subpackage: " << notable_flags.subpackage_flags.size(); + DVLOG(2) << "Categorized matching flags:"; + DVLOG(2) << " perfect_match: " << notable_flags.perfect_match_flag.size(); + DVLOG(2) << " module: " << notable_flags.module_flags.size(); + DVLOG(2) << " package: " << notable_flags.package_flags.size(); + DVLOG(2) << " most common: " << notable_flags.most_common_flags.size(); + DVLOG(2) << " subpackage: " << notable_flags.subpackage_flags.size(); vector completions; FinalizeCompletionOutput( @@ -271,13 +270,13 @@ static void PrintFlagCompletionInfo(void) { if (options.force_no_update) completions.push_back("~"); - //VLOG(1) << "Finalized with " << completions.size() - // << " chosen completions"; + DVLOG(1) << "Finalized with " << completions.size() + << " chosen completions"; for (vector::const_iterator it = completions.begin(); it != completions.end(); ++it) { - //VLOG(9) << " Completion entry: '" << *it << "'"; + DVLOG(9) << " Completion entry: '" << *it << "'"; fprintf(stdout, "%s\n", it->c_str()); } } @@ -397,7 +396,7 @@ static bool DoesSingleFlagMatch( flag.filename.find(match_token) != string::npos) return true; - // TODO(daven): All searches should probably be case-insensitive + // TODO(user): All searches should probably be case-insensitive // (especially this one...) if (options.flag_description_substring_search && flag.description.find(match_token) != string::npos) @@ -426,8 +425,8 @@ static void CategorizeAllMatchingFlags( all_matches.begin(); it != all_matches.end(); ++it) { - //VLOG(2) << "Examining match '" << (*it)->name << "'"; - //VLOG(7) << " filename: '" << (*it)->filename << "'"; + DVLOG(2) << "Examining match '" << (*it)->name << "'"; + DVLOG(7) << " filename: '" << (*it)->filename << "'"; string::size_type pos = string::npos; if (!package_dir.empty()) pos = (*it)->filename.find(package_dir); @@ -440,36 +439,34 @@ static void CategorizeAllMatchingFlags( if ((*it)->name == search_token) { // Exact match on some flag's name notable_flags->perfect_match_flag.insert(*it); - //VLOG(3) << "Result: perfect match"; + DVLOG(3) << "Result: perfect match"; } else if (!module.empty() && (*it)->filename == module) { // Exact match on module filename notable_flags->module_flags.insert(*it); - //VLOG(3) << "Result: module match"; + DVLOG(3) << "Result: module match"; } else if (!package_dir.empty() && pos != string::npos && slash == string::npos) { // In the package, since there was no slash after the package portion notable_flags->package_flags.insert(*it); - //VLOG(3) << "Result: package match"; + DVLOG(3) << "Result: package match"; } else if (false) { // In the list of the XXX most commonly supplied flags overall - // TODO(daven): Compile this list. - //VLOG(3) << "Result: most-common match"; + // TODO(user): Compile this list. + DVLOG(3) << "Result: most-common match"; } else if (!package_dir.empty() && pos != string::npos && slash != string::npos) { // In a subdirectory of the package notable_flags->subpackage_flags.insert(*it); - //VLOG(3) << "Result: subpackage match"; + DVLOG(3) << "Result: subpackage match"; } - //VLOG(3) << "Result: not special match"; + DVLOG(3) << "Result: not special match"; } } static void PushNameWithSuffix(vector* suffixes, const char* suffix) { - string s("/"); - s += ProgramInvocationShortName(); - s += suffix; - suffixes->push_back(s); + suffixes->push_back( + StringPrintf("/%s%s", ProgramInvocationShortName(), suffix)); } static void TryFindModuleAndPackageDir( @@ -480,7 +477,7 @@ static void TryFindModuleAndPackageDir( package_dir->clear(); vector suffixes; - // TODO(daven): There's some inherant ambiguity here - multiple directories + // TODO(user): There's some inherant ambiguity here - multiple directories // could share the same trailing folder and file structure (and even worse, // same file names), causing us to be unsure as to which of the two is the // actual package for this binary. In this case, we'll arbitrarily choose. @@ -499,7 +496,7 @@ static void TryFindModuleAndPackageDir( for (vector::const_iterator suffix = suffixes.begin(); suffix != suffixes.end(); ++suffix) { - // TODO(daven): Make sure the match is near the end of the string + // TODO(user): Make sure the match is near the end of the string if (it->filename.find(*suffix) != string::npos) { *module = it->filename; string::size_type sep = it->filename.rfind(PATH_SEPARATOR); @@ -696,12 +693,14 @@ static void OutputSingleGroupWithLimit( static string GetShortFlagLine( const string &line_indentation, const CommandLineFlagInfo &info) { - string prefix = - line_indentation + "--" + info.name + " [" + - (info.type == "string" ? - ("'" + info.default_value + "'") : - info.default_value) - + "] "; + string prefix; + bool is_string = (info.type == "string"); + SStringPrintf(&prefix, "%s--%s [%s%s%s] ", + line_indentation.c_str(), + info.name.c_str(), + (is_string ? "'" : ""), + info.default_value.c_str(), + (is_string ? "'" : "")); int remainder = FLAGS_tab_completion_columns - static_cast(prefix.size()); string suffix; @@ -731,8 +730,12 @@ static string GetLongFlagLine( static const char kNewlineWithIndent[] = "\n "; output.replace(output.find(" type:"), 1, string(kNewlineWithIndent)); output.replace(output.find(" default:"), 1, string(kNewlineWithIndent)); - output = line_indentation + " Details for '--" + info.name + "':\n" + - output + " defined: " + info.filename; + output = StringPrintf("%s Details for '--%s':\n" + "%s defined: %s", + line_indentation.c_str(), + info.name.c_str(), + output.c_str(), + info.filename.c_str()); // Eliminate any doubled newlines that crept in. Specifically, if // DescribeOneFlag() decided to break the line just before "type" @@ -759,7 +762,7 @@ static string GetLongFlagLine( void HandleCommandLineCompletions(void) { if (FLAGS_tab_completion_word.empty()) return; PrintFlagCompletionInfo(); - exit(0); + gflags_exitfunc(0); } _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/gflags/gflags_completions.h b/extern/libmv/third_party/gflags/gflags_completions.h deleted file mode 100644 index 9d9ce7a5f75..00000000000 --- a/extern/libmv/third_party/gflags/gflags_completions.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// --- -// Author: Dave Nicponski -// -// Implement helpful bash-style command line flag completions -// -// ** Functional API: -// HandleCommandLineCompletions() should be called early during -// program startup, but after command line flag code has been -// initialized, such as the beginning of HandleCommandLineHelpFlags(). -// It checks the value of the flag --tab_completion_word. If this -// flag is empty, nothing happens here. If it contains a string, -// however, then HandleCommandLineCompletions() will hijack the -// process, attempting to identify the intention behind this -// completion. Regardless of the outcome of this deduction, the -// process will be terminated, similar to --helpshort flag -// handling. -// -// ** Overview of Bash completions: -// Bash can be told to programatically determine completions for the -// current 'cursor word'. It does this by (in this case) invoking a -// command with some additional arguments identifying the command -// being executed, the word being completed, and the previous word -// (if any). Bash then expects a sequence of output lines to be -// printed to stdout. If these lines all contain a common prefix -// longer than the cursor word, bash will replace the cursor word -// with that common prefix, and display nothing. If there isn't such -// a common prefix, bash will display the lines in pages using 'more'. -// -// ** Strategy taken for command line completions: -// If we can deduce either the exact flag intended, or a common flag -// prefix, we'll output exactly that. Otherwise, if information -// must be displayed to the user, we'll take the opportunity to add -// some helpful information beyond just the flag name (specifically, -// we'll include the default flag value and as much of the flag's -// description as can fit on a single terminal line width, as specified -// by the flag --tab_completion_columns). Furthermore, we'll try to -// make bash order the output such that the most useful or relevent -// flags are the most likely to be shown at the top. -// -// ** Additional features: -// To assist in finding that one really useful flag, substring matching -// was implemented. Before pressing a to get completion for the -// current word, you can append one or more '?' to the flag to do -// substring matching. Here's the semantics: -// --foo Show me all flags with names prefixed by 'foo' -// --foo? Show me all flags with 'foo' somewhere in the name -// --foo?? Same as prior case, but also search in module -// definition path for 'foo' -// --foo??? Same as prior case, but also search in flag -// descriptions for 'foo' -// Finally, we'll trim the output to a relatively small number of -// flags to keep bash quiet about the verbosity of output. If one -// really wanted to see all possible matches, appending a '+' to the -// search word will force the exhaustive list of matches to be printed. -// -// ** How to have bash accept completions from a binary: -// Bash requires that it be informed about each command that programmatic -// completion should be enabled for. Example addition to a .bashrc -// file would be (your path to gflags_completions.sh file may differ): - -/* -$ complete -o bashdefault -o default -o nospace -C \ - '/usr/local/bin/gflags_completions.sh --tab_completion_columns $COLUMNS' \ - time env binary_name another_binary [...] -*/ - -// This would allow the following to work: -// $ /path/to/binary_name --vmodule -// Or: -// $ ./bin/path/another_binary --gfs_u -// (etc) -// -// Sadly, it appears that bash gives no easy way to force this behavior for -// all commands. That's where the "time" in the above example comes in. -// If you haven't specifically added a command to the list of completion -// supported commands, you can still get completions by prefixing the -// entire command with "env". -// $ env /some/brand/new/binary --vmod -// Assuming that "binary" is a newly compiled binary, this should still -// produce the expected completion output. - - -#ifndef GOOGLE_GFLAGS_COMPLETIONS_H_ -#define GOOGLE_GFLAGS_COMPLETIONS_H_ - -namespace google { - -void HandleCommandLineCompletions(void); - -} - -#endif // GOOGLE_GFLAGS_COMPLETIONS_H_ diff --git a/extern/libmv/third_party/gflags/gflags_reporting.cc b/extern/libmv/third_party/gflags/gflags_reporting.cc index fa3024d974e..c74bcc8d762 100644 --- a/extern/libmv/third_party/gflags/gflags_reporting.cc +++ b/extern/libmv/third_party/gflags/gflags_reporting.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006, Google Inc. +// Copyright (c) 1999, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -28,7 +28,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // --- -// Author: Ray Sidney +// // Revamped and reorganized by Craig Silverstein // // This file contains code for handling the 'reporting' flags. These @@ -40,7 +40,7 @@ // HandleCommandLineHelpFlags(). (Well, actually, ShowUsageWithFlags(), // ShowUsageWithFlagsRestrict(), and DescribeOneFlag() can be called // externally too, but there's little need for it.) These are all -// declared in the main commandlineflags.h header file. +// declared in the main gflags.h header file. // // HandleCommandLineHelpFlags() will check what 'reporting' flags have // been defined, if any -- the "help" part of the function name is a @@ -55,14 +55,15 @@ #include #include #include -#include "gflags.h" -#include "gflags_completions.h" +#include "gflags/gflags.h" +#include "gflags/gflags_completions.h" +#include "util.h" #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' #endif -// The 'reporting' flags. They all call exit(). +// The 'reporting' flags. They all call gflags_exitfunc(). DEFINE_bool(help, false, "show help on all flags [tip: all flags can have two dashes]"); DEFINE_bool(helpfull, false, @@ -85,11 +86,12 @@ _START_GOOGLE_NAMESPACE_ using std::string; using std::vector; + // -------------------------------------------------------------------- // DescribeOneFlag() // DescribeOneFlagInXML() // Routines that pretty-print info about a flag. These use -// a CommandLineFlagInfo, which is the way the commandlineflags +// a CommandLineFlagInfo, which is the way the gflags // API exposes static info about a flag. // -------------------------------------------------------------------- @@ -114,17 +116,19 @@ static string PrintStringFlagsWithQuotes(const CommandLineFlagInfo& flag, const char* c_string = (current ? flag.current_value.c_str() : flag.default_value.c_str()); if (strcmp(flag.type.c_str(), "string") == 0) { // add quotes for strings - return text + ": \"" + c_string + "\""; + return StringPrintf("%s: \"%s\"", text.c_str(), c_string); } else { - return text + ": " + c_string; + return StringPrintf("%s: %s", text.c_str(), c_string); } } // Create a descriptive string for a flag. // Goes to some trouble to make pretty line breaks. string DescribeOneFlag(const CommandLineFlagInfo& flag) { - string main_part = (string(" -") + flag.name + - " (" + flag.description + ')'); + string main_part; + SStringPrintf(&main_part, " -%s (%s)", + flag.name.c_str(), + flag.description.c_str()); const char* c_string = main_part.c_str(); int chars_left = static_cast(main_part.length()); string final_string = ""; @@ -164,7 +168,7 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) { } if (*c_string == '\0') break; - final_string += "\n "; + StringAppendF(&final_string, "\n "); chars_in_line = 6; } @@ -173,7 +177,7 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) { // The listed default value will be the actual default from the flag // definition in the originating source file, unless the value has // subsequently been modified using SetCommandLineOptionWithMode() with mode - // SET_FLAGS_DEFAULT, or by setting FLAGS_foo = bar before initializing. + // SET_FLAGS_DEFAULT, or by setting FLAGS_foo = bar before ParseCommandLineFlags(). AddString(PrintStringFlagsWithQuotes(flag, "default", false), &final_string, &chars_in_line); if (!flag.is_default) { @@ -181,7 +185,7 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) { &final_string, &chars_in_line); } - final_string += '\n'; + StringAppendF(&final_string, "\n"); return final_string; } @@ -196,15 +200,10 @@ static string XMLText(const string& txt) { } static void AddXMLTag(string* r, const char* tag, const string& txt) { - *r += ('<'); - *r += (tag); - *r += ('>'); - *r += (XMLText(txt)); - *r += ("'); + StringAppendF(r, "<%s>%s", tag, XMLText(txt).c_str(), tag); } + static string DescribeOneFlagInXML(const CommandLineFlagInfo& flag) { // The file and flagname could have been attributes, but default // and meaning need to avoid attribute normalization. This way it @@ -265,9 +264,9 @@ static bool FileMatchesSubstring(const string& filename, // Show help for every filename which matches any of the target substrings. // If substrings is empty, shows help for every file. If a flag's help message -// has been stripped (e.g. by adding '#define STRIP_FLAG_HELP 1' before -// including gflags/gflags.h), then this flag will not be displayed by -// '--help' and its variants. +// has been stripped (e.g. by adding '#define STRIP_FLAG_HELP 1' +// before including gflags/gflags.h), then this flag will not be displayed +// by '--help' and its variants. static void ShowUsageWithFlagsMatching(const char *argv0, const vector &substrings) { fprintf(stdout, "%s: %s\n", Basename(argv0), ProgramUsage()); @@ -347,10 +346,13 @@ static void ShowXMLOfFlags(const char *prog_name) { // -------------------------------------------------------------------- static void ShowVersion() { - fprintf(stdout, "%s\n", ProgramInvocationShortName()); - // TODO: add other stuff, like a timestamp, who built it, what - // target they built, etc. - + const char* version_string = VersionString(); + if (version_string && *version_string) { + fprintf(stdout, "%s version %s\n", + ProgramInvocationShortName(), version_string); + } else { + fprintf(stdout, "%s\n", ProgramInvocationShortName()); + } # if !defined(NDEBUG) fprintf(stdout, "Debug build (NDEBUG not #defined)\n"); # endif @@ -375,7 +377,6 @@ static void AppendPrognameStrings(vector* substrings, void HandleCommandLineHelpFlags() { const char* progname = ProgramInvocationShortName(); - extern void (*commandlineflags_exitfunc)(int); // in gflags.cc HandleCommandLineCompletions(); @@ -386,21 +387,21 @@ void HandleCommandLineHelpFlags() { // show only flags related to this binary: // E.g. for fileutil.cc, want flags containing ... "/fileutil." cc ShowUsageWithFlagsMatching(progname, substrings); - commandlineflags_exitfunc(1); // almost certainly exit() + gflags_exitfunc(1); } else if (FLAGS_help || FLAGS_helpfull) { // show all options ShowUsageWithFlagsRestrict(progname, ""); // empty restrict - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (!FLAGS_helpon.empty()) { string restrict = "/" + FLAGS_helpon + "."; ShowUsageWithFlagsRestrict(progname, restrict.c_str()); - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (!FLAGS_helpmatch.empty()) { ShowUsageWithFlagsRestrict(progname, FLAGS_helpmatch.c_str()); - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (FLAGS_helppackage) { // Shows help for all files in the same directory as main(). We @@ -419,27 +420,27 @@ void HandleCommandLineHelpFlags() { const string package = Dirname(flag->filename) + "/"; if (package != last_package) { ShowUsageWithFlagsRestrict(progname, package.c_str()); + VLOG(7) << "Found package: " << package; if (!last_package.empty()) { // means this isn't our first pkg - fprintf(stderr, "WARNING: Multiple packages contain a file=%s\n", - progname); + LOG(WARNING) << "Multiple packages contain a file=" << progname; } last_package = package; } } if (last_package.empty()) { // never found a package to print - fprintf(stderr, "WARNING: Unable to find a package for file=%s\n", - progname); + LOG(WARNING) << "Unable to find a package for file=" << progname; } - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (FLAGS_helpxml) { ShowXMLOfFlags(progname); - commandlineflags_exitfunc(1); + gflags_exitfunc(1); } else if (FLAGS_version) { ShowVersion(); // Unlike help, we may be asking for version in a script, so return 0 - commandlineflags_exitfunc(0); + gflags_exitfunc(0); + } } diff --git a/extern/libmv/third_party/gflags/mutex.h b/extern/libmv/third_party/gflags/mutex.h index 6e1e8976b6d..7c3c060a043 100644 --- a/extern/libmv/third_party/gflags/mutex.h +++ b/extern/libmv/third_party/gflags/mutex.h @@ -28,7 +28,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // --- -// Author: Craig Silverstein. // // A simple mutex wrapper, supporting locks and read-write locks. // You should assume the locks are *not* re-entrant. @@ -117,7 +116,12 @@ #if defined(NO_THREADS) typedef int MutexType; // to keep a lock-count #elif defined(_WIN32) || defined(__CYGWIN32__) || defined(__CYGWIN64__) -# define WIN32_LEAN_AND_MEAN // We only need minimal includes +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN // We only need minimal includes +# endif +# ifndef NOMINMAX +# define NOMINMAX // Don't want windows to override min()/max() +# endif # ifdef GMUTEX_TRYLOCK // We need Windows NT or later for TryEnterCriticalSection(). If you // don't need that functionality, you can remove these _WIN32_WINNT @@ -134,7 +138,10 @@ // *does* cause problems for FreeBSD, or MacOSX, but isn't needed // for locking there.) # ifdef __linux__ -# define _XOPEN_SOURCE 500 // may be needed to get the rwlock calls +# if _XOPEN_SOURCE < 500 // including not being defined at all +# undef _XOPEN_SOURCE +# define _XOPEN_SOURCE 500 // may be needed to get the rwlock calls +# endif # endif # include typedef pthread_rwlock_t MutexType; diff --git a/extern/libmv/third_party/gflags/util.h b/extern/libmv/third_party/gflags/util.h new file mode 100644 index 00000000000..8e2b1b89525 --- /dev/null +++ b/extern/libmv/third_party/gflags/util.h @@ -0,0 +1,339 @@ +// Copyright (c) 2011, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// --- +// +// Some generically useful utility routines that in google-land would +// be their own projects. We make a shortened version here. + +#ifndef GFLAGS_UTIL_H_ +#define GFLAGS_UTIL_H_ + +#include +#include "config.h" +#ifdef HAVE_INTTYPES_H +# include +#endif +#include // for va_* +#include +#include +#include +#include +#ifdef HAVE_SYS_STAT_H +# include +#endif // for mkdir() + +_START_GOOGLE_NAMESPACE_ + +// This is used for unittests for death-testing. It is defined in gflags.cc. +extern GFLAGS_DLL_DECL void (*gflags_exitfunc)(int); + +// Work properly if either strtoll or strtoq is on this system +#ifdef HAVE_STRTOLL +# define strto64 strtoll +# define strtou64 strtoull +#elif HAVE_STRTOQ +# define strto64 strtoq +# define strtou64 strtouq +#else +// Neither strtoll nor strtoq are defined. I hope strtol works! +# define strto64 strtol +# define strtou64 strtoul +#endif + +// If we have inttypes.h, it will have defined PRId32/etc for us. If +// not, take our best guess. +#ifndef PRId32 +# define PRId32 "d" +#endif +#ifndef PRId64 +# define PRId64 "lld" +#endif +#ifndef PRIu64 +# define PRIu64 "llu" +#endif + +typedef signed char int8; +typedef unsigned char uint8; + +// -- utility macros --------------------------------------------------------- + +template struct CompileAssert {}; +#define COMPILE_ASSERT(expr, msg) \ + typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] + +// Returns the number of elements in an array. +#define arraysize(arr) (sizeof(arr)/sizeof(*(arr))) + + +// -- logging and testing --------------------------------------------------- + +// For now, we ignore the level for logging, and don't show *VLOG's at +// all, except by hand-editing the lines below +#define LOG(level) std::cerr +#define VLOG(level) if (true) {} else std::cerr +#define DVLOG(level) if (true) {} else std::cerr + +// CHECK dies with a fatal error if condition is not true. It is *not* +// controlled by NDEBUG, so the check will be executed regardless of +// compilation mode. Therefore, it is safe to do things like: +// CHECK(fp->Write(x) == 4) +// We allow stream-like objects after this for debugging, but they're ignored. +#define EXPECT_TRUE(condition) \ + if (true) { \ + if (!(condition)) { \ + fprintf(stderr, "Check failed: %s\n", #condition); \ + exit(1); \ + } \ + } else std::cerr << "" + +#define EXPECT_OP(op, val1, val2) \ + if (true) { \ + if (!((val1) op (val2))) { \ + fprintf(stderr, "Check failed: %s %s %s\n", #val1, #op, #val2); \ + exit(1); \ + } \ + } else std::cerr << "" + +#define EXPECT_EQ(val1, val2) EXPECT_OP(==, val1, val2) +#define EXPECT_NE(val1, val2) EXPECT_OP(!=, val1, val2) +#define EXPECT_LE(val1, val2) EXPECT_OP(<=, val1, val2) +#define EXPECT_LT(val1, val2) EXPECT_OP(< , val1, val2) +#define EXPECT_GE(val1, val2) EXPECT_OP(>=, val1, val2) +#define EXPECT_GT(val1, val2) EXPECT_OP(> , val1, val2) +#define EXPECT_FALSE(cond) EXPECT_TRUE(!(cond)) + +// C99 declares isnan and isinf should be macros, so the #ifdef test +// should be reliable everywhere. Of course, it's not, but these +// are testing pertty marginal functionality anyway, so it's ok to +// not-run them even in situations they might, with effort, be made to work. +#ifdef isnan // Some compilers, like sun's for Solaris 10, don't define this +#define EXPECT_NAN(arg) \ + do { \ + if (!isnan(arg)) { \ + fprintf(stderr, "Check failed: isnan(%s)\n", #arg); \ + exit(1); \ + } \ + } while (0) +#else +#define EXPECT_NAN(arg) +#endif + +#ifdef isinf // Some compilers, like sun's for Solaris 10, don't define this +#define EXPECT_INF(arg) \ + do { \ + if (!isinf(arg)) { \ + fprintf(stderr, "Check failed: isinf(%s)\n", #arg); \ + exit(1); \ + } \ + } while (0) +#else +#define EXPECT_INF(arg) +#endif + +#define EXPECT_DOUBLE_EQ(val1, val2) \ + do { \ + if (((val1) < (val2) - 0.001 || (val1) > (val2) + 0.001)) { \ + fprintf(stderr, "Check failed: %s == %s\n", #val1, #val2); \ + exit(1); \ + } \ + } while (0) + +#define EXPECT_STREQ(val1, val2) \ + do { \ + if (strcmp((val1), (val2)) != 0) { \ + fprintf(stderr, "Check failed: streq(%s, %s)\n", #val1, #val2); \ + exit(1); \ + } \ + } while (0) + +// Call this in a .cc file where you will later call RUN_ALL_TESTS in main(). +#define TEST_INIT \ + static std::vector g_testlist; /* the tests to run */ \ + static int RUN_ALL_TESTS() { \ + std::vector::const_iterator it; \ + for (it = g_testlist.begin(); it != g_testlist.end(); ++it) { \ + (*it)(); /* The test will error-exit if there's a problem. */ \ + } \ + fprintf(stderr, "\nPassed %d tests\n\nPASS\n", \ + static_cast(g_testlist.size())); \ + return 0; \ + } + +// Note that this macro uses a FlagSaver to keep tests isolated. +#define TEST(a, b) \ + struct Test_##a##_##b { \ + Test_##a##_##b() { g_testlist.push_back(&Run); } \ + static void Run() { \ + FlagSaver fs; \ + fprintf(stderr, "Running test %s/%s\n", #a, #b); \ + RunTest(); \ + } \ + static void RunTest(); \ + }; \ + static Test_##a##_##b g_test_##a##_##b; \ + void Test_##a##_##b::RunTest() + +// This is a dummy class that eases the google->opensource transition. +namespace testing { +class Test {}; +} + +// Call this in a .cc file where you will later call EXPECT_DEATH +#define EXPECT_DEATH_INIT \ + static bool g_called_exit; \ + static void CalledExit(int) { g_called_exit = true; } + +#define EXPECT_DEATH(fn, msg) \ + do { \ + g_called_exit = false; \ + gflags_exitfunc = &CalledExit; \ + fn; \ + gflags_exitfunc = &exit; /* set back to its default */ \ + if (!g_called_exit) { \ + fprintf(stderr, "Function didn't die (%s): %s\n", msg, #fn); \ + exit(1); \ + } \ + } while (0) + +#define GTEST_HAS_DEATH_TEST 1 + +// -- path routines ---------------------------------------------------------- + +// Tries to create the directory path as a temp-dir. If it fails, +// changes path to some directory it *can* create. +#if defined(__MINGW32__) +#include +inline void MakeTmpdir(std::string* path) { + // I had trouble creating a directory in /tmp from mingw + *path = "./gflags_unittest_testdir"; + mkdir(path->c_str()); // mingw has a weird one-arg mkdir +} +#elif defined(_MSC_VER) +#include +#include +inline void MakeTmpdir(std::string* path) { + char tmppath_buffer[1024]; + int tmppath_len = GetTempPathA(sizeof(tmppath_buffer), tmppath_buffer); + assert(tmppath_len > 0 && tmppath_len < sizeof(tmppath_buffer)); + assert(tmppath_buffer[tmppath_len - 1] == '\\'); // API guarantees it + *path = std::string(tmppath_buffer) + "gflags_unittest_testdir"; + _mkdir(path->c_str()); +} +// Windows is missing random bits like strcasecmp, strtoll, strtoull, and +// snprintf in the usual locations. Put them somewhere sensible. +// +// TODO(keir): Get the upstream Windows port and use that instead. +#define snprintf _snprintf +#undef strtoint64 +#define strtoint64 _strtoi64 +#undef strtouint64 +#define strtouint64 _strtoui64 +#define strcasecmp _stricmp +#define va_copy(dst, src) ((dst) = (src)) +#define strto64 _strtoi64 +#define strtou64 _strtoui64 +#else +inline void MakeTmpdir(std::string* path) { + mkdir(path->c_str(), 0755); +} +#endif + +// -- string routines -------------------------------------------------------- + +inline void InternalStringPrintf(std::string* output, const char* format, + va_list ap) { + char space[128]; // try a small buffer and hope it fits + + // It's possible for methods that use a va_list to invalidate + // the data in it upon use. The fix is to make a copy + // of the structure before using it and use that copy instead. + va_list backup_ap; + va_copy(backup_ap, ap); + int bytes_written = vsnprintf(space, sizeof(space), format, backup_ap); + va_end(backup_ap); + + if ((bytes_written >= 0) && (bytes_written < sizeof(space))) { + output->append(space, bytes_written); + return; + } + + // Repeatedly increase buffer size until it fits. + int length = sizeof(space); + while (true) { + if (bytes_written < 0) { + // Older snprintf() behavior. :-( Just try doubling the buffer size + length *= 2; + } else { + // We need exactly "bytes_written+1" characters + length = bytes_written+1; + } + char* buf = new char[length]; + + // Restore the va_list before we use it again + va_copy(backup_ap, ap); + bytes_written = vsnprintf(buf, length, format, backup_ap); + va_end(backup_ap); + + if ((bytes_written >= 0) && (bytes_written < length)) { + output->append(buf, bytes_written); + delete[] buf; + return; + } + delete[] buf; + } +} + +// Clears output before writing to it. +inline void SStringPrintf(std::string* output, const char* format, ...) { + va_list ap; + va_start(ap, format); + output->clear(); + InternalStringPrintf(output, format, ap); + va_end(ap); +} + +inline void StringAppendF(std::string* output, const char* format, ...) { + va_list ap; + va_start(ap, format); + InternalStringPrintf(output, format, ap); + va_end(ap); +} + +inline std::string StringPrintf(const char* format, ...) { + va_list ap; + va_start(ap, format); + std::string output; + InternalStringPrintf(&output, format, ap); + va_end(ap); + return output; +} + +_END_GOOGLE_NAMESPACE_ + +#endif // GFLAGS_UTIL_H_ diff --git a/extern/libmv/third_party/glog/ChangeLog b/extern/libmv/third_party/glog/ChangeLog index 350fee921e3..6ac0b0f0575 100644 --- a/extern/libmv/third_party/glog/ChangeLog +++ b/extern/libmv/third_party/glog/ChangeLog @@ -1,3 +1,13 @@ +2012-01-12 Google Inc. + + * google-glog: version 0.3.2 + * Clang support. + * Demangler and stacktrace improvement for newer GCCs. + * Now fork(2) doesn't mess up log files. + * Make valgrind happier. + * Reduce warnings for more -W options. + * Provide a workaround for ERROR defined by windows.h. + 2010-06-15 Google Inc. * google-glog: version 0.3.1 diff --git a/extern/libmv/third_party/glog/README.libmv b/extern/libmv/third_party/glog/README.libmv index 8f1243b2430..025a70b76a5 100644 --- a/extern/libmv/third_party/glog/README.libmv +++ b/extern/libmv/third_party/glog/README.libmv @@ -1,38 +1,24 @@ Project: Google Logging URL: http://code.google.com/p/google-glog/ License: New BSD -Upstream version: 0.3.1 +Upstream version: 0.3.2 Local modifications: Upgrading Notes -* Had to change #include to #include "gflags/gflags.h" -* Make sure to copy over a config_YOUR_PLATFORM.h and put it in config.h - -Old changes which got obsoleted (maybe?) by 0.3.1 merge: -* The config_linux.h is generated by configure on Keir's Ubuntu 9.04 desktop. -* Commented out some struct ::tm weirdness causing compile failures on - ubuntu 8.10 and 9.04. -* Switched several initializers to memset instead of = {}. -* Changed some includes pointing to gflags. Not sure why the regular inclusion - didn't work. -* Added some compile flags to silence various warnings, allowing us to keep the - differences between upstream small. -* Don't redefine _XOPEN_SOURCE. -* Added "google::" to GetReferenceableValue in CHECK_OP_LOG. -* Add virtual destructor to Thread in googletest.h. -* Update windows/glog/log_severity to build with QT library that include WinGDI - (It cause a double definition of ERROR variable). - -Old changes which got obsoleted (maybe?) by 0.2.1 merge: -* Added #ifndef / def REG_EIP; not sure what that is. -* Added (void) arg stuff to prevent unused variable warnings. -* Added google:: namespace prefix to GetReferencableValue -* Added assignments for several functions marked with no_ignore_return, where - the return value was ignored. -* Commented out the unused function DumpPCAndSymbol() in utilities.cc to silent - gcc on the mac - -TODO(keir): Remove any obsoleted changes above if they are not necessary after -testing on more platforms. - -WARNING: Mac port not updated for 0.2.1 +* Replace with "third_party/gflags/gflags/gflags.h" which is easier + to setup things in libmv and also helps with setting up building libmv into + external applications. +* Replace "glog/logging.h" and "glog/logging.h" with and + which is needed on Windows platform because otherwise files like logging.cc will be using + relative path which points to headers used by linux instead of headers need to be used + on Windows. +* Replace _asm int 3 with __debugbreak(). Such assembler code is obsolete and doesn't work + with 64bit versions of MSVC compilers. +* Do not use stacktrace for MinGW and FreeBSD because it leads into issues accessing + some specific data on this platforms. +* Define HAVE_LIB_GFLAGS for Windows builds. +* Do not define __declspec(dllimport) for MinGW platforms. +* Setup proper includes and datatypes for int32, uint32, int64 and uint64 for MinGW +* Do not define va_copy for MinGW platforms (it's already defined there). +* Patch localtime_r to be working fine with MinGW, disable strerror_r for MinGW because + of lack of needed functions. diff --git a/extern/libmv/third_party/glog/src/base/commandlineflags.h b/extern/libmv/third_party/glog/src/base/commandlineflags.h index 6c529ccd847..483a96ee80b 100644 --- a/extern/libmv/third_party/glog/src/base/commandlineflags.h +++ b/extern/libmv/third_party/glog/src/base/commandlineflags.h @@ -55,11 +55,11 @@ #ifdef HAVE_LIB_GFLAGS -#include "third_party/gflags/gflags.h" +#include "third_party/gflags/gflags/gflags.h" #else -#include "glog/logging.h" +#include #define DECLARE_VARIABLE(type, name, tn) \ namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##tn##_instead { \ diff --git a/extern/libmv/third_party/glog/src/base/googleinit.h b/extern/libmv/third_party/glog/src/base/googleinit.h index c907308e852..5a8b515cd60 100644 --- a/extern/libmv/third_party/glog/src/base/googleinit.h +++ b/extern/libmv/third_party/glog/src/base/googleinit.h @@ -36,7 +36,7 @@ class GoogleInitializer { public: typedef void (*void_function)(void); - GoogleInitializer(const char* name, void_function f) { + GoogleInitializer(const char*, void_function f) { f(); } }; diff --git a/extern/libmv/third_party/glog/src/config_freebsd.h b/extern/libmv/third_party/glog/src/config_freebsd.h index 28fa1f1c78b..a671a0080b3 100644 --- a/extern/libmv/third_party/glog/src/config_freebsd.h +++ b/extern/libmv/third_party/glog/src/config_freebsd.h @@ -122,13 +122,13 @@ #define PACKAGE_NAME "glog" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "glog 0.3.1" +#define PACKAGE_STRING "glog 0.3.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "glog" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.3.1" +#define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ /* #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] */ @@ -151,7 +151,7 @@ #define TEST_SRC_DIR "." /* Version number of package */ -#define VERSION "0.3.1" +#define VERSION "0.3.2" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } @@ -159,3 +159,8 @@ /* Puts following code inside the Google namespace */ #define _START_GOOGLE_NAMESPACE_ namespace google { +/* isn't getting defined by configure script when clang compilers are used + and cuases compilation errors in stactrace/unwind modules */ +#ifdef __clang__ +# define NO_FRAME_POINTER +#endif diff --git a/extern/libmv/third_party/glog/src/config_linux.h b/extern/libmv/third_party/glog/src/config_linux.h index faf032949bb..19beaa5cf40 100644 --- a/extern/libmv/third_party/glog/src/config_linux.h +++ b/extern/libmv/third_party/glog/src/config_linux.h @@ -110,7 +110,11 @@ #define HAVE___BUILTIN_EXPECT 1 /* define if your compiler has __sync_val_compare_and_swap */ -/* #undef HAVE___SYNC_VAL_COMPARE_AND_SWAP */ +#define HAVE___SYNC_VAL_COMPARE_AND_SWAP 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" /* Name of package */ #define PACKAGE "glog" @@ -122,22 +126,19 @@ #define PACKAGE_NAME "glog" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "glog 0.3.1" +#define PACKAGE_STRING "glog 0.3.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "glog" +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.3.1" +#define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ -#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) - #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] -#elif defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) - #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_EIP] -#else - #undef PC_FROM_UCONTEXT -#endif +#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -149,7 +150,6 @@ /* Define to 1 if you have the ANSI C header files. */ /* #undef STDC_HEADERS */ -#define STDC_HEADERS 1 /* the namespace where STL code like vector<> is defined */ #define STL_NAMESPACE std @@ -157,10 +157,16 @@ #define TEST_SRC_DIR "." /* Version number of package */ -#define VERSION "0.3.1" +#define VERSION "0.3.2" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } /* Puts following code inside the Google namespace */ #define _START_GOOGLE_NAMESPACE_ namespace google { + +/* isn't getting defined by configure script when clang compilers are used + and cuases compilation errors in stactrace/unwind modules */ +#ifdef __clang__ +# define NO_FRAME_POINTER +#endif diff --git a/extern/libmv/third_party/glog/src/config_mac.h b/extern/libmv/third_party/glog/src/config_mac.h index 5f953d17ba9..9756fde22f3 100644 --- a/extern/libmv/third_party/glog/src/config_mac.h +++ b/extern/libmv/third_party/glog/src/config_mac.h @@ -122,13 +122,13 @@ #define PACKAGE_NAME "glog" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "glog 0.3.1" +#define PACKAGE_STRING "glog 0.3.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "glog" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.3.1" +#define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ #undef PC_FROM_UCONTEXT @@ -150,10 +150,16 @@ #define TEST_SRC_DIR "." /* Version number of package */ -#define VERSION "0.3.1" +#define VERSION "0.3.2" /* Stops putting the code inside the Google namespace */ #define _END_GOOGLE_NAMESPACE_ } /* Puts following code inside the Google namespace */ #define _START_GOOGLE_NAMESPACE_ namespace google { + +/* isn't getting defined by configure script when clang compilers are used + and cuases compilation errors in stactrace/unwind modules */ +#ifdef __clang__ +# define NO_FRAME_POINTER +#endif diff --git a/extern/libmv/third_party/glog/src/demangle.cc b/extern/libmv/third_party/glog/src/demangle.cc index 46556bf3c13..0daf30893b3 100644 --- a/extern/libmv/third_party/glog/src/demangle.cc +++ b/extern/libmv/third_party/glog/src/demangle.cc @@ -28,6 +28,11 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Author: Satoru Takabayashi +// +// For reference check out: +// http://www.codesourcery.com/public/cxx-abi/abi.html#mangling +// +// Note that we only have partial C++0x support yet. #include // for NULL #include "demangle.h" @@ -138,14 +143,12 @@ static const AbbrevPair kSubstitutionList[] = { // State needed for demangling. typedef struct { const char *mangled_cur; // Cursor of mangled name. - const char *mangled_end; // End of mangled name. char *out_cur; // Cursor of output string. const char *out_begin; // Beginning of output string. const char *out_end; // End of output string. const char *prev_name; // For constructors/destructors. int prev_name_length; // For constructors/destructors. - int nest_level; // For nested names. - int number; // Remember the previous number. + short nest_level; // For nested names. bool append; // Append flag. bool overflowed; // True if output gets overflowed. } State; @@ -161,6 +164,16 @@ static size_t StrLen(const char *str) { return len; } +// Returns true if "str" has at least "n" characters remaining. +static bool AtLeastNumCharsRemaining(const char *str, int n) { + for (int i = 0; i < n; ++i) { + if (str == '\0') { + return false; + } + } + return true; +} + // Returns true if "str" has "prefix" as a prefix. static bool StrPrefix(const char *str, const char *prefix) { size_t i = 0; @@ -174,39 +187,33 @@ static bool StrPrefix(const char *str, const char *prefix) { static void InitState(State *state, const char *mangled, char *out, int out_size) { state->mangled_cur = mangled; - state->mangled_end = mangled + StrLen(mangled); state->out_cur = out; state->out_begin = out; state->out_end = out + out_size; state->prev_name = NULL; state->prev_name_length = -1; state->nest_level = -1; - state->number = -1; state->append = true; state->overflowed = false; } -// Calculates the remaining length of the mangled name. -static int RemainingLength(State *state) { - return state->mangled_end - state->mangled_cur; -} - -// Returns true and advances "mangled_cur" if we find "c" at -// "mangled_cur" position. -static bool ParseChar(State *state, const char c) { - if (RemainingLength(state) >= 1 && *state->mangled_cur == c) { +// Returns true and advances "mangled_cur" if we find "one_char_token" +// at "mangled_cur" position. It is assumed that "one_char_token" does +// not contain '\0'. +static bool ParseOneCharToken(State *state, const char one_char_token) { + if (state->mangled_cur[0] == one_char_token) { ++state->mangled_cur; return true; } return false; } -// Returns true and advances "mangled_cur" if we find "two_chars" at -// "mangled_cur" position. -static bool ParseTwoChar(State *state, const char *two_chars) { - if (RemainingLength(state) >= 2 && - state->mangled_cur[0] == two_chars[0] && - state->mangled_cur[1] == two_chars[1]) { +// Returns true and advances "mangled_cur" if we find "two_char_token" +// at "mangled_cur" position. It is assumed that "two_char_token" does +// not contain '\0'. +static bool ParseTwoCharToken(State *state, const char *two_char_token) { + if (state->mangled_cur[0] == two_char_token[0] && + state->mangled_cur[1] == two_char_token[1]) { state->mangled_cur += 2; return true; } @@ -216,13 +223,13 @@ static bool ParseTwoChar(State *state, const char *two_chars) { // Returns true and advances "mangled_cur" if we find any character in // "char_class" at "mangled_cur" position. static bool ParseCharClass(State *state, const char *char_class) { - if (state->mangled_cur == state->mangled_end) { + if (state->mangled_cur == '\0') { return false; } const char *p = char_class; for (; *p != '\0'; ++p) { - if (*state->mangled_cur == *p) { - state->mangled_cur += 1; + if (state->mangled_cur[0] == *p) { + ++state->mangled_cur; return true; } } @@ -230,7 +237,7 @@ static bool ParseCharClass(State *state, const char *char_class) { } // This function is used for handling an optional non-terminal. -static bool Optional(bool status) { +static bool Optional(bool) { return true; } @@ -245,6 +252,16 @@ static bool OneOrMore(ParseFunc parse_func, State *state) { return false; } +// This function is used for handling * syntax. The function +// always returns true and must be followed by a termination token or a +// terminating sequence not handled by parse_func (e.g. +// ParseOneCharToken(state, 'E')). +static bool ZeroOrMore(ParseFunc parse_func, State *state) { + while (parse_func(state)) { + } + return true; +} + // Append "str" at "out_cur". If there is an overflow, "overflowed" // is set to true for later use. The output string is ensured to // always terminate with '\0' as long as there is no overflow. @@ -270,7 +287,37 @@ static bool IsLower(char c) { } static bool IsAlpha(char c) { - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); +} + +static bool IsDigit(char c) { + return c >= '0' && c <= '9'; +} + +// Returns true if "str" is a function clone suffix. These suffixes are used +// by GCC 4.5.x and later versions to indicate functions which have been +// cloned during optimization. We treat any sequence (.+.+)+ as +// a function clone suffix. +static bool IsFunctionCloneSuffix(const char *str) { + size_t i = 0; + while (str[i] != '\0') { + // Consume a single .+.+ sequence. + if (str[i] != '.' || !IsAlpha(str[i + 1])) { + return false; + } + i += 2; + while (IsAlpha(str[i])) { + ++i; + } + if (str[i] != '.' || !IsDigit(str[i + 1])) { + return false; + } + i += 2; + while (IsDigit(str[i])) { + ++i; + } + } + return true; // Consumed everything in "str". } // Append "str" with some tweaks, iff "append" state is true. @@ -309,7 +356,7 @@ static bool EnterNestedName(State *state) { } // This function is used for handling nested names. -static bool LeaveNestedName(State *state, int prev_value) { +static bool LeaveNestedName(State *state, short prev_value) { state->nest_level = prev_value; return true; } @@ -349,11 +396,11 @@ static void MaybeCancelLastSeparator(State *state) { } } -// Returns true if identifier pointed by "mangled_cur" is anonymous -// namespace. -static bool IdentifierIsAnonymousNamespace(State *state) { - const char anon_prefix[] = "_GLOBAL__N_"; - return (state->number > sizeof(anon_prefix) - 1 && // Should be longer. +// Returns true if the identifier of the given length pointed to by +// "mangled_cur" is anonymous namespace. +static bool IdentifierIsAnonymousNamespace(State *state, int length) { + static const char anon_prefix[] = "_GLOBAL__N_"; + return (length > (int)sizeof(anon_prefix) - 1 && // Should be longer. StrPrefix(state->mangled_cur, anon_prefix)); } @@ -368,10 +415,10 @@ static bool ParsePrefix(State *state); static bool ParseUnqualifiedName(State *state); static bool ParseSourceName(State *state); static bool ParseLocalSourceName(State *state); -static bool ParseNumber(State *state); +static bool ParseNumber(State *state, int *number_out); static bool ParseFloatNumber(State *state); static bool ParseSeqId(State *state); -static bool ParseIdentifier(State *state); +static bool ParseIdentifier(State *state, int length); static bool ParseOperatorName(State *state); static bool ParseSpecialName(State *state); static bool ParseCallOffset(State *state); @@ -428,17 +475,7 @@ static bool ParseSubstitution(State *state); // ::= _Z static bool ParseMangledName(State *state) { - if (ParseTwoChar(state, "_Z") && ParseEncoding(state)) { - // Append trailing version suffix if any. - // ex. _Z3foo@@GLIBCXX_3.4 - if (state->mangled_cur < state->mangled_end && - state->mangled_cur[0] == '@') { - MaybeAppend(state, state->mangled_cur); - state->mangled_cur = state->mangled_end; - } - return true; - } - return false; + return ParseTwoCharToken(state, "_Z") && ParseEncoding(state); } // ::= <(function) name> @@ -488,7 +525,7 @@ static bool ParseUnscopedName(State *state) { } State copy = *state; - if (ParseTwoChar(state, "St") && + if (ParseTwoCharToken(state, "St") && MaybeAppend(state, "std::") && ParseUnqualifiedName(state)) { return true; @@ -507,12 +544,12 @@ static bool ParseUnscopedTemplateName(State *state) { // ::= N [] E static bool ParseNestedName(State *state) { State copy = *state; - if (ParseChar(state, 'N') && + if (ParseOneCharToken(state, 'N') && EnterNestedName(state) && Optional(ParseCVQualifiers(state)) && ParsePrefix(state) && LeaveNestedName(state, copy.nest_level) && - ParseChar(state, 'E')) { + ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -565,7 +602,8 @@ static bool ParseUnqualifiedName(State *state) { // ::= static bool ParseSourceName(State *state) { State copy = *state; - if (ParseNumber(state) && ParseIdentifier(state)) { + int length = -1; + if (ParseNumber(state, &length) && ParseIdentifier(state, length)) { return true; } *state = copy; @@ -579,7 +617,7 @@ static bool ParseSourceName(State *state) { // http://gcc.gnu.org/viewcvs?view=rev&revision=124467 static bool ParseLocalSourceName(State *state) { State copy = *state; - if (ParseChar(state, 'L') && ParseSourceName(state) && + if (ParseOneCharToken(state, 'L') && ParseSourceName(state) && Optional(ParseDiscriminator(state))) { return true; } @@ -588,15 +626,17 @@ static bool ParseLocalSourceName(State *state) { } // ::= [n] -static bool ParseNumber(State *state) { +// If "number_out" is non-null, then *number_out is set to the value of the +// parsed number on success. +static bool ParseNumber(State *state, int *number_out) { int sign = 1; - if (ParseChar(state, 'n')) { + if (ParseOneCharToken(state, 'n')) { sign = -1; } const char *p = state->mangled_cur; int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { + for (;*p != '\0'; ++p) { + if (IsDigit(*p)) { number = number * 10 + (*p - '0'); } else { break; @@ -604,7 +644,9 @@ static bool ParseNumber(State *state) { } if (p != state->mangled_cur) { // Conversion succeeded. state->mangled_cur = p; - state->number = number * sign; + if (number_out != NULL) { + *number_out = number * sign; + } return true; } return false; @@ -614,19 +656,13 @@ static bool ParseNumber(State *state) { // hexadecimal string. static bool ParseFloatNumber(State *state) { const char *p = state->mangled_cur; - int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { - number = number * 16 + (*p - '0'); - } else if (*p >= 'a' && *p <= 'f') { - number = number * 16 + (*p - 'a' + 10); - } else { + for (;*p != '\0'; ++p) { + if (!IsDigit(*p) && !(*p >= 'a' && *p <= 'f')) { break; } } if (p != state->mangled_cur) { // Conversion succeeded. state->mangled_cur = p; - state->number = number; return true; } return false; @@ -636,37 +672,30 @@ static bool ParseFloatNumber(State *state) { // using digits and upper case letters static bool ParseSeqId(State *state) { const char *p = state->mangled_cur; - int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { - number = number * 36 + (*p - '0'); - } else if (*p >= 'A' && *p <= 'Z') { - number = number * 36 + (*p - 'A' + 10); - } else { + for (;*p != '\0'; ++p) { + if (!IsDigit(*p) && !(*p >= 'A' && *p <= 'Z')) { break; } } if (p != state->mangled_cur) { // Conversion succeeded. state->mangled_cur = p; - state->number = number; return true; } return false; } -// ::= -static bool ParseIdentifier(State *state) { - if (state->number == -1 || - RemainingLength(state) < state->number) { +// ::= (of given length) +static bool ParseIdentifier(State *state, int length) { + if (length == -1 || + !AtLeastNumCharsRemaining(state->mangled_cur, length)) { return false; } - if (IdentifierIsAnonymousNamespace(state)) { + if (IdentifierIsAnonymousNamespace(state, length)) { MaybeAppend(state, "(anonymous namespace)"); } else { - MaybeAppendWithLength(state, state->mangled_cur, state->number); + MaybeAppendWithLength(state, state->mangled_cur, length); } - state->mangled_cur += state->number; - state->number = -1; // Reset the number. + state->mangled_cur += length; return true; } @@ -674,12 +703,12 @@ static bool ParseIdentifier(State *state) { // ::= cv # (cast) // ::= v # vendor extended operator static bool ParseOperatorName(State *state) { - if (RemainingLength(state) < 2) { + if (!AtLeastNumCharsRemaining(state->mangled_cur, 2)) { return false; } // First check with "cv" (cast) case. State copy = *state; - if (ParseTwoChar(state, "cv") && + if (ParseTwoCharToken(state, "cv") && MaybeAppend(state, "operator ") && EnterNestedName(state) && ParseType(state) && @@ -689,7 +718,7 @@ static bool ParseOperatorName(State *state) { *state = copy; // Then vendor extended operators. - if (ParseChar(state, 'v') && ParseCharClass(state, "0123456789") && + if (ParseOneCharToken(state, 'v') && ParseCharClass(state, "0123456789") && ParseSourceName(state)) { return true; } @@ -738,34 +767,34 @@ static bool ParseOperatorName(State *state) { // stack traces. The are special data. static bool ParseSpecialName(State *state) { State copy = *state; - if (ParseChar(state, 'T') && + if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "VTIS") && ParseType(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "Tc") && ParseCallOffset(state) && + if (ParseTwoCharToken(state, "Tc") && ParseCallOffset(state) && ParseCallOffset(state) && ParseEncoding(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "GV") && + if (ParseTwoCharToken(state, "GV") && ParseName(state)) { return true; } *state = copy; - if (ParseChar(state, 'T') && ParseCallOffset(state) && + if (ParseOneCharToken(state, 'T') && ParseCallOffset(state) && ParseEncoding(state)) { return true; } *state = copy; // G++ extensions - if (ParseTwoChar(state, "TC") && ParseType(state) && - ParseNumber(state) && ParseChar(state, '_') && + if (ParseTwoCharToken(state, "TC") && ParseType(state) && + ParseNumber(state, NULL) && ParseOneCharToken(state, '_') && DisableAppend(state) && ParseType(state)) { RestoreAppend(state, copy.append); @@ -773,23 +802,23 @@ static bool ParseSpecialName(State *state) { } *state = copy; - if (ParseChar(state, 'T') && ParseCharClass(state, "FJ") && + if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "FJ") && ParseType(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "GR") && ParseName(state)) { + if (ParseTwoCharToken(state, "GR") && ParseName(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "GA") && ParseEncoding(state)) { + if (ParseTwoCharToken(state, "GA") && ParseEncoding(state)) { return true; } *state = copy; - if (ParseChar(state, 'T') && ParseCharClass(state, "hv") && + if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "hv") && ParseCallOffset(state) && ParseEncoding(state)) { return true; } @@ -801,14 +830,14 @@ static bool ParseSpecialName(State *state) { // ::= v _ static bool ParseCallOffset(State *state) { State copy = *state; - if (ParseChar(state, 'h') && - ParseNVOffset(state) && ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'h') && + ParseNVOffset(state) && ParseOneCharToken(state, '_')) { return true; } *state = copy; - if (ParseChar(state, 'v') && - ParseVOffset(state) && ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'v') && + ParseVOffset(state) && ParseOneCharToken(state, '_')) { return true; } *state = copy; @@ -818,14 +847,14 @@ static bool ParseCallOffset(State *state) { // ::= <(offset) number> static bool ParseNVOffset(State *state) { - return ParseNumber(state); + return ParseNumber(state, NULL); } // ::= <(offset) number> _ <(virtual offset) number> static bool ParseVOffset(State *state) { State copy = *state; - if (ParseNumber(state) && ParseChar(state, '_') && - ParseNumber(state)) { + if (ParseNumber(state, NULL) && ParseOneCharToken(state, '_') && + ParseNumber(state, NULL)) { return true; } *state = copy; @@ -836,7 +865,7 @@ static bool ParseVOffset(State *state) { // ::= D0 | D1 | D2 static bool ParseCtorDtorName(State *state) { State copy = *state; - if (ParseChar(state, 'C') && + if (ParseOneCharToken(state, 'C') && ParseCharClass(state, "123")) { const char * const prev_name = state->prev_name; const int prev_name_length = state->prev_name_length; @@ -845,7 +874,7 @@ static bool ParseCtorDtorName(State *state) { } *state = copy; - if (ParseChar(state, 'D') && + if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "012")) { const char * const prev_name = state->prev_name; const int prev_name_length = state->prev_name_length; @@ -858,11 +887,12 @@ static bool ParseCtorDtorName(State *state) { } // ::= -// ::= P -// ::= R -// ::= C -// ::= G -// ::= U +// ::= P # pointer-to +// ::= R # reference-to +// ::= O # rvalue reference-to (C++0x) +// ::= C # complex pair (C 2000) +// ::= G # imaginary (C 2000) +// ::= U # vendor extended type qualifier // ::= // ::= // ::= @@ -871,6 +901,11 @@ static bool ParseCtorDtorName(State *state) { // ::= // ::= // ::= +// ::= Dp # pack expansion of (C++0x) +// ::= Dt E # decltype of an id-expression or class +// # member access (C++0x) +// ::= DT E # decltype of an expression (C++0x) +// static bool ParseType(State *state) { // We should check CV-qualifers, and PRGC things first. State copy = *state; @@ -879,12 +914,23 @@ static bool ParseType(State *state) { } *state = copy; - if (ParseCharClass(state, "PRCG") && ParseType(state)) { + if (ParseCharClass(state, "OPRCG") && ParseType(state)) { + return true; + } + *state = copy; + + if (ParseTwoCharToken(state, "Dp") && ParseType(state)) { return true; } *state = copy; - if (ParseChar(state, 'U') && ParseSourceName(state) && + if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "tT") && + ParseExpression(state) && ParseOneCharToken(state, 'E')) { + return true; + } + *state = copy; + + if (ParseOneCharToken(state, 'U') && ParseSourceName(state) && ParseType(state)) { return true; } @@ -918,9 +964,9 @@ static bool ParseType(State *state) { // ParseType(). static bool ParseCVQualifiers(State *state) { int num_cv_qualifiers = 0; - num_cv_qualifiers += ParseChar(state, 'r'); - num_cv_qualifiers += ParseChar(state, 'V'); - num_cv_qualifiers += ParseChar(state, 'K'); + num_cv_qualifiers += ParseOneCharToken(state, 'r'); + num_cv_qualifiers += ParseOneCharToken(state, 'V'); + num_cv_qualifiers += ParseOneCharToken(state, 'K'); return num_cv_qualifiers > 0; } @@ -937,7 +983,7 @@ static bool ParseBuiltinType(State *state) { } State copy = *state; - if (ParseChar(state, 'u') && ParseSourceName(state)) { + if (ParseOneCharToken(state, 'u') && ParseSourceName(state)) { return true; } *state = copy; @@ -947,8 +993,9 @@ static bool ParseBuiltinType(State *state) { // ::= F [Y] E static bool ParseFunctionType(State *state) { State copy = *state; - if (ParseChar(state, 'F') && Optional(ParseChar(state, 'Y')) && - ParseBareFunctionType(state) && ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'F') && + Optional(ParseOneCharToken(state, 'Y')) && + ParseBareFunctionType(state) && ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -977,14 +1024,14 @@ static bool ParseClassEnumType(State *state) { // ::= A [<(dimension) expression>] _ <(element) type> static bool ParseArrayType(State *state) { State copy = *state; - if (ParseChar(state, 'A') && ParseNumber(state) && - ParseChar(state, '_') && ParseType(state)) { + if (ParseOneCharToken(state, 'A') && ParseNumber(state, NULL) && + ParseOneCharToken(state, '_') && ParseType(state)) { return true; } *state = copy; - if (ParseChar(state, 'A') && Optional(ParseExpression(state)) && - ParseChar(state, '_') && ParseType(state)) { + if (ParseOneCharToken(state, 'A') && Optional(ParseExpression(state)) && + ParseOneCharToken(state, '_') && ParseType(state)) { return true; } *state = copy; @@ -994,7 +1041,7 @@ static bool ParseArrayType(State *state) { // ::= M <(class) type> <(member) type> static bool ParsePointerToMemberType(State *state) { State copy = *state; - if (ParseChar(state, 'M') && ParseType(state) && + if (ParseOneCharToken(state, 'M') && ParseType(state) && ParseType(state)) { return true; } @@ -1005,14 +1052,14 @@ static bool ParsePointerToMemberType(State *state) { // ::= T_ // ::= T _ static bool ParseTemplateParam(State *state) { - if (ParseTwoChar(state, "T_")) { + if (ParseTwoCharToken(state, "T_")) { MaybeAppend(state, "?"); // We don't support template substitutions. return true; } State copy = *state; - if (ParseChar(state, 'T') && ParseNumber(state) && - ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'T') && ParseNumber(state, NULL) && + ParseOneCharToken(state, '_')) { MaybeAppend(state, "?"); // We don't support template substitutions. return true; } @@ -1032,9 +1079,9 @@ static bool ParseTemplateTemplateParam(State *state) { static bool ParseTemplateArgs(State *state) { State copy = *state; DisableAppend(state); - if (ParseChar(state, 'I') && + if (ParseOneCharToken(state, 'I') && OneOrMore(ParseTemplateArg, state) && - ParseChar(state, 'E')) { + ParseOneCharToken(state, 'E')) { RestoreAppend(state, copy.append); MaybeAppend(state, "<>"); return true; @@ -1045,16 +1092,25 @@ static bool ParseTemplateArgs(State *state) { // ::= // ::= +// ::= I * E # argument pack // ::= X E static bool ParseTemplateArg(State *state) { + State copy = *state; + if (ParseOneCharToken(state, 'I') && + ZeroOrMore(ParseTemplateArg, state) && + ParseOneCharToken(state, 'E')) { + return true; + } + *state = copy; + if (ParseType(state) || ParseExprPrimary(state)) { return true; } + *state = copy; - State copy = *state; - if (ParseChar(state, 'X') && ParseExpression(state) && - ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'X') && ParseExpression(state) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -1097,19 +1153,19 @@ static bool ParseExpression(State *state) { } *state = copy; - if (ParseTwoChar(state, "st") && ParseType(state)) { + if (ParseTwoCharToken(state, "st") && ParseType(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "sr") && ParseType(state) && + if (ParseTwoCharToken(state, "sr") && ParseType(state) && ParseUnqualifiedName(state) && ParseTemplateArgs(state)) { return true; } *state = copy; - if (ParseTwoChar(state, "sr") && ParseType(state) && + if (ParseTwoCharToken(state, "sr") && ParseType(state) && ParseUnqualifiedName(state)) { return true; } @@ -1124,28 +1180,28 @@ static bool ParseExpression(State *state) { // ::= LZ E static bool ParseExprPrimary(State *state) { State copy = *state; - if (ParseChar(state, 'L') && ParseType(state) && - ParseNumber(state) && - ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'L') && ParseType(state) && + ParseNumber(state, NULL) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; - if (ParseChar(state, 'L') && ParseType(state) && + if (ParseOneCharToken(state, 'L') && ParseType(state) && ParseFloatNumber(state) && - ParseChar(state, 'E')) { + ParseOneCharToken(state, 'E')) { return true; } *state = copy; - if (ParseChar(state, 'L') && ParseMangledName(state) && - ParseChar(state, 'E')) { + if (ParseOneCharToken(state, 'L') && ParseMangledName(state) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; - if (ParseTwoChar(state, "LZ") && ParseEncoding(state) && - ParseChar(state, 'E')) { + if (ParseTwoCharToken(state, "LZ") && ParseEncoding(state) && + ParseOneCharToken(state, 'E')) { return true; } *state = copy; @@ -1158,15 +1214,15 @@ static bool ParseExprPrimary(State *state) { // := Z <(function) encoding> E s [] static bool ParseLocalName(State *state) { State copy = *state; - if (ParseChar(state, 'Z') && ParseEncoding(state) && - ParseChar(state, 'E') && MaybeAppend(state, "::") && + if (ParseOneCharToken(state, 'Z') && ParseEncoding(state) && + ParseOneCharToken(state, 'E') && MaybeAppend(state, "::") && ParseName(state) && Optional(ParseDiscriminator(state))) { return true; } *state = copy; - if (ParseChar(state, 'Z') && ParseEncoding(state) && - ParseTwoChar(state, "Es") && Optional(ParseDiscriminator(state))) { + if (ParseOneCharToken(state, 'Z') && ParseEncoding(state) && + ParseTwoCharToken(state, "Es") && Optional(ParseDiscriminator(state))) { return true; } *state = copy; @@ -1176,7 +1232,7 @@ static bool ParseLocalName(State *state) { // := _ <(non-negative) number> static bool ParseDiscriminator(State *state) { State copy = *state; - if (ParseChar(state, '_') && ParseNumber(state)) { + if (ParseOneCharToken(state, '_') && ParseNumber(state, NULL)) { return true; } *state = copy; @@ -1187,21 +1243,21 @@ static bool ParseDiscriminator(State *state) { // ::= S _ // ::= St, etc. static bool ParseSubstitution(State *state) { - if (ParseTwoChar(state, "S_")) { + if (ParseTwoCharToken(state, "S_")) { MaybeAppend(state, "?"); // We don't support substitutions. return true; } State copy = *state; - if (ParseChar(state, 'S') && ParseSeqId(state) && - ParseChar(state, '_')) { + if (ParseOneCharToken(state, 'S') && ParseSeqId(state) && + ParseOneCharToken(state, '_')) { MaybeAppend(state, "?"); // We don't support substitutions. return true; } *state = copy; // Expand abbreviations like "St" => "std". - if (ParseChar(state, 'S')) { + if (ParseOneCharToken(state, 'S')) { const AbbrevPair *p; for (p = kSubstitutionList; p->abbrev != NULL; ++p) { if (state->mangled_cur[0] == p->abbrev[1]) { @@ -1210,7 +1266,7 @@ static bool ParseSubstitution(State *state) { MaybeAppend(state, "::"); MaybeAppend(state, p->real_name); } - state->mangled_cur += 1; + ++state->mangled_cur; return true; } } @@ -1219,13 +1275,33 @@ static bool ParseSubstitution(State *state) { return false; } +// Parse , optionally followed by either a function-clone suffix +// or version suffix. Returns true only if all of "mangled_cur" was consumed. +static bool ParseTopLevelMangledName(State *state) { + if (ParseMangledName(state)) { + if (state->mangled_cur[0] != '\0') { + // Drop trailing function clone suffix, if any. + if (IsFunctionCloneSuffix(state->mangled_cur)) { + return true; + } + // Append trailing version suffix if any. + // ex. _Z3foo@@GLIBCXX_3.4 + if (state->mangled_cur[0] == '@') { + MaybeAppend(state, state->mangled_cur); + return true; + } + return false; // Unconsumed suffix. + } + return true; + } + return false; +} + // The demangler entry point. bool Demangle(const char *mangled, char *out, int out_size) { State state; InitState(&state, mangled, out, out_size); - return (ParseMangledName(&state) && - state.overflowed == false && - RemainingLength(&state) == 0); + return ParseTopLevelMangledName(&state) && !state.overflowed; } _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/glog/log_severity.h b/extern/libmv/third_party/glog/src/glog/log_severity.h index 17805fbadd4..99945a426da 100644 --- a/extern/libmv/third_party/glog/src/glog/log_severity.h +++ b/extern/libmv/third_party/glog/src/glog/log_severity.h @@ -44,7 +44,15 @@ // you ever need to change their values or add a new severity. typedef int LogSeverity; -const int INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3, NUM_SEVERITIES = 4; +const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3, + NUM_SEVERITIES = 4; +#ifndef GLOG_NO_ABBREVIATED_SEVERITIES +# ifdef ERROR +# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail. +# endif +const int INFO = GLOG_INFO, WARNING = GLOG_WARNING, + ERROR = GLOG_ERROR, FATAL = GLOG_FATAL; +#endif // DFATAL is FATAL in debug mode, ERROR in normal mode #ifdef NDEBUG diff --git a/extern/libmv/third_party/glog/src/glog/logging.h b/extern/libmv/third_party/glog/src/glog/logging.h index a58d478ab17..005649c17c2 100644 --- a/extern/libmv/third_party/glog/src/glog/logging.h +++ b/extern/libmv/third_party/glog/src/glog/logging.h @@ -33,7 +33,6 @@ // Pretty much everybody needs to #include this file so that they can // log various happenings. // - #ifndef _LOGGING_H_ #define _LOGGING_H_ @@ -80,7 +79,7 @@ #endif #if 1 -#include "third_party/gflags/gflags.h" +#include "third_party/gflags/gflags/gflags.h" #endif namespace google { @@ -153,21 +152,21 @@ typedef unsigned __int64 uint64; // You can also do occasional logging (log every n'th occurrence of an // event): // -// LOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // The above will cause log messages to be output on the 1st, 11th, 21st, ... -// times it is executed. Note that the special COUNTER value is used to -// identify which repetition is happening. +// times it is executed. Note that the special google::COUNTER value is used +// to identify which repetition is happening. // // You can also do occasional conditional logging (log every n'th // occurrence of an event, when condition is satisfied): // -// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER +// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER // << "th big cookie"; // // You can log messages the first N times your code executes a line. E.g. // -// LOG_FIRST_N(INFO, 20) << "Got the " << COUNTER << "th cookie"; +// LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie"; // // Outputs log messages for the first 20 times it is executed. // @@ -184,7 +183,7 @@ typedef unsigned __int64 uint64; // // DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies"; // -// DLOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // All "debug mode" logging is compiled away to nothing for non-debug mode // compiles. @@ -228,11 +227,11 @@ typedef unsigned __int64 uint64; // "program with --v=1 or more"; // VLOG_EVERY_N(1, 10) // << "I'm printed every 10th occurrence, and when you run the program " -// "with --v=1 or more. Present occurence is " << COUNTER; +// "with --v=1 or more. Present occurence is " << google::COUNTER; // VLOG_IF_EVERY_N(1, (size > 1024), 10) // << "I'm printed on every 10th occurence of case when size is more " // " than 1024, when you run the program with --v=1 or more. "; -// "Present occurence is " << COUNTER; +// "Present occurence is " << google::COUNTER; // // The supported severity levels for macros that allow you to specify one // are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL. @@ -369,7 +368,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \ __FILE__, __LINE__) #define LOG_TO_STRING_INFO(message) google::LogMessage( \ - __FILE__, __LINE__, google::INFO, message) + __FILE__, __LINE__, google::GLOG_INFO, message) #else #define COMPACT_GOOGLE_LOG_INFO google::NullStream() #define LOG_TO_STRING_INFO(message) google::NullStream() @@ -377,9 +376,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 1 #define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \ - __FILE__, __LINE__, google::WARNING) + __FILE__, __LINE__, google::GLOG_WARNING) #define LOG_TO_STRING_WARNING(message) google::LogMessage( \ - __FILE__, __LINE__, google::WARNING, message) + __FILE__, __LINE__, google::GLOG_WARNING, message) #else #define COMPACT_GOOGLE_LOG_WARNING google::NullStream() #define LOG_TO_STRING_WARNING(message) google::NullStream() @@ -387,9 +386,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 2 #define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \ - __FILE__, __LINE__, google::ERROR) + __FILE__, __LINE__, google::GLOG_ERROR) #define LOG_TO_STRING_ERROR(message) google::LogMessage( \ - __FILE__, __LINE__, google::ERROR, message) + __FILE__, __LINE__, google::GLOG_ERROR, message) #else #define COMPACT_GOOGLE_LOG_ERROR google::NullStream() #define LOG_TO_STRING_ERROR(message) google::NullStream() @@ -399,7 +398,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \ __FILE__, __LINE__) #define LOG_TO_STRING_FATAL(message) google::LogMessage( \ - __FILE__, __LINE__, google::FATAL, message) + __FILE__, __LINE__, google::GLOG_FATAL, message) #else #define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal() #define LOG_TO_STRING_FATAL(message) google::NullStreamFatal() @@ -411,32 +410,32 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR #elif GOOGLE_STRIP_LOG <= 3 #define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \ - __FILE__, __LINE__, google::FATAL) + __FILE__, __LINE__, google::GLOG_FATAL) #else #define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal() #endif -#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::INFO, counter, &google::LogMessage::SendToLog) +#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog) #define SYSLOG_INFO(counter) \ - google::LogMessage(__FILE__, __LINE__, google::INFO, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_DFATAL(counter) \ google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ @@ -455,7 +454,7 @@ DECLARE_bool(stop_logging_if_full_disk); FORMAT_MESSAGE_FROM_SYSTEM, \ 0, result, 0, msg, 100, NULL); \ if (message_length > 0) { \ - google::LogMessage(__FILE__, __LINE__, ERROR, 0, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \ &google::LogMessage::SendToLog).stream() << message; \ LocalFree(message); \ } \ @@ -502,12 +501,12 @@ class LogSink; // defined below #define LOG_TO_SINK(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), true).stream() #define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), false).stream() // If a non-NULL string pointer is given, we write this message to that string. @@ -772,7 +771,7 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false) #define GOOGLE_PLOG(severity, counter) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, counter, \ + __FILE__, __LINE__, google::GLOG_ ## severity, counter, \ &google::LogMessage::SendToLog) #define PLOG_IF(severity, condition) \ @@ -811,7 +810,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ @@ -820,7 +819,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (condition && \ ((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ @@ -829,7 +828,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ @@ -838,7 +837,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ ++LOG_OCCURRENCES; \ if (LOG_OCCURRENCES <= n) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() namespace glog_internal_namespace_ { @@ -852,7 +851,7 @@ struct CrashReason; typedef google::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] #define LOG_EVERY_N(severity, n) \ - GOOGLE_GLOG_COMPILE_ASSERT(google::severity < \ + GOOGLE_GLOG_COMPILE_ASSERT(google::GLOG_ ## severity < \ google::NUM_SEVERITIES, \ INVALID_REQUESTED_LOG_SEVERITY); \ SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog) @@ -872,6 +871,27 @@ struct CrashReason; // We want the special COUNTER value available for LOG_EVERY_X()'ed messages enum PRIVATE_Counter {COUNTER}; +#ifdef GLOG_NO_ABBREVIATED_SEVERITIES +// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets +// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us +// to keep using this syntax, we define this macro to do the same thing +// as COMPACT_GOOGLE_LOG_ERROR. +#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR +#define SYSLOG_0 SYSLOG_ERROR +#define LOG_TO_STRING_0 LOG_TO_STRING_ERROR +// Needed for LOG_IS_ON(ERROR). +const LogSeverity GLOG_0 = GLOG_ERROR; +#else +// Users may include windows.h after logging.h without +// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN. +// For this case, we cannot detect if ERROR is defined before users +// actually use ERROR. Let's make an undefined symbol to warn users. +# define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail +# define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG +# define SYSLOG_0 GLOG_ERROR_MSG +# define LOG_TO_STRING_0 GLOG_ERROR_MSG +# define GLOG_0 GLOG_ERROR_MSG +#endif // Plus some debug-logging macros that get compiled to nothing for production @@ -1016,14 +1036,14 @@ public: # pragma warning(default: 4275) #endif public: - LogStream(char *buf, int len, int ctr) + LogStream(char *buf, int len, int ctr_in) : ostrstream(buf, len), - ctr_(ctr) { + ctr_(ctr_in) { self_ = this; } int ctr() const { return ctr_; } - void set_ctr(int ctr) { ctr_ = ctr; } + void set_ctr(int ctr_in) { ctr_ = ctr_in; } LogStream* self() const { return self_; } private: @@ -1465,7 +1485,7 @@ class GOOGLE_GLOG_DLL_DECL NullStream : public LogMessage::LogStream { // converted to LogStream and the message will be computed and then // quietly discarded. template -inline NullStream& operator<<(NullStream &str, const T &value) { return str; } +inline NullStream& operator<<(NullStream &str, const T &) { return str; } // Similar to NullStream, but aborts the program (without stack // trace), like LogMessageFatal. diff --git a/extern/libmv/third_party/glog/src/glog/raw_logging.h b/extern/libmv/third_party/glog/src/glog/raw_logging.h index 9e9b3772f3b..65278f62803 100644 --- a/extern/libmv/third_party/glog/src/glog/raw_logging.h +++ b/extern/libmv/third_party/glog/src/glog/raw_logging.h @@ -68,7 +68,7 @@ namespace google { // I0821 211317 file.cc:142] RAW: status is 20 #define RAW_LOG(severity, ...) \ do { \ - switch (google::severity) { \ + switch (google::GLOG_ ## severity) { \ case 0: \ RAW_LOG_INFO(__VA_ARGS__); \ break; \ @@ -100,28 +100,28 @@ namespace google { #endif // STRIP_LOG == 0 #if STRIP_LOG == 0 -#define RAW_LOG_INFO(...) google::RawLog__(google::INFO, \ +#define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG == 0 #if STRIP_LOG <= 1 -#define RAW_LOG_WARNING(...) google::RawLog__(google::WARNING, \ +#define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 1 #if STRIP_LOG <= 2 -#define RAW_LOG_ERROR(...) google::RawLog__(google::ERROR, \ +#define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 2 #if STRIP_LOG <= 3 -#define RAW_LOG_FATAL(...) google::RawLog__(google::FATAL, \ +#define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_FATAL(...) \ @@ -162,7 +162,7 @@ namespace google { // Stub log function used to work around for unused variable warnings when // building with STRIP_LOG > 0. -static inline void RawLogStub__(int ignored, ...) { +static inline void RawLogStub__(int /* ignored */, ...) { } // Helper function to implement RAW_LOG and RAW_VLOG diff --git a/extern/libmv/third_party/glog/src/logging.cc b/extern/libmv/third_party/glog/src/logging.cc index 1bb3867aa10..bf4d85be5b3 100644 --- a/extern/libmv/third_party/glog/src/logging.cc +++ b/extern/libmv/third_party/glog/src/logging.cc @@ -111,7 +111,7 @@ _END_GOOGLE_NAMESPACE_ // The default is ERROR instead of FATAL so that users can see problems // when they run a program without having to look in another file. DEFINE_int32(stderrthreshold, - GOOGLE_NAMESPACE::ERROR, + GOOGLE_NAMESPACE::GLOG_ERROR, "log messages at or above this level are copied to stderr in " "addition to logfiles. This flag obsoletes --alsologtostderr."); @@ -311,8 +311,10 @@ class LogDestination { static const int kNetworkBytes = 1400; static const string& hostname(); - private: + static void DeleteLogDestinations(); + + private: LogDestination(LogSeverity severity, const char* base_filename); ~LogDestination() { } @@ -503,7 +505,7 @@ inline void LogDestination::SetEmailLogging(LogSeverity min_severity, static void WriteToStderr(const char* message, size_t len) { // Avoid using cerr from this module since we may get called during // exit code, and cerr may be partially or fully destroyed by then. - write(STDERR_FILENO, message, len); + fwrite(message, len, 1, stderr); } inline void LogDestination::MaybeLogToStderr(LogSeverity severity, @@ -607,6 +609,13 @@ inline LogDestination* LogDestination::log_destination(LogSeverity severity) { return log_destinations_[severity]; } +void LogDestination::DeleteLogDestinations() { + for (int severity = 0; severity < NUM_SEVERITIES; ++severity) { + delete log_destinations_[severity]; + log_destinations_[severity] = NULL; + } +} + namespace { LogFileObject::LogFileObject(LogSeverity severity, @@ -719,14 +728,18 @@ bool LogFileObject::CreateLogfile(const char* time_pid_string) { // Make the symlink be relative (in the same dir) so that if the // entire log directory gets relocated the link is still valid. const char *linkdest = slash ? (slash + 1) : filename; - symlink(linkdest, linkpath.c_str()); // silently ignore failures + if (symlink(linkdest, linkpath.c_str()) != 0) { + // silently ignore failures + } // Make an additional link to the log file in a place specified by // FLAGS_log_link, if indicated if (!FLAGS_log_link.empty()) { linkpath = FLAGS_log_link + "/" + linkname; unlink(linkpath.c_str()); // delete old one if it exists - symlink(filename, linkpath.c_str()); // silently ignore failures + if (symlink(filename, linkpath.c_str()) != 0) { + // silently ignore failures + } } #endif } @@ -745,7 +758,8 @@ void LogFileObject::Write(bool force_flush, return; } - if (static_cast(file_length_ >> 20) >= MaxLogSize()) { + if (static_cast(file_length_ >> 20) >= MaxLogSize() || + PidHasChanged()) { if (file_ != NULL) fclose(file_); file_ = NULL; file_length_ = bytes_since_flush_ = 0; @@ -936,12 +950,12 @@ LogMessage::LogMessage(const char* file, int line, LogSeverity severity, LogMessage::LogMessage(const char* file, int line, const CheckOpString& result) { - Init(file, line, FATAL, &LogMessage::SendToLog); + Init(file, line, GLOG_FATAL, &LogMessage::SendToLog); stream() << "Check failed: " << (*result.str_) << " "; } LogMessage::LogMessage(const char* file, int line) { - Init(file, line, INFO, &LogMessage::SendToLog); + Init(file, line, GLOG_INFO, &LogMessage::SendToLog); } LogMessage::LogMessage(const char* file, int line, LogSeverity severity) { @@ -972,7 +986,7 @@ void LogMessage::Init(const char* file, LogSeverity severity, void (LogMessage::*send_method)()) { allocated_ = NULL; - if (severity != FATAL || !exit_on_dfatal) { + if (severity != GLOG_FATAL || !exit_on_dfatal) { allocated_ = new LogMessageData(); data_ = allocated_; data_->buf_ = new char[kMaxLogMessageLen+1]; @@ -1123,7 +1137,7 @@ void ReprintFatalMessage() { // Also write to stderr WriteToStderr(fatal_message, n); } - LogDestination::LogToAllLogfiles(ERROR, fatal_time, fatal_message, n); + LogDestination::LogToAllLogfiles(GLOG_ERROR, fatal_time, fatal_message, n); } } @@ -1181,7 +1195,7 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) { // If we log a FATAL message, flush all the log destinations, then toss // a signal for others to catch. We leave the logs in a state that // someone else can use them (as long as they flush afterwards) - if (data_->severity_ == FATAL && exit_on_dfatal) { + if (data_->severity_ == GLOG_FATAL && exit_on_dfatal) { if (data_->first_fatal_) { // Store crash information so that it is accessible from within signal // handlers that may be invoked later. @@ -1212,7 +1226,9 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) { LogDestination::WaitForSinks(data_); const char* message = "*** Check failure stack trace: ***\n"; - write(STDERR_FILENO, message, strlen(message)); + if (write(STDERR_FILENO, message, strlen(message)) < 0) { + // Ignore errors. + } Fail(); } } @@ -1231,27 +1247,31 @@ void LogMessage::RecordCrashReason( #endif } +#ifdef HAVE___ATTRIBUTE__ +# define ATTRIBUTE_NORETURN __attribute__((noreturn)) +#else +# define ATTRIBUTE_NORETURN +#endif + +static void logging_fail() ATTRIBUTE_NORETURN; + static void logging_fail() { -// #if defined(_DEBUG) && defined(_MSC_VER) -// doesn't work for my laptop (sergey) -#if 0 +#if defined(_DEBUG) && defined(_MSC_VER) // When debugging on windows, avoid the obnoxious dialog and make // it possible to continue past a LOG(FATAL) in the debugger - _asm int 3 + __debugbreak(); #else abort(); #endif } -#ifdef HAVE___ATTRIBUTE__ +typedef void (*logging_fail_func_t)() ATTRIBUTE_NORETURN; + GOOGLE_GLOG_DLL_DECL -void (*g_logging_fail_func)() __attribute__((noreturn)) = &logging_fail; -#else -GOOGLE_GLOG_DLL_DECL void (*g_logging_fail_func)() = &logging_fail; -#endif +logging_fail_func_t g_logging_fail_func = &logging_fail; void InstallFailureFunction(void (*fail_func)()) { - g_logging_fail_func = fail_func; + g_logging_fail_func = (logging_fail_func_t)fail_func; } void LogMessage::Fail() { @@ -1544,7 +1564,7 @@ static void GetTempDirectories(vector* list) { "/tmp", }; - for (int i = 0; i < ARRAYSIZE(candidates); i++) { + for (size_t i = 0; i < ARRAYSIZE(candidates); i++) { const char *d = candidates[i]; if (!d) continue; // Empty env var @@ -1631,9 +1651,9 @@ void TruncateLogFile(const char *path, int64 limit, int64 keep) { // rather scary. // Instead just truncate the file to something we can manage if (truncate(path, 0) == -1) { - PLOG(ERROR) << "Unable to truncate " << path; + PLOG(ERROR) << "Unable to truncate " << path; } else { - LOG(ERROR) << "Truncated " << path << " due to EFBIG error"; + LOG(ERROR) << "Truncated " << path << " due to EFBIG error"; } } else { PLOG(ERROR) << "Unable to open " << path; @@ -1769,7 +1789,7 @@ int posix_strerror_r(int err, char *buf, size_t len) { } LogMessageFatal::LogMessageFatal(const char* file, int line) : - LogMessage(file, line, FATAL) {} + LogMessage(file, line, GLOG_FATAL) {} LogMessageFatal::LogMessageFatal(const char* file, int line, const CheckOpString& result) : @@ -1780,4 +1800,15 @@ LogMessageFatal::~LogMessageFatal() { LogMessage::Fail(); } +void InitGoogleLogging(const char* argv0) { + glog_internal_namespace_::InitGoogleLoggingUtilities(argv0); +} + +void ShutdownGoogleLogging() { + glog_internal_namespace_::ShutdownGoogleLoggingUtilities(); + LogDestination::DeleteLogDestinations(); + delete logging_directories_list; + logging_directories_list = NULL; +} + _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/raw_logging.cc b/extern/libmv/third_party/glog/src/raw_logging.cc index b179a1eded4..42676cba5de 100644 --- a/extern/libmv/third_party/glog/src/raw_logging.cc +++ b/extern/libmv/third_party/glog/src/raw_logging.cc @@ -151,7 +151,7 @@ void RawLog__(LogSeverity severity, const char* file, int line, // libc (to side-step any libc interception). // We write just once to avoid races with other invocations of RawLog__. safe_write(STDERR_FILENO, buffer, strlen(buffer)); - if (severity == FATAL) { + if (severity == GLOG_FATAL) { if (!sync_val_compare_and_swap(&crashed, false, true)) { crash_reason.filename = file; crash_reason.line_number = line; diff --git a/extern/libmv/third_party/glog/src/signalhandler.cc b/extern/libmv/third_party/glog/src/signalhandler.cc index 9fc91b3390d..e95e9e97274 100644 --- a/extern/libmv/third_party/glog/src/signalhandler.cc +++ b/extern/libmv/third_party/glog/src/signalhandler.cc @@ -34,7 +34,7 @@ #include "utilities.h" #include "stacktrace.h" #include "symbolize.h" -#include "glog/logging.h" +#include #include #include @@ -142,7 +142,9 @@ class MinimalFormatter { // Writes the given data with the size to the standard error. void WriteToStderr(const char* data, int size) { - write(STDERR_FILENO, data, size); + if (write(STDERR_FILENO, data, size) < 0) { + // Ignore errors. + } } // The writer function can be changed by InstallFailureWriter(). @@ -167,7 +169,7 @@ void DumpTimeInfo() { void DumpSignalInfo(int signal_number, siginfo_t *siginfo) { // Get the signal name. const char* signal_name = NULL; - for (int i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { + for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { if (signal_number == kFailureSignals[i].number) { signal_name = kFailureSignals[i].name; } @@ -336,7 +338,7 @@ void InstallFailureSignalHandler() { sig_action.sa_flags |= SA_SIGINFO; sig_action.sa_sigaction = &FailureSignalHandler; - for (int i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { + for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { CHECK_ERR(sigaction(kFailureSignals[i].number, &sig_action, NULL)); } } diff --git a/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h b/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h index 0dc14c6506e..46002c1b019 100644 --- a/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h +++ b/extern/libmv/third_party/glog/src/stacktrace_libunwind-inl.h @@ -37,7 +37,7 @@ extern "C" { #define UNW_LOCAL_ONLY #include } -#include "glog/raw_logging.h" +#include #include "stacktrace.h" _START_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h b/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h index e3729e1fd39..f7d1dca85bc 100644 --- a/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h +++ b/extern/libmv/third_party/glog/src/stacktrace_x86_64-inl.h @@ -33,10 +33,6 @@ extern "C" { #include // for NULL -#if defined(__FreeBSD__) -/* devel/libunwind only includes _Unwind_Backtrace if this is set */ -#define _GNU_SOURCE 1 -#endif #include // ABI defined unwinder } #include "stacktrace.h" diff --git a/extern/libmv/third_party/glog/src/symbolize.cc b/extern/libmv/third_party/glog/src/symbolize.cc index 3465de6c6fe..d1831e4ea79 100644 --- a/extern/libmv/third_party/glog/src/symbolize.cc +++ b/extern/libmv/third_party/glog/src/symbolize.cc @@ -82,8 +82,8 @@ static ATTRIBUTE_NOINLINE void DemangleInplace(char *out, int out_size) { char demangled[256]; // Big enough for sane demangled symbols. if (Demangle(out, demangled, sizeof(demangled))) { // Demangling succeeded. Copy to out if the space allows. - int len = strlen(demangled); - if (len + 1 <= out_size) { // +1 for '\0'. + size_t len = strlen(demangled); + if (len + 1 <= (size_t)out_size) { // +1 for '\0'. SAFE_ASSERT(len < sizeof(demangled)); memmove(out, demangled, len + 1); } @@ -111,7 +111,7 @@ _END_GOOGLE_NAMESPACE_ #include "symbolize.h" #include "config.h" -#include "glog/raw_logging.h" +#include // Re-runs fn until it doesn't cause EINTR. #define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR) @@ -637,7 +637,7 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out, int out_size) { Dl_info info; if (dladdr(pc, &info)) { - if (strlen(info.dli_sname) < out_size) { + if ((int)strlen(info.dli_sname) < out_size) { strcpy(out, info.dli_sname); // Symbolization succeeded. Now we try to demangle the symbol. DemangleInplace(out, out_size); diff --git a/extern/libmv/third_party/glog/src/symbolize.h b/extern/libmv/third_party/glog/src/symbolize.h index 1ebe4dd94a2..04e482bc315 100644 --- a/extern/libmv/third_party/glog/src/symbolize.h +++ b/extern/libmv/third_party/glog/src/symbolize.h @@ -56,7 +56,7 @@ #include "utilities.h" #include "config.h" -#include "glog/logging.h" +#include #ifdef HAVE_SYMBOLIZE diff --git a/extern/libmv/third_party/glog/src/utilities.cc b/extern/libmv/third_party/glog/src/utilities.cc index 6d64b923703..27b2a905055 100644 --- a/extern/libmv/third_party/glog/src/utilities.cc +++ b/extern/libmv/third_party/glog/src/utilities.cc @@ -77,9 +77,11 @@ typedef void DebugWriter(const char*, void*); // For some environments, add two extra bytes for the leading "0x". static const int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*); -static void DebugWriteToStderr(const char* data, void *unused) { +static void DebugWriteToStderr(const char* data, void *) { // This one is signal-safe. - write(STDERR_FILENO, data, strlen(data)); + if (write(STDERR_FILENO, data, strlen(data)) < 0) { + // Ignore errors. + } } void DebugWriteToString(const char* data, void *arg) { @@ -221,9 +223,18 @@ int32 GetMainThreadPid() { return g_main_thread_pid; } +bool PidHasChanged() { + int32 pid = getpid(); + if (g_main_thread_pid == pid) { + return false; + } + g_main_thread_pid = pid; + return true; +} + pid_t GetTID() { // On Linux and FreeBSD, we try to use gettid(). -#if defined OS_LINUX || defined OS_MACOSX +#if defined OS_LINUX || defined OS_FREEBSD || defined OS_MACOSX #ifndef __NR_gettid #ifdef OS_MACOSX #define __NR_gettid SYS_gettid @@ -302,9 +313,7 @@ void SetCrashReason(const CrashReason* r) { r); } -} // namespace glog_internal_namespace_ - -void InitGoogleLogging(const char* argv0) { +void InitGoogleLoggingUtilities(const char* argv0) { CHECK(!IsGoogleLoggingInitialized()) << "You called InitGoogleLogging() twice!"; const char* slash = strrchr(argv0, '/'); @@ -319,14 +328,16 @@ void InitGoogleLogging(const char* argv0) { #endif } -void ShutdownGoogleLogging() { +void ShutdownGoogleLoggingUtilities() { CHECK(IsGoogleLoggingInitialized()) - << "You called ShutdownGoogleLogging() without InitGoogleLogging() first!"; + << "You called ShutdownGoogleLogging() without calling InitGoogleLogging() first!"; #ifdef HAVE_SYSLOG_H closelog(); #endif } +} // namespace glog_internal_namespace_ + _END_GOOGLE_NAMESPACE_ // Make an implementation of stacktrace compiled. diff --git a/extern/libmv/third_party/glog/src/utilities.h b/extern/libmv/third_party/glog/src/utilities.h index bbb0eb0746c..c8215b73f33 100644 --- a/extern/libmv/third_party/glog/src/utilities.h +++ b/extern/libmv/third_party/glog/src/utilities.h @@ -161,6 +161,7 @@ typedef double WallTime; WallTime WallTime_Now(); int32 GetMainThreadPid(); +bool PidHasChanged(); pid_t GetTID(); @@ -215,6 +216,9 @@ struct CrashReason { void SetCrashReason(const CrashReason* r); +void InitGoogleLoggingUtilities(const char* argv0); +void ShutdownGoogleLoggingUtilities(); + } // namespace glog_internal_namespace_ _END_GOOGLE_NAMESPACE_ diff --git a/extern/libmv/third_party/glog/src/vlog_is_on.cc b/extern/libmv/third_party/glog/src/vlog_is_on.cc index ed88514dce5..5eefc96324a 100644 --- a/extern/libmv/third_party/glog/src/vlog_is_on.cc +++ b/extern/libmv/third_party/glog/src/vlog_is_on.cc @@ -70,8 +70,8 @@ GOOGLE_GLOG_DLL_DECL bool SafeFNMatch_(const char* pattern, size_t patt_len, const char* str, size_t str_len) { - int p = 0; - int s = 0; + size_t p = 0; + size_t s = 0; while (1) { if (p == patt_len && s == str_len) return true; if (p == patt_len) return false; @@ -211,7 +211,7 @@ bool InitVLOG3__(int32** site_flag, int32* site_default, const char* base = strrchr(fname, '/'); base = base ? (base+1) : fname; const char* base_end = strchr(base, '.'); - size_t base_length = base_end ? (base_end - base) : strlen(base); + size_t base_length = base_end ? size_t(base_end - base) : strlen(base); // Trim out trailing "-inl" if any if (base_length >= 4 && (memcmp(base+base_length-4, "-inl", 4) == 0)) { diff --git a/extern/libmv/third_party/glog/src/windows/glog/log_severity.h b/extern/libmv/third_party/glog/src/windows/glog/log_severity.h index 5e7d09effb2..22a4191ab8b 100644 --- a/extern/libmv/third_party/glog/src/windows/glog/log_severity.h +++ b/extern/libmv/third_party/glog/src/windows/glog/log_severity.h @@ -48,7 +48,15 @@ // you ever need to change their values or add a new severity. typedef int LogSeverity; -const int INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3, NUM_SEVERITIES = 4; +const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3, + NUM_SEVERITIES = 4; +#ifndef GLOG_NO_ABBREVIATED_SEVERITIES +# ifdef ERROR +# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail. +# endif +const int INFO = GLOG_INFO, WARNING = GLOG_WARNING, + ERROR = GLOG_ERROR, FATAL = GLOG_FATAL; +#endif // DFATAL is FATAL in debug mode, ERROR in normal mode #ifdef NDEBUG diff --git a/extern/libmv/third_party/glog/src/windows/glog/logging.h b/extern/libmv/third_party/glog/src/windows/glog/logging.h index 2f41681edbe..f623cd9e793 100644 --- a/extern/libmv/third_party/glog/src/windows/glog/logging.h +++ b/extern/libmv/third_party/glog/src/windows/glog/logging.h @@ -83,7 +83,7 @@ #endif #if 1 -#include "third_party/gflags/gflags.h" +#include "third_party/gflags/gflags/gflags.h" #endif #ifdef __MINGW32__ @@ -170,21 +170,21 @@ typedef uint64_t uint64; // You can also do occasional logging (log every n'th occurrence of an // event): // -// LOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // The above will cause log messages to be output on the 1st, 11th, 21st, ... -// times it is executed. Note that the special COUNTER value is used to -// identify which repetition is happening. +// times it is executed. Note that the special google::COUNTER value is used +// to identify which repetition is happening. // // You can also do occasional conditional logging (log every n'th // occurrence of an event, when condition is satisfied): // -// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER +// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER // << "th big cookie"; // // You can log messages the first N times your code executes a line. E.g. // -// LOG_FIRST_N(INFO, 20) << "Got the " << COUNTER << "th cookie"; +// LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie"; // // Outputs log messages for the first 20 times it is executed. // @@ -201,7 +201,7 @@ typedef uint64_t uint64; // // DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies"; // -// DLOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie"; +// DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; // // All "debug mode" logging is compiled away to nothing for non-debug mode // compiles. @@ -245,11 +245,11 @@ typedef uint64_t uint64; // "program with --v=1 or more"; // VLOG_EVERY_N(1, 10) // << "I'm printed every 10th occurrence, and when you run the program " -// "with --v=1 or more. Present occurence is " << COUNTER; +// "with --v=1 or more. Present occurence is " << google::COUNTER; // VLOG_IF_EVERY_N(1, (size > 1024), 10) // << "I'm printed on every 10th occurence of case when size is more " // " than 1024, when you run the program with --v=1 or more. "; -// "Present occurence is " << COUNTER; +// "Present occurence is " << google::COUNTER; // // The supported severity levels for macros that allow you to specify one // are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL. @@ -386,7 +386,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \ __FILE__, __LINE__) #define LOG_TO_STRING_INFO(message) google::LogMessage( \ - __FILE__, __LINE__, google::INFO, message) + __FILE__, __LINE__, google::GLOG_INFO, message) #else #define COMPACT_GOOGLE_LOG_INFO google::NullStream() #define LOG_TO_STRING_INFO(message) google::NullStream() @@ -394,9 +394,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 1 #define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \ - __FILE__, __LINE__, google::WARNING) + __FILE__, __LINE__, google::GLOG_WARNING) #define LOG_TO_STRING_WARNING(message) google::LogMessage( \ - __FILE__, __LINE__, google::WARNING, message) + __FILE__, __LINE__, google::GLOG_WARNING, message) #else #define COMPACT_GOOGLE_LOG_WARNING google::NullStream() #define LOG_TO_STRING_WARNING(message) google::NullStream() @@ -404,9 +404,9 @@ DECLARE_bool(stop_logging_if_full_disk); #if GOOGLE_STRIP_LOG <= 2 #define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \ - __FILE__, __LINE__, google::ERROR) + __FILE__, __LINE__, google::GLOG_ERROR) #define LOG_TO_STRING_ERROR(message) google::LogMessage( \ - __FILE__, __LINE__, google::ERROR, message) + __FILE__, __LINE__, google::GLOG_ERROR, message) #else #define COMPACT_GOOGLE_LOG_ERROR google::NullStream() #define LOG_TO_STRING_ERROR(message) google::NullStream() @@ -416,7 +416,7 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \ __FILE__, __LINE__) #define LOG_TO_STRING_FATAL(message) google::LogMessage( \ - __FILE__, __LINE__, google::FATAL, message) + __FILE__, __LINE__, google::GLOG_FATAL, message) #else #define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal() #define LOG_TO_STRING_FATAL(message) google::NullStreamFatal() @@ -428,32 +428,32 @@ DECLARE_bool(stop_logging_if_full_disk); #define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR #elif GOOGLE_STRIP_LOG <= 3 #define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \ - __FILE__, __LINE__, google::FATAL) + __FILE__, __LINE__, google::GLOG_FATAL) #else #define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal() #endif -#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::INFO, counter, &google::LogMessage::SendToLog) +#define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog) #define SYSLOG_INFO(counter) \ - google::LogMessage(__FILE__, __LINE__, google::INFO, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_WARNING(counter) \ - google::LogMessage(__FILE__, __LINE__, google::WARNING, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_ERROR(counter) \ - google::LogMessage(__FILE__, __LINE__, google::ERROR, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToLog) #define SYSLOG_FATAL(counter) \ - google::LogMessage(__FILE__, __LINE__, google::FATAL, counter, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ &google::LogMessage::SendToSyslogAndLog) #define GOOGLE_LOG_DFATAL(counter) \ google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ @@ -472,7 +472,7 @@ DECLARE_bool(stop_logging_if_full_disk); FORMAT_MESSAGE_FROM_SYSTEM, \ 0, result, 0, msg, 100, NULL); \ if (message_length > 0) { \ - google::LogMessage(__FILE__, __LINE__, ERROR, 0, \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \ &google::LogMessage::SendToLog).stream() << message; \ LocalFree(message); \ } \ @@ -519,12 +519,12 @@ class LogSink; // defined below #define LOG_TO_SINK(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), true).stream() #define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \ google::LogMessage( \ __FILE__, __LINE__, \ - google::severity, \ + google::GLOG_ ## severity, \ static_cast(sink), false).stream() // If a non-NULL string pointer is given, we write this message to that string. @@ -789,7 +789,7 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false) #define GOOGLE_PLOG(severity, counter) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, counter, \ + __FILE__, __LINE__, google::GLOG_ ## severity, counter, \ &google::LogMessage::SendToLog) #define PLOG_IF(severity, condition) \ @@ -828,7 +828,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ @@ -837,7 +837,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (condition && \ ((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ @@ -846,7 +846,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ if (LOG_OCCURRENCES_MOD_N == 1) \ google::ErrnoLogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ @@ -855,7 +855,7 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ ++LOG_OCCURRENCES; \ if (LOG_OCCURRENCES <= n) \ google::LogMessage( \ - __FILE__, __LINE__, google::severity, LOG_OCCURRENCES, \ + __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ &what_to_do).stream() namespace glog_internal_namespace_ { @@ -869,7 +869,7 @@ struct CrashReason; typedef google::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] #define LOG_EVERY_N(severity, n) \ - GOOGLE_GLOG_COMPILE_ASSERT(google::severity < \ + GOOGLE_GLOG_COMPILE_ASSERT(google::GLOG_ ## severity < \ google::NUM_SEVERITIES, \ INVALID_REQUESTED_LOG_SEVERITY); \ SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog) @@ -889,6 +889,27 @@ struct CrashReason; // We want the special COUNTER value available for LOG_EVERY_X()'ed messages enum PRIVATE_Counter {COUNTER}; +#ifdef GLOG_NO_ABBREVIATED_SEVERITIES +// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets +// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us +// to keep using this syntax, we define this macro to do the same thing +// as COMPACT_GOOGLE_LOG_ERROR. +#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR +#define SYSLOG_0 SYSLOG_ERROR +#define LOG_TO_STRING_0 LOG_TO_STRING_ERROR +// Needed for LOG_IS_ON(ERROR). +const LogSeverity GLOG_0 = GLOG_ERROR; +#else +// Users may include windows.h after logging.h without +// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN. +// For this case, we cannot detect if ERROR is defined before users +// actually use ERROR. Let's make an undefined symbol to warn users. +# define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail +# define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG +# define SYSLOG_0 GLOG_ERROR_MSG +# define LOG_TO_STRING_0 GLOG_ERROR_MSG +# define GLOG_0 GLOG_ERROR_MSG +#endif // Plus some debug-logging macros that get compiled to nothing for production @@ -1033,14 +1054,14 @@ public: # pragma warning(default: 4275) #endif public: - LogStream(char *buf, int len, int ctr) + LogStream(char *buf, int len, int ctr_in) : ostrstream(buf, len), - ctr_(ctr) { + ctr_(ctr_in) { self_ = this; } int ctr() const { return ctr_; } - void set_ctr(int ctr) { ctr_ = ctr; } + void set_ctr(int ctr_in) { ctr_ = ctr_in; } LogStream* self() const { return self_; } private: @@ -1482,7 +1503,7 @@ class GOOGLE_GLOG_DLL_DECL NullStream : public LogMessage::LogStream { // converted to LogStream and the message will be computed and then // quietly discarded. template -inline NullStream& operator<<(NullStream &str, const T &value) { return str; } +inline NullStream& operator<<(NullStream &str, const T &) { return str; } // Similar to NullStream, but aborts the program (without stack // trace), like LogMessageFatal. diff --git a/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h b/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h index c81e67bf99c..4757a719db7 100644 --- a/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h +++ b/extern/libmv/third_party/glog/src/windows/glog/raw_logging.h @@ -72,7 +72,7 @@ namespace google { // I0821 211317 file.cc:142] RAW: status is 20 #define RAW_LOG(severity, ...) \ do { \ - switch (google::severity) { \ + switch (google::GLOG_ ## severity) { \ case 0: \ RAW_LOG_INFO(__VA_ARGS__); \ break; \ @@ -104,28 +104,28 @@ namespace google { #endif // STRIP_LOG == 0 #if STRIP_LOG == 0 -#define RAW_LOG_INFO(...) google::RawLog__(google::INFO, \ +#define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG == 0 #if STRIP_LOG <= 1 -#define RAW_LOG_WARNING(...) google::RawLog__(google::WARNING, \ +#define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 1 #if STRIP_LOG <= 2 -#define RAW_LOG_ERROR(...) google::RawLog__(google::ERROR, \ +#define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__) #endif // STRIP_LOG <= 2 #if STRIP_LOG <= 3 -#define RAW_LOG_FATAL(...) google::RawLog__(google::FATAL, \ +#define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \ __FILE__, __LINE__, __VA_ARGS__) #else #define RAW_LOG_FATAL(...) \ @@ -166,7 +166,7 @@ namespace google { // Stub log function used to work around for unused variable warnings when // building with STRIP_LOG > 0. -static inline void RawLogStub__(int ignored, ...) { +static inline void RawLogStub__(int /* ignored */, ...) { } // Helper function to implement RAW_LOG and RAW_VLOG diff --git a/extern/libmv/third_party/glog/src/windows/port.h b/extern/libmv/third_party/glog/src/windows/port.h index d5078120009..abfcf65384c 100644 --- a/extern/libmv/third_party/glog/src/windows/port.h +++ b/extern/libmv/third_party/glog/src/windows/port.h @@ -59,16 +59,14 @@ * used by both C and C++ code, so we put all the C++ together. */ -#if _MSC_VER - /* 4244: otherwise we get problems when substracting two size_t's to an int - * 4251: it's complaining about a private struct I've chosen not to dllexport - * 4355: we use this in a constructor, but we do it safely - * 4715: for some reason VC++ stopped realizing you can't return after abort() - * 4800: we know we're casting ints/char*'s to bools, and we're ok with that - * 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror() - */ -# pragma warning(disable:4244 4251 4355 4715 4800 4996) -#endif +/* 4244: otherwise we get problems when substracting two size_t's to an int + * 4251: it's complaining about a private struct I've chosen not to dllexport + * 4355: we use this in a constructor, but we do it safely + * 4715: for some reason VC++ stopped realizing you can't return after abort() + * 4800: we know we're casting ints/char*'s to bools, and we're ok with that + * 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror() + */ +#pragma warning(disable:4244 4251 4355 4715 4800 4996) /* file I/O */ #define PATH_MAX 1024 diff --git a/extern/libmv/third_party/glog/src/windows/preprocess.sh b/extern/libmv/third_party/glog/src/windows/preprocess.sh old mode 100755 new mode 100644 -- cgit v1.2.3 From d6b8b0330534e26c5cf2872121889932b5b14d87 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sun, 11 Mar 2012 20:01:26 +0000 Subject: Port changes from libmv/CMakeLists.txt to build rules files generator script --- extern/libmv/bundle.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'extern') diff --git a/extern/libmv/bundle.sh b/extern/libmv/bundle.sh index f259635035e..fbf4364f7fe 100755 --- a/extern/libmv/bundle.sh +++ b/extern/libmv/bundle.sh @@ -129,6 +129,9 @@ set(INC set(INC_SYS \${PNG_INCLUDE_DIR} \${ZLIB_INCLUDE_DIRS} + if(\${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") # this is a momentary hack to find unwind.h in 10.6.sdk + \${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + endif() ) set(SRC -- cgit v1.2.3 From 1979679ad677f949f648546d7acdfdad029a1234 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Mon, 12 Mar 2012 04:35:06 +0000 Subject: SVN maintenance. --- extern/libmv/third_party/glog/src/windows/preprocess.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 extern/libmv/third_party/glog/src/windows/preprocess.sh (limited to 'extern') diff --git a/extern/libmv/third_party/glog/src/windows/preprocess.sh b/extern/libmv/third_party/glog/src/windows/preprocess.sh old mode 100644 new mode 100755 -- cgit v1.2.3 From b22e06bf7b7aa643ae68fa08f05848475bb3dd8f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 12 Mar 2012 08:45:06 +0000 Subject: Re-bundle libmv from own branch. Should resolve compilation error on some platforms when using linux and compilation error of libmv on FreeBSB. It was a regression caused by not applied changes on config_linux.h and some changes made to utilities.cc were also occasionally missed. --- extern/libmv/ChangeLog | 19 +++++++++++-------- extern/libmv/third_party/glog/src/config_linux.h | 11 +++++++++-- extern/libmv/third_party/glog/src/utilities.cc | 6 +++--- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'extern') diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index 68c3431314a..4e5c093c484 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,4 +1,13 @@ -commit bf0c3423ba41b90638e89a56500aeaeb120fbaf1 +commit 9fe49c32e990f28c83f2bbb1d18057aed8879af7 +Author: Sergey Sharybin +Date: Mon Mar 12 09:36:15 2012 +0600 + + Code cleanup: convert line endings to Unix style (native on my platform) so it + wouldn't confuse other versioning systems used for project where libmv is bundled to, + + Also change mode to +x for glog's windows-related script. + +commit fe74ae2b53769389b0ed9d7e604c8e60be81077d Author: Sergey I. Sharybin Date: Sun Mar 11 20:34:15 2012 +0600 @@ -9,7 +18,7 @@ Date: Sun Mar 11 20:34:15 2012 +0600 it's easier to move libraries around and even use libraries installed on the operation system. -commit 3e2673282f313c5bd19720f26d769f5d240a0563 +commit 37fc726701479f2d321d6af878fa93f3176278d5 Author: Sergey I. Sharybin Date: Sun Mar 11 19:27:41 2012 +0600 @@ -480,9 +489,3 @@ Date: Fri Aug 19 00:02:12 2011 +0200 Document coordinate descent method in affine SAD matcher. Add heuristic to prevent high distortions. - -commit 75520f4bc4ccbb272a1b4149d3b8d05a90f7f896 -Author: Matthias Fauconneau -Date: Thu Aug 18 23:14:17 2011 +0200 - - Fix affine iteration. diff --git a/extern/libmv/third_party/glog/src/config_linux.h b/extern/libmv/third_party/glog/src/config_linux.h index 19beaa5cf40..5877029882a 100644 --- a/extern/libmv/third_party/glog/src/config_linux.h +++ b/extern/libmv/third_party/glog/src/config_linux.h @@ -110,7 +110,7 @@ #define HAVE___BUILTIN_EXPECT 1 /* define if your compiler has __sync_val_compare_and_swap */ -#define HAVE___SYNC_VAL_COMPARE_AND_SWAP 1 +/* #undef HAVE___SYNC_VAL_COMPARE_AND_SWAP */ /* Define to the sub-directory in which libtool stores uninstalled libraries. */ @@ -138,7 +138,13 @@ #define PACKAGE_VERSION "0.3.2" /* How to access the PC from a struct ucontext */ -#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] +#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) + #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] +#elif defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) + #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_EIP] +#else + #undef PC_FROM_UCONTEXT +#endif /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -150,6 +156,7 @@ /* Define to 1 if you have the ANSI C header files. */ /* #undef STDC_HEADERS */ +#define STDC_HEADERS 1 /* the namespace where STL code like vector<> is defined */ #define STL_NAMESPACE std diff --git a/extern/libmv/third_party/glog/src/utilities.cc b/extern/libmv/third_party/glog/src/utilities.cc index 27b2a905055..c9db2b7f7cd 100644 --- a/extern/libmv/third_party/glog/src/utilities.cc +++ b/extern/libmv/third_party/glog/src/utilities.cc @@ -233,8 +233,8 @@ bool PidHasChanged() { } pid_t GetTID() { - // On Linux and FreeBSD, we try to use gettid(). -#if defined OS_LINUX || defined OS_FREEBSD || defined OS_MACOSX + // On Linux and MACOSX , we try to use gettid(). +#if defined OS_LINUX || defined OS_MACOSX #ifndef __NR_gettid #ifdef OS_MACOSX #define __NR_gettid SYS_gettid @@ -256,7 +256,7 @@ pid_t GetTID() { // the value change to "true". lacks_gettid = true; } -#endif // OS_LINUX || OS_FREEBSD +#endif // OS_LINUX || OS_MACOSX // If gettid() could not be used, we use one of the following. #if defined OS_LINUX -- cgit v1.2.3 From e3cfca511f55495de1b58bf714fb4b8cabc633db Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 12 Mar 2012 21:18:28 +0000 Subject: Bundle latest version of Carve library which shall resolve compilation issues with clang --- extern/carve/CMakeLists.txt | 168 ++++++++++++------------- extern/carve/bundle.sh | 2 +- extern/carve/include/carve/exact.hpp | 8 +- extern/carve/include/carve/kd_node.hpp | 6 +- extern/carve/include/carve/mesh_impl.hpp | 3 +- extern/carve/include/carve/polyhedron_impl.hpp | 12 +- extern/carve/patches/strict_flags.patch | 24 ---- 7 files changed, 100 insertions(+), 123 deletions(-) (limited to 'extern') diff --git a/extern/carve/CMakeLists.txt b/extern/carve/CMakeLists.txt index cbf92ee293e..660538998a1 100644 --- a/extern/carve/CMakeLists.txt +++ b/extern/carve/CMakeLists.txt @@ -35,115 +35,115 @@ set(INC_SYS ) set(SRC - lib/carve.cpp - lib/mesh.cpp - lib/intersect_group.cpp - lib/intersect_classify_edge.cpp - lib/intersect_classify_group.cpp + lib/intersection.cpp + lib/intersect.cpp + lib/triangulator.cpp + lib/convex_hull.cpp lib/polyhedron.cpp - lib/geom3d.cpp lib/polyline.cpp - lib/csg_collector.cpp - lib/triangulator.cpp - lib/intersect_face_division.cpp - lib/intersect_half_classify_group.cpp - lib/edge.cpp - lib/math.cpp + lib/pointset.cpp lib/geom2d.cpp + lib/math.cpp + lib/intersect_half_classify_group.cpp + lib/intersect_face_division.cpp lib/tag.cpp - lib/intersection.cpp - lib/convex_hull.cpp + lib/aabb.cpp + lib/intersect_classify_group.cpp + lib/mesh.cpp + lib/timing.cpp + lib/geom3d.cpp + lib/intersect_group.cpp + lib/carve.cpp + lib/intersect_classify_edge.cpp lib/csg.cpp - lib/intersect.cpp lib/face.cpp - lib/pointset.cpp - lib/timing.cpp - lib/octree.cpp - lib/aabb.cpp + lib/csg_collector.cpp lib/intersect_debug.cpp + lib/edge.cpp + lib/octree.cpp - lib/intersect_classify_common.hpp - lib/csg_data.hpp + lib/intersect_debug.hpp lib/csg_collector.hpp + lib/csg_data.hpp + lib/intersect_classify_common.hpp lib/intersect_common.hpp - lib/intersect_classify_common_impl.hpp lib/csg_detail.hpp - lib/intersect_debug.hpp + lib/intersect_classify_common_impl.hpp - include/carve/polyhedron_decl.hpp - include/carve/geom2d.hpp - include/carve/exact.hpp - include/carve/triangulator_impl.hpp - include/carve/collection.hpp - include/carve/pointset.hpp - include/carve/djset.hpp - include/carve/kd_node.hpp - include/carve/polyline.hpp - include/carve/polyline_iter.hpp - include/carve/geom3d.hpp - include/carve/edge_decl.hpp - include/carve/face_decl.hpp + include/carve/vertex_impl.hpp include/carve/aabb_impl.hpp - include/carve/colour.hpp + include/carve/csg.hpp include/carve/pointset_iter.hpp - include/carve/polyline_decl.hpp - include/carve/rescale.hpp - include/carve/mesh_impl.hpp - include/carve/classification.hpp - include/carve/util.hpp - include/carve/triangulator.hpp - include/carve/polyhedron_base.hpp - include/carve/rtree.hpp - include/carve/math.hpp - include/carve/math_constants.hpp - include/carve/octree_decl.hpp - include/carve/input.hpp - include/carve/mesh_ops.hpp include/carve/debug_hooks.hpp - include/carve/mesh_simplify.hpp - include/carve/interpolator.hpp - include/carve/poly_decl.hpp - include/carve/csg.hpp include/carve/mesh.hpp - include/carve/carve.hpp - include/carve/gnu_cxx.h - include/carve/polyhedron_impl.hpp - include/carve/poly_impl.hpp - include/carve/aabb.hpp + include/carve/triangulator_impl.hpp + include/carve/edge_decl.hpp + include/carve/collection/unordered.hpp + include/carve/collection/unordered/tr1_impl.hpp + include/carve/collection/unordered/fallback_impl.hpp + include/carve/collection/unordered/std_impl.hpp + include/carve/collection/unordered/vcpp_impl.hpp + include/carve/collection/unordered/libstdcpp_impl.hpp + include/carve/collection/unordered/boost_impl.hpp include/carve/convex_hull.hpp - include/carve/vertex_decl.hpp + include/carve/geom.hpp + include/carve/collection_types.hpp + include/carve/cbrt.h + include/carve/util.hpp + include/carve/iobj.hpp + include/carve/polyline_decl.hpp + include/carve/polyline_impl.hpp include/carve/win32.h include/carve/edge_impl.hpp - include/carve/tag.hpp - include/carve/tree.hpp - include/carve/heap.hpp + include/carve/carve.hpp + include/carve/polyline.hpp + include/carve/face_decl.hpp include/carve/matrix.hpp - include/carve/poly.hpp - include/carve/vector.hpp - include/carve/intersection.hpp - include/carve/faceloop.hpp + include/carve/classification.hpp include/carve/geom_impl.hpp - include/carve/octree_impl.hpp - include/carve/spacetree.hpp - include/carve/collection/unordered/std_impl.hpp - include/carve/collection/unordered/tr1_impl.hpp - include/carve/collection/unordered/libstdcpp_impl.hpp - include/carve/collection/unordered/boost_impl.hpp - include/carve/collection/unordered/vcpp_impl.hpp - include/carve/collection/unordered/fallback_impl.hpp - include/carve/collection/unordered.hpp + include/carve/faceloop.hpp + include/carve/mesh_ops.hpp + include/carve/tree.hpp + include/carve/geom2d.hpp include/carve/face_impl.hpp + include/carve/polyhedron_decl.hpp + include/carve/interpolator.hpp + include/carve/poly_decl.hpp + include/carve/mesh_impl.hpp + include/carve/gnu_cxx.h + include/carve/mesh_simplify.hpp + include/carve/triangulator.hpp include/carve/pointset_impl.hpp - include/carve/cbrt.h + include/carve/rtree.hpp + include/carve/math_constants.hpp + include/carve/vector.hpp + include/carve/octree_impl.hpp + include/carve/pointset.hpp + include/carve/math.hpp + include/carve/intersection.hpp + include/carve/colour.hpp + include/carve/kd_node.hpp + include/carve/input.hpp + include/carve/geom3d.hpp + include/carve/exact.hpp + include/carve/rescale.hpp + include/carve/polyhedron_base.hpp + include/carve/heap.hpp + include/carve/spacetree.hpp + include/carve/polyhedron_impl.hpp include/carve/vcpp_config.h - include/carve/geom.hpp - include/carve/vertex_impl.hpp - include/carve/polyline_impl.hpp - include/carve/pointset_decl.hpp - include/carve/timing.hpp + include/carve/aabb.hpp + include/carve/polyline_iter.hpp + include/carve/djset.hpp + include/carve/vertex_decl.hpp include/carve/csg_triangulator.hpp - include/carve/iobj.hpp - include/carve/collection_types.hpp + include/carve/poly.hpp + include/carve/timing.hpp + include/carve/octree_decl.hpp + include/carve/pointset_decl.hpp + include/carve/tag.hpp + include/carve/collection.hpp + include/carve/poly_impl.hpp ) if(WITH_BOOST) diff --git a/extern/carve/bundle.sh b/extern/carve/bundle.sh index bc719ae5ba8..e68b2c7e90e 100755 --- a/extern/carve/bundle.sh +++ b/extern/carve/bundle.sh @@ -47,7 +47,7 @@ cat > CMakeLists.txt << EOF # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # The Original Code is Copyright (C) 2006, Blender Foundation # All rights reserved. diff --git a/extern/carve/include/carve/exact.hpp b/extern/carve/include/carve/exact.hpp index afb491211fd..0d674e66ef7 100644 --- a/extern/carve/include/carve/exact.hpp +++ b/extern/carve/include/carve/exact.hpp @@ -639,9 +639,11 @@ namespace carve { } - // XXX: not implemented yet - //exact_t operator+(const exact_t &a, const exact_t &b) { - //} + exact_t operator+(const exact_t &a, const exact_t &b) { + exact_t r; + sum_zeroelim(a, b, r); + return r; + } diff --git a/extern/carve/include/carve/kd_node.hpp b/extern/carve/include/carve/kd_node.hpp index f62584d50c2..45e0ac85739 100644 --- a/extern/carve/include/carve/kd_node.hpp +++ b/extern/carve/include/carve/kd_node.hpp @@ -230,7 +230,7 @@ namespace carve { } // distance_t must provide: - // double operator()(kd_node::data_t, vector); + // double operator()(data_t, vector); // double operator()(axis_pos, vector); template struct near_point_query { @@ -238,7 +238,7 @@ namespace carve { // q_t - the priority queue value type. // q_t.first: distance from object to query point. // q_t.second: pointer to object - typedef std::pair q_t; + typedef std::pair q_t; // the queue priority should sort from smallest distance to largest, and on equal distance, by object pointer. struct pcmp { @@ -266,7 +266,7 @@ namespace carve { } } - const typename kd_node::data_t *next() { + const data_t *next() { while (1) { if (pq.size()) { q_t t = pq.top(); diff --git a/extern/carve/include/carve/mesh_impl.hpp b/extern/carve/include/carve/mesh_impl.hpp index 23b0a436573..d55df8c8130 100644 --- a/extern/carve/include/carve/mesh_impl.hpp +++ b/extern/carve/include/carve/mesh_impl.hpp @@ -624,8 +624,7 @@ namespace carve { CARVE_ASSERT(e->rev != NULL); e = e->rev->next; CARVE_ASSERT(e->v1() == emin->v1()); - CARVE_ASSERT(e->v1()->v < e->v2()->v); - CARVE_ASSERT(e->v1()->v.x <= e->v2()->v.x); + CARVE_ASSERT(e->v1()->v <= e->v2()->v); } while (e != emin); double max_abs_x = 0.0; diff --git a/extern/carve/include/carve/polyhedron_impl.hpp b/extern/carve/include/carve/polyhedron_impl.hpp index 06d841c7192..de61324140d 100644 --- a/extern/carve/include/carve/polyhedron_impl.hpp +++ b/extern/carve/include/carve/polyhedron_impl.hpp @@ -88,9 +88,9 @@ namespace carve { *(*result)++ = f; int r = 1; - for (size_t i = 0; i < f->edges.size(); ++i) { - const std::vector &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(f->edges[i])]; - const face_t *f2 = connectedFace(f, f->edges[i]); + for (size_t i = 0; i < f->nEdges(); ++i) { + const std::vector &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(f->edge(i))]; + const face_t *f2 = connectedFace(f, f->edge(i)); if (f2) { r += _faceNeighbourhood(f2, depth - 1, (*result)); } @@ -116,7 +116,7 @@ namespace carve { int r = 0; const std::vector &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(e)]; for (size_t i = 0; i < edge_faces.size(); ++i) { - face_t *f = edge_faces[i]; + const face_t *f = edge_faces[i]; if (f && f->manifold_id == m_id) { r += _faceNeighbourhood(f, depth, &result); } } return r; @@ -131,7 +131,7 @@ namespace carve { int r = 0; const std::vector &vertex_faces = connectivity.vertex_to_face[vertexToIndex_fast(v)]; for (size_t i = 0; i < vertex_faces.size(); ++i) { - face_t *f = vertex_faces[i]; + const face_t *f = vertex_faces[i]; if (f && f->manifold_id == m_id) { r += _faceNeighbourhood(f, depth, &result); } } return r; @@ -142,7 +142,7 @@ namespace carve { // accessing connectivity information. template int Geometry<3>::vertexToEdges(const vertex_t *v, T result) const { - std::vector &e = connectivity.vertex_to_edge[vertexToIndex_fast(v)]; + const std::vector &e = connectivity.vertex_to_edge[vertexToIndex_fast(v)]; std::copy(e.begin(), e.end(), result); return e.size(); } diff --git a/extern/carve/patches/strict_flags.patch b/extern/carve/patches/strict_flags.patch index 5e4b867ba26..5c7e8967d39 100644 --- a/extern/carve/patches/strict_flags.patch +++ b/extern/carve/patches/strict_flags.patch @@ -9,30 +9,6 @@ diff -r 47dfdaff1dd5 include/carve/csg_triangulator.hpp } carve::mesh::MeshSet<3>::face_t *mergeQuad(edge_map_t::iterator i, edge_map_t &edge_map) { -diff -r 47dfdaff1dd5 include/carve/exact.hpp ---- a/include/carve/exact.hpp Thu Jan 12 15:49:04 2012 -0500 -+++ b/include/carve/exact.hpp Fri Jan 13 03:13:32 2012 +0600 -@@ -379,7 +379,7 @@ - prod_2_1(b, a, r); - } - -- static inline double prod_4_1(const double *a, const double *b, double *r) { -+ static inline void prod_4_1(const double *a, const double *b, double *r) { - double b_sp[2]; split(b[0], b_sp); - double t1[2]; prod_1_1s(a+0, b, b_sp, t1); - r[0] = t1[0]; -@@ -639,8 +639,9 @@ - } - - -- exact_t operator+(const exact_t &a, const exact_t &b) { -- } -+ // XXX: not implemented yet -+ //exact_t operator+(const exact_t &a, const exact_t &b) { -+ //} - - - diff -r 47dfdaff1dd5 src/selfintersect.cpp --- a/src/selfintersect.cpp Thu Jan 12 15:49:04 2012 -0500 +++ b/src/selfintersect.cpp Fri Jan 13 03:13:32 2012 +0600 -- cgit v1.2.3 From f127a0cd6f998c6b7975cfbe13f5144957fdcf67 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 21 Mar 2012 12:15:02 +0000 Subject: modify osx CMake hack so the CMake files can be parsed more easily by naive my error checker. --- extern/libmv/CMakeLists.txt | 14 +++++++++++--- extern/libmv/bundle.sh | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index c16d842dd65..a3a210eb436 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -37,11 +37,19 @@ set(INC set(INC_SYS ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} - if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") # this is a momentary hack to find unwind.h in 10.6.sdk - ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include - endif() ) + +# XXX - FIXME +# this is a momentary hack to find unwind.h in 10.6.sdk +if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") + list(APPEND INC_SYS + ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + ) +endif() +# XXX - END + + set(SRC libmv-capi.cpp libmv/image/array_nd.cc diff --git a/extern/libmv/bundle.sh b/extern/libmv/bundle.sh index fbf4364f7fe..2f9357a2fe1 100755 --- a/extern/libmv/bundle.sh +++ b/extern/libmv/bundle.sh @@ -129,11 +129,19 @@ set(INC set(INC_SYS \${PNG_INCLUDE_DIR} \${ZLIB_INCLUDE_DIRS} - if(\${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") # this is a momentary hack to find unwind.h in 10.6.sdk - \${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include - endif() ) + +# XXX - FIXME +# this is a momentary hack to find unwind.h in 10.6.sdk +if(\${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") + list(APPEND INC_SYS + \${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + ) +endif() +# XXX - END + + set(SRC libmv-capi.cpp ${sources} -- cgit v1.2.3 From 87681b46eafede158543233c92d5d32874014b77 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 23 Mar 2012 10:39:59 +0000 Subject: fix for cmake error on non osx systems --- extern/libmv/CMakeLists.txt | 10 ++++++---- extern/libmv/bundle.sh | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index a3a210eb436..5239c7ff7ca 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -42,10 +42,12 @@ set(INC_SYS # XXX - FIXME # this is a momentary hack to find unwind.h in 10.6.sdk -if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") - list(APPEND INC_SYS - ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include - ) +if(APPLE) + if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") + list(APPEND INC_SYS + ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + ) + endif() endif() # XXX - END diff --git a/extern/libmv/bundle.sh b/extern/libmv/bundle.sh index 2f9357a2fe1..a34e45a38b0 100755 --- a/extern/libmv/bundle.sh +++ b/extern/libmv/bundle.sh @@ -134,10 +134,12 @@ set(INC_SYS # XXX - FIXME # this is a momentary hack to find unwind.h in 10.6.sdk -if(\${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") - list(APPEND INC_SYS - \${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include - ) +if(APPLE) + if(\${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.6") + list(APPEND INC_SYS + \${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include + ) + endif() endif() # XXX - END -- cgit v1.2.3 From 81e3db364d589d747f17173b79490011d2a403f5 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 30 Mar 2012 10:37:39 +0000 Subject: Camera tracking refactoring: - Deduplicate patetrn sampling used in esm and lmicklt trackers and move SamplePattern to image/sample.h - Move computation of Pearson product-moment correlation into own function in new file image/correlation.h so all trackers can use it to check final correlation. - Remove SAD tracker. It's almost the same as brute tracker, with only two differences: 1. It does brute search of affine transformation which in some cases helps to track rotating features 2. It didn't use common tracker api which probably gave some speed advantage, but lead to a real headache to use it together with other trackers leading to duplicated code in blender side. - Switch blenedr to use brute tracker instead of sad tracker which tracking made source code much more simple to follow. --- extern/libmv/CMakeLists.txt | 3 +- extern/libmv/libmv-capi.cpp | 42 ++--- extern/libmv/libmv-capi.h | 7 +- extern/libmv/libmv/image/correlation.h | 51 ++++++ extern/libmv/libmv/image/sample.h | 18 ++ .../libmv/libmv/tracking/brute_region_tracker.cc | 24 +++ extern/libmv/libmv/tracking/brute_region_tracker.h | 5 +- extern/libmv/libmv/tracking/esm_region_tracker.cc | 38 +--- .../libmv/libmv/tracking/lmicklt_region_tracker.cc | 18 -- extern/libmv/libmv/tracking/sad.cc | 191 --------------------- extern/libmv/libmv/tracking/sad.h | 109 ------------ 11 files changed, 116 insertions(+), 390 deletions(-) create mode 100644 extern/libmv/libmv/image/correlation.h delete mode 100644 extern/libmv/libmv/tracking/sad.cc delete mode 100644 extern/libmv/libmv/tracking/sad.h (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 5239c7ff7ca..005bcdf0a3b 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -80,7 +80,6 @@ set(SRC libmv/tracking/lmicklt_region_tracker.cc libmv/tracking/pyramid_region_tracker.cc libmv/tracking/retrack_region_tracker.cc - libmv/tracking/sad.cc libmv/tracking/trklt_region_tracker.cc third_party/fast/fast_10.c @@ -104,6 +103,7 @@ set(SRC libmv/image/array_nd.h libmv/image/convolve.h libmv/image/image.h + libmv/image/correlation.h libmv/image/sample.h libmv/image/tuple.h libmv/logging/logging.h @@ -137,7 +137,6 @@ set(SRC libmv/tracking/pyramid_region_tracker.h libmv/tracking/region_tracker.h libmv/tracking/retrack_region_tracker.h - libmv/tracking/sad.h libmv/tracking/trklt_region_tracker.h third_party/fast/fast.h diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp index 465bf519dbd..7fd4bfdd9d1 100644 --- a/extern/libmv/libmv-capi.cpp +++ b/extern/libmv/libmv-capi.cpp @@ -44,8 +44,6 @@ #include "libmv/tracking/lmicklt_region_tracker.h" #include "libmv/tracking/pyramid_region_tracker.h" -#include "libmv/tracking/sad.h" - #include "libmv/simple_pipeline/callbacks.h" #include "libmv/simple_pipeline/tracks.h" #include "libmv/simple_pipeline/initialize_reconstruction.h" @@ -137,12 +135,25 @@ libmv_RegionTracker *libmv_hybridRegionTrackerNew(int max_iterations, int half_w libmv::BruteRegionTracker *brute_region_tracker = new libmv::BruteRegionTracker; brute_region_tracker->half_window_size = half_window_size; + /* do not use correlation check for brute checker itself, + * this check will happen in esm tracker */ + brute_region_tracker->minimum_correlation = 0.0; + libmv::HybridRegionTracker *hybrid_region_tracker = new libmv::HybridRegionTracker(brute_region_tracker, esm_region_tracker); return (libmv_RegionTracker *)hybrid_region_tracker; } +libmv_RegionTracker *libmv_bruteRegionTrackerNew(int half_window_size, double minimum_correlation) +{ + libmv::BruteRegionTracker *brute_region_tracker = new libmv::BruteRegionTracker; + brute_region_tracker->half_window_size = half_window_size; + brute_region_tracker->minimum_correlation = minimum_correlation; + + return (libmv_RegionTracker *)brute_region_tracker; +} + static void floatBufToImage(const float *buf, int width, int height, libmv::FloatImage *image) { int x, y, a = 0; @@ -316,33 +327,6 @@ void libmv_regionTrackerDestroy(libmv_RegionTracker *libmv_tracker) /* ************ Tracks ************ */ -void libmv_SADSamplePattern(unsigned char *image, int stride, - float warp[3][2], unsigned char *pattern, int pattern_size) -{ - libmv::mat32 mat32; - - memcpy(mat32.data, warp, sizeof(float)*3*2); - - libmv::SamplePattern(image, stride, mat32, pattern, pattern_size); -} - -float libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *warped, int pattern_size, unsigned char *image, int stride, - int width, int height, float warp[3][2]) -{ - float result; - libmv::mat32 mat32; - - memcpy(mat32.data, warp, sizeof(float)*3*2); - - result = libmv::Track(pattern, warped, pattern_size, image, stride, width, height, &mat32, 16, 16); - - memcpy(warp, mat32.data, sizeof(float)*3*2); - - return result; -} - -/* ************ Tracks ************ */ - libmv_Tracks *libmv_tracksNew(void) { libmv::Tracks *libmv_tracks = new libmv::Tracks(); diff --git a/extern/libmv/libmv-capi.h b/extern/libmv/libmv-capi.h index e10d4ef842a..e5728188afb 100644 --- a/extern/libmv/libmv-capi.h +++ b/extern/libmv/libmv-capi.h @@ -45,16 +45,11 @@ void libmv_setLoggingVerbosity(int verbosity); /* RegionTracker */ struct libmv_RegionTracker *libmv_pyramidRegionTrackerNew(int max_iterations, int pyramid_level, int half_window_size, double minimum_correlation); struct libmv_RegionTracker *libmv_hybridRegionTrackerNew(int max_iterations, int half_window_size, double minimum_correlation); +struct libmv_RegionTracker *libmv_bruteRegionTrackerNew(int half_window_size, double minimum_correlation); int libmv_regionTrackerTrack(struct libmv_RegionTracker *libmv_tracker, const float *ima1, const float *ima2, int width, int height, double x1, double y1, double *x2, double *y2); void libmv_regionTrackerDestroy(struct libmv_RegionTracker *libmv_tracker); -/* SAD Tracker */ -void libmv_SADSamplePattern(unsigned char *image, int stride, - float warp[3][2], unsigned char *pattern, int pattern_size); -float libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *warped, int pattern_size, unsigned char *image, - int stride, int width, int height, float warp[3][2]); - /* Tracks */ struct libmv_Tracks *libmv_tracksNew(void); void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y); diff --git a/extern/libmv/libmv/image/correlation.h b/extern/libmv/libmv/image/correlation.h new file mode 100644 index 00000000000..9d6aceecceb --- /dev/null +++ b/extern/libmv/libmv/image/correlation.h @@ -0,0 +1,51 @@ +// Copyright (c) 2012 libmv authors. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#ifndef LIBMV_IMAGE_CORRELATION_H +#define LIBMV_IMAGE_CORRELATION_H + +#include "libmv/image/image.h" + +namespace libmv { + +inline double PearsonProductMomentCorrelation(Array3Df image_and_gradient1_sampled, + Array3Df image_and_gradient2_sampled, + int width) { + double sX=0,sY=0,sXX=0,sYY=0,sXY=0; + for (int r = 0; r < width; ++r) { + for (int c = 0; c < width; ++c) { + double x = image_and_gradient1_sampled(r, c, 0); + double y = image_and_gradient2_sampled(r, c, 0); + sX += x; + sY += y; + sXX += x*x; + sYY += y*y; + sXY += x*y; + } + } + double N = width*width; + sX /= N, sY /= N, sXX /= N, sYY /= N, sXY /= N; + double correlation = (sXY-sX*sY)/sqrt(double((sXX-sX*sX)*(sYY-sY*sY))); + return correlation; +} + +} // namespace libmv + +#endif // LIBMV_IMAGE_IMAGE_CORRELATION_H diff --git a/extern/libmv/libmv/image/sample.h b/extern/libmv/libmv/image/sample.h index cd361231b58..ea86edf117d 100644 --- a/extern/libmv/libmv/image/sample.h +++ b/extern/libmv/libmv/image/sample.h @@ -98,6 +98,24 @@ inline void DownsampleChannelsBy2(const Array3Df &in, Array3Df *out) { } +// Sample a region centered at x,y in image with size extending by half_width +// from x,y. Channels specifies the number of channels to sample from. +inline void SamplePattern(const FloatImage &image, + double x, double y, + int half_width, + int channels, + FloatImage *sampled) { + sampled->Resize(2 * half_width + 1, 2 * half_width + 1, channels); + for (int r = -half_width; r <= half_width; ++r) { + for (int c = -half_width; c <= half_width; ++c) { + for (int i = 0; i < channels; ++i) { + (*sampled)(r + half_width, c + half_width, i) = + SampleLinear(image, y + r, x + c, i); + } + } + } +} + } // namespace libmv #endif // LIBMV_IMAGE_SAMPLE_H_ diff --git a/extern/libmv/libmv/tracking/brute_region_tracker.cc b/extern/libmv/libmv/tracking/brute_region_tracker.cc index a416710ad2b..af7f673472e 100644 --- a/extern/libmv/libmv/tracking/brute_region_tracker.cc +++ b/extern/libmv/libmv/tracking/brute_region_tracker.cc @@ -44,6 +44,7 @@ #include "libmv/image/image.h" #include "libmv/image/convolve.h" +#include "libmv/image/correlation.h" #include "libmv/image/sample.h" #include "libmv/logging/logging.h" @@ -332,6 +333,29 @@ bool BruteRegionTracker::Track(const FloatImage &image1, if (best_sad != INT_MAX) { *x2 = best_j + half_window_size; *y2 = best_i + half_window_size; + + if (minimum_correlation > 0) { + Array3Df image_and_gradient1_sampled, image_and_gradient2_sampled; + + SamplePattern(image_and_gradient1, x1, y1, half_window_size, 3, + &image_and_gradient1_sampled); + SamplePattern(image_and_gradient2, *x2, *y2, half_window_size, 3, + &image_and_gradient2_sampled); + + // Compute the Pearson product-moment correlation coefficient to check + // for sanity. + double correlation = PearsonProductMomentCorrelation(image_and_gradient1_sampled, + image_and_gradient2_sampled, + pattern_width); + LG << "Final correlation: " << correlation; + + if (correlation < minimum_correlation) { + LG << "Correlation " << correlation << " greater than " + << minimum_correlation << "; bailing."; + return false; + } + } + return true; } return false; diff --git a/extern/libmv/libmv/tracking/brute_region_tracker.h b/extern/libmv/libmv/tracking/brute_region_tracker.h index 7a9b06d8a31..8ff0c1b7965 100644 --- a/extern/libmv/libmv/tracking/brute_region_tracker.h +++ b/extern/libmv/libmv/tracking/brute_region_tracker.h @@ -27,7 +27,9 @@ namespace libmv { struct BruteRegionTracker : public RegionTracker { - BruteRegionTracker() : half_window_size(4) {} + BruteRegionTracker() + : half_window_size(4), + minimum_correlation(0.78) {} virtual ~BruteRegionTracker() {} @@ -39,6 +41,7 @@ struct BruteRegionTracker : public RegionTracker { // No point in creating getters or setters. int half_window_size; + double minimum_correlation; }; } // namespace libmv diff --git a/extern/libmv/libmv/tracking/esm_region_tracker.cc b/extern/libmv/libmv/tracking/esm_region_tracker.cc index df9c89a46d4..e0b85f19943 100644 --- a/extern/libmv/libmv/tracking/esm_region_tracker.cc +++ b/extern/libmv/libmv/tracking/esm_region_tracker.cc @@ -26,6 +26,7 @@ #include "libmv/logging/logging.h" #include "libmv/image/image.h" #include "libmv/image/convolve.h" +#include "libmv/image/correlation.h" #include "libmv/image/sample.h" #include "libmv/numeric/numeric.h" @@ -55,24 +56,6 @@ static bool RegionIsInBounds(const FloatImage &image1, return true; } -// Sample a region centered at x,y in image with size extending by half_width -// from x,y. Channels specifies the number of channels to sample from. -static void SamplePattern(const FloatImage &image, - double x, double y, - int half_width, - int channels, - FloatImage *sampled) { - sampled->Resize(2 * half_width + 1, 2 * half_width + 1, channels); - for (int r = -half_width; r <= half_width; ++r) { - for (int c = -half_width; c <= half_width; ++c) { - for (int i = 0; i < channels; ++i) { - (*sampled)(r + half_width, c + half_width, i) = - SampleLinear(image, y + r, x + c, i); - } - } - } -} - // Estimate "reasonable" error by computing autocorrelation for a small shift. // TODO(keir): Add a facility for static double EstimateReasonableError(const FloatImage &image, @@ -276,22 +259,9 @@ bool EsmRegionTracker::Track(const FloatImage &image1, if (d.squaredNorm() < min_update_squared_distance) { // Compute the Pearson product-moment correlation coefficient to check // for sanity. - // TODO(keir): Put this somewhere smarter. - double sX=0,sY=0,sXX=0,sYY=0,sXY=0; - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - double x = image_and_gradient1_sampled(r, c, 0); - double y = image_and_gradient2_sampled[new_image](r, c, 0); - sX += x; - sY += y; - sXX += x*x; - sYY += y*y; - sXY += x*y; - } - } - double N = width*width; - sX /= N, sY /= N, sXX /= N, sYY /= N, sXY /= N; - double correlation = (sXY-sX*sY)/sqrt(double((sXX-sX*sX)*(sYY-sY*sY))); + double correlation = PearsonProductMomentCorrelation(image_and_gradient1_sampled, + image_and_gradient2_sampled[new_image], + width); LG << "Final correlation: " << correlation; if (correlation < minimum_correlation) { diff --git a/extern/libmv/libmv/tracking/lmicklt_region_tracker.cc b/extern/libmv/libmv/tracking/lmicklt_region_tracker.cc index c06a1d3302c..581e984b569 100644 --- a/extern/libmv/libmv/tracking/lmicklt_region_tracker.cc +++ b/extern/libmv/libmv/tracking/lmicklt_region_tracker.cc @@ -52,24 +52,6 @@ static bool RegionIsInBounds(const FloatImage &image1, return true; } -// Sample a region centered at x,y in image with size extending by half_width -// from x,y. Channels specifies the number of channels to sample from. -static void SamplePattern(const FloatImage &image, - double x, double y, - int half_width, - int channels, - FloatImage *sampled) { - sampled->Resize(2 * half_width + 1, 2 * half_width + 1, channels); - for (int r = -half_width; r <= half_width; ++r) { - for (int c = -half_width; c <= half_width; ++c) { - for (int i = 0; i < channels; ++i) { - (*sampled)(r + half_width, c + half_width, i) = - SampleLinear(image, y + r, x + c, i); - } - } - } -} - // Estimate "reasonable" error by computing autocorrelation for a small shift. static double EstimateReasonableError(const FloatImage &image, double x, double y, diff --git a/extern/libmv/libmv/tracking/sad.cc b/extern/libmv/libmv/tracking/sad.cc deleted file mode 100644 index 0876ef2fe73..00000000000 --- a/extern/libmv/libmv/tracking/sad.cc +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** -** -** Copyright (c) 2011 libmv authors. -** -** Permission is hereby granted, free of charge, to any person obtaining a copy -** of this software and associated documentation files (the "Software"), to -** deal in the Software without restriction, including without limitation the -** rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -** sell copies of the Software, and to permit persons to whom the Software is -** furnished to do so, subject to the following conditions: -** -** The above copyright notice and this permission notice shall be included in -** all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -** IN THE SOFTWARE. -** -****************************************************************************/ - -#include "libmv/tracking/sad.h" -#include -#include -#include - -namespace libmv { - -void LaplaceFilter(ubyte* src, ubyte* dst, int width, int height, int strength) { - for(int y=1; y 255) d=255; - dst[y*width+x] = d; - } -} - -struct vec2 { - float x,y; - inline vec2(float x, float y):x(x),y(y){} -}; -inline vec2 operator*(mat32 m, vec2 v) { - return vec2(v.x*m(0,0)+v.y*m(0,1)+m(0,2),v.x*m(1,0)+v.y*m(1,1)+m(1,2)); -} - -//! fixed point bilinear sample with precision k -template inline int sample(const ubyte* image,int stride, int x, int y, int u, int v) { - const ubyte* s = &image[y*stride+x]; - return ((s[ 0] * (k-u) + s[ 1] * u) * (k-v) - + (s[stride] * (k-u) + s[stride+1] * u) * ( v) ) / (k*k); -} - -#ifdef __SSE__ -#include -int lround(float x) { return _mm_cvtss_si32(_mm_set_ss(x)); } -#elif defined(_MSC_VER) -int lround(float x) { return x+0.5; } -#endif - -//TODO(MatthiasF): SSE optimization -void SamplePattern(ubyte* image, int stride, mat32 warp, ubyte* pattern, int size) { - const int k = 256; - for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) { - vec2 p = warp*vec2(j-size/2,i-size/2); - int fx = lround(p.x*k), fy = lround(p.y*k); - int ix = fx/k, iy = fy/k; - int u = fx%k, v = fy%k; - pattern[i*size+j] = sample(image,stride,ix,iy,u,v); - } -} - -#ifdef __SSE2__ -#include - static uint SAD(/*const*/ ubyte* pattern, /*const*/ ubyte* image, int stride, int size) { - uint sad = 0; - __m128i a = _mm_setzero_si128(); - - for(int i = 0; i < size; i++) { - int j = 0; - - for(j = 0; j < size/16; j++) { - if((i*size/16+j) % 32 == 0) { - sad += _mm_extract_epi16(a,0) + _mm_extract_epi16(a,4); - a = _mm_setzero_si128(); - } - - a = _mm_adds_epu16(a, _mm_sad_epu8( _mm_loadu_si128((__m128i*)(pattern+i*size+j*16)), - _mm_loadu_si128((__m128i*)(image+i*stride+j*16)))); - } - - for(j = j*16; j < size; j++) { - sad += abs((int)pattern[i*size+j] - image[i*stride+j]); - } - } - - sad += _mm_extract_epi16(a,0) + _mm_extract_epi16(a,4); - - return sad; -} -#else -static uint SAD(const ubyte* pattern, const ubyte* image, int stride, int size) { - uint sad=0; - for(int i = 0; i < size; i++) { - for(int j = 0; j < size; j++) { - sad += abs((int)pattern[i*size+j] - image[i*stride+j]); - } - } - return sad; -} -#endif - -float sq(float x) { return x*x; } -float Track(ubyte* reference, ubyte* warped, int size, ubyte* image, int stride, int w, int h, mat32* warp, float areaPenalty, float conditionPenalty) { - mat32 m=*warp; - uint min=-1; - - // exhaustive search integer pixel translation - int ix = m(0,2), iy = m(1,2); - for(int y = size/2; y < h-size/2; y++) { - for(int x = size/2; x < w-size/2; x++) { - m(0,2) = x, m(1,2) = y; - uint sad = SAD(warped,&image[(y-size/2)*stride+(x-size/2)],stride,size); - // TODO: using chroma could help disambiguate some cases - if(sad < min) { - min = sad; - ix = x, iy = y; - } - } - } - m(0,2) = ix, m(1,2) = iy; - min=-1; //reset score since direct warped search match too well (but the wrong pattern). - - // 6D coordinate descent to find affine transform - ubyte* match = new ubyte[size*size]; - float step = 0.5; - for(int p = 0; p < 8; p++) { //foreach precision level - for(int i = 0; i < 2; i++) { // iterate twice per precision level - //TODO: other sweep pattern might converge better - for(int d=0; d < 6; d++) { // iterate dimension sequentially (cyclic descent) - for(float e = -step; e <= step; e+=step) { //solve subproblem (evaluate only along one coordinate) - mat32 t = m; - t.data[d] += e; - //TODO: better performance would also allow a more exhaustive search - SamplePattern(image,stride,t,match,size); - uint sad = SAD(reference,match,size,size); - // regularization: keep constant area and good condition - float area = t(0,0)*t(1,1)-t(0,1)*t(1,0); - float x = sq(t(0,0))+sq(t(0,1)), y = sq(t(1,0))+sq(t(1,1)); - float condition = x>y ? x/y : y/x; - sad += size*size*( areaPenalty*sq(area-1) + conditionPenalty*sq(condition-1) ); - if(sad < min) { - min = sad; - m = t; - } - } - } - } - step /= 2; - } - *warp = m; - - // Compute Pearson product-moment correlation coefficient - uint sX=0,sY=0,sXX=0,sYY=0,sXY=0; - SamplePattern(image,stride,m,match,size); - SAD(reference,match,size,size); - for(int i = 0; i < size; i++) { - for(int j = 0; j < size; j++) { - int x = reference[i*size+j]; - int y = match[i*size+j]; - sX += x; - sY += y; - sXX += x*x; - sYY += y*y; - sXY += x*y; - } - } - delete[] match; - const int N = size*size; - sX /= N, sY /= N, sXX /= N, sYY /= N, sXY /= N; - return (sXY-sX*sY)/sqrt(double((sXX-sX*sX)*(sYY-sY*sY))); -} - -} // namespace libmv diff --git a/extern/libmv/libmv/tracking/sad.h b/extern/libmv/libmv/tracking/sad.h deleted file mode 100644 index 9fe323b74c4..00000000000 --- a/extern/libmv/libmv/tracking/sad.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (c) 2011 libmv authors. -** -** Permission is hereby granted, free of charge, to any person obtaining a copy -** of this software and associated documentation files (the "Software"), to -** deal in the Software without restriction, including without limitation the -** rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -** sell copies of the Software, and to permit persons to whom the Software is -** furnished to do so, subject to the following conditions: -** -** The above copyright notice and this permission notice shall be included in -** all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -** IN THE SOFTWARE. -** -****************************************************************************/ - -#ifndef LIBMV_TRACKING_SAD_H_ -#define LIBMV_TRACKING_SAD_H_ - -#ifdef __cplusplus -namespace libmv { -#endif - -typedef unsigned char ubyte; -typedef unsigned int uint; - -/*! - Convolve \a src into \a dst with the discrete laplacian operator. - - \a src and \a dst should be \a width x \a height images. - \a strength is an interpolation coefficient (0-256) between original image and the laplacian. - - \note Make sure the search region is filtered with the same strength as the pattern. -*/ -void LaplaceFilter(ubyte* src, ubyte* dst, int width, int height, int strength); - -/// Affine transformation matrix in column major order. -struct mat32 { - float data[3*2]; -#ifdef __cplusplus - inline mat32(int d=1) { for(int i=0;i<3*2;i++) data[i]=0; if(d!=0) for(int i=0;i<2;i++) m(i,i)=d; } - inline float m(int i, int j) const { return data[j*2+i]; } - inline float& m(int i, int j) { return data[j*2+i]; } - inline float operator()(int i, int j) const { return m(i,j); } - inline float& operator()(int i, int j) { return m(i,j); } - inline operator bool() const { for (int i=0; i<3*2; i++) if(data[i]!=0) return true; return false; } -#endif -}; - -/*! - Sample \a pattern from \a image. - - \a warp is the transformation to apply to \a image when sampling the \a pattern. -*/ -void SamplePattern(ubyte* image, int stride, mat32 warp, ubyte* pattern, int size); - -/*! - Track \a pattern in \a image. - - This template matcher computes the - \link http://en.wikipedia.org/wiki/Sum_of_absolute_differences Sum of Absolute Differences (SAD) \endlink - for each integer pixel position in the search region and then iteratively - refine subpixel position using a square search. - A similar method is used for motion estimation in video encoders. - - \a reference is the pattern to track. - \a warped is a warped version of reference for fast unsampled integer search. - Best is to directly extract an already warped pattern from previous frame. - The \a size of the patterns should be aligned to 16. - \a image is a reference to the region to search. - \a stride is size of \a image lines. - - On input, \a warp is the predicted affine transformation (e.g from previous frame) - On return, \a warp is the affine transformation which best match the reference \a pattern - - \a areaPenalty and conditionPenalty control the regularization and need to be tweaked depending on the motion. - Setting them to 0 will allow any transformation (including unrealistic distortions and scaling). - Good values are between 0-32. 16 can be used as a realistic default. - areaPenalty control scaling (decrease to allow pull/zoom, increase to allow only 2D rotation). - a large conditionPenalty avoid a large ratio between the largest and smallest axices. - It need to be decreased for non-2D rotation (when pattern appears to scale along an axis). - - \return Pearson product-moment correlation coefficient between reference and matched pattern. - This measure of the linear dependence between the patterns - ranges from −1 (negative correlation) to 1 (positive correlation). - A value of 0 implies that there is no linear correlation between the variables. - - \note To track affine features: - - Sample reference pattern using estimated (e.g previous frame) warp. - - - \note \a stride allow you to reference your search region instead of copying. - \note For a 16x speedup, compile this tracker with SSE2 support. -*/ -float Track(ubyte* reference, ubyte* warped, int size, ubyte* image, int stride, int width, int height, mat32* warp, - float areaPenalty, float conditionPenalty); - -#ifdef __cplusplus -} // namespace libmv -#endif - -#endif // LIBMV_TRACKING_SAD_H_ -- cgit v1.2.3 From ce95b0be1e40b7f696e2b78cebb245d76182c157 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 11 Apr 2012 13:51:37 +0000 Subject: libmv: bundle new upstream version from own branch which should support compilation of glog on hurd platform. --- extern/libmv/CMakeLists.txt | 5 +- extern/libmv/ChangeLog | 40 ++++-- extern/libmv/files.txt | 4 +- extern/libmv/third_party/glog/src/config.h | 2 + extern/libmv/third_party/glog/src/config_hurd.h | 166 ++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 18 deletions(-) create mode 100644 extern/libmv/third_party/glog/src/config_hurd.h (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 005bcdf0a3b..51f254264b6 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -47,7 +47,7 @@ if(APPLE) list(APPEND INC_SYS ${CMAKE_OSX_SYSROOT}/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include ) - endif() + endif() endif() # XXX - END @@ -102,8 +102,8 @@ set(SRC libmv/base/vector_utils.h libmv/image/array_nd.h libmv/image/convolve.h - libmv/image/image.h libmv/image/correlation.h + libmv/image/image.h libmv/image/sample.h libmv/image/tuple.h libmv/logging/logging.h @@ -217,6 +217,7 @@ else() third_party/glog/src/base/mutex.h third_party/glog/src/config_freebsd.h third_party/glog/src/config.h + third_party/glog/src/config_hurd.h third_party/glog/src/config_linux.h third_party/glog/src/config_mac.h third_party/glog/src/demangle.h diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index 4e5c093c484..ac5a404bafa 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,3 +1,29 @@ +commit 9618d9a1d48bb3c28da605d9027f57a74f462785 +Author: Sergey Sharybin +Date: Wed Apr 11 14:17:14 2012 +0600 + + Added configuration file for glog to compile smooth on Hurd platform. + + Patch by Pino Toscano , thanks! + +commit 63b2bd20237c8599fa73ce42556e4fb99b9f7cca +Author: Sergey Sharybin +Date: Thu Mar 22 17:03:34 2012 +0600 + + Trackers refactoring: + - Deduplicate pattern sampling used in esm and lmicklt trackers + and move SamplePattern to image/sample.h + - Move computation of Pearson product-moment correlation into + own function in new file image/correlation.h so all trackers + can use it to check final correlation. + - Remove SAD tracker. It's almost the same as brute tracker, + with only two differences: + 1. It does brute search of affine transformation which in some cases + helps to track rotating features + 2. It didn't use common tracker api which probably gave some speed + advantage, but lead to a real headache to use it together with + other trackers leading to duplicated code in 3d-party software. + commit 9fe49c32e990f28c83f2bbb1d18057aed8879af7 Author: Sergey Sharybin Date: Mon Mar 12 09:36:15 2012 +0600 @@ -475,17 +501,3 @@ Date: Fri Aug 19 14:19:27 2011 +0200 Add LaplaceFilter. Add regularization in affine SAD Tracker (keep constant area and good condition number). UI: Better track display (+enable line antialiasing). - -commit 6d26d9a8ccc4ce009fbf253898fea8864dd5001a -Author: Matthias Fauconneau -Date: Fri Aug 19 10:25:26 2011 +0200 - - Add optimization for integer pixel search. - Allows more agressive settings for affine coordinate descent. - -commit 70ceae81c0ab561b07e640ecb9933f0a902b57cd -Author: Matthias Fauconneau -Date: Fri Aug 19 00:02:12 2011 +0200 - - Document coordinate descent method in affine SAD matcher. - Add heuristic to prevent high distortions. diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt index 028af579d11..426a573de4e 100644 --- a/extern/libmv/files.txt +++ b/extern/libmv/files.txt @@ -6,6 +6,7 @@ libmv/image/array_nd.cc libmv/image/array_nd.h libmv/image/convolve.cc libmv/image/convolve.h +libmv/image/correlation.h libmv/image/image.h libmv/image/sample.h libmv/image/tuple.h @@ -64,8 +65,6 @@ libmv/tracking/pyramid_region_tracker.h libmv/tracking/region_tracker.h libmv/tracking/retrack_region_tracker.cc libmv/tracking/retrack_region_tracker.h -libmv/tracking/sad.cc -libmv/tracking/sad.h libmv/tracking/trklt_region_tracker.cc libmv/tracking/trklt_region_tracker.h third_party/fast/fast_10.c @@ -103,6 +102,7 @@ third_party/glog/src/base/googleinit.h third_party/glog/src/base/mutex.h third_party/glog/src/config_freebsd.h third_party/glog/src/config.h +third_party/glog/src/config_hurd.h third_party/glog/src/config_linux.h third_party/glog/src/config_mac.h third_party/glog/src/demangle.cc diff --git a/extern/libmv/third_party/glog/src/config.h b/extern/libmv/third_party/glog/src/config.h index 102bf9e4034..f5c9c0b0a7b 100644 --- a/extern/libmv/third_party/glog/src/config.h +++ b/extern/libmv/third_party/glog/src/config.h @@ -12,4 +12,6 @@ #include "config_linux.h" #elif defined(_MSC_VER) #include "windows/config.h" +#elif defined(__GNU__) + #include "config_hurd.h" #endif diff --git a/extern/libmv/third_party/glog/src/config_hurd.h b/extern/libmv/third_party/glog/src/config_hurd.h new file mode 100644 index 00000000000..47aefa423d6 --- /dev/null +++ b/extern/libmv/third_party/glog/src/config_hurd.h @@ -0,0 +1,166 @@ +/* src/config.h. Generated from config.h.in by configure. */ +/* src/config.h.in. Generated from configure.ac by autoheader. */ + +/* Namespace for Google classes */ +#define GOOGLE_NAMESPACE google + +/* Define if you have the `dladdr' function */ +/* #undef HAVE_DLADDR */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_EXECINFO_H 1 + +/* Define if you have the `fcntl' function */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_GLOB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `pthread' library (-lpthread). */ +#define HAVE_LIBPTHREAD 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LIBUNWIND_H */ + +/* define if you have google gflags library */ +#define HAVE_LIB_GFLAGS 1 + +/* define if you have google gmock library */ +/* #undef HAVE_LIB_GMOCK */ + +/* define if you have google gtest library */ +/* #undef HAVE_LIB_GTEST */ + +/* define if you have libunwind */ +/* #undef HAVE_LIB_UNWIND */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* define if the compiler implements namespaces */ +#define HAVE_NAMESPACES 1 + +/* Define if you have POSIX threads libraries and header files. */ +#define HAVE_PTHREAD 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_PWD_H 1 + +/* define if the compiler implements pthread_rwlock_* */ +#define HAVE_RWLOCK 1 + +/* Define if you have the `sigaltstack' function */ +#define HAVE_SIGALTSTACK 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYSCALL_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYSLOG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SYSCALL_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UCONTEXT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UTSNAME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UCONTEXT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* define if the compiler supports using expression for operator */ +#define HAVE_USING_OPERATOR 1 + +/* define if your compiler has __attribute__ */ +#define HAVE___ATTRIBUTE__ 1 + +/* define if your compiler has __builtin_expect */ +#define HAVE___BUILTIN_EXPECT 1 + +/* define if your compiler has __sync_val_compare_and_swap */ +/* #undef HAVE___SYNC_VAL_COMPARE_AND_SWAP */ + +/* Name of package */ +#define PACKAGE "glog" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "opensource@google.com" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "glog" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "glog 0.3.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "glog" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.3.1" + +/* How to access the PC from a struct ucontext */ +#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) + #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] +#elif defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) + #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_EIP] +#else + #undef PC_FROM_UCONTEXT +#endif + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 4 + +/* Define to 1 if you have the ANSI C header files. */ +/* #undef STDC_HEADERS */ + +#define STDC_HEADERS 1 +/* the namespace where STL code like vector<> is defined */ +#define STL_NAMESPACE std + +/* location of source code */ +#define TEST_SRC_DIR "." + +/* Version number of package */ +#define VERSION "0.3.1" + +/* Stops putting the code inside the Google namespace */ +#define _END_GOOGLE_NAMESPACE_ } + +/* Puts following code inside the Google namespace */ +#define _START_GOOGLE_NAMESPACE_ namespace google { -- cgit v1.2.3 From e6c45cc1de178c083fbcbcc83f2438ff8575b7b0 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 12 Apr 2012 11:37:51 +0000 Subject: libmv: bundle new upstream version from own branch with rigid registration implementation Currently not used in blender code but is needed for some current work. --- extern/libmv/CMakeLists.txt | 2 + extern/libmv/ChangeLog | 41 ++++- extern/libmv/files.txt | 2 + extern/libmv/libmv-capi.cpp | 56 +++++++ extern/libmv/libmv-capi.h | 4 + extern/libmv/libmv/numeric/numeric.h | 11 ++ extern/libmv/libmv/simple_pipeline/resect.cc | 10 -- .../libmv/simple_pipeline/rigid_registration.cc | 182 +++++++++++++++++++++ .../libmv/simple_pipeline/rigid_registration.h | 68 ++++++++ 9 files changed, 358 insertions(+), 18 deletions(-) create mode 100644 extern/libmv/libmv/simple_pipeline/rigid_registration.cc create mode 100644 extern/libmv/libmv/simple_pipeline/rigid_registration.h (limited to 'extern') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 51f254264b6..02723b64b62 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -72,6 +72,7 @@ set(SRC libmv/simple_pipeline/pipeline.cc libmv/simple_pipeline/reconstruction.cc libmv/simple_pipeline/resect.cc + libmv/simple_pipeline/rigid_registration.cc libmv/simple_pipeline/tracks.cc libmv/tracking/brute_region_tracker.cc libmv/tracking/esm_region_tracker.cc @@ -128,6 +129,7 @@ set(SRC libmv/simple_pipeline/pipeline.h libmv/simple_pipeline/reconstruction.h libmv/simple_pipeline/resect.h + libmv/simple_pipeline/rigid_registration.h libmv/simple_pipeline/tracks.h libmv/tracking/brute_region_tracker.h libmv/tracking/esm_region_tracker.h diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index ac5a404bafa..33068bddf90 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,3 +1,36 @@ +commit fa3842e472e3b9c789e47bf6d8f592aa40a84f16 +Author: Sergey Sharybin +Date: Thu Apr 12 12:32:48 2012 +0600 + + implementation of some basic algorithms for point cloud orientation: + + - Implementation of rigid registration algorithm which searches transformation + form one point cloud to another assuming that points in this clouds are + already paired (points with the same index in different clouds belongs to + the same pair) which minimizes average distance between points in pairs. + + Algorithm uses Levenberg-Marquardt solver to find such transformation. + + Supports registration of rotation-scale-transform (which is probably most + common usage) and rotation only (which might be useful for basic modal + tripod solver). + + - Implementation of Iterative-Point-Clouds algorithm which searches + transformation from one arbitrary point cloud to another making + points as closest to each other as possible. + + This algorithm doesn't require points be initially paired, but for + good result clouds should have rough initial orientation. If they're + arbitrary oriented from the very beginning, algorithm might fail + producing good resold. + + Iteration is based on building pairs of closest to each other points + and registering rigid transformation between them which incrementally + constructs final result. + + TODO: building pairs might be speedup a lot using data structures like + AABB trees, K-D trees or so. + commit 9618d9a1d48bb3c28da605d9027f57a74f462785 Author: Sergey Sharybin Date: Wed Apr 11 14:17:14 2012 +0600 @@ -493,11 +526,3 @@ Author: Matthias Fauconneau Date: Fri Aug 19 14:59:24 2011 +0200 Expose regularization parameters (areaPenalty and conditionPenalty) in API. - -commit 3e84ae5fbac10451d4935418f6281a90cedace11 -Author: Matthias Fauconneau -Date: Fri Aug 19 14:19:27 2011 +0200 - - Add LaplaceFilter. - Add regularization in affine SAD Tracker (keep constant area and good condition number). - UI: Better track display (+enable line antialiasing). diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt index 426a573de4e..1e564d3a2f2 100644 --- a/extern/libmv/files.txt +++ b/extern/libmv/files.txt @@ -48,6 +48,8 @@ libmv/simple_pipeline/reconstruction.cc libmv/simple_pipeline/reconstruction.h libmv/simple_pipeline/resect.cc libmv/simple_pipeline/resect.h +libmv/simple_pipeline/rigid_registration.cc +libmv/simple_pipeline/rigid_registration.h libmv/simple_pipeline/tracks.cc libmv/simple_pipeline/tracks.h libmv/tracking/brute_region_tracker.cc diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp index 7fd4bfdd9d1..e4708e5907d 100644 --- a/extern/libmv/libmv-capi.cpp +++ b/extern/libmv/libmv-capi.cpp @@ -36,6 +36,8 @@ #include "Math/v3d_optimization.h" +#include "libmv/numeric/numeric.h" + #include "libmv/tracking/esm_region_tracker.h" #include "libmv/tracking/brute_region_tracker.h" #include "libmv/tracking/hybrid_region_tracker.h" @@ -51,6 +53,7 @@ #include "libmv/simple_pipeline/detect.h" #include "libmv/simple_pipeline/pipeline.h" #include "libmv/simple_pipeline/camera_intrinsics.h" +#include "libmv/simple_pipeline/rigid_registration.h" #include #include @@ -838,3 +841,56 @@ void libmv_InvertIntrinsics(double focal_length, double principal_x, double prin intrinsics.InvertIntrinsics(x, y, x1, y1); } } + +/* ************ point clouds ************ */ + +void libmvTransformToMat4(libmv::Mat3 &R, libmv::Vec3 &S, libmv::Vec3 &t, double M[4][4]) +{ + for (int j = 0; j < 3; ++j) + for (int k = 0; k < 3; ++k) + M[j][k] = R(k, j) * S(j); + + for (int i = 0; i < 3; ++i) { + M[3][0] = t(0); + M[3][1] = t(1); + M[3][2] = t(2); + + M[0][3] = M[1][3] = M[2][3] = 0; + } + + M[3][3] = 1.0; +} + +void libmv_rigidRegistration(float (*reference_points)[3], float (*points)[3], int total_points, + int use_scale, int use_translation, double M[4][4]) +{ + libmv::Mat3 R; + libmv::Vec3 S; + libmv::Vec3 t; + libmv::vector reference_points_vector, points_vector; + + for (int i = 0; i < total_points; i++) { + reference_points_vector.push_back(libmv::Vec3(reference_points[i][0], + reference_points[i][1], + reference_points[i][2])); + + points_vector.push_back(libmv::Vec3(points[i][0], + points[i][1], + points[i][2])); + } + + if (use_scale && use_translation) { + libmv::RigidRegistration(reference_points_vector, points_vector, R, S, t); + } + else if (use_translation) { + S = libmv::Vec3(1.0, 1.0, 1.0); + libmv::RigidRegistration(reference_points_vector, points_vector, R, t); + } + else { + S = libmv::Vec3(1.0, 1.0, 1.0); + t = libmv::Vec3::Zero(); + libmv::RigidRegistration(reference_points_vector, points_vector, R); + } + + libmvTransformToMat4(R, S, t, M); +} diff --git a/extern/libmv/libmv-capi.h b/extern/libmv/libmv-capi.h index e5728188afb..01019832374 100644 --- a/extern/libmv/libmv-capi.h +++ b/extern/libmv/libmv-capi.h @@ -129,6 +129,10 @@ void libmv_applyCameraIntrinsics(double focal_length, double principal_x, double void libmv_InvertIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3, double x, double y, double *x1, double *y1); +/* point clouds */ +void libmv_rigidRegistration(float (*reference_points)[3], float (*points)[3], int total_points, + int use_scale, int use_translation, double M[4][4]); + #ifdef __cplusplus } #endif diff --git a/extern/libmv/libmv/numeric/numeric.h b/extern/libmv/libmv/numeric/numeric.h index bb7f9b364ef..ad707fb76f2 100644 --- a/extern/libmv/libmv/numeric/numeric.h +++ b/extern/libmv/libmv/numeric/numeric.h @@ -474,6 +474,17 @@ inline Mat23 SkewMatMinimal(const Vec2 &x) { 1, 0, -x(0); return skew; } + +/// Returns the rotaiton matrix built from given vector of euler angles +inline Mat3 RotationFromEulerVector(Vec3 euler_vector) { + double theta = euler_vector.norm(); + if (theta == 0.0) { + return Mat3::Identity(); + } + Vec3 w = euler_vector / theta; + Mat3 w_hat = CrossProductMatrix(w); + return Mat3::Identity() + w_hat*sin(theta) + w_hat*w_hat*(1 - cos(theta)); +} } // namespace libmv #endif // LIBMV_NUMERIC_NUMERIC_H diff --git a/extern/libmv/libmv/simple_pipeline/resect.cc b/extern/libmv/libmv/simple_pipeline/resect.cc index 6e71c3c7206..b30d959b512 100644 --- a/extern/libmv/libmv/simple_pipeline/resect.cc +++ b/extern/libmv/libmv/simple_pipeline/resect.cc @@ -42,16 +42,6 @@ Mat2X PointMatrixFromMarkers(const vector &markers) { return points; } -Mat3 RotationFromEulerVector(Vec3 euler_vector) { - double theta = euler_vector.norm(); - if (theta == 0.0) { - return Mat3::Identity(); - } - Vec3 w = euler_vector / theta; - Mat3 w_hat = CrossProductMatrix(w); - return Mat3::Identity() + w_hat*sin(theta) + w_hat*w_hat*(1 - cos(theta)); -} - // Uses an incremental rotation: // // x = R' * R * X + t; diff --git a/extern/libmv/libmv/simple_pipeline/rigid_registration.cc b/extern/libmv/libmv/simple_pipeline/rigid_registration.cc new file mode 100644 index 00000000000..f7cb1e66e7d --- /dev/null +++ b/extern/libmv/libmv/simple_pipeline/rigid_registration.cc @@ -0,0 +1,182 @@ +// Copyright (c) 2012 libmv authors. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#include "libmv/simple_pipeline/rigid_registration.h" +#include "libmv/numeric/levenberg_marquardt.h" + +namespace libmv { + +template +struct RigidRegistrationCostFunction { + public: + typedef Vec FMatrixType; + typedef RigidTransformation XMatrixType; + + RigidRegistrationCostFunction(const vector &reference_points, + const vector &points): + reference_points_(reference_points), + points_(points) {} + + Vec CalculateResiduals(const Mat3 &R, + const Vec3 &S, + const Vec3 &t) const { + Vec residuals(points_.size()); + residuals.setZero(); + + // Convert scale vector to matrix + Mat3 SMat = Mat3::Identity(); + SMat(0, 0) *= S(0); + SMat(1, 1) *= S(1); + SMat(2, 2) *= S(2); + + for (int i = 0; i < points_.size(); i++) { + Vec3 transformed_point = R * SMat * points_[i] + t; + + double norm = (transformed_point - reference_points_[i]).norm(); + + residuals(i) = norm * norm; + } + + return residuals; + } + + Vec operator()(const Vec9 &RSt) const { + Mat3 R = RotationFromEulerVector(RSt.head<3>()); + Vec3 S = RSt.segment<3>(3); + Vec3 t = RSt.tail<3>(); + + return CalculateResiduals(R, S, t); + } + + Vec operator()(const Vec3 &euler) const { + Mat3 R = RotationFromEulerVector(euler); + + return CalculateResiduals(R, Vec3(1.0, 1.0, 1.0), Vec3::Zero()); + } + + Vec operator()(const Vec6 &Rt) const { + Mat3 R = RotationFromEulerVector(Rt.head<3>()); + Vec3 t = Rt.tail<3>(); + + return CalculateResiduals(R, Vec3(1.0, 1.0, 1.0), t); + } + + private: + vector reference_points_; + vector points_; +}; + +static double RigidRegistrationError(const vector &reference_points, + const vector &points, + const Mat3 &R, + const Vec3 &S, + const Vec3 &t) { + double error = 0.0; + + Mat3 SMat = Mat3::Identity(); + SMat(0, 0) *= S(0); + SMat(1, 1) *= S(1); + SMat(2, 2) *= S(2); + + for (int i = 0; i < points.size(); i++) { + Vec3 new_point = R * SMat * points[i] + t; + + double norm = (new_point - reference_points[i]).norm(); + error += norm * norm; + } + error /= points.size(); + + return error; +} + +double RigidRegistration(const vector &reference_points, + const vector &points, + Mat3 &R, + Vec3 &S, + Vec3 &t) { + typedef LevenbergMarquardt > Solver; + + RigidRegistrationCostFunction rigidregistration_cost(reference_points, points); + Solver solver(rigidregistration_cost); + + Vec9 RSt = Vec9::Zero(); + + RSt(3) = RSt(4) = RSt(5) = 1.0; + + Solver::SolverParameters params; + /*Solver::Results results = */ solver.minimize(params, &RSt); + /* TODO(sergey): better error handling here */ + + LG << "Rigid registration completed, rotation is:" << RSt.head<3>().transpose() + << ", scale is " << RSt.segment<3>(3).transpose() + << ", translation is " << RSt.tail<3>().transpose(); + + // Decompose individual rotation and translation + R = RotationFromEulerVector(RSt.head<3>()); + S = RSt.segment<3>(3); + t = RSt.tail<3>(); + + return RigidRegistrationError(reference_points, points, R, S, t); +} + +double RigidRegistration(const vector &reference_points, + const vector &points, + Mat3 &R, + Vec3 &t) { + typedef LevenbergMarquardt > Solver; + + RigidRegistrationCostFunction rigidregistration_cost(reference_points, points); + Solver solver(rigidregistration_cost); + + Vec6 Rt = Vec6::Zero(); + Solver::SolverParameters params; + /*Solver::Results results = */solver.minimize(params, &Rt); + /* TODO(sergey): better error handling here */ + + LG << "Rigid registration completed, rotation is:" << Rt.head<3>().transpose() + << ", translation is " << Rt.tail<3>().transpose(); + + R = RotationFromEulerVector(Rt.head<3>()); + t = Rt.tail<3>(); + + return RigidRegistrationError(reference_points, points, R, Vec3(1.0, 1.0, 1.0), t); +} + +double RigidRegistration(const vector &reference_points, + const vector &points, + Mat3 &R) { + typedef LevenbergMarquardt > Solver; + + RigidRegistrationCostFunction rigidregistration_cost(reference_points, points); + Solver solver(rigidregistration_cost); + + Vec3 euler = Vec3::Zero(); + Solver::SolverParameters params; + /*Solver::Results results = */solver.minimize(params, &euler); + /* TODO(sergey): better error handling here */ + + LG << "Rigid registration completed, rotation is:" << euler.transpose(); + + R = RotationFromEulerVector(euler); + + return RigidRegistrationError(reference_points, points, R, Vec3(1.0, 1.0, 1.0), Vec3::Zero()); +} + +} // namespace libmv diff --git a/extern/libmv/libmv/simple_pipeline/rigid_registration.h b/extern/libmv/libmv/simple_pipeline/rigid_registration.h new file mode 100644 index 00000000000..21ea57af507 --- /dev/null +++ b/extern/libmv/libmv/simple_pipeline/rigid_registration.h @@ -0,0 +1,68 @@ +// Copyright (c) 2012 libmv authors. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#ifndef LIBMV_SIMPLE_PIPELINE_RIGID_REGISTRATION_H_ +#define LIBMV_SIMPLE_PIPELINE_RIGID_REGISTRATION_H_ + +#include "libmv/base/vector.h" +#include "libmv/numeric/numeric.h" + +namespace libmv { + +/*! + Searched for an affine transformation of rigid 3D object defined by it's + vertices positions from it's current state called points to it's desired + state called reference points. + + Returns rotation matrix, per-component scale vector and translation which + transforms points to the mot close state to reference_points. + + Return value is an average squared distance between reference state + and transformed one. + + Minimzation of distance between point pairs is used to register such a + rigid transformation and algorithm assumes that pairs of points are + defined by point's index in a vector, so points with the same index + belongs to the same pair. + */ +double RigidRegistration(const vector &reference_points, + const vector &points, + Mat3 &R, + Vec3 &S, + Vec3 &t); + +/*! + * Same as RigidRegistration but provides registration of rotation and translation only + */ +double RigidRegistration(const vector &reference_points, + const vector &points, + Mat3 &R, + Vec3 &t); + +/*! + * Same as RigidRegistration but provides registration of rotation only + */ +double RigidRegistration(const vector &reference_points, + const vector &points, + Mat3 &R); + +} // namespace libmv + +#endif // LIBMV_SIMPLE_PIPELINE_RIGID_REGISTRATION_H_ -- cgit v1.2.3