Sun Oct 16 2011 08:43:09

Asterisk developer's documentation


stringfields.h File Reference

String fields in structures. More...

Include dependency graph for stringfields.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_string_field_mgr
struct  ast_string_field_pool

Defines

#define ast_calloc_with_stringfields(n, type, size)
 Allocate a structure with embedded stringfields in a single allocation.
#define AST_DECLARE_STRING_FIELDS(field_list)
 Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)   const ast_string_field name
 Declare a string field.
#define AST_STRING_FIELD_ALLOCATION(x)   *((ast_string_field_allocation *) (x - sizeof(ast_string_field_allocation)))
 Macro to provide access to the allocation field that lives immediately in front of a string field.
#define ast_string_field_build(x, field, fmt, args...)   __ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args)
 Set a field to a complex (built) value.
#define ast_string_field_build_va(x, field, fmt, args1, args2)   __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args1, args2)
 Set a field to a complex (built) value.
#define ast_string_field_free_memory(x)   __ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, -1, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 free all memory - to be called before destroying the object
#define ast_string_field_init(x, size)   __ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Initialize a field pool and fields.
#define ast_string_field_ptr_build(x, ptr, fmt, args...)   __ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args)
 Set a field to a complex (built) value.
#define ast_string_field_ptr_build_va(x, ptr, fmt, args1, args2)   __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args1, args2)
 Set a field to a complex (built) value with prebuilt va_lists.
#define ast_string_field_ptr_set(x, ptr, data)
 Set a field to a simple string value.
#define ast_string_field_set(x, field, data)
 Set a field to a simple string value.

Typedefs

typedef const char * ast_string_field
typedef uint16_t ast_string_field_allocation

Functions

void *attribute_malloc __ast_calloc_with_stringfields (unsigned int num_structs, size_t struct_size, size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size, const char *file, int lineno, const char *func)
ast_string_field __ast_string_field_alloc_space (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed)
int __ast_string_field_init (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, int needed, const char *file, int lineno, const char *func)
void __ast_string_field_ptr_build (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format,...)
void __ast_string_field_ptr_build_va (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, va_list a1, va_list a2)
int __ast_string_field_ptr_grow (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed, const ast_string_field *ptr)
void __ast_string_field_release_active (struct ast_string_field_pool *pool_head, const ast_string_field ptr)

Variables

const char * __ast_string_field_empty

Detailed Description

String fields in structures.

This file contains objects and macros used to manage string fields in structures without requiring them to be allocated as fixed-size buffers or requiring individual allocations for for each field.

Using this functionality is quite simple. An example structure with three fields is defined like this:

  struct sample_fields {
     int x1;
     AST_DECLARE_STRING_FIELDS(
        AST_STRING_FIELD(foo);
        AST_STRING_FIELD(bar);
        AST_STRING_FIELD(blah);
     );
     long x2;
  };

When an instance of this structure is allocated (either statically or dynamically), the fields and the pool of storage for them must be initialized:

  struct sample_fields *x;
  
  x = ast_calloc(1, sizeof(*x));
  if (x == NULL || ast_string_field_init(x, 252)) {
   if (x)
      ast_free(x);
   x = NULL;
   ... handle error
  }

Fields will default to pointing to an empty string, and will revert to that when ast_string_field_set() is called with a NULL argument. A string field will never contain NULL.

ast_string_field_init(x, 0) will reset fields to the initial value while keeping the pool allocated.

Reading the fields is much like using 'const char * const' fields in the structure: you cannot write to the field or to the memory it points to.

Writing to the fields must be done using the wrapper macros listed below; and assignments are always by value (i.e. strings are copied): ast_string_field_set() stores a simple value; ast_string_field_build() builds the string using a printf-style format; ast_string_field_build_va() is the varargs version of the above (for portability reasons it uses two vararg arguments); variants of these function allow passing a pointer to the field as an argument.

  ast_string_field_set(x, foo, "infinite loop");
  ast_string_field_set(x, foo, NULL); // set to an empty string
  ast_string_field_ptr_set(x, &x->bar, "right way");

  ast_string_field_build(x, blah, "%d %s", zipcode, city);
  ast_string_field_ptr_build(x, &x->blah, "%d %s", zipcode, city);

  ast_string_field_build_va(x, bar, fmt, args1, args2)
  ast_string_field_ptr_build_va(x, &x->bar, fmt, args1, args2)

When the structure instance is no longer needed, the fields and their storage pool must be freed:

This completes the API description.

Definition in file stringfields.h.


Define Documentation

#define ast_calloc_with_stringfields (   n,
  type,
  size 
)
Value:
__ast_calloc_with_stringfields(n, sizeof(type), offsetof(type, __field_mgr), offsetof(type, __field_mgr_pool), \
                   size, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Allocate a structure with embedded stringfields in a single allocation.

Parameters:
nNumber of structures to allocate (see ast_calloc)
typeThe type of structure to allocate
sizeThe number of bytes of space (minimum) to allocate for stringfields to use

This function will allocate memory for one or more structures that use stringfields, and also allocate space for the stringfields and initialize the stringfield management structure embedded in the outer structure.

Since:
1.8

Definition at line 269 of file stringfields.h.

Referenced by jack_data_alloc(), sla_build_trunk(), sla_build_station(), load_config(), load_module(), sip_register(), sip_subscribe_mwi(), register_group(), register_group_feature(), ast_log(), ast_manager_register2(), raise_exception(), build_profile(), build_extension(), and append_mailbox_mapping().

#define AST_DECLARE_STRING_FIELDS (   field_list)
Value:
struct ast_string_field_pool *__field_mgr_pool; \
   field_list              \
   struct ast_string_field_mgr __field_mgr

Declare the fields needed in a structure.

Parameters:
field_listThe list of fields to declare, using AST_STRING_FIELD() for each one. Internally, string fields are stored as a pointer to the head of the pool, followed by individual string fields, and then a struct ast_string_field_mgr which describes the space allocated. We split the two variables so they can be used as markers around the field_list, and this allows us to determine how many entries are in the field, and play with them. In particular, for writing to the fields, we rely on __field_mgr_pool to be a non-const pointer, so we know it has the same size as ast_string_field, and we can use it to locate the fields.

Definition at line 229 of file stringfields.h.

#define AST_STRING_FIELD (   name)    const ast_string_field name

Declare a string field.

Parameters:
nameThe field name

Definition at line 214 of file stringfields.h.

#define AST_STRING_FIELD_ALLOCATION (   x)    *((ast_string_field_allocation *) (x - sizeof(ast_string_field_allocation)))

Macro to provide access to the allocation field that lives immediately in front of a string field.

Parameters:
xPointer to the string field

Definition at line 304 of file stringfields.h.

Referenced by __ast_string_field_alloc_space(), __ast_string_field_ptr_grow(), __ast_string_field_release_active(), and __ast_string_field_ptr_build_va().

#define ast_string_field_build (   x,
  field,
  fmt,
  args... 
)    __ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args)

Set a field to a complex (built) value.

Parameters:
xPointer to a structure containing fields
fieldName of the field to set
fmtprintf-style format string
argsArguments for format string
Returns:
nothing

Definition at line 360 of file stringfields.h.

Referenced by load_config(), build_user(), sip_sendhtml(), create_addr_from_peer(), build_callid_pvt(), build_callid_registry(), build_contact(), parse_register_contact(), set_nonce_randdata(), parse_moved_contact(), handle_request_subscribe(), sip_sipredirect(), __ast_channel_alloc_ap(), init_acf_query(), caldav_write_event(), parse_cdata(), t30_phase_e_handler(), and build_profile().

#define ast_string_field_build_va (   x,
  field,
  fmt,
  args1,
  args2 
)    __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args1, args2)

Set a field to a complex (built) value.

Parameters:
xPointer to a structure containing fields
fieldName of the field to set
fmtprintf-style format string
args1argument one
args2argument two
Returns:
nothing

Definition at line 384 of file stringfields.h.

Referenced by __ast_channel_alloc_ap().

#define ast_string_field_init (   x,
  size 
)    __ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Initialize a field pool and fields.

Parameters:
xPointer to a structure containing fields
sizeAmount of storage to allocate. Use 0 to reset fields to the default value, and release all but the most recent pool. size<0 (used internally) means free all pools.
Returns:
0 on success, non-zero on failure

Definition at line 243 of file stringfields.h.

Referenced by alloc_queue(), tds_load_module(), init_pvt(), new_iax(), build_peer(), build_user(), sip_monitor_instance_init(), sip_alloc(), temp_pvt_init(), transmit_response_using_temp(), temp_peer(), __ast_channel_alloc_ap(), ast_dummy_channel_alloc(), init_acf_query(), auth_http_callback(), acf_retrieve_docs(), ast_register_application2(), init_outgoing(), build_calendar(), ast_calendar_event_alloc(), caldav_load_calendar(), ewscal_load_calendar(), exchangecal_load_calendar(), ical_load_calendar(), realtime_odbc(), realtime_multi_odbc(), update_odbc(), session_details_new(), build_route(), and build_profile().

#define ast_string_field_ptr_build (   x,
  ptr,
  fmt,
  args... 
)    __ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args)

Set a field to a complex (built) value.

Parameters:
xPointer to a structure containing fields
ptrPointer to a field within the structure
fmtprintf-style format string
argsArguments for format string
Returns:
nothing

Definition at line 349 of file stringfields.h.

#define ast_string_field_ptr_build_va (   x,
  ptr,
  fmt,
  args1,
  args2 
)    __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args1, args2)

Set a field to a complex (built) value with prebuilt va_lists.

Parameters:
xPointer to a structure containing fields
ptrPointer to a field within the structure
fmtprintf-style format string
args1Arguments for format string in va_list format
args2a second copy of the va_list for the sake of bsd, with no va_list copy operation
Returns:
nothing

Definition at line 372 of file stringfields.h.

#define ast_string_field_ptr_set (   x,
  ptr,
  data 
)

Set a field to a simple string value.

Parameters:
xPointer to a structure containing fields
ptrPointer to a field within the structure
dataString value to be copied into the field
Returns:
nothing

Definition at line 313 of file stringfields.h.

Referenced by reply_digest().

#define ast_string_field_set (   x,
  field,
  data 
)
Value:
do {     \
   ast_string_field_ptr_set(x, &(x)->field, data);    \
   } while (0)

Set a field to a simple string value.

Parameters:
xPointer to a structure containing fields
fieldName of the field to set
dataString value to be copied into the field
Returns:
nothing

Definition at line 337 of file stringfields.h.

Referenced by do_forward(), wait_for_answer(), dial_exec_full(), disa_exec(), findmeexec(), handle_options(), conf_start_moh(), sla_build_trunk(), sla_build_station(), init_queue(), queue_set_param(), alloc_queue(), ring_entry(), vm_execmain(), ast_cdr_setaccount(), ast_cdr_setpeeraccount(), load_config(), tds_load_module(), ast_cel_fabricate_channel_from_event(), agent_new(), alsa_new(), console_new(), set_pvt_defaults(), store_callerid(), init_pvt(), dahdi_new(), gtalk_new(), __oh323_new(), new_iax(), __find_callno(), iax2_call(), ast_iax2_new(), check_access(), authenticate_request(), authenticate_verify(), register_verify(), authenticate_reply(), registry_authrequest(), save_osptoken(), socket_process(), iax2_request(), build_peer(), build_user(), cache_get_callno_locked(), jingle_new(), local_call(), mgcp_new(), read_config(), misdn_facility_ie_handler(), nbs_new(), oss_new(), phone_new(), sip_monitor_instance_init(), create_addr_from_peer(), create_addr(), sip_call(), sip_new(), sip_alloc(), sip_subscribe_mwi(), respprep(), reqprep(), transmit_response_using_temp(), get_realm(), extract_uri(), initreqprep(), __sip_subscribe_mwi_do(), transmit_register(), transmit_refer(), reg_source_db(), parse_ok_contact(), parse_register_contact(), sip_set_redirstr(), get_pai(), get_rpid(), get_destination(), get_also_info(), check_peer_ok(), check_user_full(), reply_digest(), parse_moved_contact(), handle_response_publish(), handle_response_invite(), handle_response_notify(), handle_response_subscribe(), handle_response(), sip_park(), handle_cc_notify(), handle_request_options(), handle_request_invite(), handle_request_refer(), handle_request_bye(), handle_request_publish(), handle_incoming(), sip_send_mwi_to_peer(), sip_poke_peer(), sip_request_call(), set_peer_defaults(), skinny_new(), unistim_new(), usbradio_new(), __ast_channel_alloc_ap(), ast_set_hangupsource(), ast_call_forward(), __ast_change_name_nolink(), ast_channel_change_linkedid(), ast_set_owners_and_peers(), ast_do_masquerade(), begin_dial_channel(), monitor_dial(), register_group(), register_group_feature(), feature_request_and_dial(), init_acf_query(), logger_print_normal(), ast_log(), ast_manager_register2(), raise_exception(), acf_retrieve_docs(), ast_register_application2(), apply_outgoing(), build_calendar(), copy_event_data(), calendar_write_exec(), caldav_add_event(), caldav_load_calendar(), startelm(), endelm(), ewscal_load_calendar(), exchangecal_load_calendar(), icalendar_add_event(), ical_load_calendar(), custom_prepare(), generic_fax_exec(), receivefax_exec(), sendfax_exec(), acf_faxopt_write(), t30_phase_e_handler(), moh_handle_digit(), set_moh_exec(), build_route(), build_profile(), build_extension(), append_mailbox_mapping(), analog_new_ast_channel(), sig_pri_handle_subcmds(), and ast_parse_digest().


Typedef Documentation

typedef const char* ast_string_field

Definition at line 115 of file stringfields.h.

typedef uint16_t ast_string_field_allocation

Definition at line 298 of file stringfields.h.


Function Documentation

void* attribute_malloc __ast_calloc_with_stringfields ( unsigned int  num_structs,
size_t  struct_size,
size_t  field_mgr_offset,
size_t  field_mgr_pool_offset,
size_t  pool_size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1808 of file utils.c.

References optimal_alloc_size(), allocation, __ast_calloc(), ast_calloc, ast_string_field_pool::base, __ast_string_field_empty, ast_string_field_mgr::embedded_pool, and ast_string_field_pool::size.

{
   struct ast_string_field_mgr *mgr;
   struct ast_string_field_pool *pool;
   struct ast_string_field_pool **pool_head;
   size_t pool_size_needed = sizeof(*pool) + pool_size;
   size_t size_to_alloc = optimal_alloc_size(struct_size + pool_size_needed);
   void *allocation;
   unsigned int x;

#if defined(__AST_DEBUG_MALLOC)  
   if (!(allocation = __ast_calloc(num_structs, size_to_alloc, file, lineno, func))) {
      return NULL;
   }
#else
   if (!(allocation = ast_calloc(num_structs, size_to_alloc))) {
      return NULL;
   }
#endif

   for (x = 0; x < num_structs; x++) {
      void *base = allocation + (size_to_alloc * x);
      const char **p;

      mgr = base + field_mgr_offset;
      pool_head = base + field_mgr_pool_offset;
      pool = base + struct_size;

      p = (const char **) pool_head + 1;
      while ((struct ast_string_field_mgr *) p != mgr) {
         *p++ = __ast_string_field_empty;
      }

      mgr->embedded_pool = pool;
      *pool_head = pool;
      pool->size = size_to_alloc - struct_size - sizeof(*pool);
#if defined(__AST_DEBUG_MALLOC)
      mgr->owner_file = file;
      mgr->owner_func = func;
      mgr->owner_line = lineno;
#endif
   }

   return allocation;
}
ast_string_field __ast_string_field_alloc_space ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
size_t  needed 
)

Definition at line 1644 of file utils.c.

References add_string_pool(), AST_STRING_FIELD_ALLOCATION, and ast_string_field_mgr::last_alloc.

Referenced by __ast_string_field_ptr_build_va().

{
   char *result = NULL;
   size_t space = (*pool_head)->size - (*pool_head)->used;
   size_t to_alloc = needed + sizeof(ast_string_field_allocation);

   /* This +1 accounts for alignment on SPARC */
   if (__builtin_expect(to_alloc + 1 > space, 0)) {
      size_t new_size = (*pool_head)->size;

      while (new_size < to_alloc) {
         new_size *= 2;
      }

#if defined(__AST_DEBUG_MALLOC)
      if (add_string_pool(mgr, pool_head, new_size, mgr->owner_file, mgr->owner_line, mgr->owner_func))
         return NULL;
#else
      if (add_string_pool(mgr, pool_head, new_size, __FILE__, __LINE__, __FUNCTION__))
         return NULL;
#endif
   }

   result = (*pool_head)->base + (*pool_head)->used;
#ifdef __sparc__
   /* SPARC requires that the allocation field be aligned. */
   if ((long) result % sizeof(ast_string_field_allocation)) {
      result++;
      (*pool_head)->used++;
   }
#endif
   (*pool_head)->used += to_alloc;
   (*pool_head)->active += needed;
   result += sizeof(ast_string_field_allocation);
   AST_STRING_FIELD_ALLOCATION(result) = needed;
   mgr->last_alloc = result;

   return result;
}
int __ast_string_field_init ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
int  needed,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1577 of file utils.c.

References __ast_string_field_empty, ast_string_field_mgr::last_alloc, ast_string_field_mgr::embedded_pool, add_string_pool(), ast_log(), LOG_WARNING, ast_string_field_pool::prev, ast_string_field_pool::used, ast_string_field_pool::active, and ast_free.

{
   const char **p = (const char **) pool_head + 1;
   struct ast_string_field_pool *cur = NULL;
   struct ast_string_field_pool *preserve = NULL;

   /* clear fields - this is always necessary */
   while ((struct ast_string_field_mgr *) p != mgr) {
      *p++ = __ast_string_field_empty;
   }

   mgr->last_alloc = NULL;
#if defined(__AST_DEBUG_MALLOC)
   mgr->owner_file = file;
   mgr->owner_func = func;
   mgr->owner_line = lineno;
#endif
   if (needed > 0) {    /* allocate the initial pool */
      *pool_head = NULL;
      mgr->embedded_pool = NULL;
      return add_string_pool(mgr, pool_head, needed, file, lineno, func);
   }

   /* if there is an embedded pool, we can't actually release *all*
    * pools, we must keep the embedded one. if the caller is about
    * to free the structure that contains the stringfield manager
    * and embedded pool anyway, it will be freed as part of that
    * operation.
    */
   if ((needed < 0) && mgr->embedded_pool) {
      needed = 0;
   }

   if (needed < 0) {    /* reset all pools */
      cur = *pool_head;
   } else if (mgr->embedded_pool) { /* preserve the embedded pool */
      preserve = mgr->embedded_pool;
      cur = *pool_head;
   } else {       /* preserve the last pool */
      if (*pool_head == NULL) {
         ast_log(LOG_WARNING, "trying to reset empty pool\n");
         return -1;
      }
      preserve = *pool_head;
      cur = preserve->prev;
   }

   if (preserve) {
      preserve->prev = NULL;
      preserve->used = preserve->active = 0;
   }

   while (cur) {
      struct ast_string_field_pool *prev = cur->prev;

      if (cur != preserve) {
         ast_free(cur);
      }
      cur = prev;
   }

   *pool_head = preserve;

   return 0;
}
void __ast_string_field_ptr_build ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
ast_string_field ptr,
const char *  format,
  ... 
)

Definition at line 1793 of file utils.c.

References __ast_string_field_ptr_build_va().

{
   va_list ap1, ap2;

   va_start(ap1, format);
   va_start(ap2, format);     /* va_copy does not exist on FreeBSD */

   __ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap1, ap2);

   va_end(ap1);
   va_end(ap2);
}
void __ast_string_field_ptr_build_va ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
ast_string_field ptr,
const char *  format,
va_list  a1,
va_list  a2 
)

Definition at line 1728 of file utils.c.

References available(), AST_STRING_FIELD_ALLOCATION, ast_string_field_mgr::last_alloc, __ast_string_field_alloc_space(), and __ast_string_field_release_active().

Referenced by __ast_string_field_ptr_build().

{
   size_t needed;
   size_t available;
   size_t space = (*pool_head)->size - (*pool_head)->used;
   ssize_t grow;
   char *target;

   /* if the field already has space allocated, try to reuse it;
      otherwise, try to use the empty space at the end of the current
      pool
   */
   if (*ptr != __ast_string_field_empty) {
      target = (char *) *ptr;
      available = AST_STRING_FIELD_ALLOCATION(*ptr);
      if (*ptr == mgr->last_alloc) {
         available += space;
      }
   } else {
      target = (*pool_head)->base + (*pool_head)->used + sizeof(ast_string_field_allocation);
#ifdef __sparc__
      if ((long) target % sizeof(ast_string_field_allocation)) {
         target++;
         space--;
      }
#endif
      available = space - sizeof(ast_string_field_allocation);
   }

   needed = vsnprintf(target, available, format, ap1) + 1;

   va_end(ap1);

   if (needed > available) {
      /* the allocation could not be satisfied using the field's current allocation
         (if it has one), or the space available in the pool (if it does not). allocate
         space for it, adding a new string pool if necessary.
      */
      if (!(target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed))) {
         return;
      }
      vsprintf(target, format, ap2);
      __ast_string_field_release_active(*pool_head, *ptr);
      *ptr = target;
   } else if (*ptr != target) {
      /* the allocation was satisfied using available space in the pool, but not
         using the space already allocated to the field
      */
      __ast_string_field_release_active(*pool_head, *ptr);
      mgr->last_alloc = *ptr = target;
      AST_STRING_FIELD_ALLOCATION(target) = needed;
      (*pool_head)->used += needed + sizeof(ast_string_field_allocation);
      (*pool_head)->active += needed;
   } else if ((grow = (needed - AST_STRING_FIELD_ALLOCATION(*ptr))) > 0) {
      /* the allocation was satisfied by using available space in the pool *and*
         the field was the last allocated field from the pool, so it grew
      */
      (*pool_head)->used += grow;
      (*pool_head)->active += grow;
      AST_STRING_FIELD_ALLOCATION(*ptr) += grow;
   }
}
int __ast_string_field_ptr_grow ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
size_t  needed,
const ast_string_field ptr 
)

Definition at line 1685 of file utils.c.

References AST_STRING_FIELD_ALLOCATION, and ast_string_field_mgr::last_alloc.

{
   ssize_t grow = needed - AST_STRING_FIELD_ALLOCATION(*ptr);
   size_t space = (*pool_head)->size - (*pool_head)->used;

   if (*ptr != mgr->last_alloc) {
      return 1;
   }

   if (space < grow) {
      return 1;
   }

   (*pool_head)->used += grow;
   (*pool_head)->active += grow;
   AST_STRING_FIELD_ALLOCATION(*ptr) += grow;

   return 0;
}
void __ast_string_field_release_active ( struct ast_string_field_pool pool_head,
const ast_string_field  ptr 
)

Definition at line 1707 of file utils.c.

References ast_string_field_pool::prev, ast_string_field_pool::active, AST_STRING_FIELD_ALLOCATION, and ast_free.

Referenced by __ast_string_field_ptr_build_va().

{
   struct ast_string_field_pool *pool, *prev;

   if (ptr == __ast_string_field_empty) {
      return;
   }

   for (pool = pool_head, prev = NULL; pool; prev = pool, pool = pool->prev) {
      if ((ptr >= pool->base) && (ptr <= (pool->base + pool->size))) {
         pool->active -= AST_STRING_FIELD_ALLOCATION(ptr);
         if ((pool->active == 0) && prev) {
            prev->prev = pool->prev;
            ast_free(pool);
         }
         break;
      }
   }
}

Variable Documentation

Definition at line 1522 of file utils.c.

Referenced by __ast_string_field_init(), and __ast_calloc_with_stringfields().