mojoshader.c
changeset 541 0240ccafb610
parent 540 e65090ad5caa
child 542 a56d3bfd2e36
equal deleted inserted replaced
540:e65090ad5caa 541:0240ccafb610
   263     if (retval == NULL)
   263     if (retval == NULL)
   264         out_of_memory(ctx);
   264         out_of_memory(ctx);
   265     return retval;
   265     return retval;
   266 } // Malloc
   266 } // Malloc
   267 
   267 
       
   268 static inline char *StrDup(Context *ctx, const char *str)
       
   269 {
       
   270     char *retval = (char *) Malloc(ctx, strlen(str) + 1);
       
   271     if (retval == NULL)
       
   272         out_of_memory(ctx);
       
   273     else
       
   274         strcpy(retval, str);
       
   275     return retval;
       
   276 } // StrDup
   268 
   277 
   269 static inline void Free(Context *ctx, void *ptr)
   278 static inline void Free(Context *ctx, void *ptr)
   270 {
   279 {
   271     if (ptr != NULL)  // check for NULL in case of dumb free() impl.
   280     if (ptr != NULL)  // check for NULL in case of dumb free() impl.
   272         ctx->free(ptr, ctx->malloc_data);
   281         ctx->free(ptr, ctx->malloc_data);
   426 static int output_line(Context *ctx, const char *fmt, ...) ISPRINTF(2,3);
   435 static int output_line(Context *ctx, const char *fmt, ...) ISPRINTF(2,3);
   427 static int output_line(Context *ctx, const char *fmt, ...)
   436 static int output_line(Context *ctx, const char *fmt, ...)
   428 {
   437 {
   429     OutputListNode *item = NULL;
   438     OutputListNode *item = NULL;
   430 
   439 
   431     if (isfail(ctx))
   440     if (isfail(ctx) || ctx->out_of_memory)
   432         return FAIL;  // we failed previously, don't go on...
   441         return;  // we failed previously, don't go on...
   433 
   442 
   434     char *scratch = get_scratch_buffer(ctx);
   443     char *scratch = get_scratch_buffer(ctx);
   435 
   444 
   436     const int indent = ctx->indent;
   445     const int indent = ctx->indent;
   437     if (indent > 0)
   446     if (indent > 0)
  6942         {
  6951         {
  6943             if (var->used)
  6952             if (var->used)
  6944             {
  6953             {
  6945                 const char *name = ctx->profile->get_const_array_varname(ctx,
  6954                 const char *name = ctx->profile->get_const_array_varname(ctx,
  6946                                                       var->index, var->count);
  6955                                                       var->index, var->count);
  6947                 char *namecpy = (char *) Malloc(ctx, strlen(name) + 1);
  6956                 char *namecpy = StrDup(ctx, name);
  6948                 if (namecpy != NULL)
  6957                 if (namecpy != NULL)
  6949                 {
  6958                 {
  6950                     strcpy(namecpy, name);
       
  6951                     wptr->type = MOJOSHADER_UNIFORM_FLOAT;
  6959                     wptr->type = MOJOSHADER_UNIFORM_FLOAT;
  6952                     wptr->index = var->index;
  6960                     wptr->index = var->index;
  6953                     wptr->array_count = var->count;
  6961                     wptr->array_count = var->count;
  6954                     wptr->constant = (var->constant != NULL) ? 1 : 0;
  6962                     wptr->constant = (var->constant != NULL) ? 1 : 0;
  6955                     wptr->name = namecpy;
  6963                     wptr->name = namecpy;