Changeset 93ebe4e in mainline for uspace/lib/c/include/adt


Ignore:
Timestamp:
2011-03-29T19:04:41Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3317724, 99b65d2, d011038, ebebd38
Parents:
2afc54d (diff), 5fe7692 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge Petr Koupy's fix for ticket #273.

Location:
uspace/lib/c/include/adt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/adt/generic_char_map.h

    r2afc54d r93ebe4e  
    4747#define GENERIC_CHAR_MAP_MAGIC_VALUE    0x12345622
    4848
     49/** Generic destructor function pointer. */
     50#define DTOR_T(identifier) \
     51        void (*identifier)(const void *)
     52
    4953/** Character string to generic type map declaration.
    5054 *  @param[in] name     Name of the map.
     
    6468        int name##_add(name##_t *, const uint8_t *, const size_t, type *); \
    6569        int name##_count(name##_t *); \
    66         void name##_destroy(name##_t *); \
    67         void name##_exclude(name##_t *, const uint8_t *, const size_t); \
     70        void name##_destroy(name##_t *, DTOR_T()); \
     71        void name##_exclude(name##_t *, const uint8_t *, const size_t, DTOR_T()); \
    6872        type *name##_find(name##_t *, const uint8_t *, const size_t); \
    6973        int name##_initialize(name##_t *); \
     
    8488             type *value) \
    8589        { \
    86                 int rc; \
    8790                int index; \
    8891                if (!name##_is_valid(map)) \
     
    9194                if (index < 0) \
    9295                        return index; \
    93                 rc = char_map_add(&map->names, name, length, index); \
    94                 if (rc != EOK) { \
    95                         name##_items_exclude_index(&map->values, index); \
    96                         return rc; \
    97                 } \
    98                 return EOK; \
     96                return char_map_add(&map->names, name, length, index); \
    9997        } \
    10098        \
     
    105103        } \
    106104        \
    107         void name##_destroy(name##_t *map) \
     105        void name##_destroy(name##_t *map, DTOR_T(dtor)) \
    108106        { \
    109107                if (name##_is_valid(map)) { \
    110108                        char_map_destroy(&map->names); \
    111                         name##_items_destroy(&map->values); \
     109                        name##_items_destroy(&map->values, dtor); \
    112110                } \
    113111        } \
    114112        \
    115113        void name##_exclude(name##_t *map, const uint8_t *name, \
    116             const size_t length) \
     114            const size_t length, DTOR_T(dtor)) \
    117115        { \
    118116                if (name##_is_valid(map)) { \
     
    121119                        if (index != CHAR_MAP_NULL) \
    122120                                name##_items_exclude_index(&map->values, \
    123                                      index); \
     121                                     index, dtor); \
    124122                } \
    125123        } \
  • uspace/lib/c/include/adt/generic_field.h

    r2afc54d r93ebe4e  
    4646#define GENERIC_FIELD_MAGIC_VALUE               0x55667788
    4747
     48/** Generic destructor function pointer. */
     49#define DTOR_T(identifier) \
     50        void (*identifier)(const void *)
     51
    4852/** Generic type field declaration.
    4953 *
     
    6367        int name##_add(name##_t *, type *); \
    6468        int name##_count(name##_t *); \
    65         void name##_destroy(name##_t *); \
    66         void name##_exclude_index(name##_t *, int); \
     69        void name##_destroy(name##_t *, DTOR_T()); \
     70        void name##_exclude_index(name##_t *, int, DTOR_T()); \
    6771        type **name##_get_field(name##_t *); \
    6872        type *name##_get_index(name##_t *, int); \
     
    103107        } \
    104108        \
    105         void name##_destroy(name##_t *field) \
     109        void name##_destroy(name##_t *field, DTOR_T(dtor)) \
    106110        { \
    107111                if (name##_is_valid(field)) { \
    108112                        int index; \
    109113                        field->magic = 0; \
    110                         for (index = 0; index < field->next; index++) { \
    111                                 if (field->items[index]) \
    112                                         free(field->items[index]); \
     114                        if (dtor) { \
     115                                for (index = 0; index < field->next; index++) { \
     116                                        if (field->items[index]) \
     117                                                dtor(field->items[index]); \
     118                                } \
    113119                        } \
    114120                        free(field->items); \
     
    116122        } \
    117123         \
    118         void name##_exclude_index(name##_t *field, int index) \
     124        void name##_exclude_index(name##_t *field, int index, DTOR_T(dtor)) \
    119125        { \
    120126                if (name##_is_valid(field) && (index >= 0) && \
    121127                    (index < field->next) && (field->items[index])) { \
    122                         free(field->items[index]); \
     128                        if (dtor) \
     129                                dtor(field->items[index]); \
    123130                        field->items[index] = NULL; \
    124131                } \
  • uspace/lib/c/include/adt/int_map.h

    r2afc54d r93ebe4e  
    4949#define INT_MAP_ITEM_MAGIC_VALUE        0x55667788
    5050
     51/** Generic destructor function pointer. */
     52#define DTOR_T(identifier) \
     53        void (*identifier)(const void *)
     54
    5155/** Integer to generic type map declaration.
    5256 *
     
    7276        \
    7377        int name##_add(name##_t *, int, type *); \
    74         void name##_clear(name##_t *); \
     78        void name##_clear(name##_t *, DTOR_T()); \
    7579        int name##_count(name##_t *); \
    76         void name##_destroy(name##_t *); \
    77         void name##_exclude(name##_t *, int); \
    78         void name##_exclude_index(name##_t *, int); \
     80        void name##_destroy(name##_t *, DTOR_T()); \
     81        void name##_exclude(name##_t *, int, DTOR_T()); \
     82        void name##_exclude_index(name##_t *, int, DTOR_T()); \
    7983        type *name##_find(name##_t *, int); \
    8084        int name##_update(name##_t *, int, int); \
     
    8286        int name##_initialize(name##_t *); \
    8387        int name##_is_valid(name##_t *); \
    84         void name##_item_destroy(name##_item_t *); \
     88        void name##_item_destroy(name##_item_t *, DTOR_T()); \
    8589        int name##_item_is_valid(name##_item_t *);
    8690
     
    115119        } \
    116120        \
    117         void name##_clear(name##_t *map) \
     121        void name##_clear(name##_t *map, DTOR_T(dtor)) \
    118122        { \
    119123                if (name##_is_valid(map)) { \
     
    122126                                if (name##_item_is_valid(&map->items[index])) { \
    123127                                        name##_item_destroy( \
    124                                             &map->items[index]); \
     128                                            &map->items[index], dtor); \
    125129                                } \
    126130                        } \
     
    135139        } \
    136140        \
    137         void name##_destroy(name##_t *map) \
     141        void name##_destroy(name##_t *map, DTOR_T(dtor)) \
    138142        { \
    139143                if (name##_is_valid(map)) { \
     
    143147                                if (name##_item_is_valid(&map->items[index])) { \
    144148                                        name##_item_destroy( \
    145                                             &map->items[index]); \
     149                                            &map->items[index], dtor); \
    146150                                } \
    147151                        } \
     
    150154        } \
    151155        \
    152         void name##_exclude(name##_t *map, int key) \
     156        void name##_exclude(name##_t *map, int key, DTOR_T(dtor)) \
    153157        { \
    154158                if (name##_is_valid(map)) { \
     
    158162                                    (map->items[index].key == key)) { \
    159163                                        name##_item_destroy( \
    160                                             &map->items[index]); \
    161                                 } \
    162                         } \
    163                 } \
    164         } \
    165         \
    166         void name##_exclude_index(name##_t *map, int index) \
     164                                            &map->items[index], dtor); \
     165                                } \
     166                        } \
     167                } \
     168        } \
     169        \
     170        void name##_exclude_index(name##_t *map, int index, DTOR_T(dtor)) \
    167171        { \
    168172                if (name##_is_valid(map) && (index >= 0) && \
    169173                    (index < map->next) && \
    170174                    name##_item_is_valid(&map->items[index])) { \
    171                         name##_item_destroy(&map->items[index]); \
     175                        name##_item_destroy(&map->items[index], dtor); \
    172176                } \
    173177        } \
     
    236240        } \
    237241        \
    238         void name##_item_destroy(name##_item_t *item) \
     242        void name##_item_destroy(name##_item_t *item, DTOR_T(dtor)) \
    239243        { \
    240244                if (name##_item_is_valid(item)) { \
    241245                        item->magic = 0; \
    242246                        if (item->value) { \
    243                                 free(item->value); \
     247                                if (dtor) \
     248                                        dtor(item->value); \
    244249                                item->value = NULL; \
    245250                        } \
Note: See TracChangeset for help on using the changeset viewer.