| 117 | } |
| 118 | |
| 119 | txSlot *fxAllocateSlots(txMachine* the, txSize theCount) |
| 120 | { |
| 121 | txSize needed = theCount * sizeof(txSlot); |
| 122 | |
| 123 | if (NULL == the->heap) { |
| 124 | #ifndef modGetLargestMalloc |
| 125 | return machine_alloc(needed, 0); |
| 126 | #else |
| 127 | extern void fxGrowSlots(txMachine* the, txSize theCount); |
| 128 | static uint8_t *pending; //@@ not thread safe... |
| 129 | |
| 130 | if (NULL == the->stack) |
| 131 | return machine_alloc(needed, 0); |
| 132 | |
| 133 | if (pending) { |
| 134 | txSlot *result = (txSlot *)pending; |
| 135 | pending = NULL; |
| 136 | return result; |
| 137 | } |
| 138 | |
| 139 | while (needed) { |
| 140 | size_t largest = modGetLargestMalloc() & ~0x0F; |
| 141 | if (largest > needed) |
| 142 | largest = needed; |
| 143 | pending = c_malloc(largest); |
| 144 | if (!pending) |
| 145 | return NULL; |
| 146 | |
| 147 | fxGrowSlots(the, largest / sizeof(txSlot)); |
| 148 | |
| 149 | #ifdef mxDebug |
| 150 | if (pending) |
| 151 | fxAbort(the, XS_FATAL_CHECK_EXIT); |
| 152 | #endif |
| 153 | |
| 154 | needed -= largest; |
| 155 | } |
| 156 | |
| 157 | return (void *)-1; |
| 158 | #endif |
| 159 | } |
| 160 | |
| 161 | the->growHeapDirection = -1; |
| 162 | txSlot *result = (txSlot *)mc_xs_slot_allocator(the, needed); |
| 163 | if (!result && the->firstBlock) { |
| 164 | #ifdef mxDebug |
| 165 | fxReport(the, "# Slot allocation: failed. trying to make room...\n"); |
| 166 | #endif |
| 167 | fxCollect(the, XS_COMPACT_FLAG | XS_ORGANIC_FLAG); /* expecting memory from the chunk pool */ |
| 168 | #ifdef mxDebug |
| 169 | fxReport(the, "# Slot allocation: %d bytes returned\n", the->firstBlock->limit - the->firstBlock->current); |
| 170 | #endif |
| 171 | the->maximumChunksSize -= the->firstBlock->limit - the->firstBlock->current; |
| 172 | the->heap_ptr = (uint8_t*)the->firstBlock->current; |
| 173 | the->firstBlock->limit = the->firstBlock->current; |
| 174 | |
| 175 | result = (txSlot *)mc_xs_slot_allocator(the, needed); |
| 176 | } |
nothing calls this directly
no test coverage detected