Changeset 80425
- Timestamp:
- 07/12/11 10:21:45 (4 years ago)
- Location:
- branches/gsoc11-rev-upgrade/base/src/libmachista1.0
- Files:
-
- 2 added
- 3 edited
-
Makefile (modified) (1 diff)
-
hashmap.c (added)
-
hashmap.h (added)
-
libmachista.c (modified) (6 diffs)
-
libmachista.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/gsoc11-rev-upgrade/base/src/libmachista1.0/Makefile
r80152 r80425 1 OBJS= libmachista.o 1 OBJS= libmachista.o hashmap.o 2 2 SHLIB_NAME= libmachista${SHLIB_SUFFIX} 3 3 INSTALLDIR= ${DESTDIR}${datadir}/macports/Tcl/libmachista1.0 -
branches/gsoc11-rev-upgrade/base/src/libmachista1.0/libmachista.c
r80151 r80425 49 49 50 50 #include "libmachista.h" 51 #include "hashmap.h" 51 52 52 53 typedef struct macho_input { … … 57 58 /* This is macho_handle_t. The corresponding typedef is in the header */ 58 59 struct macho_handle { 59 /* this isn't handled as a linked list on purpose, because the mht_results are given out to the 60 * user and should not have a next pointer (as it doesn't make any sense in that context */ 61 size_t mht_result_count; 62 macho_t **mht_results; 60 HashMap *result_map; 63 61 }; 64 62 … … 399 397 400 398 /* Parse a (possible Mach-O) file. For a more detailed description, see the header */ 401 int macho_parse_file(macho_handle_t *handle, const char *filepath, macho_t **res) {399 int macho_parse_file(macho_handle_t *handle, const char *filepath, const macho_t **res) { 402 400 int fd; 403 401 struct stat st; 404 402 void *data; 405 403 macho_input_t input_file; 404 405 /* Check hashmap for precomputed results */ 406 const macho_t *cached_res = hashMapGet(handle->result_map, filepath); 407 if (cached_res != NULL) { 408 *res = cached_res; 409 return MACHO_SUCCESS; 410 } 411 406 412 407 413 /* Open input file */ … … 430 436 return MACHO_EMEM; 431 437 432 int ret = parse_macho(*res, &input_file); 438 /* The output parameter *res should be read-only for the user of the lib only, but writable for 439 * us */ 440 int ret = parse_macho((macho_t *)*res, &input_file); 433 441 if (ret == MACHO_SUCCESS) { 434 /* TODO: Insert into hashmap for caching */ 435 macho_t **handle_list = realloc(handle->mht_results, (handle->mht_result_count + 1) * sizeof(*handle->mht_results)); 436 if (handle_list == NULL) { 437 free_macho_t(*res); 442 /* Insert into hashmap for caching */ 443 if (0 == hashMapPut(handle->result_map, filepath, *res, NULL)) { 444 free_macho_t((macho_t *)*res); 438 445 *res = NULL; 439 446 ret = MACHO_EMEM; 440 } else {441 handle->mht_results = handle_list;442 handle->mht_result_count++;443 handle->mht_results[handle->mht_result_count - 1] = *res;444 447 } 445 448 } else { 446 449 /* An error occured, free mt */ 447 free_macho_t( *res);450 free_macho_t((macho_t *)*res); 448 451 *res = NULL; 449 452 } … … 461 464 if (mht == NULL) 462 465 return NULL; 463 memset(mht, 0, sizeof(mht)); 466 mht->result_map = hashMapCreate((void (*)(const void *))free_macho_t); 467 if (mht->result_map == NULL) { 468 free(mht); 469 return NULL; 470 } 464 471 return mht; 465 472 } … … 470 477 return; 471 478 472 for (size_t i = 0; i < handle->mht_result_count; ++i) 473 free_macho_t(handle->mht_results[i]); 474 free(handle->mht_results); 479 hashMapDestroy(handle->result_map); 475 480 476 481 free(handle); -
branches/gsoc11-rev-upgrade/base/src/libmachista1.0/libmachista.h
r80151 r80425 125 125 * On error, the contents of res are undefined and should not be used. The memory associated with 126 126 * the result *res will be free()'d and should thus not be used after calling macho_destroy_handle 127 * on the macho_handle_t used for the call. 127 * on the macho_handle_t used for the call. *res should also never be modified or otherwise 128 * free()'d. 128 129 */ 129 int macho_parse_file(macho_handle_t *handle, const char *filepath, macho_t **res);130 int macho_parse_file(macho_handle_t *handle, const char *filepath, const macho_t **res); 130 131 131 132 /**
Note: See TracChangeset
for help on using the changeset viewer.

