[Bf-blender-cvs] [c605711] master: Libmv cleanup: move aligned malloc implementation into own file

Sergey Sharybin noreply at git.blender.org
Wed Apr 23 12:03:56 CEST 2014


Commit: c605711c6b21a7f41c063b93335c6d57b671af19
Author: Sergey Sharybin
Date:   Wed Apr 23 16:02:30 2014 +0600
https://developer.blender.org/rBc605711c6b21a7f41c063b93335c6d57b671af19

Libmv cleanup: move aligned malloc implementation into own file

It was rather stupid having it in brute region tracker,
now it is in own file in base library.

===================================================================

M	extern/libmv/CMakeLists.txt
M	extern/libmv/ChangeLog
M	extern/libmv/SConscript
M	extern/libmv/files.txt
A	extern/libmv/libmv/base/aligned_malloc.cc
A	extern/libmv/libmv/base/aligned_malloc.h
M	extern/libmv/libmv/tracking/brute_region_tracker.cc

===================================================================

diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt
index f44c78c..c3c5143 100644
--- a/extern/libmv/CMakeLists.txt
+++ b/extern/libmv/CMakeLists.txt
@@ -59,6 +59,7 @@ if(WITH_LIBMV)
 	list(APPEND SRC
 		libmv-capi.cc
 		libmv-util.cc
+		libmv/base/aligned_malloc.cc
 		libmv/image/array_nd.cc
 		libmv/image/convolve.cc
 		libmv/multiview/conditioning.cc
@@ -96,6 +97,7 @@ if(WITH_LIBMV)
 		third_party/gflags/gflags_reporting.cc
 
 		libmv-util.h
+		libmv/base/aligned_malloc.h
 		libmv/base/id_generator.h
 		libmv/base/scoped_ptr.h
 		libmv/base/vector.h
diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog
index b324777..f1b4ca7 100644
--- a/extern/libmv/ChangeLog
+++ b/extern/libmv/ChangeLog
@@ -1,3 +1,20 @@
+commit d14049e00dabf8fdf49056779f0a3718fbb39e8f
+Author: Sergey Sharybin <sergey.vfx at gmail.com>
+Date:   Wed Apr 23 15:08:16 2014 +0600
+
+    Move aligned malloc implementation into own file
+    
+    It was rather stupid having it in brute region tracker,
+    now it is in own file in base library (which was also
+    added in this commit, before this it consist of header
+    files only).
+    
+    Reviewers: keir
+    
+    Reviewed By: keir
+    
+    Differential Revision: https://developer.blender.org/D479
+
 commit 0ddf3851bfcb8de43660b119a25a77a25674200d
 Author: Sergey Sharybin <sergey.vfx at gmail.com>
 Date:   Mon Apr 21 14:14:03 2014 +0600
@@ -672,12 +689,3 @@ Date:   Tue Jun 18 19:24:07 2013 +0600
       We could end up with something smarter in the
       future, but for now i'm not as much fan of
       forcing compiler's flag.
-
-commit 2b90b3915671cb629f7aabed30a88f28450294f8
-Author: Sergey Sharybin <sergey.vfx at gmail.com>
-Date:   Sat Jun 1 16:20:35 2013 +0600
-
-    Pass vectors by a reference
-    
-    Saves couple of time which used to waste on copying objects,
-    also solves win32 compilation errors caused by alignment.
diff --git a/extern/libmv/SConscript b/extern/libmv/SConscript
index 72acb4b..dc12950 100644
--- a/extern/libmv/SConscript
+++ b/extern/libmv/SConscript
@@ -19,6 +19,7 @@ if env['WITH_BF_LIBMV']:
     defs.append('LIBMV_NO_FAST_DETECTOR')
 
     src = env.Glob('*.cc')
+    src += env.Glob('libmv/base/*.cc')
     src += env.Glob('libmv/image/*.cc')
     src += env.Glob('libmv/multiview/*.cc')
     src += env.Glob('libmv/numeric/*.cc')
diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt
index 316a94f..60a9930 100644
--- a/extern/libmv/files.txt
+++ b/extern/libmv/files.txt
@@ -1,3 +1,5 @@
+libmv/base/aligned_malloc.cc
+libmv/base/aligned_malloc.h
 libmv/base/id_generator.h
 libmv/base/scoped_ptr.h
 libmv/base/vector.h
diff --git a/extern/libmv/libmv/base/aligned_malloc.cc b/extern/libmv/libmv/base/aligned_malloc.cc
new file mode 100644
index 0000000..24a393a
--- /dev/null
+++ b/extern/libmv/libmv/base/aligned_malloc.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2014 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/base/aligned_malloc.h"
+
+#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
+// Needed for memalign on Linux and _aligned_alloc on Windows.
+#  ifdef FREE_WINDOWS
+/* make sure _aligned_malloc is included */
+#    ifdef __MSVCRT_VERSION__
+#      undef __MSVCRT_VERSION__
+#    endif
+
+#    define __MSVCRT_VERSION__ 0x0700
+#  endif  // FREE_WINDOWS
+
+#  include <malloc.h>
+#else
+// Apple's malloc is 16-byte aligned, and does not have malloc.h, so include
+// stdilb instead.
+#  include <cstdlib>
+#endif
+
+namespace libmv {
+
+void *aligned_malloc(int size, int alignment) {
+#ifdef _WIN32
+  return _aligned_malloc(size, alignment);
+#elif __APPLE__
+  // On Mac OS X, both the heap and the stack are guaranteed 16-byte aligned so
+  // they work natively with SSE types with no further work.
+  CHECK_EQ(alignment, 16);
+  return malloc(size);
+#elif defined(__FreeBSD__) || defined(__NetBSD__)
+  void *result;
+
+  if (posix_memalign(&result, alignment, size)) {
+    // non-zero means allocation error
+    // either no allocation or bad alignment value
+    return NULL;
+  }
+  return result;
+#else  // This is for Linux.
+  return memalign(alignment, size);
+#endif
+}
+
+void aligned_free(void *ptr) {
+#ifdef _WIN32
+  _aligned_free(ptr);
+#else
+  free(ptr);
+#endif
+}
+
+}  // namespace libmv
diff --git a/extern/libmv/libmv/base/aligned_malloc.h b/extern/libmv/libmv/base/aligned_malloc.h
new file mode 100644
index 0000000..096ff6e
--- /dev/null
+++ b/extern/libmv/libmv/base/aligned_malloc.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2014 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_BASE_ALIGNED_MALLOC_H_
+#define LIBMV_BASE_ALIGNED_MALLOC_H_
+
+namespace libmv {
+
+// Allocate block of size bytes at least aligned to a given value.
+void *aligned_malloc(int size, int alignment);
+
+// Free memory allocated by aligned_malloc.
+void aligned_free(void *ptr);
+
+}  // namespace libmv
+
+#endif  // LIBMV_BASE_ALIGNED_MALLOC_H_
diff --git a/extern/libmv/libmv/tracking/brute_region_tracker.cc b/extern/libmv/libmv/tracking/brute_region_tracker.cc
index fc721eb..4a2aef6 100644
--- a/extern/libmv/libmv/tracking/brute_region_tracker.cc
+++ b/extern/libmv/libmv/tracking/brute_region_tracker.cc
@@ -21,27 +21,10 @@
 #include "libmv/tracking/brute_region_tracker.h"
 
 #ifdef __SSE2__
-#include <emmintrin.h>
-#endif
-
-#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
-// Needed for memalign on Linux and _aligned_alloc on Windows.
-#ifdef FREE_WINDOWS
-/* make sure _aligned_malloc is included */
-#ifdef __MSVCRT_VERSION__
-#undef __MSVCRT_VERSION__
-#endif
-
-#define __MSVCRT_VERSION__ 0x0700
-#endif
-
-#include <malloc.h>
-#else
-// Apple's malloc is 16-byte aligned, and does not have malloc.h, so include
-// stdilb instead.
-#include <cstdlib>
+#  include <emmintrin.h>
 #endif
 
+#include "libmv/base/aligned_malloc.h"
 #include "libmv/image/image.h"
 #include "libmv/image/convolve.h"
 #include "libmv/image/correlation.h"
@@ -51,37 +34,6 @@
 namespace libmv {
 namespace {
 
-// TODO(keir): It's stupid that this is needed here. Push this somewhere else.
-void *aligned_malloc(int size, int alignment) {
-#ifdef _WIN32
-  return _aligned_malloc(size, alignment);
-#elif __APPLE__
-  // On Mac OS X, both the heap and the stack are guaranteed 16-byte aligned so
-  // they work natively with SSE types with no further work.
-  CHECK_EQ(alignment, 16);
-  return malloc(size);
-#elif defined(__FreeBSD__) || defined(__NetBSD__)
-  void *result;
-
-  if (posix_memalign(&result, alignment, size)) {
-    // non-zero means allocation error
-    // either no allocation or bad alignment value
-    return NULL;
-  }
-  return result;
-#else  // This is for Linux.
-  return memalign(alignment, size);
-#endif
-}
-
-void aligned_free(void *ptr) {
-#ifdef _WIN32
-  _aligned_free(ptr);
-#else
-  free(ptr);
-#endif
-}
-
 bool RegionIsInBounds(const FloatImage &image1,
                       double x, double y,
                       int half_window_size) {




More information about the Bf-blender-cvs mailing list