in src/cpp/modules/tapenade/utils/adStack.c [213:268]
void pushNArray(char *x, unsigned int nbChars, int checkReadOnly) {
if (checkReadOnly) checkPushInReadOnly() ;
if (checkReadOnly) maintraffic += nbChars ;
/* unsigned long int lfrom = getCurLocation() ; //Trace */
unsigned int nbmax = ONE_BLOCK_SIZE-(curStackTop-(curStack->contents)) ;
if (nbChars <= nbmax) {
memcpy(curStackTop,x,nbChars) ;
curStackTop+=nbChars ;
} else {
char *inx = x+(nbChars-nbmax) ;
if (nbmax>0) memcpy(curStackTop,inx,nbmax) ;
while (inx>x) {
if (curStack->next)
curStack = curStack->next ;
else {
/* Create new block: */
DoubleChainedBlock *newStack ;
char *contents = (char *)malloc(ONE_BLOCK_SIZE*sizeof(char)) ;
newStack = (DoubleChainedBlock*)malloc(sizeof(DoubleChainedBlock)) ;
if ((contents == NULL) || (newStack == NULL)) {
DoubleChainedBlock *stack = curStack ;
int nbBlocks = (stack?-1:0) ;
while(stack) {
stack = stack->prev ;
nbBlocks++ ;
}
printf("Out of memory (allocated %i blocks of %i bytes)\n",
nbBlocks, ONE_BLOCK_SIZE) ;
exit(0);
}
curStack->next = newStack ;
newStack->prev = curStack ;
newStack->rank = curStack->rank + 1 ;
newStack->next = NULL ;
newStack->contents = contents ;
curStack = newStack ;
/* new block created! */
}
inx -= ONE_BLOCK_SIZE ;
if(inx>x)
memcpy(curStack->contents,inx,ONE_BLOCK_SIZE) ;
else {
unsigned int nbhead = (inx-x)+ONE_BLOCK_SIZE ;
curStackTop = curStack->contents ;
memcpy(curStackTop,x,nbhead) ;
curStackTop += nbhead ;
}
}
}
/* unsigned long int lto = getCurLocation() ; //Trace */
/* printf("pushNArray(") ; //Trace */
/* showLocation(lfrom) ; //Trace */
/* printf("=>") ; //Trace */
/* showLocation(lto) ; //Trace */
/* printf(")") ; //Trace */
}