Skip to content

Commit

Permalink
Added allocator debug output.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 19, 2009
1 parent 5b8e98b commit f9c9597
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions utils/mojoshader-compiler.c
Expand Up @@ -15,6 +15,29 @@
static const char **include_paths = NULL;
static unsigned int include_path_count = 0;

#if MOJOSHADER_DEBUG_MALLOC
static void *Malloc(int len)
{
void *ptr = malloc(len + sizeof (int));
int *store = (int *) ptr;
printf("malloc() %d bytes (%p)\n", len, ptr);
if (ptr == NULL) return NULL;
*store = len;
return (void *) (store + 1);
} // Malloc


static void Free(void *_ptr)
{
int *ptr = (((int *) _ptr) - 1);
int len = *ptr;
printf("free() %d bytes (%p)\n", len, ptr);
free(ptr);
} // Free
#else
#define Malloc NULL
#define Free NULL
#endif

static int open_include(MOJOSHADER_includeType inctype, const char *fname,
const char *parent, const char **outdata,
Expand Down Expand Up @@ -92,8 +115,8 @@ static int preprocess(const char *fname, const char *buf, int len,
const MOJOSHADER_preprocessData *pd;
int retval = 0;

pd = MOJOSHADER_preprocess(fname, buf, len, defs, defcount,
open_include, close_include, NULL, NULL, NULL);
pd = MOJOSHADER_preprocess(fname, buf, len, defs, defcount, open_include,
close_include, Malloc, Free, NULL);

if (pd->error_count > 0)
{
Expand Down

0 comments on commit f9c9597

Please sign in to comment.