mojoshader_preprocessor.c
changeset 1188 25000edc0176
parent 1182 179ffe99c57f
child 1195 f4ef8606c68d
equal deleted inserted replaced
1187:0687a8d78a54 1188:25000edc0176
    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;
       
    72 static inline void *Malloc(Context *ctx, const size_t len)
    71 static inline void *Malloc(Context *ctx, const size_t len)
    73 {
    72 {
    74     void *retval = (len == 0) ? &zeromalloc : ctx->malloc((int) len, ctx->malloc_data);
    73     void *retval = ctx->malloc((int) len, ctx->malloc_data);
    75     if (retval == NULL)
    74     if (retval == NULL)
    76         out_of_memory(ctx);
    75         out_of_memory(ctx);
    77     return retval;
    76     return retval;
    78 } // Malloc
    77 } // Malloc
    79 
    78 
    80 static inline void Free(Context *ctx, void *ptr)
    79 static inline void Free(Context *ctx, void *ptr)
    81 {
    80 {
    82     if ((ptr != &zeromalloc) && (ptr != NULL))
    81     ctx->free(ptr, ctx->malloc_data);
    83         ctx->free(ptr, ctx->malloc_data);
       
    84 } // Free
    82 } // Free
    85 
    83 
    86 static void *MallocBridge(int bytes, void *data)
    84 static void *MallocBridge(int bytes, void *data)
    87 {
    85 {
    88     return Malloc((Context *) data, (size_t) bytes);
    86     return Malloc((Context *) data, (size_t) bytes);