- got fed up with not being able to put a breakpoint on MEM_
errors, switched MEM_set_error_stream to MEM_set_error_callback that calls a function to print result instead of just giving a FILE * Note: requires intern recompile
This commit is contained in:
@@ -98,8 +98,8 @@ extern "C" {
|
|||||||
* blocks. */
|
* blocks. */
|
||||||
void MEM_printmemlist(void);
|
void MEM_printmemlist(void);
|
||||||
|
|
||||||
/** Set the stream for error output. */
|
/** Set the callback function for error output. */
|
||||||
void MEM_set_error_stream(FILE*);
|
void MEM_set_error_callback(void (*func)(char *));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Are the start/end block markers still correct ?
|
* Are the start/end block markers still correct ?
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h> /* memcpy */
|
#include <string.h> /* memcpy */
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@@ -104,12 +105,13 @@ static char *check_memlist(MemHead *memh);
|
|||||||
/* vars */
|
/* vars */
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
int totblock= 0;
|
int totblock= 0;
|
||||||
int mem_in_use= 0;
|
int mem_in_use= 0;
|
||||||
|
|
||||||
static struct localListBase _membase;
|
static struct localListBase _membase;
|
||||||
static struct localListBase *membase = &_membase;
|
static struct localListBase *membase = &_membase;
|
||||||
static FILE* err_stream = NULL;
|
static void (*error_callback)(char *) = NULL;
|
||||||
|
|
||||||
#ifdef malloc
|
#ifdef malloc
|
||||||
#undef malloc
|
#undef malloc
|
||||||
@@ -128,6 +130,18 @@ static FILE* err_stream = NULL;
|
|||||||
/* implementation */
|
/* implementation */
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void print_error(char *str, ...)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, str);
|
||||||
|
vsprintf(buf, str, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (error_callback) error_callback(buf);
|
||||||
|
}
|
||||||
|
|
||||||
int MEM_check_memory_integrity()
|
int MEM_check_memory_integrity()
|
||||||
{
|
{
|
||||||
char* err_val = NULL;
|
char* err_val = NULL;
|
||||||
@@ -142,9 +156,9 @@ int MEM_check_memory_integrity()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MEM_set_error_stream(FILE* i)
|
void MEM_set_error_callback(void (*func)(char *))
|
||||||
{
|
{
|
||||||
err_stream = i;
|
error_callback = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -204,7 +218,7 @@ void *MEM_mallocN(unsigned int len, char *str)
|
|||||||
mem_in_use += len;
|
mem_in_use += len;
|
||||||
return (++memh);
|
return (++memh);
|
||||||
}
|
}
|
||||||
if (err_stream) fprintf(err_stream, "Malloc returns nill: len=%d in %s\n",len,str);
|
print_error("Malloc returns nill: len=%d in %s\n",len,str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +252,7 @@ void *MEM_callocN(unsigned int len, char *str)
|
|||||||
mem_in_use += len;
|
mem_in_use += len;
|
||||||
return (++memh);
|
return (++memh);
|
||||||
}
|
}
|
||||||
if (err_stream) fprintf(err_stream, "Calloc returns nill: len=%d in %s\n",len,str);
|
print_error("Calloc returns nill: len=%d in %s\n",len,str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +264,7 @@ void MEM_printmemlist()
|
|||||||
membl = membase->first;
|
membl = membase->first;
|
||||||
if (membl) membl = MEMNEXT(membl);
|
if (membl) membl = MEMNEXT(membl);
|
||||||
while(membl) {
|
while(membl) {
|
||||||
if (err_stream) fprintf(err_stream, "%s len: %d %p\n",membl->name,membl->len, membl+1);
|
print_error("%s len: %d %p\n",membl->name,membl->len, membl+1);
|
||||||
if(membl->next)
|
if(membl->next)
|
||||||
membl= MEMNEXT(membl->next);
|
membl= MEMNEXT(membl->next);
|
||||||
else break;
|
else break;
|
||||||
@@ -266,7 +280,7 @@ short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
|
|||||||
|
|
||||||
if (memh == 0){
|
if (memh == 0){
|
||||||
MemorY_ErroR("free","attempt to free NULL pointer");
|
MemorY_ErroR("free","attempt to free NULL pointer");
|
||||||
/* if (err_stream) fprintf(err_stream, "%d\n", (memh+4000)->tag1); */
|
/* print_error(err_stream, "%d\n", (memh+4000)->tag1); */
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +382,7 @@ static void rem_memblock(MemHead *memh)
|
|||||||
|
|
||||||
static void MemorY_ErroR(char *block, char *error)
|
static void MemorY_ErroR(char *block, char *error)
|
||||||
{
|
{
|
||||||
if (err_stream) fprintf(err_stream,"Memoryblock %s: %s\n",block,error);
|
print_error("Memoryblock %s: %s\n",block,error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *check_memlist(MemHead *memh)
|
static char *check_memlist(MemHead *memh)
|
||||||
|
@@ -589,10 +589,15 @@ static void error_cb(char *err)
|
|||||||
error("%s", err);
|
error("%s", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mem_error_cb(char *errorStr)
|
||||||
|
{
|
||||||
|
fprintf(stderr, errorStr);
|
||||||
|
}
|
||||||
|
|
||||||
void setCallbacks(void)
|
void setCallbacks(void)
|
||||||
{
|
{
|
||||||
/* Error output from the alloc routines: */
|
/* Error output from the alloc routines: */
|
||||||
MEM_set_error_stream(stderr);
|
MEM_set_error_callback(mem_error_cb);
|
||||||
|
|
||||||
|
|
||||||
/* BLI_blenlib: */
|
/* BLI_blenlib: */
|
||||||
|
Reference in New Issue
Block a user