Memory allocator: Clarify consistency check function

Also make it to return truth when everything is good and
false otherwise.
This commit is contained in:
Sergey Sharybin
2018-03-20 16:51:33 +01:00
parent 4f97f58513
commit a5bb918392
8 changed files with 16 additions and 12 deletions

View 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

View 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. */

View 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;

View 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);
}

View 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);

View 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;
}

View 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;

View 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 */