VirtualBox

Changeset 2769 in kBuild for trunk/src/kmk/expand.c


Ignore:
Timestamp:
Feb 1, 2015 12:44:30 AM (10 years ago)
Author:
bird
Message:

String expansion 'compilation' and 'execution' code is mostly done.

File:
1 edited

Legend:

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

    r2765 r2769  
    212212
    213213#ifdef CONFIG_WITH_VALUE_LENGTH
    214 /* Static worker for reference_variable() that expands the recursive
     214/* Worker for reference_variable() and kmk_exec_* that expands the recursive
    215215   variable V. The main difference between this and
    216216   recursively_expand[_for_file] is that this worker avoids the temporary
    217217   buffer and outputs directly into the current variable buffer (O).  */
    218 static char *
     218char *
    219219reference_recursive_variable (char *o, struct variable *v)
    220220{
     
    12181218}
    12191219
    1220 /* Restore a previously-saved variable_buffer setting (free the current one).
    1221  */
     1220#ifdef CONFIG_WITH_COMPILER
     1221/* Same as install_variable_buffer, except we supply a size hint.  */
     1222
     1223char *
     1224install_variable_buffer_with_hint (char **bufp, unsigned int *lenp, unsigned int size_hint)
     1225{
     1226  struct recycled_buffer *recycled;
     1227  char *buf;
     1228
     1229  *bufp = variable_buffer;
     1230  *lenp = variable_buffer_length;
     1231
     1232  recycled = recycled_head;
     1233  if (recycled)
     1234    {
     1235      recycled_head = recycled->next;
     1236      variable_buffer_length = recycled->length;
     1237      variable_buffer = buf = (char *)recycled;
     1238    }
     1239  else
     1240    {
     1241      if (size_hint < 512)
     1242        variable_buffer_length = (size_hint + 1 + 63) & ~(unsigned int)63;
     1243      else if (size_hint < 4096)
     1244        variable_buffer_length = (size_hint + 1 + 1023) & ~(unsigned int)1023;
     1245      else
     1246        variable_buffer_length = (size_hint + 1 + 4095) & ~(unsigned int)4095;
     1247      variable_buffer = buf = xmalloc (variable_buffer_length);
     1248    }
     1249  buf[0] = '\0';
     1250  return buf;
     1251}
     1252#endif /* CONFIG_WITH_COMPILER */
     1253
     1254/* Restore a previously-saved variable_buffer setting (free the
     1255   current one). */
    12221256
    12231257void
     
    12341268  variable_buffer_length = len;
    12351269}
     1270
     1271
     1272/* Used to make sure there is at least SIZE bytes of buffer space
     1273   available starting at PTR.  */
     1274char *
     1275ensure_variable_buffer_space(char *ptr, unsigned int size)
     1276{
     1277  unsigned int offset = (unsigned int)(ptr - variable_buffer);
     1278  assert(offset <= variable_buffer_length);
     1279  if (variable_buffer_length - offset < size)
     1280    {
     1281      unsigned minlen = size + offset;
     1282      variable_buffer_length *= 2;
     1283      if (variable_buffer_length < minlen + 100)
     1284        variable_buffer_length = (minlen + 100 + 63) & ~(unsigned int)63;
     1285      variable_buffer = xrealloc (variable_buffer, variable_buffer_length);
     1286      ptr = variable_buffer + offset;
     1287    }
     1288  return ptr;
     1289}
     1290
Note: See TracChangeset for help on using the changeset viewer.

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