Changeset a1074de
- Timestamp:
- Mar 7, 2010, 10:26:09 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- bf7aa1d
- Parents:
- 0e57335
- git-author:
- Anders Kaseorg <andersk@mit.edu> (02/27/10 22:21:53)
- git-committer:
- Anders Kaseorg <andersk@mit.edu> (03/07/10 22:26:09)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
dict.c
r0f15f12 ra1074de 71 71 } 72 72 73 void owl_dict_noop_free(void *x) { 73 void owl_dict_noop_delete(void *x) 74 { 74 75 return; 75 76 } … … 77 78 /* Returns 0 on success. Will copy the key but make 78 79 a reference to the value. Will clobber an existing 79 entry with the same key iff free_on_replace!=NULL,80 and will run free_on_replace on the old element.80 entry with the same key iff delete_on_replace!=NULL, 81 and will run delete_on_replace on the old element. 81 82 Will return -2 if replace=NULL and match was found. 82 83 */ 83 int owl_dict_insert_element(owl_dict *d, const char *k, void *v, void (*free_on_replace)(void *old)) { 84 int owl_dict_insert_element(owl_dict *d, const char *k, void *v, void (*delete_on_replace)(void *old)) 85 { 84 86 int pos, found; 85 87 char *dupk; 86 88 found = _owl_dict_find_pos(d, k, &pos); 87 if (found && free_on_replace) {88 free_on_replace(d->els[pos].v);89 if (found && delete_on_replace) { 90 delete_on_replace(d->els[pos].v); 89 91 d->els[pos].v = v; 90 92 return(0); 91 } else if (found && ! free_on_replace) {93 } else if (found && !delete_on_replace) { 92 94 return(-2); 93 95 } else { -
filterelement.c
r27f6487 ra1074de 292 292 owl_dict_create(&filters); 293 293 294 owl_dict_insert_element(&filters, f->name, &fe_visiting, owl_dict_noop_ free);294 owl_dict_insert_element(&filters, f->name, &fe_visiting, owl_dict_noop_delete); 295 295 296 296 rv = _owl_filterelement_is_toodeep(fe, &filters); … … 311 311 } else if (nval == NULL) { 312 312 f = owl_global_get_filter(&g, fe->field); 313 owl_dict_insert_element(seen, fe->field, &fe_visiting, owl_dict_noop_ free);313 owl_dict_insert_element(seen, fe->field, &fe_visiting, owl_dict_noop_delete); 314 314 if(f) rv = _owl_filterelement_is_toodeep(f->root, seen); 315 owl_dict_insert_element(seen, fe->field, &fe_visited, owl_dict_noop_ free);315 owl_dict_insert_element(seen, fe->field, &fe_visited, owl_dict_noop_delete); 316 316 } 317 317 } else { -
tester.c
r8c59178 ra1074de 113 113 printf("# BEGIN testing owl_dict\n"); 114 114 FAIL_UNLESS("create", 0==owl_dict_create(&d)); 115 FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_ free));116 FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_ free));117 FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_ free));118 FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_ free));115 FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete)); 116 FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete)); 117 FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_delete)); 118 FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_delete)); 119 119 FAIL_UNLESS("reinsert d (no replace)", -2==owl_dict_insert_element(&d, "d", dv, 0)); 120 120 FAIL_UNLESS("find a", av==owl_dict_find_element(&d, "a"));
Note: See TracChangeset
for help on using the changeset viewer.