- Timestamp:
- Sep 18, 2006, 5:02:39 AM (19 years ago)
- Location:
- trunk/src/gmake
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/Makefile.kmk
r530 r533 23 23 CONFIG_WITH_INCLUDEDEP \ 24 24 CONFIG_WITH_TOUPPER_TOLOWER \ 25 KMK \ 26 \ 27 KMK_HELPERS \ 28 VARIABLE_HASH \ 29 CONFIG_WITH_OPTIMIZATION_HACKS \ 25 30 CONFIG_WITH_VALUE_LENGTH \ 26 CONFIG_WITH_COMPARE \ 27 KMK \ 28 CONFIG_WITH_OPTIMIZATION_HACKS \ 29 VARIABLE_HASH 30 31 CONFIG_WITH_COMPARE 32 31 33 kmk_SOURCES = \ 32 34 main.c \ -
trunk/src/gmake/expand.c
r530 r533 537 537 } 538 538 539 #ifdef CONFIG_WITH_VALUE_LENGTH 540 /* Expands the specified string, appending it to the specified variable value. */ 541 void 542 append_expanded_string_to_variable (struct variable *v, char *value) 543 { 544 char *p; 545 546 /* switch the variable buffer to the variable value buffer. */ 547 char *saved_buffer = variable_buffer; 548 unsigned int saved_buffer_length = variable_buffer_length; 549 variable_buffer = v->value; 550 variable_buffer_length = v->value_alloc_len; 551 552 /* skip the current value and start appending a space and the expanded string. */ 553 p = v->value + v->value_length; 554 if (v->value_length != 0) 555 p = variable_buffer_output (p, " ", 1); 556 p = variable_expand_string (p, value, (long)-1); 557 558 /* update the variable. (The variable_expand_string return is annoying!) */ 559 p = strchr (p, '\0'); 560 v->value = variable_buffer; 561 v->value_length = p - v->value; 562 v->value_alloc_len = variable_buffer_length; 563 564 /* restore the variable buffer. */ 565 variable_buffer = saved_buffer; 566 variable_buffer_length = saved_buffer_length; 567 } 568 #endif /* CONFIG_WITH_VALUE_LENGTH */ 539 569 540 570 static char * -
trunk/src/gmake/function.c
r531 r533 36 36 #endif 37 37 38 #ifdef KMK 38 #ifdef KMK_HELPERS 39 39 # include "kbuild.h" 40 40 #endif … … 887 887 char *result = 0; 888 888 #ifdef CONFIG_WITH_VALUE_LENGTH 889 if (len > (unsigned int)var->value_length)889 if (len >= (unsigned int)var->value_alloc_len) 890 890 { 891 891 free (var->value); 892 var->value = xmalloc (len + 1); 892 var->value_alloc_len = (len + 32) & ~31; 893 var->value = xmalloc (var->value_alloc_len); 893 894 } 894 895 memcpy (var->value, p, len); … … 2330 2331 { STRING_SIZE_TUPLE("comp-vars"), 3, 3, 1, func_comp_vars}, 2331 2332 #endif 2332 #ifdef KMK 2333 #ifdef KMK_HELPERS 2333 2334 { STRING_SIZE_TUPLE("kb-src-tool"), 1, 1, 0, func_kbuild_source_tool}, 2334 2335 { STRING_SIZE_TUPLE("kb-obj-base"), 1, 1, 0, func_kbuild_object_base}, -
trunk/src/gmake/variable.c
r531 r533 364 364 else 365 365 assert (value_length == strlen (value)); 366 v->value_length = value_length;367 366 if (!duplicate_value) 368 367 { … … 370 369 free (v->value); 371 370 v->value = value; 371 v->value_alloc_len = value_length + 1; 372 372 } 373 373 else 374 374 { 375 v->value = xrealloc (v->value, v->value_length + 1); 376 bcopy (value, v->value, v->value_length + 1); 375 if ((unsigned int)v->value_alloc_len <= value_length) 376 { 377 free (v->value); 378 v->value_alloc_len = (value_length + 0x40) & ~0x3f; 379 v->value = xmalloc (v->value_alloc_len); 380 } 381 memcpy (v->value, value, value_length + 1); 377 382 } 383 v->value_length = value_length; 378 384 #else 379 385 if (v->value != 0) … … 408 414 v->value_length = value_length; 409 415 if (!duplicate_value) 410 v->value = value; 416 { 417 v->value_alloc_len = value_length + 1; 418 v->value = value; 419 } 411 420 else 412 421 { 413 v->value = xmalloc (v->value_length + 1); 414 bcopy (value, v->value, v->value_length + 1); 422 v->value_alloc_len = (value_length + 32) & ~31; 423 v->value = xmalloc (v->value_alloc_len); 424 memcpy (v->value, value, value_length + 1); 415 425 } 416 426 #else … … 1075 1085 #ifdef CONFIG_WITH_VALUE_LENGTH 1076 1086 v->value_length = strlen (v->value); 1087 v->value_alloc_len = v->value_length + 1; 1077 1088 #endif 1078 1089 } … … 1259 1270 return result_0; 1260 1271 } 1272 1273 1274 #ifdef CONFIG_WITH_VALUE_LENGTH 1275 static struct variable * 1276 do_variable_definition_append (const struct floc *flocp, struct variable *v, char *value, 1277 enum Variable_origin origin) 1278 { 1279 if (env_overrides && origin == o_env) 1280 origin = o_env_override; 1281 1282 if (env_overrides && v->origin == o_env) 1283 /* V came from in the environment. Since it was defined 1284 before the switches were parsed, it wasn't affected by -e. */ 1285 v->origin = o_env_override; 1286 1287 /* A variable of this name is already defined. 1288 If the old definition is from a stronger source 1289 than this one, don't redefine it. */ 1290 if ((int) origin < (int) v->origin) 1291 return v; 1292 v->origin = origin; 1293 1294 /* location */ 1295 if (flocp != 0) 1296 v->fileinfo = *flocp; 1297 1298 /* The juicy bits, append the specified value to the variable 1299 This is a heavily exercied code path in kBuild. */ 1300 if (v->recursive) 1301 { 1302 /* The previous definition of the variable was recursive. 1303 The new value is the unexpanded old and new values. */ 1304 unsigned int value_len = strlen (value); 1305 unsigned int new_value_len = value_len + (v->value_length != 0 ? 1 + v->value_length : 0); 1306 1307 /* adjust the size. */ 1308 if ((unsigned)v->value_alloc_len <= new_value_len) 1309 { 1310 v->value_alloc_len = (new_value_len + 0x80) + 0x7f; 1311 v->value = xrealloc (v->value, v->value_alloc_len); 1312 } 1313 1314 /* insert the new bits */ 1315 if (v->value_length != 0) 1316 { 1317 v->value[v->value_length] = ' '; 1318 memcpy (&v->value[v->value_length + 1], value, value_len + 1); 1319 } 1320 else 1321 memcpy (v->value, value, value_len + 1); 1322 v->value_length = new_value_len; 1323 } 1324 else 1325 { 1326 /* The previous definition of the variable was simple. 1327 The new value comes from the old value, which was expanded 1328 when it was set; and from the expanded new value. */ 1329 append_expanded_string_to_variable(v, value); 1330 } 1331 1332 /* update the variable */ 1333 return v; 1334 } 1335 #endif /* CONFIG_WITH_VALUE_LENGTH */ 1261 1336 1262 1337 … … 1335 1410 else 1336 1411 { 1412 #ifdef CONFIG_WITH_VALUE_LENGTH 1413 v->append = append; 1414 return do_variable_definition_append (flocp, v, value, origin); 1415 #else /* !CONFIG_WITH_VALUE_LENGTH */ 1416 1337 1417 /* Paste the old and new values together in VALUE. */ 1338 1418 … … 1341 1421 1342 1422 val = value; 1343 #ifdef CONFIG_WITH_VALUE_LENGTH1344 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 else1359 {1360 /* The previous definition of the variable was simple.1361 The new value comes from the old value, which was expanded1362 when it was set; and from the expanded new value. Allocate1363 memory for the expansion as we may still need the rest of the1364 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 */1386 1423 if (v->recursive) 1387 1424 /* The previous definition of the variable was recursive. … … 1643 1680 v->value = p; 1644 1681 #ifdef CONFIG_WITH_VALUE_LENGTH 1645 v->value_length = -1;1682 v->value_length = v->value_alloc_len = -1; 1646 1683 #endif 1647 1684 -
trunk/src/gmake/variable.h
r531 r533 59 59 #ifdef CONFIG_WITH_VALUE_LENGTH 60 60 int value_length; /* The length of the value, usually unused. */ 61 int value_alloc_len; /* The amount of memory we've actually allocated. */ 62 /* FIXME: make lengths unsigned! */ 61 63 #endif 62 64 char *value; /* Variable value. */ … … 128 130 extern void install_variable_buffer PARAMS ((char **bufp, unsigned int *lenp)); 129 131 extern void restore_variable_buffer PARAMS ((char *buf, unsigned int len)); 132 #ifdef CONFIG_WITH_VALUE_LENGTH 133 extern void append_expanded_string_to_variable PARAMS ((struct variable *v, char *value)); 134 #endif 130 135 131 136 /* function.c */
Note:
See TracChangeset
for help on using the changeset viewer.