Magellan Linux

Diff of /trunk/mkinitrd-magellan/klibc/usr/dash/memalloc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1121 by niro, Sat Sep 1 22:45:15 2007 UTC revision 1122 by niro, Wed Aug 18 21:11:40 2010 UTC
# Line 106  struct stack_block { Line 106  struct stack_block {
106    
107  struct stack_block stackbase;  struct stack_block stackbase;
108  struct stack_block *stackp = &stackbase;  struct stack_block *stackp = &stackbase;
 struct stackmark *markp;  
109  char *stacknxt = stackbase.space;  char *stacknxt = stackbase.space;
110  size_t stacknleft = MINSIZE;  size_t stacknleft = MINSIZE;
111  char *sstrend = stackbase.space + MINSIZE;  char *sstrend = stackbase.space + MINSIZE;
 int herefd = -1;  
112    
113  pointer  pointer
114  stalloc(size_t nbytes)  stalloc(size_t nbytes)
# Line 161  stunalloc(pointer p) Line 159  stunalloc(pointer p)
159    
160    
161    
162  void  void pushstackmark(struct stackmark *mark, size_t len)
 setstackmark(struct stackmark *mark)  
163  {  {
164   mark->stackp = stackp;   mark->stackp = stackp;
165   mark->stacknxt = stacknxt;   mark->stacknxt = stacknxt;
166   mark->stacknleft = stacknleft;   mark->stacknleft = stacknleft;
167   mark->marknext = markp;   grabstackblock(len);
168   markp = mark;  }
169    
170    void setstackmark(struct stackmark *mark)
171    {
172     pushstackmark(mark, stacknxt == stackp->space && stackp != &stackbase);
173  }  }
174    
175    
# Line 178  popstackmark(struct stackmark *mark) Line 179  popstackmark(struct stackmark *mark)
179   struct stack_block *sp;   struct stack_block *sp;
180    
181   INTOFF;   INTOFF;
  markp = mark->marknext;  
182   while (stackp != mark->stackp) {   while (stackp != mark->stackp) {
183   sp = stackp;   sp = stackp;
184   stackp = sp->prev;   stackp = sp->prev;
# Line 214  growstackblock(void) Line 214  growstackblock(void)
214    
215   if (stacknxt == stackp->space && stackp != &stackbase) {   if (stacknxt == stackp->space && stackp != &stackbase) {
216   struct stack_block *oldstackp;   struct stack_block *oldstackp;
  struct stackmark *xmark;  
217   struct stack_block *sp;   struct stack_block *sp;
218   struct stack_block *prevstackp;   struct stack_block *prevstackp;
219   size_t grosslen;   size_t grosslen;
# Line 230  growstackblock(void) Line 229  growstackblock(void)
229   stacknxt = sp->space;   stacknxt = sp->space;
230   stacknleft = newlen;   stacknleft = newlen;
231   sstrend = sp->space + newlen;   sstrend = sp->space + newlen;
   
  /*  
  * Stack marks pointing to the start of the old block  
  * must be relocated to point to the new block  
  */  
  xmark = markp;  
  while (xmark != NULL && xmark->stackp == oldstackp) {  
  xmark->stackp = stackp;  
  xmark->stacknxt = stacknxt;  
  xmark->stacknleft = stacknleft;  
  xmark = xmark->marknext;  
  }  
232   INTON;   INTON;
233   } else {   } else {
234   char *oldspace = stacknxt;   char *oldspace = stacknxt;
# Line 254  growstackblock(void) Line 241  growstackblock(void)
241   }   }
242  }  }
243    
 void  
 grabstackblock(size_t len)  
 {  
  len = SHELL_ALIGN(len);  
  stacknxt += len;  
  stacknleft -= len;  
 }  
   
244  /*  /*
245   * The following routines are somewhat easier to use than the above.   * The following routines are somewhat easier to use than the above.
246   * The user declares a variable of type STACKSTR, which may be declared   * The user declares a variable of type STACKSTR, which may be declared
# Line 284  void * Line 263  void *
263  growstackstr(void)  growstackstr(void)
264  {  {
265   size_t len = stackblocksize();   size_t len = stackblocksize();
  if (herefd >= 0 && len >= 1024) {  
  xwrite(herefd, stackblock(), len);  
  return stackblock();  
  }  
266   growstackblock();   growstackblock();
267   return stackblock() + len;   return stackblock() + len;
268  }  }

Legend:
Removed from v.1121  
changed lines
  Added in v.1122