Push an item into the stack, returns 1 on success, 0 on out of memory. */
| 100 | |
| 101 | /* Push an item into the stack, returns 1 on success, 0 on out of memory. */ |
| 102 | static inline int raxStackPush(raxStack *ts, void *ptr) { |
| 103 | if (ts->items == ts->maxitems) { |
| 104 | if (ts->stack == ts->static_items) { |
| 105 | ts->stack = rax_malloc(sizeof(void*)*ts->maxitems*2); |
| 106 | if (ts->stack == NULL) { |
| 107 | ts->stack = ts->static_items; |
| 108 | ts->oom = 1; |
| 109 | errno = ENOMEM; |
| 110 | return 0; |
| 111 | } |
| 112 | memcpy(ts->stack,ts->static_items,sizeof(void*)*ts->maxitems); |
| 113 | } else { |
| 114 | void **newalloc = rax_realloc(ts->stack,sizeof(void*)*ts->maxitems*2); |
| 115 | if (newalloc == NULL) { |
| 116 | ts->oom = 1; |
| 117 | errno = ENOMEM; |
| 118 | return 0; |
| 119 | } |
| 120 | ts->stack = newalloc; |
| 121 | } |
| 122 | ts->maxitems *= 2; |
| 123 | } |
| 124 | ts->stack[ts->items] = ptr; |
| 125 | ts->items++; |
| 126 | return 1; |
| 127 | } |
| 128 | |
| 129 | /* Pop an item from the stack, the function returns NULL if there are no |
| 130 | * items to pop. */ |
no test coverage detected