VirtualBox

Changeset 1809 in kBuild for trunk/src/kmk


Ignore:
Timestamp:
Oct 10, 2008 2:27:38 AM (16 years ago)
Author:
bird
Message:

kmk: More length and alloc optimizations. Made all the length optimizations from yesterday CONFIG_WITH_VALUE_LENGTH instead of KMK.

Location:
trunk/src/kmk
Files:
7 edited

Legend:

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

    r1808 r1809  
    228228  char *o;
    229229  unsigned int line_offset;
    230 #ifdef KMK
     230#ifdef CONFIG_WITH_VALUE_LENGTH
    231231  const char *eos;
    232232#endif
     
    248248    }
    249249
    250 #ifdef KMK
     250#ifdef CONFIG_WITH_VALUE_LENGTH
    251251  /* Simple first, 50% of the kBuild calls to this function does
    252252     not need any expansion at all. Should be worth a special case. */
     
    261261    }
    262262  eos = string + length;
    263 #endif /* KMK - optimization */
     263#endif /* CONFIG_WITH_VALUE_LENGTH */
    264264
    265265  /* If we want a subset of the string, allocate a temporary buffer for it.
     
    270270      memcpy(abuf, string, length);
    271271      abuf[length] = '\0';
    272 #ifdef KMK
     272#ifdef CONFIG_WITH_VALUE_LENGTH
    273273      p1 += abuf - string;
    274274      eos += abuf - string;
    275 #endif /* KMK - optimization */
     275#endif /* CONFIG_WITH_VALUE_LENGTH */
    276276      string = abuf;
    277277    }
     
    284284         at the next $ or the end of the input.  */
    285285
    286 #ifndef KMK
     286#ifndef CONFIG_WITH_VALUE_LENGTH
    287287      p1 = strchr (p, '$');
    288 #endif /* !KMK - optimization  */
     288#endif
    289289
    290290      o = variable_buffer_output (o, p, p1 != 0 ? (unsigned int)(p1 - p) : strlen (p) + 1);
     
    327327               If so, expand it before expanding the entire reference.  */
    328328
    329 #ifndef KMK
     329#ifndef CONFIG_WITH_VALUE_LENGTH
    330330            end = strchr (beg, closeparen);
    331 #else  /* KMK - optimization */
     331#else
    332332            end = memchr (beg, closeparen, eos - beg);
    333 #endif /* KMK - optimization */
     333#endif
    334334            if (end == 0)
    335335              /* Unterminated variable reference.  */
     
    470470      else
    471471        ++p;
    472 #ifdef KMK
     472#ifdef CONFIG_WITH_VALUE_LENGTH
    473473      p1 = memchr (p, '$', eos - p);
    474 #endif /* KMK - optimization */
     474#endif
    475475    }
    476476
     
    481481  return (variable_buffer + line_offset);
    482482}
    483 #ifdef KMK
     483#ifdef CONFIG_WITH_VALUE_LENGTH
    484484
    485485
     
    494494  char *o;
    495495  unsigned int line_offset;
    496 #ifdef KMK
     496#ifdef CONFIG_WITH_VALUE_LENGTH
    497497  const char *eos;
    498498#endif
     
    514514    }
    515515
    516 #ifdef KMK
     516#ifdef CONFIG_WITH_VALUE_LENGTH
    517517  /* Simple first, 50% of the kBuild calls to this function does
    518518     not need any expansion at all. Should be worth a special case. */
     
    528528    }
    529529  eos = string + length;
    530 #endif /* KMK - optimization */
     530#endif /* CONFIG_WITH_VALUE_LENGTH */
    531531
    532532  /* If we want a subset of the string, allocate a temporary buffer for it.
     
    537537      memcpy(abuf, string, length);
    538538      abuf[length] = '\0';
    539 #ifdef KMK
     539#ifdef CONFIG_WITH_VALUE_LENGTH
    540540      p1 += abuf - string;
    541541      eos += abuf - string;
     
    551551         at the next $ or the end of the input.  */
    552552
    553 #ifndef KMK
     553#ifndef CONFIG_WITH_VALUE_LENGTH
    554554      p1 = strchr (p, '$');
    555 #endif /* !KMK */
     555#endif
    556556
    557557      /*o = variable_buffer_output (o, p, p1 != 0 ? (unsigned int)(p1 - p) : strlen (p) + 1); - why +1 ? */
     
    595595               If so, expand it before expanding the entire reference.  */
    596596
    597 #ifndef KMK
     597#ifndef CONFIG_WITH_VALUE_LENGTH
    598598            end = strchr (beg, closeparen);
    599 #else  /* KMK - optimization */
     599#else
    600600            end = memchr (beg, closeparen, eos - beg);
    601 #endif /* KMK - optimization */
     601#endif
    602602            if (end == 0)
    603603              /* Unterminated variable reference.  */
     
    738738      else
    739739        ++p;
    740 #ifdef KMK
     740#ifdef CONFIG_WITH_VALUE_LENGTH
    741741      p1 = memchr (p, '$', eos - p);
    742 #endif /* KMK - optimization */
     742#endif
    743743    }
    744744
     
    750750  return (variable_buffer + line_offset);
    751751}
    752 #endif /* KMK - optimization */
     752#endif /* CONFIG_WITH_VALUE_LENGTH */
    753753
    754754
     
    904904#endif
    905905
    906 #ifndef KMK
    907 # ifdef CONFIG_WITH_VALUE_LENGTH
    908   buf = variable_expand_string (buf, v->value, v->value_length);
    909 # else
     906#ifdef CONFIG_WITH_VALUE_LENGTH
     907  variable_expand_string_2 (buf, v->value, v->value_length, &buf);
     908  return buf;
     909#else
    910910  buf = variable_expand_string (buf, v->value, strlen (v->value));
    911 # endif
    912911  return (buf + strlen (buf));
    913 #else  /* KMK - optimization */
    914 # ifdef CONFIG_WITH_VALUE_LENGTH
    915   variable_expand_string_2 (buf, v->value, v->value_length, &buf);
    916 # else
    917   variable_expand_string_2 (buf, v->value, strlen (v->value), &buf);
    918 #  error "huh, this is supposed to be defined"
    919 # endif
    920   assert (*buf == '\0');
    921   return buf;
    922 #endif /* KMK - optimization */
    923 }
    924 
    925 #ifdef CONFIG_WITH_VALUE_LENGTH
    926 /* Expands the specified string, appending it to the specified variable value. */
     912#endif
     913}
     914
     915#ifdef CONFIG_WITH_VALUE_LENGTH
     916/* Expands the specified string, appending it to the specified
     917   variable value. */
    927918void
    928 append_expanded_string_to_variable (struct variable *v, const char *value, int append)
    929 {
    930 char *tmp;
    931   unsigned int value_len = strlen (value);
     919append_expanded_string_to_variable (struct variable *v, const char *value,
     920                                    unsigned int value_len, int append)
     921{
    932922  char *p = (char *) memchr (value, '$', value_len);
    933923  if (!p)
     
    955945          /* Append the assignment value. */
    956946          p = variable_buffer_output (p, value, off_dollar);
    957 # ifndef KMK
    958           p = variable_expand_string (p, value + off_dollar, value_len - off_dollar);
    959           p = strchr (p, '\0');
    960 # else
    961           tmp = variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    962           assert (*p == '\0');
    963           tmp = strchr (tmp, '\0');
    964           assert (tmp == p);
    965 # endif
     947          variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    966948        }
    967949      else
     
    969951          /* Expand the assignemnt value. */
    970952          p = variable_buffer_output (p, value, off_dollar);
    971 #ifndef KMK
    972           p = variable_expand_string (p, value + off_dollar, value_len - off_dollar);
    973           p = strchr (p, '\0');
    974 #else
    975           tmp = variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    976           assert (*p == '\0');
    977           tmp = strchr (tmp, '\0');
    978           assert (tmp == p);
    979 #endif
     953          variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    980954
    981955          /* Append a space followed by the old value. */
     
    10461020}
    10471021
    1048 #ifdef KMK /* possible optimization... */
    1049 /* The special, and most comment case, of
    1050    allocated_variable_expand_for_file. */
     1022#ifdef CONFIG_WITH_VALUE_LENGTH
     1023/* Handle the most common case in allocated_variable_expand_for_file
     1024   specially and provide some additional string lenght features. */
    10511025
    10521026char *
    1053 allocated_variable_expand_2 (const char *line, long length, unsigned int *value_len)
     1027allocated_variable_expand_2 (const char *line, unsigned int length,
     1028                             unsigned int *value_len)
    10541029{
    10551030  char *value;
     
    10591034  variable_buffer = 0;
    10601035
    1061 #if 0 /* for profiling */
    1062   if (length < 0)
    1063     length = strlen (line);
    1064 #endif
    1065 
    10661036  if (!value_len)
    1067     value = variable_expand_string (NULL, line, length);
     1037    value = variable_expand_string (NULL, line, length != ~0U ? length : -1);
    10681038  else
    10691039    {
    10701040      char *eol;
    1071       value = variable_expand_string_2 (NULL, line, length, &eol);
     1041      value = variable_expand_string_2 (NULL, line,
     1042                                        length != ~0U ? length : -1, &eol);
    10721043      *value_len = eol - value;
    10731044    }
     
    10781049  return value;
    10791050}
    1080 
    1081 #endif
     1051#endif /* CONFIG_WITH_VALUE_LENGTH */
     1052
    10821053/* Install a new variable_buffer context, returning the current one for
    10831054   safe-keeping.  */
  • trunk/src/kmk/function.c

    r1805 r1809  
    931931  char *list = expand_argument (argv[1], NULL);
    932932  const char *body = argv[2];
    933 #ifdef KMK
     933#ifdef CONFIG_WITH_VALUE_LENGTH
    934934  long body_len = strlen (body);
    935 #endif /* KMK - optimization */
     935#endif
    936936
    937937  int doneany = 0;
     
    947947  while ((p = find_next_token (&list_iterator, &len)) != 0)
    948948    {
    949 #ifndef KMK
     949#ifndef CONFIG_WITH_VALUE_LENGTH
    950950      char *result = 0;
    951 #endif /* KMK - optimization */
    952 #ifdef CONFIG_WITH_VALUE_LENGTH
     951
     952      free (var->value);
     953      var->value = savestring (p, len);
     954      result = allocated_variable_expand (body);
     955
     956      o = variable_buffer_output (o, result, strlen (result));
     957      o = variable_buffer_output (o, " ", 1);
     958      doneany = 1;
     959      free (result);
     960#else  /* CONFIG_WITH_VALUE_LENGTH */
    953961      if (len >= (unsigned int)var->value_alloc_len)
    954962        {
     
    960968      var->value[len] = '\0';
    961969      var->value_length = len;
    962 #else
    963       free (var->value);
    964       var->value = savestring (p, len);
    965 #endif
    966 
    967 #ifndef KMK
    968       result = allocated_variable_expand (body);
    969 
    970       o = variable_buffer_output (o, result, strlen (result));
    971       o = variable_buffer_output (o, " ", 1);
    972       doneany = 1;
    973       free (result);
    974 #else  /* KMK - optimization */
     970
    975971      variable_expand_string_2 (o, body, body_len, &o);
    976972      o = variable_buffer_output (o, " ", 1);
    977973      doneany = 1;
    978 #endif /* KMK - optimization */
     974#endif /* CONFIG_WITH_VALUE_LENGTH */
    979975    }
    980976
     
    43144310
    43154311      v->exp_count = EXP_COUNT_MAX;
    4316 #ifndef KMK
     4312#ifndef CONFIG_WITH_VALUE_LENGTH
    43174313      o = variable_expand_string (o, body, flen+3);
    43184314      v->exp_count = 0;
    43194315
    43204316      o += strlen (o);
    4321 #else  /* KMK - optimization */
     4317#else  /* CONFIG_WITH_VALUE_LENGTH */
    43224318      variable_expand_string_2 (o, body, flen+3, &o);
    43234319      v->exp_count = 0;
    4324 #endif /* KMK - optimization */
     4320#endif /* CONFIG_WITH_VALUE_LENGTH */
    43254321#ifdef CONFIG_WITH_EVALPLUS
    43264322    }
  • trunk/src/kmk/kbuild.c

    r1799 r1809  
    17711771    if (!s_fNoCompileCmdsDepsDefined)
    17721772    {
    1773         do_variable_definition(NILF, "_DEPFILES_INCLUDED", pDep->value, o_file, f_append, 0 /* !target_var */);
     1773        do_variable_definition_2(NILF, "_DEPFILES_INCLUDED", pDep->value, pDep->value_length,
     1774                                 pDep->flavor == f_simple, 0, o_file, f_append, 0 /* !target_var */);
    17741775        eval_include_dep(pDep->value, NILF, iVer >= 2 ? incdep_queue : incdep_read_it);
    17751776    }
     
    18011802    memcpy(pszDst, "_CMDS_", sizeof("_CMDS_"));
    18021803    pVar = kbuild_get_recursive_variable(pszSrcVar);
    1803     do_variable_definition(NILF, pszDstVar, pVar->value, o_file, f_simple, 0 /* !target_var */);
     1804    do_variable_definition_2(NILF, pszDstVar, pVar->value, pVar->value_length,
     1805                             pVar->flavor == f_simple, 0, o_file, f_simple, 0 /* !target_var */);
    18041806
    18051807    memcpy(pszSrc, "_OUTPUT", sizeof("_OUTPUT"));
    18061808    memcpy(pszDst, "_OUTPUT_", sizeof("_OUTPUT_"));
    18071809    pVar = kbuild_get_recursive_variable(pszSrcVar);
    1808     pOutput = do_variable_definition(NILF, pszDstVar, pVar->value, o_file, f_simple, 0 /* !target_var */);
     1810    pOutput = do_variable_definition_2(NILF, pszDstVar, pVar->value, pVar->value_length,
     1811                                       pVar->flavor == f_simple, 0, o_file, f_simple, 0 /* !target_var */);
    18091812
    18101813    memcpy(pszSrc, "_OUTPUT_MAYBE", sizeof("_OUTPUT_MAYBE"));
    18111814    memcpy(pszDst, "_OUTPUT_MAYBE_", sizeof("_OUTPUT_MAYBE_"));
    18121815    pVar = kbuild_query_recursive_variable(pszSrcVar);
    1813     pOutputMaybe = do_variable_definition(NILF, pszDstVar, pVar ? pVar->value : "", o_file, f_simple, 0 /* !target_var */);
     1816    if (pVar)
     1817        pOutputMaybe = do_variable_definition_2(NILF, pszDstVar, pVar->value, pVar->value_length,
     1818                                                pVar->flavor == f_simple, 0, o_file, f_simple, 0 /* !target_var */);
     1819    else
     1820        pOutputMaybe = do_variable_definition_2(NILF, pszDstVar, "", 0, 1, 0, o_file, f_simple, 0 /* !target_var */);
    18141821
    18151822    memcpy(pszSrc, "_DEPEND", sizeof("_DEPEND"));
     
    18221829    *psz++ = ' ';
    18231830    memcpy(psz, pSource->value, pSource->value_length + 1);
    1824     do_variable_definition(NILF, pszDstVar, pszVal, o_file, f_simple, 0 /* !target_var */);
    1825     free(pszVal);
     1831    do_variable_definition_2(NILF, pszDstVar, pszVal, pVar->value_length + 1 + pDeps->value_length + 1 + pSource->value_length,
     1832                             pVar->flavor == f_simple && pDeps->flavor == f_simple && pSource->flavor == f_simple,
     1833                             pszVal, o_file, f_simple, 0 /* !target_var */);
    18261834
    18271835    memcpy(pszSrc, "_DEPORD", sizeof("_DEPORD"));
     
    18341842    *psz++ = ' ';
    18351843    memcpy(psz, pOrderDeps->value, pOrderDeps->value_length + 1);
    1836     do_variable_definition(NILF, pszDstVar, pszVal, o_file, f_simple, 0 /* !target_var */);
    1837     free(pszVal);
     1844    do_variable_definition_2(NILF, pszDstVar, pszVal,
     1845                             pVar->value_length + 1 + pDirDep->value_length + 1 + pOrderDeps->value_length,
     1846                             pVar->flavor == f_simple && pDirDep->flavor == f_simple && pOrderDeps->flavor == f_simple,
     1847                             pszVal, o_file, f_simple, 0 /* !target_var */);
    18381848
    18391849    /*
    18401850    _OUT_FILES      += $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_)
    18411851    */
     1852    /** @todo use append? */
    18421853    pVar = kbuild_get_variable("_OUT_FILES");
    18431854    psz = pszVal = xmalloc(pVar->value_length + 1 + pOutput->value_length + 1 + pOutputMaybe->value_length + 1);
     
    18471858    *psz++ = ' ';
    18481859    memcpy(psz, pOutputMaybe->value, pOutputMaybe->value_length + 1);
    1849     do_variable_definition(NILF, "_OUT_FILES", pszVal, o_file, f_simple, 0 /* !target_var */);
    1850     free(pszVal);
     1860    do_variable_definition_2(NILF, "_OUT_FILES", pszVal,
     1861                             pVar->value_length + 1 + pOutput->value_length + 1 + pOutputMaybe->value_length,
     1862                             pVar->flavor == f_simple && pOutput->flavor == f_simple && pOutputMaybe->flavor == f_simple,
     1863                             pszVal, o_file, f_simple, 0 /* !target_var */);
    18511864
    18521865    /*
     
    18541867    */
    18551868    memcpy(pszDstVar + pTarget->value_length, "_OBJS_", sizeof("_OBJS_"));
    1856     do_variable_definition(NILF, pszDstVar, pObj->value, o_file, f_append, 0 /* !target_var */);
     1869    do_variable_definition_2(NILF, pszDstVar, pObj->value, pObj->value_length,
     1870                             pObj->flavor == f_simple, 0, o_file, f_append, 0 /* !target_var */);
    18571871
    18581872    /*
  • trunk/src/kmk/main.c

    r1744 r1809  
    5555#  define INCL_BASE
    5656#  include <os2.h>
    57 # endif 
     57# endif
    5858#endif /* KMK*/
    5959
     
    375375    N_("\
    376376  -j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg.\n"),
    377 #endif 
     377#endif
    378378    N_("\
    379379  -k, --keep-going            Keep going when some targets can't be made.\n"),
     
    11231123/* Determins the number of CPUs that are currently online.
    11241124   This is used to setup the default number of job slots. */
    1125 static int 
     1125static int
    11261126get_online_cpu_count(void)
    11271127{
     
    11511151    return cpus ? cpus : 1;
    11521152
    1153 # else 
     1153# else
    11541154  /* UNIX like systems, try sysconf and sysctl. */
    11551155  int cpus = -1;
     
    11571157  int mib[2];
    11581158  size_t sz;
    1159 #  endif 
     1159#  endif
    11601160
    11611161#  ifdef _SC_NPROCESSORS_ONLN
  • trunk/src/kmk/read.c

    r1807 r1809  
    418418    if (!fstat (fileno (ebuf.fp), &st))
    419419      {
    420         unsigned int stream_buf_size = 256*1024;
     420        int stream_buf_size = 256*1024;
    421421        if (st.st_size < stream_buf_size)
    422           stream_buf_size = (st.st_size + 0xfff) & ~0xfffU;
     422          stream_buf_size = (st.st_size + 0xfff) & ~0xfff;
    423423        stream_buf = xmalloc (stream_buf_size);
    424424        setvbuf (ebuf.fp, stream_buf, _IOFBF, stream_buf_size);
     
    28032803{
    28042804  char *eol;
    2805 #ifdef KMK
     2805#ifdef CONFIG_WITH_VALUE_LENGTH
    28062806  char *end;
    28072807#endif
     
    28152815
    28162816  eol = ebuf->buffer = ebuf->bufnext;
    2817 #ifdef KMK
     2817#ifdef CONFIG_WITH_VALUE_LENGTH
    28182818  end = ebuf->bufstart + ebuf->size;
    28192819#endif
     
    28262826
    28272827      /* Find the next newline.  At EOS, stop.  */
    2828 #ifndef KMK
     2828#ifndef CONFIG_WITH_VALUE_LENGTH
    28292829      eol = p = strchr (eol , '\n');
    28302830#else
  • trunk/src/kmk/variable.c

    r1808 r1809  
    467467struct variable *
    468468define_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)
    472473#else
    473474struct variable *
     
    510511        {
    511512#ifdef CONFIG_WITH_VALUE_LENGTH
    512           if (value_length == ~0U)
    513             value_length = strlen (value);
     513          if (value_len == ~0U)
     514            value_len = strlen (value);
    514515          else
    515             assert (value_length == strlen (value));
     516            assert (value_len == strlen (value));
    516517          if (!duplicate_value)
    517518            {
     
    519520                free (v->value);
    520521              v->value = (char *)value;
    521               v->value_alloc_len = value_length + 1;
     522              v->value_alloc_len = value_len + 1;
    522523            }
    523524          else
    524525            {
    525               if ((unsigned int)v->value_alloc_len <= value_length)
     526              if ((unsigned int)v->value_alloc_len <= value_len)
    526527                {
    527528                  free (v->value);
    528                   v->value_alloc_len = (value_length + 0x40) & ~0x3f;
     529                  v->value_alloc_len = (value_len + 0x40) & ~0x3f;
    529530                  v->value = xmalloc (v->value_alloc_len);
    530531                }
    531               memcpy (v->value, value, value_length + 1);
     532              memcpy (v->value, value, value_len + 1);
    532533            }
    533           v->value_length = value_length;
     534          v->value_length = value_len;
    534535#else
    535536          if (v->value != 0)
     
    558559  hash_insert_at (&set->table, v, var_slot);
    559560#ifdef CONFIG_WITH_VALUE_LENGTH
    560   if (value_length == ~0U)
    561     value_length = strlen (value);
     561  if (value_len == ~0U)
     562    value_len = strlen (value);
    562563  else
    563     assert (value_length == strlen (value));
    564   v->value_length = value_length;
     564    assert (value_len == strlen (value));
     565  v->value_length = value_len;
    565566  if (!duplicate_value)
    566567    {
    567       v->value_alloc_len = value_length + 1;
     568      v->value_alloc_len = value_len + 1;
    568569      v->value = (char *)value;
    569570    }
    570571  else
    571572    {
    572       v->value_alloc_len = (value_length + 32) & ~31;
     573      v->value_alloc_len = (value_len + 32) & ~31;
    573574      v->value = xmalloc (v->value_alloc_len);
    574       memcpy (v->value, value, value_length + 1);
     575      memcpy (v->value, value, value_len + 1);
    575576    }
    576577#else
     
    16181619    {
    16191620      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)
    16211622          v->value_alloc_len = (new_value_len + 1 + value_len + 0x7f) + ~0x7fU;
    16221623      if (append || !v->value_length)
     
    16551656
    16561657static struct variable *
    1657 do_variable_definition_append (const struct floc *flocp, struct variable *v, const char *value,
    1658                                enum variable_origin origin, int append)
     1658do_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)
    16591662{
    16601663  if (env_overrides && origin == o_env)
     
    16791682  /* The juicy bits, append the specified value to the variable
    16801683     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);
    16831688  else
    16841689    /* The previous definition of the variable was simple.
    16851690       The new value comes from the old value, which was expanded
    16861691       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);
    16881693
    16891694  /* update the variable */
     
    16971702
    16981703struct variable *
     1704#ifndef CONFIG_WITH_VALUE_LENGTH
    16991705do_variable_definition (const struct floc *flocp, const char *varname,
    17001706                        const char *value, enum variable_origin origin,
    17011707                        enum variable_flavor flavor, int target_var)
     1708#else  /* CONFIG_WITH_VALUE_LENGTH */
     1709do_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 */
    17021717{
    17031718  const char *p;
     
    17081723  const size_t varname_len = strlen (varname); /* bird */
    17091724#ifdef CONFIG_WITH_VALUE_LENGTH
    1710   unsigned int value_len = ~0U;
     1725  assert (value_len == ~0U || value_len == strlen (value));
    17111726#endif
    17121727
     
    17241739         variable buffer, and we may still need that if we're looking at a
    17251740         target-specific variable.  */
    1726 #if !defined(KMK) || !defined(CONFIG_WITH_VALUE_LENGTH)
     1741#ifndef CONFIG_WITH_VALUE_LENGTH
    17271742      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 */
    17311760      break;
    17321761    case f_conditional:
     
    17891818#ifdef CONFIG_WITH_VALUE_LENGTH
    17901819            v->append = append;
     1820            v = do_variable_definition_append (flocp, v, value, value_len,
     1821                                               simple_value, origin,
    17911822# ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
    1792             return do_variable_definition_append (flocp, v, value, origin, org_flavor == f_append);
     1823                                              org_flavor == f_append);
    17931824# else
    1794             return do_variable_definition_append (flocp, v, value, origin, 1);
     1825                                              1);
    17951826# endif
     1827            if (free_value)
     1828               free (free_value);
     1829            return v;
    17961830#else /* !CONFIG_WITH_VALUE_LENGTH */
    17971831
     
    19732007  if (alloc_value)
    19742008    free (alloc_value);
     2009#else
     2010  if (free_value)
     2011    free (free_value);
    19752012#endif
    19762013
     
    20002037  register char *end;
    20012038  enum variable_flavor flavor = f_bogus;
    2002 #ifndef KMK
     2039#ifndef CONFIG_WITH_VALUE_LENGTH
    20032040  char *name;
    2004 #endif /* KMK - optimization */
     2041#endif
    20052042
    20062043  while (1)
     
    20862123
    20872124  /* Expand the name, so "$(foo)bar = baz" works.  */
    2088 #ifndef KMK
     2125#ifndef CONFIG_WITH_VALUE_LENGTH
    20892126  name = alloca (end - beg + 1);
    20902127  memcpy (name, beg, end - beg);
    20912128  name[end - beg] = '\0';
    20922129  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 */
    21022133
    21032134  if (v->name[0] == '\0')
  • trunk/src/kmk/variable.h

    r1808 r1809  
    136136#endif
    137137char *allocated_variable_expand_for_file (const char *line, struct file *file);
    138 #ifndef KMK
     138#ifndef CONFIG_WITH_VALUE_LENGTH
    139139#define allocated_variable_expand(line) \
    140140  allocated_variable_expand_for_file (line, (struct file *) 0)
    141 #else  /* KMK */
     141#else  /* CONFIG_WITH_VALUE_LENGTH */
    142142# define allocated_variable_expand(line) \
    143143  allocated_variable_expand_2 (line, -1, NULL)
    144 char *allocated_variable_expand_2(const char *line, long length, unsigned int *value_len);
    145 #endif
     144char *allocated_variable_expand_2(const char *line, unsigned int length, unsigned int *value_len);
     145#endif /* CONFIG_WITH_VALUE_LENGTH */
    146146char *expand_argument (const char *str, const char *end);
    147147char *variable_expand_string (char *line, const char *string, long length);
    148 #ifdef KMK
     148#ifdef CONFIG_WITH_VALUE_LENGTH
    149149char *variable_expand_string_2 (char *line, const char *string, long length, char **eol);
    150150#endif
     
    152152void restore_variable_buffer (char *buf, unsigned int len);
    153153#ifdef CONFIG_WITH_VALUE_LENGTH
    154 extern void append_expanded_string_to_variable (struct variable *v, const char *value, int append);
     154void append_expanded_string_to_variable (struct variable *v, const char *value,
     155                                         unsigned int value_len, int append);
    155156#endif
    156157
     
    184185void merge_variable_set_lists (struct variable_set_list **to_list,
    185186                               struct variable_set_list *from_list);
     187#ifndef CONFIG_WITH_VALUE_LENGTH
    186188struct variable *do_variable_definition (const struct floc *flocp,
    187189                                         const char *name, const char *value,
     
    189191                                         enum variable_flavor flavor,
    190192                                         int target_var);
     193#else  /* CONFIG_WITH_VALUE_LENGTH */
     194# define do_variable_definition(flocp, varname, value, origin, flavor, target_var) \
     195    do_variable_definition_2 ((flocp), (varname), (value), ~0U, 0, NULL, \
     196                              (origin), (flavor), (target_var))
     197
     198struct variable *do_variable_definition_2 (const struct floc *flocp,
     199                                           const char *varname,
     200                                           const char *value,
     201                                           unsigned int value_len,
     202                                           int simple_value, char *free_value,
     203                                           enum variable_origin origin,
     204                                           enum variable_flavor flavor,
     205                                           int target_var);
     206#endif /* CONFIG_WITH_VALUE_LENGTH */
    191207struct variable *parse_variable_definition (struct variable *v, char *line);
    192208struct variable *try_variable_definition (const struct floc *flocp, char *line,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette