MCPcopy Create free account
hub / github.com/F-Stack/f-stack / raxStackPush

Function raxStackPush

app/redis-6.2.6/src/rax.c:102–127  ·  view source on GitHub ↗

Push an item into the stack, returns 1 on success, 0 on out of memory. */

Source from the content-addressed store, hash-verified

100
101/* Push an item into the stack, returns 1 on success, 0 on out of memory. */
102static 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. */

Callers 6

raxLowWalkFunction · 0.85
raxIteratorNextStepFunction · 0.85
raxSeekGreatestFunction · 0.85
raxIteratorPrevStepFunction · 0.85
raxSeekFunction · 0.85
raxRandomWalkFunction · 0.85

Calls 1

memcpyFunction · 0.50

Tested by

no test coverage detected