void gsfinish_string_builder(struct gsstringbuilder *sb) { void *newnursury; char *extent; *sb->end++ = 0; if (gs_sys_block_in_gc_from_space(BLOCK_CONTAINING(sb))) return; extent = END_OF_BLOCK(BLOCK_CONTAINING(sb)); newnursury = (uintptr)sb->end % sizeof(void *) ? sb->end + (sizeof(void *) - (uintptr)sb->end % sizeof(void *)) : sb->end; if ((char*)newnursury <= extent - 0x100) { lock(&gsstringbuilder_lock); if (gsstringbuilder_nursury) { struct gs_blockdesc *block; ulong sz; block = BLOCK_CONTAINING(gsstringbuilder_nursury); sz = (char*)END_OF_BLOCK(block) - (char*)gsstringbuilder_nursury; if (sz < extent - (char*)newnursury) gsstringbuilder_nursury = newnursury ; } else { gsstringbuilder_nursury = newnursury; } unlock(&gsstringbuilder_lock); } }
void vPortFree( void *pv ) { unsigned char *puc = ( unsigned char * ) pv; xBlockLink *pxLink; if( pv ) { /* The memory being freed will have an xBlockLink structure immediately before it. */ puc -= heapSTRUCT_SIZE; /* This casting is to keep the compiler from issuing warnings. */ pxLink = ( void * ) puc; vTaskSuspendAll(); { xBlockLink *previousPrevious, *previous, *successor = 0; previousPrevious = NULL; previous = &xStartAddr; while (previous->pxNextAddrBlock != &xEnd) { successor = previous->pxNextAddrBlock; if ((unsigned int) successor >= (unsigned int) pxLink) break; previousPrevious = previous; previous = successor; } /* We need to re-caculate the xFreeBytesRemaining before pxLink->xBlockSize is updated in the following 'if' statements. */ xFreeBytesRemaining += pxLink->xBlockSize; if (successor != &xEnd && END_OF_BLOCK(pxLink) == successor) { /* contiguous with successor, so they can be merged */ prvRemoveFromFreeList(successor, previous); pxLink->xBlockSize += successor->xBlockSize; } if (previous != &xStartAddr && END_OF_BLOCK(previous) == pxLink) { /* contiguous with predecessor, so they can be merged */ prvRemoveFromFreeList(previous, previousPrevious); previous->xBlockSize += pxLink->xBlockSize; pxLink = previous; } prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) ); } xTaskResumeAll(); } }
int gsextend_string_builder(struct gsstringbuilder *sb, ulong sz) { if ((char*)END_OF_BLOCK(BLOCK_CONTAINING(sb)) - sb->end < sz + 1) return -1 ; else return 0 ; }
/* ↓ It is part of the interface of this file that §c{parsedfile->last_seg} contains the allocated memory. */ void * gsparsed_file_extend(gsparsedfile *parsedfile, ulong n) { struct input_block *nursury_seg; void *res; struct gsparsedfile_segment *seg; seg = parsedfile->last_seg; nursury_seg = BLOCK_CONTAINING(seg->extent); if ((uchar*)END_OF_BLOCK(nursury_seg) - (uchar*)seg->extent < n) { gsparsed_file_add_segment(parsedfile); seg = parsedfile->last_seg; nursury_seg = BLOCK_CONTAINING(seg->extent); } res = seg->extent; seg->extent = (uchar*)seg->extent + n; if ((uintptr)seg->extent % sizeof(void*)) seg->extent = (uchar*)seg->extent + sizeof(void*) - ((uintptr)seg->extent % sizeof(void*)); return res; }
void gsstring_builder_vprint(struct gsstringbuilder *buf, char *fmt, va_list arg) { buf->end = vseprint(buf->end, (char*)END_OF_BLOCK(BLOCK_CONTAINING(buf)), fmt, arg); }