Memory allocator: Clarify consistency check function
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 20 Mar 2018 15:51:33 +0000 (16:51 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 20 Mar 2018 15:51:33 +0000 (16:51 +0100)
Also make it to return truth when everything is good and
false otherwise.

doc/guides/blender-guardedalloc.txt
intern/guardedalloc/MEM_guardedalloc.h
intern/guardedalloc/intern/mallocn.c
intern/guardedalloc/intern/mallocn_guarded_impl.c
intern/guardedalloc/intern/mallocn_intern.h
intern/guardedalloc/intern/mallocn_lockfree_impl.c
intern/guardedalloc/test/simpletest/memtest.c
source/blender/blenkernel/intern/scene.c

index 3db647a..2e49f25 100644 (file)
@@ -51,7 +51,7 @@ void MEM_printmemlist(void);
 - if err_stream is set by MEM_set_error_stream() this function dumps a list of all
 currently allocated memory blocks with length and name to the stream
 
-int MEM_check_memory_integrity(void);
+bool MEM_consistency_check(void);
 
 - this function tests if the internal structures of the memory manager are intact
 - returns 0 on success and !=0 on error
index a579212..6565020 100644 (file)
@@ -165,8 +165,8 @@ extern "C" {
        /**
         * Are the start/end block markers still correct ?
         *
-        * @retval 0 for correct memory, 1 for corrupted memory. */
-       extern bool (*MEM_check_memory_integrity)(void);
+        * @retval true for correct memory, false for corrupted memory. */
+       extern bool (*MEM_consistency_check)(void);
 
        /** Set thread locking functions for safe memory allocation from multiple
         * threads, pass NULL pointers to disable thread locking again. */
index b973037..a95cc91 100644 (file)
@@ -53,7 +53,7 @@ void (*MEM_printmemlist)(void) = MEM_lockfree_printmemlist;
 void (*MEM_callbackmemlist)(void (*func)(void *)) = MEM_lockfree_callbackmemlist;
 void (*MEM_printmemlist_stats)(void) = MEM_lockfree_printmemlist_stats;
 void (*MEM_set_error_callback)(void (*func)(const char *)) = MEM_lockfree_set_error_callback;
-bool (*MEM_check_memory_integrity)(void) = MEM_lockfree_check_memory_integrity;
+bool (*MEM_consistency_check)(void) = MEM_lockfree_consistency_check;
 void (*MEM_set_lock_callback)(void (*lock)(void), void (*unlock)(void)) = MEM_lockfree_set_lock_callback;
 void (*MEM_set_memory_debug)(void) = MEM_lockfree_set_memory_debug;
 size_t (*MEM_get_memory_in_use)(void) = MEM_lockfree_get_memory_in_use;
@@ -119,7 +119,7 @@ void MEM_use_guarded_allocator(void)
        MEM_callbackmemlist = MEM_guarded_callbackmemlist;
        MEM_printmemlist_stats = MEM_guarded_printmemlist_stats;
        MEM_set_error_callback = MEM_guarded_set_error_callback;
-       MEM_check_memory_integrity = MEM_guarded_check_memory_integrity;
+       MEM_consistency_check = MEM_guarded_consistency_check;
        MEM_set_lock_callback = MEM_guarded_set_lock_callback;
        MEM_set_memory_debug = MEM_guarded_set_memory_debug;
        MEM_get_memory_in_use = MEM_guarded_get_memory_in_use;
index d012cce..d09f1b8 100644 (file)
@@ -282,7 +282,7 @@ static void mem_unlock_thread(void)
                thread_unlock_callback();
 }
 
-bool MEM_guarded_check_memory_integrity(void)
+bool MEM_guarded_consistency_check(void)
 {
        const char *err_val = NULL;
        MemHead *listend;
@@ -292,7 +292,7 @@ bool MEM_guarded_check_memory_integrity(void)
        
        err_val = check_memlist(listend);
 
-       return (err_val != NULL);
+       return (err_val == NULL);
 }
 
 
index 4b2282a..754a79f 100644 (file)
@@ -137,7 +137,7 @@ void MEM_lockfree_printmemlist(void);
 void MEM_lockfree_callbackmemlist(void (*func)(void *));
 void MEM_lockfree_printmemlist_stats(void);
 void MEM_lockfree_set_error_callback(void (*func)(const char *));
-bool MEM_lockfree_check_memory_integrity(void);
+bool MEM_lockfree_consistency_check(void);
 void MEM_lockfree_set_lock_callback(void (*lock)(void), void (*unlock)(void));
 void MEM_lockfree_set_memory_debug(void);
 size_t MEM_lockfree_get_memory_in_use(void);
@@ -166,7 +166,7 @@ void MEM_guarded_printmemlist(void);
 void MEM_guarded_callbackmemlist(void (*func)(void *));
 void MEM_guarded_printmemlist_stats(void);
 void MEM_guarded_set_error_callback(void (*func)(const char *));
-bool MEM_guarded_check_memory_integrity(void);
+bool MEM_guarded_consistency_check(void);
 void MEM_guarded_set_lock_callback(void (*lock)(void), void (*unlock)(void));
 void MEM_guarded_set_memory_debug(void);
 size_t MEM_guarded_get_memory_in_use(void);
index 2899a37..4c6ba0c 100644 (file)
@@ -469,7 +469,7 @@ void MEM_lockfree_set_error_callback(void (*func)(const char *))
        error_callback = func;
 }
 
-bool MEM_lockfree_check_memory_integrity(void)
+bool MEM_lockfree_consistency_check(void)
 {
        return true;
 }
index 79d55dd..d306337 100644 (file)
@@ -90,7 +90,7 @@ int main(int argc, char *argv[])
        if (verbose > 1) MEM_printmemlist();
 
        /* memory is there: test it */
-       error_status = MEM_check_memory_integrity();
+       error_status = MEM_consistency_check();
 
        if (verbose) {
                if (error_status) {
@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
        ip = (int*) p[6];
        *(ip+10005) = 0;
        
-       retval = MEM_check_memory_integrity();
+       retval = MEM_consistency_check();
 
        /* the test should have failed */
        error_status |= !retval;                
index 9b3299b..60cf496 100644 (file)
@@ -1966,6 +1966,10 @@ void BKE_scene_update_for_newframe_ex(EvaluationContext *eval_ctx, Main *bmain,
        (void) do_invisible_flush;
 #endif
 
+       if (!MEM_consistency_check()) {
+               abort();
+       }
+
        DAG_editors_update_pre(bmain, sce, true);
 
        /* keep this first */