Changeset 3438 for trunk/src/kash/var.c
- Timestamp:
- Sep 9, 2020, 10:01:39 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/var.c
r2641 r3438 41 41 #endif 42 42 43 #include <assert.h> 43 44 #include <stddef.h> 44 45 #include <stdlib.h> … … 270 271 } 271 272 } 273 274 275 #ifndef SH_FORKED_MODE 276 /* 277 * This routine is called to copy variable state from parent to child shell. 278 */ 279 void 280 subshellinitvar(shinstance *psh, shinstance *inherit) 281 { 282 unsigned i; 283 for (i = 0; i < K_ELEMENTS(inherit->vartab); i++) { 284 struct var const *vsrc = inherit->vartab[i]; 285 if (!vsrc) { 286 } else { 287 struct var **ppdst = &psh->vartab[i]; 288 do 289 { 290 struct var *dst; 291 if (!(vsrc->flags & VSTRFIXED)) { 292 dst = (struct var *)ckmalloc(psh, sizeof(*dst)); 293 } else { 294 /* VSTRFIXED is used when the structure is a fixed allocation in 295 the shinstance structure, so scan those to find which it is: */ 296 size_t left = ((struct var *)&inherit->vartab[0] - &inherit->vatty); 297 struct var const *fixedsrc = &inherit->vatty; 298 dst = &psh->vatty; 299 while (left-- > 0) 300 if (vsrc != fixedsrc) { 301 fixedsrc++; 302 dst++; 303 } else 304 break; 305 assert(left < 256 /*whatever, just no rollover*/); 306 } 307 *dst = *vsrc; 308 309 if (!(vsrc->flags & VTEXTFIXED)) { 310 dst->text = savestr(psh, vsrc->text); 311 dst->flags &= ~VSTACK; 312 } 313 314 *ppdst = dst; 315 ppdst = &dst->next; 316 317 vsrc = vsrc->next; 318 } while (vsrc); 319 *ppdst = NULL; 320 } 321 } 322 323 /** @todo We don't always need to copy local variables. */ 324 if (inherit->localvars) { 325 struct localvar const *vsrc = inherit->localvars; 326 struct localvar **ppdst = &psh->localvars; 327 do 328 { 329 struct localvar *dst = ckmalloc(psh, sizeof(*dst)); 330 331 dst->flags = vsrc->flags & ~VSTACK; 332 if (vsrc->flags & VTEXTFIXED) 333 dst->text = savestr(psh, vsrc->text); 334 else 335 dst->text = vsrc->text; 336 337 dst->vp = find_var(psh, vsrc->vp->text, NULL, NULL); 338 assert(dst->vp); 339 340 *ppdst = dst; 341 ppdst = &dst->next; 342 343 vsrc = vsrc->next; 344 } while (vsrc); 345 } 346 } 347 #endif /* !SH_FORKED_MODE */ 272 348 273 349 /*
Note:
See TracChangeset
for help on using the changeset viewer.