[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59696] trunk/blender/intern/guardedalloc: use strict flags for guarded alloc

Campbell Barton ideasman42 at gmail.com
Sun Sep 1 04:46:34 CEST 2013


Revision: 59696
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59696
Author:   campbellbarton
Date:     2013-09-01 02:46:34 +0000 (Sun, 01 Sep 2013)
Log Message:
-----------
use strict flags for guarded alloc

Modified Paths:
--------------
    trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
    trunk/blender/intern/guardedalloc/intern/mallocn.c

Modified: trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2013-09-01 00:46:04 UTC (rev 59695)
+++ trunk/blender/intern/guardedalloc/MEM_guardedalloc.h	2013-09-01 02:46:34 UTC (rev 59696)
@@ -190,7 +190,7 @@
 	 * Are the start/end block markers still correct ?
 	 *
 	 * @retval 0 for correct memory, 1 for corrupted memory. */
-	int MEM_check_memory_integrity(void);
+	bool MEM_check_memory_integrity(void);
 
 	/** Set thread locking functions for safe memory allocation from multiple
 	 * threads, pass NULL pointers to disable thread locking again. */
@@ -207,13 +207,13 @@
 	/** Get mapped memory usage. */
 	uintptr_t MEM_get_mapped_memory_in_use(void);
 	/** Get amount of memory blocks in use. */
-	int MEM_get_memory_blocks_in_use(void);
+	unsigned int MEM_get_memory_blocks_in_use(void);
 
 	/** Reset the peak memory statistic to zero. */
 	void MEM_reset_peak_memory(void);
 
 	/** Get the peak memory usage in bytes, including mmap allocations. */
-	uintptr_t MEM_get_peak_memory(void)
+	size_t MEM_get_peak_memory(void)
 #if MEM_GNU_ATTRIBUTES
 	__attribute__((warn_unused_result))
 #endif

Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c	2013-09-01 00:46:04 UTC (rev 59695)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c	2013-09-01 02:46:34 UTC (rev 59696)
@@ -37,6 +37,9 @@
 #include <stdarg.h>
 #include <sys/types.h>
 
+/* to ensure strict conversions */
+#include "../../source/blender/blenlib/BLI_strict_flags.h"
+
 /* mmap exception */
 #if defined(WIN32)
 #  include "mmap_win.h"
@@ -61,15 +64,6 @@
 
 #include "atomic_ops.h"
 
-/* Blame Microsoft for LLP64 and no inttypes.h, quick workaround needed: */
-#if defined(WIN64)
-#  define SIZET_FORMAT "%I64u"
-#  define SIZET_ARG(a) ((unsigned long long)(a))
-#else
-#  define SIZET_FORMAT "%lu"
-#  define SIZET_ARG(a) ((unsigned long)(a))
-#endif
-
 /* Only for debugging:
  * store original buffer's name when doing MEM_dupallocN
  * helpful to profile issues with non-freed "dup_alloc" buffers,
@@ -118,6 +112,18 @@
 }
 #endif
 
+/* Blame Microsoft for LLP64 and no inttypes.h, quick workaround needed: */
+#if defined(WIN64)
+#  define SIZET_FORMAT "%I64u"
+#  define SIZET_ARG(a) ((unsigned long long)(a))
+#else
+#  define SIZET_FORMAT "%lu"
+#  define SIZET_ARG(a) ((unsigned long)(a))
+#endif
+
+#define SIZET_ALIGN_4(len) ((len + 3) & ~(size_t)3)
+
+
 /* --------------------------------------------------------------------- */
 /* Data definition                                                       */
 /* --------------------------------------------------------------------- */
@@ -227,7 +233,7 @@
 static void (*thread_lock_callback)(void) = NULL;
 static void (*thread_unlock_callback)(void) = NULL;
 
-static int malloc_debug_memset = 0;
+static bool malloc_debug_memset = false;
 
 #ifdef malloc
 #undef malloc
@@ -298,7 +304,7 @@
 		thread_unlock_callback();
 }
 
-int MEM_check_memory_integrity(void)
+bool MEM_check_memory_integrity(void)
 {
 	const char *err_val = NULL;
 	MemHead *listend;
@@ -325,7 +331,7 @@
 
 void MEM_set_memory_debug(void)
 {
-	malloc_debug_memset = 1;
+	malloc_debug_memset = true;
 }
 
 size_t MEM_allocN_len(const void *vmemh)
@@ -518,7 +524,7 @@
 {
 	MemHead *memh;
 
-	len = (len + 3) & ~3;   /* allocate in units of 4 */
+	len = SIZET_ALIGN_4(len);
 	
 	memh = (MemHead *)malloc(len + sizeof(MemHead) + sizeof(MemTail));
 
@@ -543,7 +549,7 @@
 {
 	MemHead *memh;
 
-	len = (len + 3) & ~3;   /* allocate in units of 4 */
+	len = SIZET_ALIGN_4(len);
 
 	memh = (MemHead *)calloc(len + sizeof(MemHead) + sizeof(MemTail), 1);
 
@@ -566,7 +572,7 @@
 {
 	MemHead *memh;
 
-	len = (len + 3) & ~3;   /* allocate in units of 4 */
+	len = SIZET_ALIGN_4(len);
 
 #if defined(WIN32)
 	/* our windows mmap implementation is not thread safe */
@@ -632,7 +638,7 @@
 {
 	MemHead *membl;
 	MemPrintBlock *pb, *printblock;
-	int totpb, a, b;
+	unsigned int totpb, a, b;
 #ifdef HAVE_MALLOC_H
 	size_t mem_in_use_slop;
 #endif
@@ -1078,9 +1084,9 @@
 	return(name);
 }
 
-uintptr_t MEM_get_peak_memory(void)
+size_t MEM_get_peak_memory(void)
 {
-	uintptr_t _peak_mem;
+	size_t _peak_mem;
 
 	mem_lock_thread();
 	_peak_mem = peak_mem;
@@ -1118,9 +1124,9 @@
 	return _mmap_in_use;
 }
 
-int MEM_get_memory_blocks_in_use(void)
+unsigned int MEM_get_memory_blocks_in_use(void)
 {
-	int _totblock;
+	unsigned int _totblock;
 
 	mem_lock_thread();
 	_totblock = totblock;




More information about the Bf-blender-cvs mailing list