Changes in dict.c [4c7c21f:f25df21]
Legend:
- Unmodified
- Added
- Removed
-
dict.c
r4c7c21f rf25df21 15 15 #define GROWBY 3 / 2 16 16 17 voidowl_dict_create(owl_dict *d) {17 int owl_dict_create(owl_dict *d) { 18 18 d->size=0; 19 19 d->els=g_new(owl_dict_el, INITSIZE); 20 20 d->avail=INITSIZE; 21 if (d->els==NULL) return(-1); 22 return(0); 21 23 } 22 24 … … 58 60 /* Appends dictionary keys to a list. Duplicates the keys, 59 61 * so they will need to be freed by the caller. */ 60 voidowl_dict_get_keys(const owl_dict *d, owl_list *l) {62 int owl_dict_get_keys(const owl_dict *d, owl_list *l) { 61 63 int i; 64 char *dupk; 62 65 for (i=0; i<d->size; i++) { 63 owl_list_append_element(l, g_strdup(d->els[i].k)); 66 if ((dupk = g_strdup(d->els[i].k)) == NULL) return(-1); 67 owl_list_append_element(l, dupk); 64 68 } 69 return(0); 65 70 } 66 71 … … 79 84 { 80 85 int pos, found; 86 char *dupk; 81 87 found = _owl_dict_find_pos(d, k, &pos); 82 88 if (found && delete_on_replace) { … … 93 99 if (d->els==NULL) return(-1); 94 100 } 101 if ((dupk = g_strdup(k)) == NULL) return(-1); 95 102 if (pos!=d->size) { 96 103 /* shift forward to leave us a slot */ … … 99 106 } 100 107 d->size++; 101 d->els[pos].k = g_strdup(k);108 d->els[pos].k = dupk; 102 109 d->els[pos].v = v; 103 110 return(0);
Note: See TracChangeset
for help on using the changeset viewer.