MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxGrowSlots

Function fxGrowSlots

xs/sources/xsMemory.c:678–741  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

676}
677
678void fxGrowSlots(txMachine* the, txSize theCount)
679{
680 txSlot* aHeap;
681 txSlot* aSlot;
682
683 aHeap = fxAllocateSlots(the, theCount);
684 if (!aHeap) {
685 fxReport(the, "# Slot allocation: failed for %ld bytes\n", theCount * sizeof(txSlot));
686 fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
687 }
688 if ((void *)-1 == aHeap)
689 return;
690
691 if (the->firstHeap && the->growHeapDirection) {
692 if (the->growHeapDirection > 0) {
693 the->firstHeap->value.reference = aHeap + theCount;
694 the->maximumHeapCount += theCount;
695 theCount -= 1;
696 aSlot = aHeap;
697 }
698 else {
699 *aHeap = *(the->firstHeap);
700 the->maximumHeapCount += theCount;
701 theCount -= 1;
702 the->firstHeap = aHeap;
703 aSlot = aHeap + 1;
704 }
705 }
706 else {
707 the->maximumHeapCount += theCount - 1;
708 aHeap->next = the->firstHeap;
709 aHeap->ID = 0;
710 aHeap->flag = 0;
711 aHeap->kind = 0;
712 aHeap->value.reference = aHeap + theCount;
713 theCount -= 2;
714 the->firstHeap = aHeap;
715 aSlot = aHeap + 1;
716 }
717 while (theCount--) {
718 txSlot* next = aSlot + 1;
719 aSlot->next = next;
720 aSlot->flag = XS_NO_FLAG;
721 aSlot->kind = XS_UNDEFINED_KIND;
722 #if mxPoisonSlots
723 ASAN_POISON_MEMORY_REGION(&aSlot->value, sizeof(aSlot->value));
724 #endif
725 aSlot = next;
726 }
727 aSlot->next = the->freeHeap;
728 aSlot->flag = XS_NO_FLAG;
729 aSlot->kind = XS_UNDEFINED_KIND;
730#if mxPoisonSlots
731 ASAN_POISON_MEMORY_REGION(&aSlot->value, sizeof(aSlot->value));
732#endif
733 the->freeHeap = aHeap + 1;
734 the->collectFlag &= ~XS_TRASHING_SLOTS_FLAG;
735#if mxReport

Callers 3

fxAllocateFunction · 0.85
fxNewSlotFunction · 0.85
fxAllocateSlotsFunction · 0.85

Calls 2

fxAllocateSlotsFunction · 0.70
fxAbortFunction · 0.70

Tested by

no test coverage detected