ui/common/context.c

changeset 1091
1524b5dc4d4d
parent 1089
a3db51a94b37
equal deleted inserted replaced
1090:ab2e458df182 1091:1524b5dc4d4d
690 void* ui_cx_mempool(UiContext *ctx) { 690 void* ui_cx_mempool(UiContext *ctx) {
691 return ctx->mp; 691 return ctx->mp;
692 } 692 }
693 693
694 void* ui_malloc(UiContext *ctx, size_t size) { 694 void* ui_malloc(UiContext *ctx, size_t size) {
695 return ctx ? cxMalloc(ctx->allocator, size) : NULL; 695 return ctx ? cxMalloc(ctx->allocator, size) : malloc(size);
696 } 696 }
697 697
698 void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) { 698 void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) {
699 return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : NULL; 699 return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : calloc(nelem, elsize);
700 } 700 }
701 701
702 void ui_free(UiContext *ctx, void *ptr) { 702 void ui_free(UiContext *ctx, void *ptr) {
703 if(ctx && ptr) { 703 if(ptr) {
704 cxFree(ctx->allocator, ptr); 704 if(ctx) {
705 cxFree(ctx->allocator, ptr);
706 } else {
707 free(ptr);
708 }
705 } 709 }
706 } 710 }
707 711
708 void* ui_realloc(UiContext *ctx, void *ptr, size_t size) { 712 void* ui_realloc(UiContext *ctx, void *ptr, size_t size) {
709 return ctx ? cxRealloc(ctx->allocator, ptr, size) : NULL; 713 return ctx ? cxRealloc(ctx->allocator, ptr, size) : realloc(ptr, size);
710 } 714 }
711 715
712 char* ui_strdup(UiContext *ctx, const char *str) { 716 char* ui_strdup(UiContext *ctx, const char *str) {
713 if(!ctx) { 717 if(!ctx) {
714 return NULL; 718 return strdup(str ? str : "");
715 } 719 }
716 cxstring s = cx_str(str); 720 cxstring s = cx_str(str);
717 cxmutstr d = cx_strdup_a(ctx->allocator, s); 721 cxmutstr d = cx_strdup_a(ctx->allocator, s);
718 return d.ptr; 722 return d.ptr;
719 } 723 }

mercurial