Changeset 1809 for trunk/src/kmk/variable.c
- Timestamp:
- Oct 10, 2008, 4:27:38 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/variable.c
r1808 r1809 467 467 struct variable * 468 468 define_variable_in_set (const char *name, unsigned int length, 469 const char *value, unsigned int value_length, int duplicate_value, 470 enum variable_origin origin, int recursive, 471 struct variable_set *set, const struct floc *flocp) 469 const char *value, unsigned int value_len, 470 int duplicate_value, enum variable_origin origin, 471 int recursive, struct variable_set *set, 472 const struct floc *flocp) 472 473 #else 473 474 struct variable * … … 510 511 { 511 512 #ifdef CONFIG_WITH_VALUE_LENGTH 512 if (value_len gth== ~0U)513 value_len gth= strlen (value);513 if (value_len == ~0U) 514 value_len = strlen (value); 514 515 else 515 assert (value_len gth== strlen (value));516 assert (value_len == strlen (value)); 516 517 if (!duplicate_value) 517 518 { … … 519 520 free (v->value); 520 521 v->value = (char *)value; 521 v->value_alloc_len = value_len gth+ 1;522 v->value_alloc_len = value_len + 1; 522 523 } 523 524 else 524 525 { 525 if ((unsigned int)v->value_alloc_len <= value_len gth)526 if ((unsigned int)v->value_alloc_len <= value_len) 526 527 { 527 528 free (v->value); 528 v->value_alloc_len = (value_len gth+ 0x40) & ~0x3f;529 v->value_alloc_len = (value_len + 0x40) & ~0x3f; 529 530 v->value = xmalloc (v->value_alloc_len); 530 531 } 531 memcpy (v->value, value, value_len gth+ 1);532 memcpy (v->value, value, value_len + 1); 532 533 } 533 v->value_length = value_len gth;534 v->value_length = value_len; 534 535 #else 535 536 if (v->value != 0) … … 558 559 hash_insert_at (&set->table, v, var_slot); 559 560 #ifdef CONFIG_WITH_VALUE_LENGTH 560 if (value_len gth== ~0U)561 value_len gth= strlen (value);561 if (value_len == ~0U) 562 value_len = strlen (value); 562 563 else 563 assert (value_len gth== strlen (value));564 v->value_length = value_len gth;564 assert (value_len == strlen (value)); 565 v->value_length = value_len; 565 566 if (!duplicate_value) 566 567 { 567 v->value_alloc_len = value_len gth+ 1;568 v->value_alloc_len = value_len + 1; 568 569 v->value = (char *)value; 569 570 } 570 571 else 571 572 { 572 v->value_alloc_len = (value_len gth+ 32) & ~31;573 v->value_alloc_len = (value_len + 32) & ~31; 573 574 v->value = xmalloc (v->value_alloc_len); 574 memcpy (v->value, value, value_len gth+ 1);575 memcpy (v->value, value, value_len + 1); 575 576 } 576 577 #else … … 1618 1619 { 1619 1620 v->value_alloc_len *= 2; 1620 if ( v->value_alloc_len < new_value_len + 1)1621 if ((unsigned)v->value_alloc_len < new_value_len + 1) 1621 1622 v->value_alloc_len = (new_value_len + 1 + value_len + 0x7f) + ~0x7fU; 1622 1623 if (append || !v->value_length) … … 1655 1656 1656 1657 static struct variable * 1657 do_variable_definition_append (const struct floc *flocp, struct variable *v, const char *value, 1658 enum variable_origin origin, int append) 1658 do_variable_definition_append (const struct floc *flocp, struct variable *v, 1659 const char *value, unsigned int value_len, 1660 int simple_value, enum variable_origin origin, 1661 int append) 1659 1662 { 1660 1663 if (env_overrides && origin == o_env) … … 1679 1682 /* The juicy bits, append the specified value to the variable 1680 1683 This is a heavily exercised code path in kBuild. */ 1681 if (v->recursive) 1682 append_string_to_variable (v, value, strlen (value), append); 1684 if (value_len == ~0U) 1685 value_len = strlen (value); 1686 if (v->recursive || simple_value) 1687 append_string_to_variable (v, value, value_len, append); 1683 1688 else 1684 1689 /* The previous definition of the variable was simple. 1685 1690 The new value comes from the old value, which was expanded 1686 1691 when it was set; and from the expanded new value. */ 1687 append_expanded_string_to_variable (v, value, append);1692 append_expanded_string_to_variable (v, value, value_len, append); 1688 1693 1689 1694 /* update the variable */ … … 1697 1702 1698 1703 struct variable * 1704 #ifndef CONFIG_WITH_VALUE_LENGTH 1699 1705 do_variable_definition (const struct floc *flocp, const char *varname, 1700 1706 const char *value, enum variable_origin origin, 1701 1707 enum variable_flavor flavor, int target_var) 1708 #else /* CONFIG_WITH_VALUE_LENGTH */ 1709 do_variable_definition_2 (const struct floc *flocp, 1710 const char *varname, const char *value, 1711 unsigned int value_len, int simple_value, 1712 char *free_value, 1713 enum variable_origin origin, 1714 enum variable_flavor flavor, 1715 int target_var) 1716 #endif /* CONFIG_WITH_VALUE_LENGTH */ 1702 1717 { 1703 1718 const char *p; … … 1708 1723 const size_t varname_len = strlen (varname); /* bird */ 1709 1724 #ifdef CONFIG_WITH_VALUE_LENGTH 1710 unsigned int value_len = ~0U;1725 assert (value_len == ~0U || value_len == strlen (value)); 1711 1726 #endif 1712 1727 … … 1724 1739 variable buffer, and we may still need that if we're looking at a 1725 1740 target-specific variable. */ 1726 #if !defined(KMK) || !defined(CONFIG_WITH_VALUE_LENGTH)1741 #ifndef CONFIG_WITH_VALUE_LENGTH 1727 1742 p = alloc_value = allocated_variable_expand (value); 1728 #else /* KMK - optimization */ 1729 p = alloc_value = allocated_variable_expand_2 (value, -1, &value_len); 1730 #endif /* KMK - optimization */ 1743 #else /* CONFIG_WITH_VALUE_LENGTH */ 1744 if (!simple_value) 1745 p = alloc_value = allocated_variable_expand_2 (value, value_len, &value_len); 1746 else 1747 { 1748 if (value_len == ~0U) 1749 value_len = strlen (value); 1750 if (!free_value) 1751 p = alloc_value = savestring (value, value_len); 1752 else 1753 { 1754 assert (value == free_value); 1755 p = alloc_value = free_value; 1756 free_value = 0; 1757 } 1758 } 1759 #endif /* CONFIG_WITH_VALUE_LENGTH */ 1731 1760 break; 1732 1761 case f_conditional: … … 1789 1818 #ifdef CONFIG_WITH_VALUE_LENGTH 1790 1819 v->append = append; 1820 v = do_variable_definition_append (flocp, v, value, value_len, 1821 simple_value, origin, 1791 1822 # ifdef CONFIG_WITH_PREPEND_ASSIGNMENT 1792 return do_variable_definition_append (flocp, v, value, origin,org_flavor == f_append);1823 org_flavor == f_append); 1793 1824 # else 1794 return do_variable_definition_append (flocp, v, value, origin,1);1825 1); 1795 1826 # endif 1827 if (free_value) 1828 free (free_value); 1829 return v; 1796 1830 #else /* !CONFIG_WITH_VALUE_LENGTH */ 1797 1831 … … 1973 2007 if (alloc_value) 1974 2008 free (alloc_value); 2009 #else 2010 if (free_value) 2011 free (free_value); 1975 2012 #endif 1976 2013 … … 2000 2037 register char *end; 2001 2038 enum variable_flavor flavor = f_bogus; 2002 #ifndef KMK2039 #ifndef CONFIG_WITH_VALUE_LENGTH 2003 2040 char *name; 2004 #endif /* KMK - optimization */2041 #endif 2005 2042 2006 2043 while (1) … … 2086 2123 2087 2124 /* Expand the name, so "$(foo)bar = baz" works. */ 2088 #ifndef KMK2125 #ifndef CONFIG_WITH_VALUE_LENGTH 2089 2126 name = alloca (end - beg + 1); 2090 2127 memcpy (name, beg, end - beg); 2091 2128 name[end - beg] = '\0'; 2092 2129 v->name = allocated_variable_expand (name); 2093 #else /* KMK - optimizations */ 2094 //if (memchr (beg, '$', end - beg)) /* (Mostly for cleaning up the profiler result.) */ 2095 v->name = allocated_variable_expand_2 (beg, end - beg, NULL); 2096 //else 2097 // { 2098 // v->name = memcpy (xmalloc (end - beg + 1), beg, end - beg); 2099 // v->name[end - beg] = '\0'; 2100 // } 2101 #endif /* KMK - optimizations */ 2130 #else /* CONFIG_WITH_VALUE_LENGTH */ 2131 v->name = allocated_variable_expand_2 (beg, end - beg, NULL); 2132 #endif /* CONFIG_WITH_VALUE_LENGTH */ 2102 2133 2103 2134 if (v->name[0] == '\0')
Note:
See TracChangeset
for help on using the changeset viewer.