testparse.c
branchtrunk
changeset 50 427f32b5eeff
parent 48 86dc2c772d26
child 53 8c856f73908e
equal deleted inserted replaced
49:780cd8790dff 50:427f32b5eeff
     1 #include <stdio.h>
     1 #include <stdio.h>
     2 #include <stdlib.h>
     2 #include <stdlib.h>
     3 #include "mojoshader.h"
     3 #include "mojoshader.h"
     4 
     4 
     5 
     5 
     6 #if DEBUG_MALLOC
     6 #if MOJOSHADER_DEBUG_MALLOC
     7 static void *Malloc(int len)
     7 static void *Malloc(int len)
     8 {
     8 {
     9     void *ptr = malloc(len + sizeof (int));
     9     void *ptr = malloc(len + sizeof (int));
    10     int *store = (int *) ptr;
    10     int *store = (int *) ptr;
    11     printf("malloc() %d bytes (%p)\n", len, ptr);
    11     printf("malloc() %d bytes (%p)\n", len, ptr);
    15 } // Malloc
    15 } // Malloc
    16 
    16 
    17 
    17 
    18 static void Free(void *_ptr)
    18 static void Free(void *_ptr)
    19 {
    19 {
    20     int *ptr = (((int *) ptr) - 1);
    20     int *ptr = (((int *) _ptr) - 1);
    21     int *store = (int *) ptr;
    21     int len = *ptr;
    22     int len = *store;
       
    23     printf("free() %d bytes (%p)\n", len, ptr);
    22     printf("free() %d bytes (%p)\n", len, ptr);
    24     free(ptr);
    23     free(ptr);
    25 } // Free
    24 } // Free
    26 #else
    25 #else
    27 #define Malloc NULL
    26 #define Malloc NULL