memalloc.c (248980) | memalloc.c (250527) |
---|---|
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 --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> | 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 --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 248980 2013-04-01 17:18:22Z jilles $"); | 39__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 250527 2013-05-11 20:51:00Z jilles $"); |
40 41#include <sys/param.h> 42#include "shell.h" 43#include "output.h" 44#include "memalloc.h" 45#include "error.h" 46#include "mystring.h" 47#include "expand.h" --- 71 unchanged lines hidden (view full) --- 119 120struct stack_block { 121 struct stack_block *prev; 122 /* Data follows */ 123}; 124#define SPACE(sp) ((char*)(sp) + ALIGN(sizeof(struct stack_block))) 125 126static struct stack_block *stackp; | 40 41#include <sys/param.h> 42#include "shell.h" 43#include "output.h" 44#include "memalloc.h" 45#include "error.h" 46#include "mystring.h" 47#include "expand.h" --- 71 unchanged lines hidden (view full) --- 119 120struct stack_block { 121 struct stack_block *prev; 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; 130char *sstrend; 131 132 133static void 134stnewblock(int nbytes) 135{ --- 45 unchanged lines hidden (view full) --- 181 182 183void 184setstackmark(struct stackmark *mark) 185{ 186 mark->stackp = stackp; 187 mark->stacknxt = stacknxt; 188 mark->stacknleft = stacknleft; | 127char *stacknxt; 128int stacknleft; 129char *sstrend; 130 131 132static void 133stnewblock(int nbytes) 134{ --- 45 unchanged lines hidden (view full) --- 180 181 182void 183setstackmark(struct stackmark *mark) 184{ 185 mark->stackp = stackp; 186 mark->stacknxt = stacknxt; 187 mark->stacknleft = stacknleft; |
189 mark->marknext = markp; 190 markp = mark; | 188 /* Ensure this block stays in place. */ 189 if (stackp != NULL && stacknxt == SPACE(stackp)) 190 stalloc(1); |
191} 192 193 194void 195popstackmark(struct stackmark *mark) 196{ 197 struct stack_block *sp; 198 199 INTOFF; | 191} 192 193 194void 195popstackmark(struct stackmark *mark) 196{ 197 struct stack_block *sp; 198 199 INTOFF; |
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; --- 15 unchanged lines hidden (view full) --- 224growstackblock(int min) 225{ 226 char *p; 227 int newlen; 228 char *oldspace; 229 int oldlen; 230 struct stack_block *sp; 231 struct stack_block *oldstackp; | 200 while (stackp != mark->stackp) { 201 sp = stackp; 202 stackp = sp->prev; 203 ckfree(sp); 204 } 205 stacknxt = mark->stacknxt; 206 stacknleft = mark->stacknleft; 207 sstrend = stacknxt + stacknleft; --- 15 unchanged lines hidden (view full) --- 223growstackblock(int min) 224{ 225 char *p; 226 int newlen; 227 char *oldspace; 228 int oldlen; 229 struct stack_block *sp; 230 struct stack_block *oldstackp; |
232 struct stackmark *xmark; | |
233 234 if (min < stacknleft) 235 min = stacknleft; 236 if ((unsigned int)min >= 237 INT_MAX / 2 - ALIGN(sizeof(struct stack_block))) 238 error("Out of space"); 239 min += stacknleft; 240 min += ALIGN(sizeof(struct stack_block)); --- 8 unchanged lines hidden (view full) --- 249 oldstackp = stackp; 250 stackp = oldstackp->prev; 251 sp = ckrealloc((pointer)oldstackp, newlen); 252 sp->prev = stackp; 253 stackp = sp; 254 stacknxt = SPACE(sp); 255 stacknleft = newlen - (stacknxt - (char*)sp); 256 sstrend = stacknxt + stacknleft; | 231 232 if (min < stacknleft) 233 min = stacknleft; 234 if ((unsigned int)min >= 235 INT_MAX / 2 - ALIGN(sizeof(struct stack_block))) 236 error("Out of space"); 237 min += stacknleft; 238 min += ALIGN(sizeof(struct stack_block)); --- 8 unchanged lines hidden (view full) --- 247 oldstackp = stackp; 248 stackp = oldstackp->prev; 249 sp = ckrealloc((pointer)oldstackp, newlen); 250 sp->prev = stackp; 251 stackp = sp; 252 stacknxt = SPACE(sp); 253 stacknleft = newlen - (stacknxt - (char*)sp); 254 sstrend = stacknxt + stacknleft; |
257 258 /* 259 * Stack marks pointing to the start of the old block 260 * must be relocated to point to the new block 261 */ 262 xmark = markp; 263 while (xmark != NULL && xmark->stackp == oldstackp) { 264 xmark->stackp = stackp; 265 xmark->stacknxt = stacknxt; 266 xmark->stacknleft = stacknleft; 267 xmark = xmark->marknext; 268 } | |
269 INTON; 270 } else { 271 newlen -= ALIGN(sizeof(struct stack_block)); 272 p = stalloc(newlen); 273 if (oldlen != 0) 274 memcpy(p, oldspace, oldlen); 275 stunalloc(p); 276 } --- 66 unchanged lines hidden --- | 255 INTON; 256 } else { 257 newlen -= ALIGN(sizeof(struct stack_block)); 258 p = stalloc(newlen); 259 if (oldlen != 0) 260 memcpy(p, oldspace, oldlen); 261 stunalloc(p); 262 } --- 66 unchanged lines hidden --- |