mojoshader_preprocessor.c
changeset 1182 179ffe99c57f
parent 1142 7b554e065321
child 1188 25000edc0176
equal deleted inserted replaced
1181:b873f3b0f838 1182:179ffe99c57f
    66 static inline void out_of_memory(Context *ctx)
    66 static inline void out_of_memory(Context *ctx)
    67 {
    67 {
    68     ctx->out_of_memory = 1;
    68     ctx->out_of_memory = 1;
    69 } // out_of_memory
    69 } // out_of_memory
    70 
    70 
       
    71 static char zeromalloc = 0;
    71 static inline void *Malloc(Context *ctx, const size_t len)
    72 static inline void *Malloc(Context *ctx, const size_t len)
    72 {
    73 {
    73     void *retval = ctx->malloc((int) len, ctx->malloc_data);
    74     void *retval = (len == 0) ? &zeromalloc : ctx->malloc((int) len, ctx->malloc_data);
    74     if (retval == NULL)
    75     if (retval == NULL)
    75         out_of_memory(ctx);
    76         out_of_memory(ctx);
    76     return retval;
    77     return retval;
    77 } // Malloc
    78 } // Malloc
    78 
    79 
    79 static inline void Free(Context *ctx, void *ptr)
    80 static inline void Free(Context *ctx, void *ptr)
    80 {
    81 {
    81     ctx->free(ptr, ctx->malloc_data);
    82     if ((ptr != &zeromalloc) && (ptr != NULL))
       
    83         ctx->free(ptr, ctx->malloc_data);
    82 } // Free
    84 } // Free
    83 
    85 
    84 static void *MallocBridge(int bytes, void *data)
    86 static void *MallocBridge(int bytes, void *data)
    85 {
    87 {
    86     return Malloc((Context *) data, (size_t) bytes);
    88     return Malloc((Context *) data, (size_t) bytes);