Changeset 1817 for trunk/src


Ignore:
Timestamp:
Oct 10, 2008, 9:10:26 AM (17 years ago)
Author:
bird
Message:

kmk: pass end-of-line around to the condition evalalutation. Don't alloca and copy the first part of an if condition to the stack, just use the buffer. Use allocated_variable_expand_2 where possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/read.c

    r1811 r1817  
    139139static void do_define (char *name, unsigned int namelen,
    140140                       enum variable_origin origin, struct ebuffer *ebuf);
     141#ifndef CONFIG_WITH_VALUE_LENGTH
    141142static int conditional_line (char *line, int len, const struct floc *flocp);
     143#else
     144static int conditional_line (char *line, char *eol, int len, const struct floc *flocp);
     145#endif
    142146#ifndef CONFIG_WITH_INCLUDEDEP
    143147static void record_files (struct nameseq *filenames, const char *pattern,
     
    189193      warn_undefined_variables_flag = 0;
    190194
     195#ifndef CONFIG_WITH_VALUE_LENGTH
    191196      value = allocated_variable_expand ("$(MAKEFILES)");
     197#else
     198      value = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(MAKEFILES)"), NULL);
     199#endif
    192200
    193201      warn_undefined_variables_flag = save;
     
    686694      if (!in_ignored_define)
    687695        {
     696#ifndef CONFIG_WITH_VALUE_LENGTH
    688697          int i = conditional_line (p, wlen, fstart);
     698#else
     699          int i = conditional_line (p, eol, wlen, fstart);
     700#endif
    689701          if (i != -2)
    690702            {
     
    831843                  /* Expand the line so we can use indirect and constructed
    832844                     variable names in an export command.  */
    833                   cp = ap = allocated_variable_expand (p2); ///// FIXME
     845#ifndef CONFIG_WITH_VALUE_LENGTH
     846                  cp = ap = allocated_variable_expand (p2);
     847#else
     848                  cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL);
     849#endif
    834850
    835851                  for (p = find_next_token (&cp, &l); p != 0;
     
    861877              /* Expand the line so we can use indirect and constructed
    862878                 variable names in an unexport command.  */
    863               cp = ap = allocated_variable_expand (p2); ///// FIXME
     879#ifndef CONFIG_WITH_VALUE_LENGTH
     880              cp = ap = allocated_variable_expand (p2);
     881#else
     882              cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL);
     883#endif
    864884
    865885              for (p = find_next_token (&cp, &l); p != 0;
     
    920940          if (memchr (name, '$', eol - name))
    921941            {
    922               free_me = name = allocated_variable_expand (name);
     942              unsigned int name_len;
     943              free_me = name = allocated_variable_expand_2 (name, eol - name, &name_len);
     944              eol = name + name_len;
    923945              while (isspace ((unsigned char)*name))
    924946                ++name;
    925               eol = strchr (name, '\0');
    926947            }
    927948
     
    949970          int noerror = (p[0] != 'i');
    950971
    951           p = allocated_variable_expand (p2); //// FIXME
     972#ifndef CONFIG_WITH_VALUE_LENGTH
     973          p = allocated_variable_expand (p2);
     974#else
     975          p = allocated_variable_expand_2 (p2, eol - p2, NULL);
     976#endif
    952977
    953978          /* If no filenames, it's a no-op.  */
     
    16181643
    16191644static int
     1645#ifndef CONFIG_WITH_VALUE_LENGTH
    16201646conditional_line (char *line, int len, const struct floc *flocp)
     1647#else
     1648conditional_line (char *line, char *eol, int len, const struct floc *flocp)
     1649#endif
    16211650{
    16221651  char *cmdname;
     
    16321661  unsigned int i;
    16331662  unsigned int o;
     1663#ifdef CONFIG_WITH_VALUE_LENGTH
     1664  assert (strchr (line, '\0') == eol);
     1665#endif
    16341666
    16351667  /* Compare a word, both length and contents. */
     
    17171749      /* If it's 'else' or 'endif' or an illegal conditional, fail.  */
    17181750      if (word1eq("else") || word1eq("endif")
     1751#ifndef CONFIG_WITH_VALUE_LENGTH
    17191752          || conditional_line (line, len, flocp) < 0)
     1753#else
     1754          || conditional_line (line, eol, len, flocp) < 0)
     1755#endif
    17201756        EXTRANEOUS ();
    17211757      else
     
    17701806      /* Expand the thing we're looking up, so we can use indirect and
    17711807         constructed variable names.  */
     1808#ifndef CONFIG_WITH_VALUE_LENGTH
    17721809      var = allocated_variable_expand (line);
     1810#else
     1811      var = allocated_variable_expand_2 (line, eol - line, NULL);
     1812#endif
    17731813
    17741814      /* Make sure there's only one variable name to test.  */
     
    18061846      unsigned int l;
    18071847      char termin = *line == '(' ? ',' : *line;
     1848#ifdef CONFIG_WITH_VALUE_LENGTH
     1849      char *buf_pos;
     1850#endif
    18081851
    18091852      if (termin != ',' && termin != '"' && termin != '\'')
     
    18371880            --p;
    18381881          *p = '\0';
     1882#ifdef CONFIG_WITH_VALUE_LENGTH
     1883          l = p - s1;
     1884#endif
    18391885        }
    18401886      else
    1841         *line++ = '\0';
    1842 
     1887        {
     1888#ifdef CONFIG_WITH_VALUE_LENGTH
     1889          l = line - s1;
     1890#endif
     1891          *line++ = '\0';
     1892        }
     1893
     1894#ifndef CONFIG_WITH_VALUE_LENGTH
    18431895      s2 = variable_expand (s1);
    18441896      /* We must allocate a new copy of the expanded string because
     
    18471899      s1 = alloca (l + 1);
    18481900      memcpy (s1, s2, l + 1);
     1901#else
     1902      s1 = variable_expand_string_2 (NULL, s1, l, &buf_pos);
     1903      ++buf_pos;
     1904#endif
    18491905
    18501906      if (termin != ',')
     
    18861942
    18871943      *line = '\0';
     1944#ifdef CONFIG_WITH_VALUE_LENGTH
     1945      l = line - s2;
     1946#endif
    18881947      line = next_token (++line);
    18891948      if (*line != '\0')
    18901949        EXTRANEOUS ();
    18911950
     1951#ifndef CONFIG_WITH_VALUE_LENGTH
    18921952      s2 = variable_expand (s2);
     1953#else
     1954      if ((size_t)buf_pos & 7)
     1955        buf_pos = variable_buffer_output (buf_pos, "\0\0\0\0\0\0\0\0",
     1956                                          8 - (size_t)buf_pos & 7);
     1957      s2 = variable_expand_string (buf_pos, s2, l);
     1958#endif
    18931959#ifdef CONFIG_WITH_SET_CONDITIONALS
    18941960      if (cmdtype == c_if1of || cmdtype == c_ifn1of)
     
    33983464        warn_undefined_variables_flag = 0;
    33993465
     3466#ifndef CONFIG_WITH_VALUE_LENGTH
    34003467        home_dir = allocated_variable_expand ("$(HOME)");
     3468#else
     3469        home_dir = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(HOME)"), NULL);
     3470#endif
    34013471
    34023472        warn_undefined_variables_flag = save;
Note: See TracChangeset for help on using the changeset viewer.