174 #ifndef _ASTERISK_STRINGFIELDS_H 175 #define _ASTERISK_STRINGFIELDS_H 221 AST_VECTOR(ast_string_field_vector,
const char **);
230 struct ast_string_field_vector string_fields;
265 const char *
file,
int lineno,
const char *func);
293 const
char *file,
int lineno, const
char *func) __attribute__((format(printf, 4, 0)));
299 #define AST_STRING_FIELD(name) const ast_string_field name 307 #define AST_STRING_FIELD_EXTENDED(name) AST_STRING_FIELD(name) 337 #define AST_DECLARE_STRING_FIELDS(field_list) \ 338 struct ast_string_field_pool *__field_mgr_pool; \ 340 struct ast_string_field_mgr __field_mgr 353 #define ast_string_field_init(x, size) \ 356 if (((void *)(x)) != NULL) { \ 357 __res__ = __ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, size, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ 368 #define ast_string_field_free_memory(x) \ 371 if (((void *)(x)) != NULL) { \ 372 __res__ = __ast_string_field_free_memory(&(x)->__field_mgr, &(x)->__field_mgr_pool, \ 373 AST_STRINGFIELD_DESTROY, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ 380 const char *file,
int lineno,
const char *func);
395 #define ast_string_field_init_extended(x, field) \ 398 if (((void *)(x)) != NULL) { \ 399 ast_string_field *non_const = (ast_string_field *)&(x)->field; \ 400 *non_const = __ast_string_field_empty; \ 401 __res__ = AST_VECTOR_APPEND(&(x)->__field_mgr.string_fields, non_const); \ 411 int needed,
const char *file,
int lineno,
const char *func);
426 #define ast_calloc_with_stringfields(n, type, size) \ 427 __ast_calloc_with_stringfields(n, sizeof(type), offsetof(type, __field_mgr), \ 428 offsetof(type, __field_mgr_pool), size, __FILE__, __LINE__, __PRETTY_FUNCTION__) 435 size_t struct_size,
size_t field_mgr_offset,
size_t field_mgr_pool_offset,
size_t pool_size,
436 const char *file,
int lineno,
const char *func);
460 #define AST_STRING_FIELD_ALLOCATION(x) *((ast_string_field_allocation *) (x - __alignof__(ast_string_field_allocation))) 470 #define ast_string_field_ptr_set(x, ptr, data) \ 473 if (((void *)(x)) != NULL) { \ 474 __res__ = ast_string_field_ptr_set_by_fields((x)->__field_mgr_pool, (x)->__field_mgr, ptr, data); \ 479 #define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func) \ 482 const char *__d__ = (data); \ 483 size_t __dlen__ = (__d__) ? strlen(__d__) + 1 : 1; \ 484 ast_string_field *__p__ = (ast_string_field *) (ptr); \ 485 ast_string_field target = *__p__; \ 486 if (__dlen__ == 1) { \ 487 __ast_string_field_release_active(field_mgr_pool, *__p__); \ 488 *__p__ = __ast_string_field_empty; \ 489 } else if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) || \ 490 (!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) || \ 491 (target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__, file, lineno, func))) { \ 492 if (target != *__p__) { \ 493 __ast_string_field_release_active(field_mgr_pool, *__p__); \ 496 memcpy(* (void **) __p__, __d__, __dlen__); \ 503 #define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \ 504 __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, __FILE__, __LINE__, __PRETTY_FUNCTION__) 514 #define ast_string_field_set(x, field, data) \ 517 if (((void *)(x)) != NULL) { \ 518 __res__ = ast_string_field_ptr_set(x, &(x)->field, data); \ 531 #define ast_string_field_ptr_build(x, ptr, fmt, args...) \ 534 if (((void *)(x)) != NULL) { \ 535 __ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \ 536 &(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \ 550 #define ast_string_field_build(x, field, fmt, args...) \ 553 if (((void *)(x)) != NULL) { \ 554 __ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \ 555 &(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \ 569 #define ast_string_field_ptr_build_va(x, ptr, fmt, args) \ 572 if (((void *)(x)) != NULL) { \ 573 __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args, \ 574 __FILE__, __LINE__, __PRETTY_FUNCTION__); \ 588 #define ast_string_field_build_va(x, field, fmt, args) \ 591 if (((void *)(x)) != NULL) { \ 592 __ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args, \ 593 __FILE__, __LINE__, __PRETTY_FUNCTION__); \ 607 #define ast_string_fields_cmp(instance1, instance2) \ 610 if (((void *)(instance1)) != NULL && ((void *)(instance2)) != NULL) { \ 611 __res__ = __ast_string_fields_cmp(&(instance1)->__field_mgr.string_fields, \ 612 &(instance2)->__field_mgr.string_fields); \ 627 #define ast_string_fields_copy(copy, orig) \ 630 if (((void *)(copy)) != NULL && ((void *)(orig)) != NULL) { \ 631 __res__ = __ast_string_fields_copy(((copy)->__field_mgr_pool), \ 632 (struct ast_string_field_mgr *)&((copy)->__field_mgr), \ 633 (struct ast_string_field_mgr *)&((orig)->__field_mgr), \ 634 __FILE__, __LINE__, __PRETTY_FUNCTION__); \ 641 const char *file,
int lineno,
const char *func);
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.
uint16_t ast_string_field_allocation
AST_VECTOR(ast_string_field_vector, const char **)
struct ast_string_field_pool * embedded_pool
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)
int __ast_string_fields_cmp(struct ast_string_field_vector *left, struct ast_string_field_vector *right)
const char * __ast_string_field_empty
const char * ast_string_field
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,...)
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)
void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, const ast_string_field ptr)
Vector container support.
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)
ast_stringfield_cleanup_type
struct ast_string_field_pool * prev
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.
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)
static snd_pcm_format_t format
ast_string_field last_alloc