@@ -38,6 +38,61 @@ typedef struct _str_dlist {
3838 struct list_head list ;
3939} str_dlist ;
4040
41+ static inline str_list * _new_str_list (str * val , osips_malloc_t alloc_item )
42+ {
43+ str_list * new_el ;
44+ if (!alloc_item )
45+ return NULL ;
46+ new_el = alloc_item (sizeof * new_el + val -> len + 1 );
47+ if (!new_el )
48+ return NULL ;
49+ memset (new_el , 0 , sizeof * new_el );
50+ new_el -> s .s = (char * )(new_el + 1 );
51+ str_cpy (& new_el -> s , val );
52+ new_el -> s .s [new_el -> s .len ] = '\0' ;
53+ return new_el ;
54+ }
55+
56+ #define new_pkg_str_list (val ) \
57+ _new_str_list(val, osips_pkg_malloc)
58+
59+ #define new_shm_str_list (val ) \
60+ _new_str_list(val, osips_shm_malloc)
61+
62+ static inline str_list * _insert_str_list (str_list * * list , str * val , osips_malloc_t alloc_item )
63+ {
64+ str_list * new_el = _new_str_list (val , alloc_item );
65+ if (!new_el )
66+ return NULL ;
67+
68+ new_el -> next = * list ;
69+ * list = new_el ;
70+ return * list ;
71+ }
72+
73+ #define insert_pkg_str_list (list , val ) \
74+ _insert_str_list(list, val, osips_pkg_malloc)
75+
76+ #define insert_shm_str_list (list , val ) \
77+ _insert_str_list(list, val, osips_shm_malloc)
78+
79+ static inline str_list * _add_str_list (str_list * * list , str * val , osips_malloc_t alloc_item )
80+ {
81+ str_list * new_el = _new_str_list (val , alloc_item );
82+ if (!new_el )
83+ return NULL ;
84+
85+ add_last (new_el , * list );
86+ return * list ;
87+ }
88+
89+ #define add_pkg_str_list (list , val ) \
90+ _add_str_list(list, val, osips_pkg_malloc)
91+
92+ #define add_shm_str_list (list , val ) \
93+ _add_str_list(list, val, osips_shm_malloc)
94+
95+
4196static inline void _free_str_list (str_list * list ,
4297 osips_free_t free_item , osips_free_t free_str )
4398{
@@ -67,15 +122,10 @@ static inline str_list *dup_shm_str_list(const str_list *list)
67122 const str_list * it ;
68123
69124 for (it = list ; it ; it = it -> next ) {
70- item = shm_malloc ( sizeof * item + it -> s . len + 1 );
125+ item = new_shm_str_list (( str * ) & it -> s );
71126 if (!item )
72127 goto oom ;
73128
74- item -> s .s = (char * )(item + 1 );
75- str_cpy (& item -> s , & it -> s );
76- item -> s .s [item -> s .len ] = '\0' ;
77-
78- item -> next = NULL ;
79129 add_last (item , ret );
80130 }
81131
0 commit comments