memalloc.c (78962f36d22bd936f32bac4ece58586c9abacb9b) | memalloc.c (ff802dc7bbf970a8cd17c40600c49b29540f4f58) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 113 unchanged lines hidden (view full) --- 122 /* Data follows */ 123}; 124#define SPACE(sp) ((char*)(sp) + ALIGN(sizeof(struct stack_block))) 125 126static struct stack_block *stackp; 127static struct stackmark *markp; 128char *stacknxt; 129int stacknleft; | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 113 unchanged lines hidden (view full) --- 122 /* Data follows */ 123}; 124#define SPACE(sp) ((char*)(sp) + ALIGN(sizeof(struct stack_block))) 125 126static struct stack_block *stackp; 127static struct stackmark *markp; 128char *stacknxt; 129int stacknleft; |
130int sstrnleft; | 130char *sstrend; |
131 132 133static void 134stnewblock(int nbytes) 135{ 136 struct stack_block *sp; 137 int allocsize; 138 139 if (nbytes < MINSIZE) 140 nbytes = MINSIZE; 141 142 allocsize = ALIGN(sizeof(struct stack_block)) + ALIGN(nbytes); 143 144 INTOFF; 145 sp = ckmalloc(allocsize); 146 sp->prev = stackp; 147 stacknxt = SPACE(sp); 148 stacknleft = allocsize - (stacknxt - (char*)sp); | 131 132 133static void 134stnewblock(int nbytes) 135{ 136 struct stack_block *sp; 137 int allocsize; 138 139 if (nbytes < MINSIZE) 140 nbytes = MINSIZE; 141 142 allocsize = ALIGN(sizeof(struct stack_block)) + ALIGN(nbytes); 143 144 INTOFF; 145 sp = ckmalloc(allocsize); 146 sp->prev = stackp; 147 stacknxt = SPACE(sp); 148 stacknleft = allocsize - (stacknxt - (char*)sp); |
149 sstrend = stacknxt + stacknleft; |
|
149 stackp = sp; 150 INTON; 151} 152 153 154pointer 155stalloc(int nbytes) 156{ --- 42 unchanged lines hidden (view full) --- 199 markp = mark->marknext; 200 while (stackp != mark->stackp) { 201 sp = stackp; 202 stackp = sp->prev; 203 ckfree(sp); 204 } 205 stacknxt = mark->stacknxt; 206 stacknleft = mark->stacknleft; | 150 stackp = sp; 151 INTON; 152} 153 154 155pointer 156stalloc(int nbytes) 157{ --- 42 unchanged lines hidden (view full) --- 200 markp = mark->marknext; 201 while (stackp != mark->stackp) { 202 sp = stackp; 203 stackp = sp->prev; 204 ckfree(sp); 205 } 206 stacknxt = mark->stacknxt; 207 stacknleft = mark->stacknleft; |
208 sstrend = stacknxt + stacknleft; |
|
207 INTON; 208} 209 210 211/* 212 * When the parser reads in a string, it wants to stick the string on the 213 * stack and only adjust the stack pointer when it knows how big the 214 * string is. Stackblock (defined in stack.h) returns a pointer to a block --- 30 unchanged lines hidden (view full) --- 245 INTOFF; 246 oldstackp = stackp; 247 stackp = oldstackp->prev; 248 sp = ckrealloc((pointer)oldstackp, newlen); 249 sp->prev = stackp; 250 stackp = sp; 251 stacknxt = SPACE(sp); 252 stacknleft = newlen - (stacknxt - (char*)sp); | 209 INTON; 210} 211 212 213/* 214 * When the parser reads in a string, it wants to stick the string on the 215 * stack and only adjust the stack pointer when it knows how big the 216 * string is. Stackblock (defined in stack.h) returns a pointer to a block --- 30 unchanged lines hidden (view full) --- 247 INTOFF; 248 oldstackp = stackp; 249 stackp = oldstackp->prev; 250 sp = ckrealloc((pointer)oldstackp, newlen); 251 sp->prev = stackp; 252 stackp = sp; 253 stacknxt = SPACE(sp); 254 stacknleft = newlen - (stacknxt - (char*)sp); |
255 sstrend = stacknxt + stacknleft; |
|
253 254 /* 255 * Stack marks pointing to the start of the old block 256 * must be relocated to point to the new block 257 */ 258 xmark = markp; 259 while (xmark != NULL && xmark->stackp == oldstackp) { 260 xmark->stackp = stackp; --- 40 unchanged lines hidden (view full) --- 301 * CHECKSTACKSPACE can be called before USTPUTC to ensure that there 302 * is space for at least one character. 303 */ 304 305static char * 306growstrstackblock(int n, int min) 307{ 308 growstackblock(min); | 256 257 /* 258 * Stack marks pointing to the start of the old block 259 * must be relocated to point to the new block 260 */ 261 xmark = markp; 262 while (xmark != NULL && xmark->stackp == oldstackp) { 263 xmark->stackp = stackp; --- 40 unchanged lines hidden (view full) --- 304 * CHECKSTACKSPACE can be called before USTPUTC to ensure that there 305 * is space for at least one character. 306 */ 307 308static char * 309growstrstackblock(int n, int min) 310{ 311 growstackblock(min); |
309 sstrnleft = stackblocksize() - n; | |
310 return stackblock() + n; 311} 312 313char * 314growstackstr(void) 315{ 316 int len; 317 318 len = stackblocksize(); 319 return (growstrstackblock(len, 0)); 320} 321 322 323/* 324 * Called from CHECKSTRSPACE. 325 */ 326 327char * | 312 return stackblock() + n; 313} 314 315char * 316growstackstr(void) 317{ 318 int len; 319 320 len = stackblocksize(); 321 return (growstrstackblock(len, 0)); 322} 323 324 325/* 326 * Called from CHECKSTRSPACE. 327 */ 328 329char * |
328makestrspace(int min) | 330makestrspace(int min, char *p) |
329{ 330 int len; 331 | 331{ 332 int len; 333 |
332 len = stackblocksize() - sstrnleft; | 334 len = p - stackblock(); |
333 return (growstrstackblock(len, min)); 334} 335 336 | 335 return (growstrstackblock(len, min)); 336} 337 338 |
337 338void 339ungrabstackstr(char *s, char *p) 340{ 341 stacknleft += stacknxt - s; 342 stacknxt = s; 343 sstrnleft = stacknleft - (p - s); 344} 345 346 | |
347char * 348stputbin(const char *data, int len, char *p) 349{ 350 CHECKSTRSPACE(len, p); 351 memcpy(p, data, len); | 339char * 340stputbin(const char *data, int len, char *p) 341{ 342 CHECKSTRSPACE(len, p); 343 memcpy(p, data, len); |
352 sstrnleft -= len; | |
353 return (p + len); 354} 355 356char * 357stputs(const char *data, char *p) 358{ 359 return (stputbin(data, strlen(data), p)); 360} | 344 return (p + len); 345} 346 347char * 348stputs(const char *data, char *p) 349{ 350 return (stputbin(data, strlen(data), p)); 351} |