174#ifndef _ASTERISK_STRINGFIELDS_H
175#define _ASTERISK_STRINGFIELDS_H
269 const char *
file,
int lineno,
const char *func);
282 ast_string_field *ptr,
const char *format, ...) __attribute__((format(printf, 7, 8)));
297 const
char *
file,
int lineno, const
char *func) __attribute__((format(printf, 4, 0)));
303#define AST_STRING_FIELD(name) const ast_string_field name
311#define AST_STRING_FIELD_EXTENDED(name) AST_STRING_FIELD(name)
341#define AST_DECLARE_STRING_FIELDS(field_list) \
342 struct ast_string_field_pool *__field_mgr_pool; \
344 struct ast_string_field_mgr __field_mgr
359#define ast_string_field_init(x, size) \
362 if (((void *)(x)) != (void *)NULL) { \
363 __res__ = __ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, size, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
374#define ast_string_field_free_memory(x) \
377 if (((void *)(x)) != (void *)NULL) { \
378 __res__ = __ast_string_field_free_memory(&(x)->__field_mgr, &(x)->__field_mgr_pool, \
379 AST_STRINGFIELD_DESTROY, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
386 const char *
file,
int lineno,
const char *func);
401#define ast_string_field_init_extended(x, field) \
404 if (((void *)(x)) != (void *)NULL) { \
405 ast_string_field *non_const = (ast_string_field *)&(x)->field; \
406 *non_const = __ast_string_field_empty; \
407 __res__ = AST_VECTOR_APPEND(&(x)->__field_mgr.string_fields, non_const); \
417 int needed,
const char *
file,
int lineno,
const char *func);
432#define ast_calloc_with_stringfields(n, type, size) \
433 __ast_calloc_with_stringfields(n, sizeof(type), offsetof(type, __field_mgr), \
434 offsetof(type, __field_mgr_pool), size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
441 size_t struct_size,
size_t field_mgr_offset,
size_t field_mgr_pool_offset,
size_t pool_size,
442 const char *
file,
int lineno,
const char *func);
465#define AST_STRING_FIELD_ALLOCATION(x) *((ast_string_field_allocation *) (x - __alignof__(ast_string_field_allocation)))
475#define ast_string_field_ptr_set(x, ptr, data) \
478 if (((void *)(x)) != (void *)NULL) { \
479 __res__ = ast_string_field_ptr_set_by_fields((x)->__field_mgr_pool, (x)->__field_mgr, ptr, data); \
484#define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func) \
487 const char *__d__ = (data); \
488 ast_string_field *__p__ = (ast_string_field *) (ptr); \
489 ast_string_field target = *__p__; \
490 if (__d__ == NULL || *__d__ == '\0') { \
491 __ast_string_field_release_active(field_mgr_pool, *__p__); \
492 *__p__ = __ast_string_field_empty; \
494 size_t __dlen__ = strlen(__d__) + 1; \
495 if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) || \
496 (!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) || \
497 (target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__, file, lineno, func))) { \
498 if (target != *__p__) { \
499 __ast_string_field_release_active(field_mgr_pool, *__p__); \
502 memcpy(* (void **) __p__, __d__, __dlen__); \
510#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \
511 __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, __FILE__, __LINE__, __PRETTY_FUNCTION__)
521#define ast_string_field_set(x, field, data) \
524 if (((void *)(x)) != (void *)NULL) { \
525 __res__ = ast_string_field_ptr_set(x, &(x)->field, data); \
537#define ast_string_field_ptr_build(x, ptr, fmt, args...) \
540 if (((void *)(x)) != (void *)NULL) { \
541 __ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
542 &(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \
555#define ast_string_field_build(x, field, fmt, args...) \
558 if (((void *)(x)) != (void *)NULL) { \
559 __ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
560 &(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \
573#define ast_string_field_ptr_build_va(x, ptr, fmt, args) \
576 if (((void *)(x)) != (void *)NULL) { \
577 __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args, \
578 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
591#define ast_string_field_build_va(x, field, fmt, args) \
594 if (((void *)(x)) != (void *)NULL) { \
595 __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args, \
596 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
610#define ast_string_fields_cmp(instance1, instance2) \
613 if (((void *)(instance1)) != (void *)NULL && ((void *)(instance2)) != (void *)NULL) { \
614 __res__ = __ast_string_fields_cmp(&(instance1)->__field_mgr.string_fields, \
615 &(instance2)->__field_mgr.string_fields); \
630#define ast_string_fields_copy(copy, orig) \
633 if (((void *)(copy)) != (void *)NULL && ((void *)(orig)) != (void *)NULL) { \
634 __res__ = __ast_string_fields_copy(((copy)->__field_mgr_pool), \
635 (struct ast_string_field_mgr *)&((copy)->__field_mgr), \
636 (struct ast_string_field_mgr *)&((orig)->__field_mgr), \
637 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
644 const char *
file,
int lineno,
const char *func);
Inlinable API function macro.
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 ap, const char *file, int lineno, const char *func)
int __ast_string_fields_cmp(struct ast_string_field_vector *left, struct ast_string_field_vector *right)
void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, const ast_string_field ptr)
int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool, struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr, const char *file, int lineno, const char *func)
void __ast_string_field_ptr_build(const char *file, int lineno, const char *func, struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format,...)
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)
Internal initialization function.
uint16_t ast_string_field_allocation
ast_stringfield_cleanup_type
@ AST_STRINGFIELD_DESTROY
const char * __ast_string_field_empty
int __ast_string_field_free_memory(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, enum ast_stringfield_cleanup_type cleanup_type, const char *file, int lineno, const char *func)
Internal cleanup function.
const char * ast_string_field
void * __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, const char *file, int lineno, const char *func)
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)
struct ast_string_field_vector string_fields
struct ast_string_field_pool * embedded_pool
ast_string_field last_alloc
struct ast_string_field_pool * prev
Vector container support.
#define AST_VECTOR(name, type)
Define a vector structure.