- Timestamp:
- Sep 18, 2006, 1:49:49 AM (19 years ago)
- Location:
- trunk/src/gmake
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/function.c
r530 r531 886 886 { 887 887 char *result = 0; 888 888 #ifdef CONFIG_WITH_VALUE_LENGTH 889 if (len > (unsigned int)var->value_length) 890 { 891 free (var->value); 892 var->value = xmalloc (len + 1); 893 } 894 memcpy (var->value, p, len); 895 var->value[len] = '\0'; 896 var->value_length = len; 897 #else 889 898 { 890 891 892 893 894 895 899 char save = p[len]; 900 901 p[len] = '\0'; 902 free (var->value); 903 var->value = (char *) xstrdup ((char*) p); 904 p[len] = save; 896 905 } 906 #endif 897 907 898 908 result = allocated_variable_expand (body); -
trunk/src/gmake/kbuild.c
r530 r531 51 51 kbuild_get_variable(const char *pszName) 52 52 { 53 #ifndef NDEBUG 54 unsigned i; 55 #endif 53 56 struct variable *pVar = lookup_variable(pszName, strlen(pszName)); 54 57 if (!pVar) … … 56 59 if (pVar->recursive) 57 60 fatal(NILF, _("variable `%s' is defined as `recursive' instead of `simple'!"), pszName); 58 pVar->value_length = strlen(pVar->value); 61 #ifndef NDEBUG 62 i = strlen(pVar->value); 63 if (i != pVar->value_length) 64 { 65 printf("%d != %d %s\n", pVar->value_length, i, pVar->name); 66 __asm int 3; 67 } 68 #endif 59 69 return pVar; 60 70 } … … 70 80 kbuild_get_recursive_variable(const char *pszName) 71 81 { 82 #ifndef NDEBUG 83 unsigned i; 84 #endif 72 85 struct variable *pVar = lookup_variable(pszName, strlen(pszName)); 73 86 if (!pVar) 74 87 fatal(NILF, _("variable `%s' isn't defined!"), pszName); 75 pVar->value_length = strlen(pVar->value); 88 #ifndef NDEBUG 89 i = strlen(pVar->value); 90 if (i != pVar->value_length) 91 { 92 printf("%d != %d %s\n", pVar->value_length, i, pVar->name); 93 __asm int 3; 94 } 95 #endif 76 96 return pVar; 77 97 } … … 90 110 struct variable *pVar = lookup_variable(pszName, strlen(pszName)); 91 111 if (pVar) 92 pVar->value_length = strlen(pVar->value); 112 { 113 #ifndef NDEBUG 114 unsigned i = strlen(pVar->value); 115 if (i != pVar->value_length) 116 { 117 printf("%d != %d %s\n", pVar->value_length, i, pVar->name); 118 __asm int 3; 119 } 120 #endif 121 } 93 122 return pVar; 94 123 } … … 230 259 *pszEnd = '\0'; 231 260 if (!strchr(pszEnd, '$')) 232 pVar = define_variable(pszVarName, strlen(pszVarName), psz, o_file, 0 /* !recursive */); 261 pVar = define_variable_vl(pszVarName, strlen(pszVarName), psz, pszEnd - psz, 262 1 /* duplicate */, o_file, 0 /* !recursive */); 233 263 else 234 264 { … … 244 274 { 245 275 *pszExpEnd = '\0'; 246 pVar = define_variable(pszVarName, strlen(pszVarName), pszExp, o_file, 0 /* !recursive */); 276 pVar = define_variable_vl(pszVarName, strlen(pszVarName), pszExp, 277 pszExpEnd - pszExp, 1 /* duplicate */, 278 o_file, 0 /* !recursive */); 247 279 } 248 280 else … … 362 394 + pszSrcEnd - pszSrc 363 395 + 1; 364 psz = pszResult = alloca(cch);396 psz = pszResult = xmalloc(cch); 365 397 366 398 memcpy(psz, pPathTarget->value, pPathTarget->value_length); psz += pPathTarget->value_length; … … 374 406 * Define the variable in the current set and return it. 375 407 */ 376 return define_variable(pszVarName, strlen(pszVarName), pszResult, o_file, 0 /* !recursive */); 408 return define_variable_vl(pszVarName, strlen(pszVarName), pszResult, cch - 1, 409 0 /* use pszResult */, o_file, 0 /* !recursive */); 377 410 } 378 411 … … 440 473 *pszEnd = '\0'; 441 474 if (!strchr(pszEnd, '$')) 442 pVar = define_variable(pszVarName, strlen(pszVarName), psz, o_file, 0 /* !recursive */); 475 pVar = define_variable_vl(pszVarName, strlen(pszVarName), psz, pszEnd - psz, 476 1 /* duplicate */, o_file, 0 /* !recursive */); 443 477 else 444 478 { … … 454 488 { 455 489 *pszExpEnd = '\0'; 456 pVar = define_variable(pszVarName, strlen(pszVarName), pszExp, o_file, 0 /* !recursive */); 490 pVar = define_variable_vl(pszVarName, strlen(pszVarName), pszExp, 491 pszExpEnd - pszExp, 1 /* duplicate */, 492 o_file, 0 /* !recursive */); 457 493 } 458 494 else … … 954 990 free(paVars[iVar].pszExp); 955 991 } 956 psz[-(cchTotal != 0)] = '\0'; 957 958 pVar = define_variable(pszVarName, strlen(pszVarName), pszResult, o_file, 0 /* !recursive */); 959 free(pszResult); 992 if (psz != pszResult) 993 psz--; 994 *psz = '\0'; 995 cchTotal = psz - pszResult; 996 997 pVar = define_variable_vl(pszVarName, strlen(pszVarName), pszResult, cchTotal, 998 0 /* take pszResult */ , o_file, 0 /* !recursive */); 960 999 return pVar; 961 1000 } … … 1021 1060 memcpy(psz, pObjSuff->value, pObjSuff->value_length); psz += pObjSuff->value_length; 1022 1061 memcpy(psz, pDepSuff->value, pDepSuff->value_length + 1); 1023 *ppDep = define_variable ("dep", 3, pszResult, o_file, 0 /* !recursive */);1062 *ppDep = define_variable_vl("dep", 3, pszResult, cch - 1, 1 /*dup*/, o_file, 0 /* !recursive */); 1024 1063 1025 1064 /* … … 1027 1066 */ 1028 1067 *psz = '\0'; 1029 pObj = define_variable(pszVarName, strlen(pszVarName), pszResult, o_file, 0 /* !recursive */); 1068 pObj = define_variable_vl(pszVarName, strlen(pszVarName), pszResult, psz - pszResult, 1069 1/* dup */, o_file, 0 /* !recursive */); 1030 1070 1031 1071 /* … … 1077 1117 1078 1118 /* set global variable */ 1079 define_variable_ global(pszName, cch, pszResult, o_file, 0 /* !recursive */, NILF);1119 define_variable_vl_global(pszName, cch, pszResult, psz - pszResult, 1/*dup*/, o_file, 0 /* !recursive */, NILF); 1080 1120 1081 1121 /* … … 1092 1132 *psz = '\0'; 1093 1133 } 1094 *ppDirDep = define_variable ("dirdep", 6, pszResult, o_file, 0 /* !recursive */);1134 *ppDirDep = define_variable_vl("dirdep", 6, pszResult, psz - pszResult, 1/*dup*/, o_file, 0 /* !recursive */); 1095 1135 1096 1136 return pObj; -
trunk/src/gmake/variable.c
r530 r531 314 314 that it should be recursively re-expanded. */ 315 315 316 #ifdef CONFIG_WITH_VALUE_LENGTH 316 317 struct variable * 317 318 define_variable_in_set (const char *name, unsigned int length, 318 char *value, enum variable_origin origin, 319 int recursive, struct variable_set *set, 319 char *value, unsigned int value_length, int duplicate_value, 320 enum variable_origin origin, int recursive, 321 struct variable_set *set, const struct floc *flocp) 322 #else 323 struct variable * 324 define_variable_in_set (const char *name, unsigned int length, 325 char *value, enum variable_origin origin, 326 int recursive, struct variable_set *set, 320 327 const struct floc *flocp) 328 #endif 321 329 { 322 330 struct variable *v; … … 352 360 { 353 361 #ifdef CONFIG_WITH_VALUE_LENGTH 354 v->value_length = strlen (value); 355 v->value = xrealloc (v->value, v->value_length + 1); 356 bcopy (value, v->value, v->value_length + 1); 362 if (value_length == ~0U) 363 value_length = strlen (value); 364 else 365 assert (value_length == strlen (value)); 366 v->value_length = value_length; 367 if (!duplicate_value) 368 { 369 if (v->value != 0) 370 free (v->value); 371 v->value = value; 372 } 373 else 374 { 375 v->value = xrealloc (v->value, v->value_length + 1); 376 bcopy (value, v->value, v->value_length + 1); 377 } 357 378 #else 358 379 if (v->value != 0) … … 381 402 hash_insert_at (&set->table, v, var_slot); 382 403 #ifdef CONFIG_WITH_VALUE_LENGTH 383 v->value_length = strlen (value); 384 v->value = xmalloc (v->value_length + 1); 385 bcopy (value, v->value, v->value_length + 1); 404 if (value_length == ~0U) 405 value_length = strlen (value); 406 else 407 assert (value_length == strlen (value)); 408 v->value_length = value_length; 409 if (!duplicate_value) 410 v->value = value; 411 else 412 { 413 v->value = xmalloc (v->value_length + 1); 414 bcopy (value, v->value, v->value_length + 1); 415 } 386 416 #else 387 417 v->value = xstrdup (value); … … 1044 1074 v->value = xstrdup (default_shell); 1045 1075 #ifdef CONFIG_WITH_VALUE_LENGTH 1046 v->value_length = -1;1076 v->value_length = strlen (v->value); 1047 1077 #endif 1048 1078 } … … 1244 1274 int conditional = 0; 1245 1275 const size_t varname_len = strlen (varname); /* bird */ 1276 # ifdef CONFIG_WITH_VALUE_LENGTH 1277 unsigned int value_len = ~0U; 1278 # endif 1246 1279 1247 1280 /* Calculate the variable's new value in VALUE. */ … … 1308 1341 1309 1342 val = value; 1343 #ifdef CONFIG_WITH_VALUE_LENGTH 1344 if (v->recursive) 1345 { 1346 /* The previous definition of the variable was recursive. 1347 The new value is the unexpanded old and new values. */ 1348 flavor = f_recursive; 1349 oldlen = v->value_length; assert (oldlen == strlen (v->value)); 1350 vallen = strlen (val); 1351 1352 value_len = oldlen + 1 + vallen; 1353 p = alloc_value = xmalloc (value_len + 1); 1354 memcpy (p, v->value, oldlen); 1355 p[oldlen] = ' '; 1356 memcpy (&p[oldlen + 1], val, vallen + 1); 1357 } 1358 else 1359 { 1360 /* The previous definition of the variable was simple. 1361 The new value comes from the old value, which was expanded 1362 when it was set; and from the expanded new value. Allocate 1363 memory for the expansion as we may still need the rest of the 1364 buffer if we're looking at a target-specific variable. */ 1365 char *buf; 1366 unsigned int len; 1367 install_variable_buffer (&buf, &len); 1368 1369 p = variable_buffer; 1370 if ( v->value && *v->value ) 1371 { 1372 p = variable_buffer_output (p, v->value, v->value_length); 1373 p = variable_buffer_output (p, " ", 1); 1374 } 1375 p = variable_expand_string (p, val, (long)-1); 1376 1377 p = strchr (p, '\0'); /* returns adjusted start, not end. */ 1378 alloc_value = variable_buffer; 1379 value_len = p - alloc_value; 1380 p = alloc_value; 1381 1382 variable_buffer = NULL; /* hackish */ 1383 restore_variable_buffer (buf, len); 1384 } 1385 #else /* !CONFIG_WITH_VALUE_LENGTH */ 1310 1386 if (v->recursive) 1311 1387 /* The previous definition of the variable was recursive. … … 1320 1396 val = alloc_value = allocated_variable_expand (val); 1321 1397 1322 #ifdef CONFIG_WITH_VALUE_LENGTH 1323 oldlen = v->value_length; 1324 assert(oldlen == strlen (v->value)); 1325 #endif 1398 oldlen = strlen (v->value); 1326 1399 vallen = strlen (val); 1327 1400 p = (char *) alloca (oldlen + 1 + vallen + 1); … … 1329 1402 p[oldlen] = ' '; 1330 1403 bcopy (val, &p[oldlen + 1], vallen + 1); 1404 #endif /* !CONFIG_WITH_VALUE_LENGTH */ 1331 1405 } 1332 1406 } … … 1430 1504 { 1431 1505 v = define_variable_in_set (varname, varname_len, default_shell, 1506 # ifdef CONFIG_WITH_VALUE_LENGTH 1507 ~0U, 1 /* duplicate_value */, 1508 # endif 1432 1509 origin, flavor == f_recursive, 1433 1510 (target_var … … 1439 1516 else 1440 1517 v = lookup_variable (varname, varname_len); 1518 # ifdef CONFIG_WITH_VALUE_LENGTH 1519 if (alloc_value) 1520 free (alloc_value); 1521 # endif 1441 1522 } 1442 1523 else … … 1450 1531 1451 1532 v = define_variable_in_set (varname, varname_len, p, 1533 #ifdef CONFIG_WITH_VALUE_LENGTH 1534 value_len, !alloc_value, 1535 #endif 1452 1536 origin, flavor == f_recursive, 1453 1537 (target_var … … 1457 1541 v->conditional = conditional; 1458 1542 1543 #ifndef CONFIG_WITH_VALUE_LENGTH 1459 1544 if (alloc_value) 1460 1545 free (alloc_value); 1546 #endif 1461 1547 1462 1548 return v; -
trunk/src/gmake/variable.h
r530 r531 162 162 const struct variable_set *set)); 163 163 164 #ifdef CONFIG_WITH_VALUE_LENGTH 165 166 extern struct variable *define_variable_in_set 167 PARAMS ((const char *name, unsigned int length, char *value, 168 unsigned int value_length, int duplicate_value, 169 enum variable_origin origin, int recursive, 170 struct variable_set *set, const struct floc *flocp)); 171 172 /* Define a variable in the current variable set. */ 173 174 #define define_variable(n,l,v,o,r) \ 175 define_variable_in_set((n),(l),(v), ~0U,1,(o),(r),\ 176 current_variable_set_list->set,NILF) 177 178 #define define_variable_vl(n,l,v,vl,dv,o,r) \ 179 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),\ 180 current_variable_set_list->set,NILF) 181 182 /* Define a variable with a location in the current variable set. */ 183 184 #define define_variable_loc(n,l,v,o,r,f) \ 185 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\ 186 current_variable_set_list->set,(f)) 187 188 /* Define a variable with a location in the global variable set. */ 189 190 #define define_variable_global(n,l,v,o,r,f) \ 191 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),NULL,(f)) 192 193 #define define_variable_vl_global(n,l,v,vl,dv,o,r,f) \ 194 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),NULL,(f)) 195 196 /* Define a variable in FILE's variable set. */ 197 198 #define define_variable_for_file(n,l,v,o,r,f) \ 199 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),(f)->variables->set,NILF) 200 201 #else 202 164 203 extern struct variable *define_variable_in_set 165 204 PARAMS ((const char *name, unsigned int length, char *value, … … 188 227 #define define_variable_for_file(n,l,v,o,r,f) \ 189 228 define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF) 229 230 #endif 190 231 191 232 /* Warn that NAME is an undefined variable. */
Note:
See TracChangeset
for help on using the changeset viewer.