From: Marion Guthmuller Date: Mon, 5 Dec 2011 10:16:17 +0000 (+0100) Subject: Merge branch 'master' into MC_LTL X-Git-Tag: exp_20120216~133^2~21 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4a18fb7c6c81b1f58a9f8111fcf0ade106c4746b?hp=1f834c56a869248347fa4dd12a41ded689989935 Merge branch 'master' into MC_LTL --- diff --git a/ChangeLog b/ChangeLog index 226f5c1efe..63e07eda6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,9 @@ SimGrid (3.7) NOT RELEASED; urgency=low XBT: * Mallocators: allow value NULL for the reset function. + * Dicts: new function xbt_dict_new_homogeneous(void(*)(void*)) to + create homogeneous dictionaries, where all the elements share the + same free function. -- $date Da SimGrid team diff --git a/examples/gras/all2all/all2all.c b/examples/gras/all2all/all2all.c index db1504b568..8e3b0f434d 100644 --- a/examples/gras/all2all/all2all.c +++ b/examples/gras/all2all/all2all.c @@ -82,7 +82,7 @@ int sender(int argc, char *argv[]) xbt_peer_t h; /* iterator */ int connected = 0; - gras_socket_t peer = NULL; /* socket to node */ + volatile gras_socket_t peer = NULL; /* socket to node */ /* xbt_dynar for peers */ diff --git a/examples/gras/properties/properties.c b/examples/gras/properties/properties.c index b0ae355e49..99214987f2 100644 --- a/examples/gras/properties/properties.c +++ b/examples/gras/properties/properties.c @@ -43,8 +43,7 @@ int alice(int argc, char *argv[]) XBT_INFO("== Trying to modify a process property"); value = gras_process_property_value("new prop"); xbt_assert(!value, "Property 'new prop' exists before I add it!"); - xbt_dict_set(process_props, "new prop", xbt_strdup("new value"), - xbt_free_f); + xbt_dict_set(process_props, "new prop", xbt_strdup("new value"), NULL); /* Test if we have changed the value */ value = gras_process_property_value("new prop"); @@ -78,7 +77,7 @@ int bob(int argc, char *argv[]) XBT_INFO ("== Set a host property that alice will try to retrieve in SG (from bob->hello)"); - xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), xbt_free_f); + xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), NULL); XBT_INFO("== Dump all the properties of host1 again to check the addition"); xbt_dict_foreach(host_props, cursor, key, data) diff --git a/examples/gras/replay/replay.c b/examples/gras/replay/replay.c index 3b19f419cc..fb1babee26 100644 --- a/examples/gras/replay/replay.c +++ b/examples/gras/replay/replay.c @@ -56,7 +56,7 @@ int master(int argc, char *argv[]) xbt_workload_elm_t cmd; xbt_dict_cursor_t dict_cursor; - xbt_dict_t pals_int = xbt_dict_new(); + xbt_dict_t pals_int = xbt_dict_new_homogeneous(NULL); xbt_dynar_foreach(cmds, cursor, cmd) { int *p = xbt_dict_get_or_null(pals_int, cmd->who); if (!p) { @@ -88,7 +88,7 @@ int master(int argc, char *argv[]) xbt_dict_free(&pals_int); /* Check who came */ - xbt_dict_t pals = xbt_dict_new(); + xbt_dict_t pals = xbt_dict_new_homogeneous(NULL); gras_socket_t pal; xbt_dynar_foreach(peers, cursor, peer) { //XBT_INFO("%s is here",peer->name); @@ -199,7 +199,7 @@ int worker(int argc, char *argv[]) int connected = 0; gras_cb_register("commands", worker_commands_cb); - globals->peers = xbt_dict_new(); + globals->peers = xbt_dict_new_homogeneous(NULL); if (gras_if_RL()) XBT_INFO("Sensor %s starting. Connecting to master on %s", diff --git a/examples/msg/masterslave/CMakeLists.txt b/examples/msg/masterslave/CMakeLists.txt index dc90fe30c9..b6b352f84d 100644 --- a/examples/msg/masterslave/CMakeLists.txt +++ b/examples/msg/masterslave/CMakeLists.txt @@ -9,6 +9,7 @@ add_executable(masterslave_bypass "masterslave_bypass.c") add_executable(masterslave_console "masterslave_console.c") add_executable(masterslave_cluster "masterslave_cluster.c") add_executable(masterslave_kill "masterslave_kill.c") +add_executable(masterslave_arg "masterslave_arg.c") ### Add definitions for compile if(WIN32) @@ -18,6 +19,7 @@ target_link_libraries(masterslave_mailbox simgrid ) target_link_libraries(masterslave_bypass simgrid ) target_link_libraries(masterslave_console simgrid ) target_link_libraries(masterslave_kill simgrid ) +target_link_libraries(masterslave_arg simgrid ) else(WIN32) target_link_libraries(masterslave_forwarder simgrid m ) target_link_libraries(masterslave_failure simgrid m ) @@ -25,5 +27,6 @@ target_link_libraries(masterslave_mailbox simgrid m ) target_link_libraries(masterslave_bypass simgrid m ) target_link_libraries(masterslave_console simgrid m ) target_link_libraries(masterslave_kill simgrid m ) +target_link_libraries(masterslave_arg simgrid m ) endif(WIN32) target_link_libraries(masterslave_cluster simgrid) \ No newline at end of file diff --git a/examples/msg/masterslave/masterslave_arg.c b/examples/msg/masterslave/masterslave_arg.c new file mode 100644 index 0000000000..1fc804fe71 --- /dev/null +++ b/examples/msg/masterslave/masterslave_arg.c @@ -0,0 +1,146 @@ +/* Copyright (c) 2010. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ + +/* Create a log channel to have nice outputs. */ +#include "xbt/log.h" +#include "xbt/asserts.h" +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); + +int master(int argc, char *argv[]); +int slave(int argc, char *argv[]); + +#define task_comp_size 50000000 +#define task_comm_size 1000000 + +long number_of_jobs; +long number_of_slaves; + +static long my_random(long n) +{ + return n * (rand() / ((double)RAND_MAX + 1)); +} + +/** Emitter function */ +int master(int argc, char *argv[]) +{ + int i; + + for (i = 1; i <= number_of_jobs; i++) { + char mailbox[256]; + char sprintf_buffer[256]; + m_task_t task = NULL; + + sprintf(mailbox, "slave-%ld", i % number_of_slaves); + sprintf(sprintf_buffer, "Task_%d", i); + task = + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); + XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, + number_of_jobs, mailbox); + + MSG_task_send(task, mailbox); + } + + XBT_DEBUG + ("All tasks have been dispatched. Let's tell everybody the computation is over."); + for (i = 0; i < number_of_slaves; i++) { + char mailbox[80]; + + sprintf(mailbox, "slave-%ld", i % number_of_slaves); + m_task_t finalize = MSG_task_create("finalize", 0, 0, 0); + MSG_task_send(finalize, mailbox); + } + + XBT_DEBUG("Goodbye now!"); + return 0; +} /* end_of_master */ + +/** Receiver function */ +int slave(int argc, char *argv[]) +{ + m_task_t task = NULL; + _XBT_GNUC_UNUSED int res; + + XBT_DEBUG("mailbox: %s",MSG_process_get_name(MSG_process_self())); + while (1) { + res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self())); + xbt_assert(res == MSG_OK, "MSG_task_get failed"); + + XBT_DEBUG("Received \"%s\"", MSG_task_get_name(task)); + if (!strcmp(MSG_task_get_name(task), "finalize")) { + MSG_task_destroy(task); + break; + } + XBT_DEBUG("Processing \"%s\"", MSG_task_get_name(task)); + MSG_task_execute(task); + XBT_DEBUG("\"%s\" done", MSG_task_get_name(task)); + MSG_task_destroy(task); + task = NULL; + } + XBT_DEBUG("I'm done. See you!"); + return 0; +} /* end_of_slave */ /* end_of_test_all */ + +/** Main function */ +int main(int argc, char *argv[]) +{ + MSG_error_t res = MSG_OK; + long i; + + MSG_global_init(&argc, argv); + if (argc < 4) { + printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]); + printf("example: %s msg_platform.xml 10 5\n", argv[0]); + exit(1); + } + + MSG_set_channel_number(0); + MSG_function_register("master", master); + MSG_function_register("slave", slave); + + MSG_create_environment(argv[1]); + + number_of_jobs = atol(argv[2]); + number_of_slaves = atol(argv[3]); + long number_max = MSG_get_host_number(); + XBT_INFO("Got %ld slaves, %ld tasks to process, and %d hosts", number_of_slaves, number_of_jobs,MSG_get_host_number()); + + m_host_t *host_table = MSG_get_host_table(); + + MSG_process_create( "master", + master, + NULL, + host_table[my_random(number_max)] + ); + + for(i = 0 ; i + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/cloud.xml b/examples/platforms/cloud.xml new file mode 100644 index 0000000000..662de61d6b --- /dev/null +++ b/examples/platforms/cloud.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/platforms/data_center.xml b/examples/platforms/data_center.xml new file mode 100644 index 0000000000..9ebf896527 --- /dev/null +++ b/examples/platforms/data_center.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/simdag/properties/sd_prop.c b/examples/simdag/properties/sd_prop.c index a23a66f2b9..3aa9f41ef5 100644 --- a/examples/simdag/properties/sd_prop.c +++ b/examples/simdag/properties/sd_prop.c @@ -54,7 +54,7 @@ int main(int argc, char **argv) /* Trying to set a new property */ - xbt_dict_set(props, "NewProp", strdup("newValue"), free); + xbt_dict_set(props, "NewProp", strdup("newValue"), NULL); /* Print the properties of the workstation 1 */ xbt_dict_foreach(props, cursor, key, data) { @@ -88,7 +88,7 @@ int main(int argc, char **argv) XBT_INFO("\tProperty: %s is undefined", exist); else { XBT_INFO("\tProperty: %s old value: %s", exist, value); - xbt_dict_set(props, exist, strdup("250"), free); + xbt_dict_set(props, exist, strdup("250"), NULL); } /* Test if we have changed the value */ diff --git a/include/simgrid_config.h.in b/include/simgrid_config.h.in index 4c1feb7d61..0581c3e32f 100644 --- a/include/simgrid_config.h.in +++ b/include/simgrid_config.h.in @@ -1,5 +1,3 @@ -/* $Id$ */ - /* simgrid_config.h - Results of the configure made visible to user code */ /* Copyright (c) 2009, 2010, 2011. Da SimGrid team. All rights reserved. */ @@ -20,9 +18,9 @@ SG_BEGIN_DECL() #define MAKE_SIMGRID_VERSION(major, minor, patch) \ (100UL * (100UL * (major) + (minor)) + (patch)) -#cmakedefine SIMGRID_VERSION_MAJOR @SIMGRID_VERSION_MAJOR@ -#cmakedefine SIMGRID_VERSION_MINOR @SIMGRID_VERSION_MINOR@ -#cmakedefine SIMGRID_VERSION_PATCH @SIMGRID_VERSION_PATCH@ +#define SIMGRID_VERSION_MAJOR @SIMGRID_VERSION_MAJOR@ +#define SIMGRID_VERSION_MINOR @SIMGRID_VERSION_MINOR@ +#define SIMGRID_VERSION_PATCH @SIMGRID_VERSION_PATCH@ #define SIMGRID_VERSION MAKE_SIMGRID_VERSION(SIMGRID_VERSION_MAJOR, \ SIMGRID_VERSION_MINOR, \ diff --git a/include/xbt/dict.h b/include/xbt/dict.h index cb5cde6ef4..5c6f6df546 100644 --- a/include/xbt/dict.h +++ b/include/xbt/dict.h @@ -1,6 +1,6 @@ /* xbt/dict.h -- api to a generic dictionary */ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2004-2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -45,6 +45,7 @@ SG_BEGIN_DECL() /** \brief Dictionary data type (opaque structure) */ typedef struct s_xbt_dict *xbt_dict_t; XBT_PUBLIC(xbt_dict_t) xbt_dict_new(void); +XBT_PUBLIC(xbt_dict_t) xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn); XBT_PUBLIC(void) xbt_dict_free(xbt_dict_t * dict); XBT_PUBLIC(unsigned int) xbt_dict_size(xbt_dict_t dict); diff --git a/include/xbt/graphxml_parse.h b/include/xbt/graphxml_parse.h index ab0b5ee80f..8b39e7b1b5 100644 --- a/include/xbt/graphxml_parse.h +++ b/include/xbt/graphxml_parse.h @@ -1,5 +1,3 @@ -/* $Id $ */ - /* Copyright (c) 2006, 2007, 2009, 2010. The SimGrid Team. * All rights reserved. */ diff --git a/include/xbt/hash.h b/include/xbt/hash.h index b4bd66dccd..6cbc514598 100644 --- a/include/xbt/hash.h +++ b/include/xbt/hash.h @@ -1,5 +1,3 @@ -/* $Id: str.h,v 1.5 2007/05/02 10:08:55 mquinson Exp $ */ - /* hash.h - Various hashing functions. */ /* Copyright (c) 2008, 2009, 2010. The SimGrid Team. diff --git a/include/xbt/strbuff.h b/include/xbt/strbuff.h index eb1f59f29f..d3f9636909 100644 --- a/include/xbt/strbuff.h +++ b/include/xbt/strbuff.h @@ -1,5 +1,3 @@ -/* $Id: buff.h 3483 2007-05-07 11:18:56Z mquinson $ */ - /* strbuff -- string buffers */ /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. diff --git a/src/amok/PeerManagement/peermanagement.c b/src/amok/PeerManagement/peermanagement.c index a842c92423..1f02fe01bc 100644 --- a/src/amok/PeerManagement/peermanagement.c +++ b/src/amok/PeerManagement/peermanagement.c @@ -261,7 +261,7 @@ static void _amok_pm_join(void *p) mod->groups = NULL; mod->done = 0; - mod->groups = xbt_dict_new(); + mod->groups = xbt_dict_new_homogeneous(NULL); /* callbacks */ gras_cb_register("amok_pm_kill", &amok_pm_cb_kill); diff --git a/src/bindings/lua/lua_console.c b/src/bindings/lua/lua_console.c index 82b7f6bc28..50f48e4eaa 100644 --- a/src/bindings/lua/lua_console.c +++ b/src/bindings/lua/lua_console.c @@ -363,7 +363,7 @@ int console_host_set_property(lua_State *L) { return -1; } xbt_dict_t props = MSG_host_get_properties(host); - xbt_dict_set(props,prop_id,xbt_strdup(prop_value),free); + xbt_dict_set(props,prop_id,xbt_strdup(prop_value),NULL); return 0; } diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index e3ae3be63c..e3dddcc9e5 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -880,9 +880,9 @@ static int gras_add_process_function(lua_State * L) if (xbt_dict_is_empty(machine_set) || xbt_dict_is_empty(process_function_set) || xbt_dynar_is_empty(process_list)) { - process_function_set = xbt_dict_new(); + process_function_set = xbt_dict_new_homogeneous(NULL); process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free); - machine_set = xbt_dict_new(); + machine_set = xbt_dict_new_homogeneous(NULL); } xbt_dict_set(machine_set, process_host, NULL, NULL); diff --git a/src/context_sysv_config.h.in b/src/context_sysv_config.h.in index f144e94d12..3217ead2df 100644 --- a/src/context_sysv_config.h.in +++ b/src/context_sysv_config.h.in @@ -1,5 +1,3 @@ -/* $Id$ */ - /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ diff --git a/src/gras/DataDesc/cbps.c b/src/gras/DataDesc/cbps.c index bb96f6df60..cfb2b2a536 100644 --- a/src/gras/DataDesc/cbps.c +++ b/src/gras/DataDesc/cbps.c @@ -32,7 +32,7 @@ gras_cbps_t gras_cbps_new(void) res = xbt_new(s_gras_cbps_t, 1); res->lints = xbt_dynar_new(sizeof(int), NULL); - res->space = xbt_dict_new(); + res->space = xbt_dict_new_homogeneous(NULL); /* no leak, the content is freed manually on block_end */ res->frames = xbt_dynar_new(sizeof(xbt_dynar_t), NULL); res->globals = xbt_dynar_new(sizeof(char *), NULL); diff --git a/src/gras/DataDesc/datadesc.c b/src/gras/DataDesc/datadesc.c index dcccee2b10..220607fae1 100644 --- a/src/gras/DataDesc/datadesc.c +++ b/src/gras/DataDesc/datadesc.c @@ -158,7 +158,7 @@ void gras_datadesc_init(void) ddt = gras_datadesc_ref("xbt_peer_t", ddt); /* Dict containing the constant value (for the parsing macro) */ - gras_dd_constants = xbt_dict_new(); + gras_dd_constants = xbt_dict_new_homogeneous(xbt_free_f); } diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index e00f6a93f1..91da76f88c 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -98,7 +98,7 @@ static XBT_INLINE void gras_dd_alloc_ref(xbt_dict_t refs, long int size, char ** *(void **) r_ref); if (detect_cycle) - xbt_dict_set_ext(refs, (const char *) r_ref, r_len, ptr, xbt_free_f); + xbt_dict_set_ext(refs, (const char *) r_ref, r_len, ptr, NULL); } } @@ -395,7 +395,7 @@ int gras_datadesc_memcpy(gras_datadesc_type_t type, void *src, void *dst) dst); if (!state) { state = gras_cbps_new(); - refs = xbt_dict_new(); + refs = xbt_dict_new_homogeneous(xbt_free_f); } TRY { @@ -638,7 +638,7 @@ void gras_datadesc_send(gras_socket_t sock, if (!state) { state = gras_cbps_new(); - refs = xbt_dict_new(); + refs = xbt_dict_new_homogeneous(NULL); } TRY { @@ -976,7 +976,7 @@ gras_datadesc_recv(gras_socket_t sock, if (!state) { state = gras_cbps_new(); - refs = xbt_dict_new(); + refs = xbt_dict_new_homogeneous(xbt_free_f); } xbt_assert(type, "called with NULL type descriptor"); diff --git a/src/gras/DataDesc/ddt_parse.c b/src/gras/DataDesc/ddt_parse.c index ab540b9ec1..77f5d661c5 100644 --- a/src/gras/DataDesc/ddt_parse.c +++ b/src/gras/DataDesc/ddt_parse.c @@ -811,5 +811,5 @@ void gras_datadesc_set_const(const char *name, int value) int *stored = xbt_new(int, 1); *stored = value; - xbt_dict_set(gras_dd_constants, name, stored, xbt_free_f); + xbt_dict_set(gras_dd_constants, name, stored, NULL); } diff --git a/src/gras/Transport/transport.c b/src/gras/Transport/transport.c index 8aabcc482c..b090bfdec4 100644 --- a/src/gras/Transport/transport.c +++ b/src/gras/Transport/transport.c @@ -52,14 +52,14 @@ static void gras_trp_plugin_new(const char *name, gras_trp_setup_t setup) } if (plug) - xbt_dict_set(_gras_trp_plugins, name, plug, gras_trp_plugin_free); + xbt_dict_set(_gras_trp_plugins, name, plug, NULL); } void gras_trp_init(void) { if (!_gras_trp_started) { /* make room for all plugins */ - _gras_trp_plugins = xbt_dict_new(); + _gras_trp_plugins = xbt_dict_new_homogeneous(gras_trp_plugin_free); #ifdef HAVE_WINSOCK2_H /* initialize the windows mechanism */ diff --git a/src/gras/Virtu/rl_process.c b/src/gras/Virtu/rl_process.c index f120573df9..cc364ceced 100644 --- a/src/gras/Virtu/rl_process.c +++ b/src/gras/Virtu/rl_process.c @@ -39,8 +39,8 @@ void gras_process_init() gras_procdata_init(); /* initialize the host & process properties */ - _host_properties = xbt_dict_new(); - _process_properties = xbt_dict_new(); + _host_properties = xbt_dict_new_homogeneous(xbt_free_f); + _process_properties = xbt_dict_new_homogeneous(xbt_free_f); env_iter = environ; while (*env_iter) { char *equal, *buf = xbt_strdup(*env_iter); @@ -52,8 +52,7 @@ void gras_process_init() continue; } *equal = '\0'; - xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1), - xbt_free_f); + xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1), NULL); free(buf); env_iter++; } diff --git a/src/gras/Virtu/sg_emul.c b/src/gras/Virtu/sg_emul.c index 7892f4ce33..7d55dee696 100644 --- a/src/gras/Virtu/sg_emul.c +++ b/src/gras/Virtu/sg_emul.c @@ -41,7 +41,7 @@ static unsigned int locbufsize; void gras_emul_init(void) { if (!benchmark_set) { - benchmark_set = xbt_dict_new(); + benchmark_set = xbt_dict_new_homogeneous(xbt_free_f); timer = xbt_os_timer_new(); } } @@ -61,7 +61,7 @@ static void store_in_dict(xbt_dict_t dict, const char *key, double value) ir = xbt_dict_get_or_null(dict, key); if (!ir) { ir = xbt_new0(double, 1); - xbt_dict_set(dict, key, ir, xbt_free_f); + xbt_dict_set(dict, key, ir, NULL); } *ir = value; } diff --git a/src/include/mc/datatypes.h b/src/include/mc/datatypes.h index d9b8c01d6b..073cbd5d7d 100644 --- a/src/include/mc/datatypes.h +++ b/src/include/mc/datatypes.h @@ -1,5 +1,3 @@ -/* $Id: datatypes.h 5497 2008-05-26 12:19:15Z cristianrosa $ */ - /* Copyright (c) 2008 Martin Quinson, Cristian Rosa. All rights reserved. */ diff --git a/src/include/mc/mc.h b/src/include/mc/mc.h index ce4697626f..41f4425967 100644 --- a/src/include/mc/mc.h +++ b/src/include/mc/mc.h @@ -1,5 +1,3 @@ -/* $Id: simix.h 5497 2008-05-26 12:19:15Z cristianrosa $ */ - /* Copyright (c) 2008 Martin Quinson, Cristian Rosa. All rights reserved. */ diff --git a/src/instr/instr_config.c b/src/instr/instr_config.c index 7c38522121..3103180bb8 100644 --- a/src/instr/instr_config.c +++ b/src/instr/instr_config.c @@ -81,7 +81,7 @@ int TRACE_start() XBT_DEBUG ("Tracing is on"); /* other trace initialization */ - created_categories = xbt_dict_new(); + created_categories = xbt_dict_new_homogeneous(xbt_free); TRACE_surf_alloc(); TRACE_smpi_alloc(); return 0; diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index 7a27800d57..df21be5b9a 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -38,7 +38,7 @@ void TRACE_category_with_color (const char *category, const char *color) //check if category is already created char *created = xbt_dict_get_or_null(created_categories, category); if (created) return; - xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free); + xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL); //define final_color char final_color[INSTR_DEFAULT_STR_SIZE]; diff --git a/src/instr/instr_paje.c b/src/instr/instr_paje.c index 3c1591c188..b523297717 100644 --- a/src/instr/instr_paje.c +++ b/src/instr/instr_paje.c @@ -18,9 +18,9 @@ xbt_dict_t trivaEdgeTypes = NULL; /* all host types defined */ void instr_paje_init (container_t root) { - allContainers = xbt_dict_new (); - trivaNodeTypes = xbt_dict_new (); - trivaEdgeTypes = xbt_dict_new (); + allContainers = xbt_dict_new_homogeneous(NULL); + trivaNodeTypes = xbt_dict_new_homogeneous(xbt_free); + trivaEdgeTypes = xbt_dict_new_homogeneous(xbt_free); rootContainer = root; } @@ -70,8 +70,8 @@ static type_t newType (const char *typename, const char *key, const char *color, ret->name = xbt_strdup (typename); ret->father = father; ret->kind = kind; - ret->children = xbt_dict_new (); - ret->values = xbt_dict_new (); + ret->children = xbt_dict_new_homogeneous(NULL); + ret->values = xbt_dict_new_homogeneous(NULL); ret->color = xbt_strdup (color); char str_id[INSTR_DEFAULT_STR_SIZE]; @@ -215,7 +215,7 @@ container_t newContainer (const char *name, e_container_types kind, container_t default: xbt_die ("Congratulations, you have found a bug on newContainer function of instr_routing.c"); break; } } - new->children = xbt_dict_new(); + new->children = xbt_dict_new_homogeneous(NULL); if (new->father){ xbt_dict_set(new->father->children, new->name, new, NULL); new_pajeCreateContainer (new); @@ -226,7 +226,7 @@ container_t newContainer (const char *name, e_container_types kind, container_t xbt_dict_set (allContainers, new->name, new, NULL); //register NODE types for triva configuration - xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), xbt_free); + xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), NULL); } return new; } diff --git a/src/instr/instr_resource_utilization.c b/src/instr/instr_resource_utilization.c index ba5c51b503..4c4b2e3b69 100644 --- a/src/instr/instr_resource_utilization.c +++ b/src/instr/instr_resource_utilization.c @@ -26,8 +26,7 @@ static void __TRACE_surf_check_variable_set_to_zero(double now, container_t container = getContainerByName (resource); type_t type = getVariableType (variable, NULL, container->type); new_pajeSetVariable (now, container, type, 0); - xbt_dict_set(platform_variables, resource, array, - xbt_dynar_free_voidp); + xbt_dict_set(platform_variables, resource, array, NULL); } else { xbt_dynar_t array = xbt_dict_get(platform_variables, resource); unsigned int i; @@ -153,7 +152,7 @@ void TRACE_surf_host_set_utilization(const char *resource, void TRACE_surf_resource_utilization_alloc() { - platform_variables = xbt_dict_new(); + platform_variables = xbt_dict_new_homogeneous(xbt_dynar_free_voidp); } void TRACE_surf_resource_utilization_release() diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index 784bf3dd13..2a1dc65ffc 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -63,8 +63,8 @@ static void linkContainers (container_t father, container_t src, container_t dst if (xbt_dict_get_or_null (filter, aux2)) return; //ok, not found, register it - xbt_dict_set (filter, aux1, xbt_strdup ("1"), xbt_free); - xbt_dict_set (filter, aux2, xbt_strdup ("1"), xbt_free); + xbt_dict_set (filter, aux1, xbt_strdup ("1"), NULL); + xbt_dict_set (filter, aux2, xbt_strdup ("1"), NULL); } //declare type @@ -73,7 +73,7 @@ static void linkContainers (container_t father, container_t src, container_t dst type_t link_type = getLinkType (link_typename, father->type, src->type, dst->type); //register EDGE types for triva configuration - xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), xbt_free); + xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), NULL); //create the link static long long counter = 0; @@ -285,7 +285,7 @@ static void instr_routing_parse_end_platform () { xbt_dynar_free(¤tContainer); currentContainer = NULL; - xbt_dict_t filter = xbt_dict_new (); + xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free); recursiveGraphExtraction (global_routing->root, getRootContainer(), filter); xbt_dict_free(&filter); platform_created = 1; @@ -468,8 +468,8 @@ static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xb xbt_graph_t instr_routing_platform_graph (void) { xbt_graph_t ret = xbt_graph_new_graph (0, NULL); - xbt_dict_t nodes = xbt_dict_new (); - xbt_dict_t edges = xbt_dict_new (); + xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL); + xbt_dict_t edges = xbt_dict_new_homogeneous(NULL); recursiveXBTGraphExtraction (ret, nodes, edges, global_routing->root, getRootContainer()); return ret; } diff --git a/src/instr/instr_smpi.c b/src/instr/instr_smpi.c index 8cddd98a46..d4fab07c5b 100644 --- a/src/instr/instr_smpi.c +++ b/src/instr/instr_smpi.c @@ -82,7 +82,7 @@ static char *TRACE_smpi_put_key(int src, int dst, char *key, int n) xbt_dynar_t d = xbt_dict_get_or_null(keys, aux); if (d == NULL) { d = xbt_dynar_new(sizeof(char *), &xbt_free_ref); - xbt_dict_set(keys, aux, d, xbt_free); + xbt_dict_set(keys, aux, d, NULL); } //generate the key static unsigned long long counter = 0; @@ -123,7 +123,7 @@ void TRACE_internal_smpi_set_category (const char *category) if (xbt_dict_get_or_null (process_category, processid)) xbt_dict_remove (process_category, processid); if (category != NULL) - xbt_dict_set (process_category, processid, xbt_strdup(category), xbt_free); + xbt_dict_set (process_category, processid, xbt_strdup(category), NULL); } const char *TRACE_internal_smpi_get_category (void) @@ -137,8 +137,8 @@ const char *TRACE_internal_smpi_get_category (void) void TRACE_smpi_alloc() { - keys = xbt_dict_new(); - process_category = xbt_dict_new(); + keys = xbt_dict_new_homogeneous(xbt_free); + process_category = xbt_dict_new_homogeneous(xbt_free); } void TRACE_smpi_start(void) diff --git a/src/instr/jedule/jedule_events.c b/src/instr/jedule/jedule_events.c index bab0e0c7c6..8d235a0209 100644 --- a/src/instr/jedule/jedule_events.c +++ b/src/instr/jedule/jedule_events.c @@ -63,7 +63,7 @@ void create_jed_event(jed_event_t *event, char *name, double start_time, (*event)->resource_subsets = xbt_dynar_new(sizeof(jed_res_subset_t), NULL); (*event)->characteristics_list = xbt_dynar_new(sizeof(char*), NULL); - (*event)->info_hash = xbt_dict_new(); + (*event)->info_hash = xbt_dict_new_homogeneous(NULL); } diff --git a/src/instr/jedule/jedule_platform.c b/src/instr/jedule/jedule_platform.c index d6b488bb97..54fdb74257 100644 --- a/src/instr/jedule/jedule_platform.c +++ b/src/instr/jedule/jedule_platform.c @@ -91,7 +91,7 @@ void jed_simgrid_add_resources(jed_simgrid_container_t parent, parent->is_lowest = 1; xbt_dynar_free(&parent->container_children); parent->container_children = NULL; - parent->name2id = xbt_dict_new(); + parent->name2id = xbt_dict_new_homogeneous(xbt_free); parent->last_id = 0; parent->resource_list = xbt_dynar_new(sizeof(char *), NULL); @@ -100,7 +100,7 @@ void jed_simgrid_add_resources(jed_simgrid_container_t parent, xbt_dynar_foreach(host_names, iter, host_name) { buf = bprintf("%d", parent->last_id); (parent->last_id)++; - xbt_dict_set(parent->name2id, host_name, buf, xbt_free); + xbt_dict_set(parent->name2id, host_name, buf, NULL); xbt_dict_set(host2_simgrid_parent_container, host_name, parent, NULL); xbt_dynar_push(parent->resource_list, &host_name); } @@ -204,7 +204,7 @@ void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list, unsigned int iter; xbt_dict_t parent2hostgroup; // group hosts by parent - parent2hostgroup = xbt_dict_new(); + parent2hostgroup = xbt_dict_new_homogeneous(NULL); xbt_assert( host_names != NULL ); @@ -262,9 +262,9 @@ void jedule_add_meta_info(jedule_t jedule, char *key, char *value) { void jed_create_jedule(jedule_t *jedule) { *jedule = (jedule_t)calloc(1,sizeof(s_jedule_t)); - host2_simgrid_parent_container = xbt_dict_new(); - container_name2container = xbt_dict_new(); - (*jedule)->jedule_meta_info = xbt_dict_new(); + host2_simgrid_parent_container = xbt_dict_new_homogeneous(NULL); + container_name2container = xbt_dict_new_homogeneous(NULL); + (*jedule)->jedule_meta_info = xbt_dict_new_homogeneous(NULL); } void jed_free_jedule(jedule_t jedule) { diff --git a/src/mc/private.h b/src/mc/private.h index 3960433e22..fbab06e45d 100644 --- a/src/mc/private.h +++ b/src/mc/private.h @@ -1,5 +1,3 @@ -/* $Id: private.h 5497 2008-05-26 12:19:15Z cristianrosa $ */ - /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo. All rights reserved. */ diff --git a/src/msg/msg_actions.c b/src/msg/msg_actions.c index 580915586c..ea4bdba612 100644 --- a/src/msg/msg_actions.c +++ b/src/msg/msg_actions.c @@ -84,8 +84,8 @@ static int MSG_action_runner(int argc, char *argv[]) void _MSG_action_init() { - action_funs = xbt_dict_new(); - action_queues = xbt_dict_new(); + action_funs = xbt_dict_new_homogeneous(NULL); + action_queues = xbt_dict_new_homogeneous(NULL); MSG_function_register_default(MSG_action_runner); } @@ -190,7 +190,7 @@ MSG_error_t MSG_action_trace_run(char *path) if (path) fclose(action_fp); xbt_dict_free(&action_queues); - action_queues = xbt_dict_new(); + action_queues = xbt_dict_new_homogeneous(NULL); return res; } diff --git a/src/simdag/sd_daxloader.c b/src/simdag/sd_daxloader.c index a47704d031..684f656f0c 100644 --- a/src/simdag/sd_daxloader.c +++ b/src/simdag/sd_daxloader.c @@ -286,8 +286,8 @@ xbt_dynar_t SD_daxload(const char *filename) dax_lineno = 1; result = xbt_dynar_new(sizeof(SD_task_t), dax_task_free); - files = xbt_dict_new(); - jobs = xbt_dict_new(); + files = xbt_dict_new_homogeneous(&dax_task_free); + jobs = xbt_dict_new_homogeneous(NULL); root_task = SD_task_create_comp_seq("root", NULL, 0); /* by design the root task is always SCHEDULABLE */ __SD_task_set_state(root_task, SD_SCHEDULABLE); @@ -430,7 +430,7 @@ void STag_dax__uses(void) file = xbt_dict_get_or_null(files, A_dax__uses_file); if (file == NULL) { file = SD_task_create_comm_e2e(A_dax__uses_file, NULL, size); - xbt_dict_set(files, A_dax__uses_file, file, &dax_task_free); + xbt_dict_set(files, A_dax__uses_file, file, NULL); } else { if (SD_task_get_amount(file) != size) { XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f", diff --git a/src/simdag/sd_dotloader.c b/src/simdag/sd_dotloader.c index 006a682cac..8ee8eacf87 100644 --- a/src/simdag/sd_dotloader.c +++ b/src/simdag/sd_dotloader.c @@ -159,9 +159,9 @@ xbt_dynar_t SD_dotload_generic(const char * filename) dag_dot = agread(in_file, NIL(Agdisc_t *)); result = xbt_dynar_new(sizeof(SD_task_t), dot_task_free); - files = xbt_dict_new(); - jobs = xbt_dict_new(); - computers = xbt_dict_new(); + files = xbt_dict_new_homogeneous(&dot_task_free); + jobs = xbt_dict_new_homogeneous(NULL); + computers = xbt_dict_new_homogeneous(NULL); root_task = SD_task_create_comp_seq("root", NULL, 0); /* by design the root task is always SCHEDULABLE */ __SD_task_set_state(root_task, SD_SCHEDULABLE); @@ -368,7 +368,7 @@ void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge) #ifdef HAVE_TRACING TRACE_sd_dotloader (file, agget (edge, (char*)"category")); #endif - xbt_dict_set(files, name, file, &dot_task_free); + xbt_dict_set(files, name, file, NULL); } else { if (SD_task_get_amount(file) != size) { XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f", @@ -406,7 +406,7 @@ void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge) #ifdef HAVE_TRACING TRACE_sd_dotloader (file, agget (edge, (char*)"category")); #endif - xbt_dict_set(files, name, file, &dot_task_free); + xbt_dict_set(files, name, file, NULL); } else { if (SD_task_get_amount(file) != size) { XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f", diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 45733ca37d..c575ee45ab 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -86,7 +86,7 @@ void SIMIX_global_init(int *argc, char **argv) xbt_swag_new(xbt_swag_offset(proc, destroy_hookup)); simix_global->maestro_process = NULL; - simix_global->registered_functions = xbt_dict_new(); + simix_global->registered_functions = xbt_dict_new_homogeneous(NULL); simix_global->create_process_function = SIMIX_process_create; simix_global->kill_process_function = SIMIX_process_kill; diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 451ddcc5b3..db4429b655 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -84,14 +84,14 @@ void SIMIX_host_destroy(void *h) */ xbt_dict_t SIMIX_host_get_dict(void) { - xbt_dict_t host_dict = xbt_dict_new(); + xbt_dict_t host_dict = xbt_dict_new_homogeneous(NULL); xbt_lib_cursor_t cursor = NULL; char *name = NULL; void **host = NULL; xbt_lib_foreach(host_lib, cursor, name, host){ if(host[SIMIX_HOST_LEVEL]) - xbt_dict_set(host_dict,name,host[SIMIX_HOST_LEVEL],NULL); + xbt_dict_set(host_dict,name,host[SIMIX_HOST_LEVEL], NULL); } return host_dict; } diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index d4290260d6..9f9885701b 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -26,7 +26,7 @@ static void SIMIX_rdv_free(void *data); void SIMIX_network_init(void) { - rdv_points = xbt_dict_new(); + rdv_points = xbt_dict_new_homogeneous(SIMIX_rdv_free); } void SIMIX_network_exit(void) @@ -49,7 +49,7 @@ smx_rdv_t SIMIX_rdv_create(const char *name) rdv->comm_fifo = xbt_fifo_new(); if (rdv->name) - xbt_dict_set(rdv_points, rdv->name, rdv, SIMIX_rdv_free); + xbt_dict_set(rdv_points, rdv->name, rdv, NULL); } return rdv; } @@ -554,7 +554,7 @@ XBT_INLINE void SIMIX_comm_start(smx_action_t action) */ void SIMIX_comm_finish(smx_action_t action) { - unsigned int destroy_count = 0; + volatile unsigned int destroy_count = 0; smx_req_t req; while ((req = xbt_fifo_shift(action->request_list))) { diff --git a/src/smpi/smpi_bench.c b/src/smpi/smpi_bench.c index 80c1896159..9998aff42c 100644 --- a/src/smpi/smpi_bench.c +++ b/src/smpi/smpi_bench.c @@ -111,7 +111,7 @@ int smpi_sample_1(int global, const char *file, int line, int iters, double thre smpi_bench_end(); /* Take time from previous MPI call into account */ if (!samples) { - samples = xbt_dict_new(); + samples = xbt_dict_new_homogeneous(free); } data = xbt_dict_get_or_null(samples, loc); if (!data) { @@ -122,7 +122,7 @@ int smpi_sample_1(int global, const char *file, int line, int iters, double thre data->iters = iters; data->threshold = threshold; data->started = 0; - xbt_dict_set(samples, loc, data, &free); + xbt_dict_set(samples, loc, data, NULL); return 0; } free(loc); @@ -190,13 +190,13 @@ void *smpi_shared_malloc(size_t size, const char *file, int line) shared_data_t *data; if (!allocs) { - allocs = xbt_dict_new(); + allocs = xbt_dict_new_homogeneous(free); } data = xbt_dict_get_or_null(allocs, loc); if (!data) { data = (shared_data_t *) xbt_malloc0(sizeof(int) + size); data->count = 1; - xbt_dict_set(allocs, loc, data, &free); + xbt_dict_set(allocs, loc, data, NULL); } else { data->count++; } @@ -230,7 +230,7 @@ int smpi_shared_known_call(const char* func, const char* input) { int known; if(!calls) { - calls = xbt_dict_new(); + calls = xbt_dict_new_homogeneous(NULL); } TRY { xbt_dict_get(calls, loc); /* Succeed or throw */ @@ -253,7 +253,7 @@ void* smpi_shared_get_call(const char* func, const char* input) { void* data; if(!calls) { - calls = xbt_dict_new(); + calls = xbt_dict_new_homogeneous(NULL); } data = xbt_dict_get(calls, loc); free(loc); @@ -264,7 +264,7 @@ void* smpi_shared_set_call(const char* func, const char* input, void* data) { char* loc = bprintf("%s:%s", func, input); if(!calls) { - calls = xbt_dict_new(); + calls = xbt_dict_new_homogeneous(NULL); } xbt_dict_set(calls, loc, data, NULL); free(loc); diff --git a/src/smpi/smpi_f77.c b/src/smpi/smpi_f77.c index 2f84829faf..e6d9d10c2e 100644 --- a/src/smpi/smpi_f77.c +++ b/src/smpi/smpi_f77.c @@ -79,7 +79,7 @@ void mpi_init__(int* ierr) { comm_lookup = xbt_dynar_new(sizeof(MPI_Comm), NULL); new_comm(MPI_COMM_WORLD); - request_lookup = xbt_dict_new(); + request_lookup = xbt_dict_new_homogeneous(NULL); datatype_lookup = xbt_dynar_new(sizeof(MPI_Datatype), NULL); new_datatype(MPI_BYTE); diff --git a/src/surf/gtnets/gtnets_interface.cc b/src/surf/gtnets/gtnets_interface.cc index 0d366a4e2f..0d41371c0d 100644 --- a/src/surf/gtnets/gtnets_interface.cc +++ b/src/surf/gtnets/gtnets_interface.cc @@ -1,4 +1,3 @@ -/* $Id$ */ /* Copyright (c) 2007 Kayo Fujiwara. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it diff --git a/src/surf/gtnets/gtnets_simulator.cc b/src/surf/gtnets/gtnets_simulator.cc index dc750d3776..626d2ca906 100644 --- a/src/surf/gtnets/gtnets_simulator.cc +++ b/src/surf/gtnets/gtnets_simulator.cc @@ -1,4 +1,3 @@ -/* $Id$ */ /* Copyright (c) 2007 Kayo Fujiwara. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it diff --git a/src/surf/gtnets/gtnets_topology.cc b/src/surf/gtnets/gtnets_topology.cc index 7f9913653e..d3f2f13293 100644 --- a/src/surf/gtnets/gtnets_topology.cc +++ b/src/surf/gtnets/gtnets_topology.cc @@ -1,5 +1,3 @@ -/* $ID$ */ - /* Copyright (c) 2007 Kayo Fujiwara. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it diff --git a/src/surf/gtnets/gtnets_topology.h b/src/surf/gtnets/gtnets_topology.h index 0f2a2a2169..a73ad4d925 100644 --- a/src/surf/gtnets/gtnets_topology.h +++ b/src/surf/gtnets/gtnets_topology.h @@ -1,5 +1,3 @@ -/* $ID$ */ - /* Copyright (c) 2007, 2009, 2010. The SimGrid Team. * All rights reserved. */ diff --git a/src/surf/network.c b/src/surf/network.c index 9abdaf3ab9..0a2aff0e8a 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -40,7 +40,7 @@ static void gap_append(double size, const link_CM02_t link, surf_action_network_ if(sg_sender_gap > 0.0) { if(!gap_lookup) { - gap_lookup = xbt_dict_new(); + gap_lookup = xbt_dict_new_homogeneous(NULL); } fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, src); action->sender.gap = 0.0; diff --git a/src/surf/ns3/ns3_simulator.cc b/src/surf/ns3/ns3_simulator.cc index 8b8a00cc40..5e2c1084ba 100644 --- a/src/surf/ns3/ns3_simulator.cc +++ b/src/surf/ns3/ns3_simulator.cc @@ -61,7 +61,7 @@ void NS3Sim::create_flow_NS3( uint32_t totalBytes, void * action) { - if(!dict_socket) dict_socket = xbt_dict_new(); + if(!dict_socket) dict_socket = xbt_dict_new_homogeneous(free); PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny(), @@ -80,7 +80,7 @@ void NS3Sim::create_flow_NS3( mysocket->action = action; transformSocketPtr(sock); - xbt_dict_set(dict_socket,socket_key, mysocket,free); + xbt_dict_set(dict_socket,socket_key, mysocket,NULL); sock->Bind(InetSocketAddress(port_number)); XBT_DEBUG("Create flow starting to %fs + %fs = %fs",start-ns3_time(), ns3_time(), start); diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 38e071a983..1d11084198 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -728,10 +728,10 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) if (strcmp(cluster->availability_trace, "") || strcmp(cluster->state_trace, "")) { - patterns = xbt_dict_new(); - xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), free); - xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), free); - xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), free); + patterns = xbt_dict_new_homogeneous(xbt_free_f); + xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL); + xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL); + xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), NULL); } @@ -766,7 +766,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) memset(&host, 0, sizeof(host)); host.id = host_id; if (strcmp(cluster->availability_trace, "")) { - xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free); + xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL); char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns); XBT_DEBUG("\tavailability_file=\"%s\"", avail_file); host.power_trace = tmgr_trace_new(avail_file); @@ -1039,12 +1039,12 @@ static void routing_parse_Srandom(void) random->generator, random->seed, random_radical); if (!random_value) - random_value = xbt_dict_new(); + random_value = xbt_dict_new_homogeneous(free); if (!strcmp(random_radical, "")) { res = random_generate(random); rd_value = bprintf("%f", res); - xbt_dict_set(random_value, random_id, rd_value, free); + xbt_dict_set(random_value, random_id, rd_value, NULL); } else { radical_elements = xbt_str_split(random_radical, ","); xbt_dynar_foreach(radical_elements, iter, groups) { @@ -1057,7 +1057,7 @@ static void routing_parse_Srandom(void) tmpbuf = bprintf("%s%d", random_id, atoi(xbt_dynar_getfirst_as(radical_ends, char *))); - xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), free); + xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL); xbt_free(tmpbuf); break; @@ -1071,7 +1071,7 @@ static void routing_parse_Srandom(void) i)); res = random_generate(random); tmpbuf = bprintf("%s%d", random_id, i); - xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), free); + xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL); xbt_free(tmpbuf); } break; @@ -1082,7 +1082,7 @@ static void routing_parse_Srandom(void) res = random_generate(random); rd_name = bprintf("%s_router", random_id); rd_value = bprintf("%f", res); - xbt_dict_set(random_value, rd_name, rd_value, free); + xbt_dict_set(random_value, rd_name, rd_value, NULL); xbt_dynar_free(&radical_ends); } diff --git a/src/surf/surf_routing_cluster.c b/src/surf/surf_routing_cluster.c index bc11f8fe2f..9c8e028779 100644 --- a/src/surf/surf_routing_cluster.c +++ b/src/surf/surf_routing_cluster.c @@ -66,9 +66,9 @@ AS_t model_cluster_create(void) void surf_routing_cluster_add_link(const char* host_id,surf_parsing_link_up_down_t info) { if(!cluster_host_link) - cluster_host_link = xbt_dict_new(); + cluster_host_link = xbt_dict_new_homogeneous(xbt_free); - xbt_dict_set(cluster_host_link,host_id,info,xbt_free); + xbt_dict_set(cluster_host_link,host_id,info,NULL); } void surf_routing_cluster_add_backbone(AS_t as, void* bb) { diff --git a/src/surf/surf_routing_dijkstra.c b/src/surf/surf_routing_dijkstra.c index 778f37d629..3450eea057 100644 --- a/src/surf/surf_routing_dijkstra.c +++ b/src/surf/surf_routing_dijkstra.c @@ -79,7 +79,7 @@ static xbt_node_t route_graph_new_node(as_dijkstra_t as, elm = xbt_new0(struct graph_node_map_element, 1); elm->node = node; xbt_dict_set_ext(as->graph_node_map, (char *) (&id), sizeof(int), - (xbt_set_elm_t) elm, &graph_node_map_elem_free); + (xbt_set_elm_t) elm, NULL); return node; } @@ -387,7 +387,7 @@ static void dijkstra_get_route_and_latency(AS_t asg, elm->pred_arr = pred_arr; elm->size = size; xbt_dict_set_ext(as->route_cache, (char *) (&src_id), sizeof(int), - (xbt_set_elm_t) elm, &route_cache_elem_free); + (xbt_set_elm_t) elm, NULL); } if (!as->cached) @@ -447,10 +447,10 @@ void model_dijkstra_both_end(AS_t as) if(!THIS->route_graph) THIS->route_graph = xbt_graph_new_graph(1, NULL); if(!THIS->graph_node_map) - THIS->graph_node_map = xbt_dict_new(); + THIS->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free); if (THIS->cached && !THIS->route_cache) - THIS->route_cache = xbt_dict_new(); + THIS->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free); /* Add the loopback if needed */ if (as->hierarchy == SURF_ROUTING_BASE) @@ -480,10 +480,10 @@ void model_dijkstra_both_parse_route (AS_t asg, const char *src, if(!as->route_graph) as->route_graph = xbt_graph_new_graph(1, NULL); if(!as->graph_node_map) - as->graph_node_map = xbt_dict_new(); + as->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free); if (as->cached && !as->route_cache) - as->route_cache = xbt_dict_new(); + as->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free); if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES ) diff --git a/src/surf/surf_routing_generic.c b/src/surf/surf_routing_generic.c index b3fbf54521..414bdd7380 100644 --- a/src/surf/surf_routing_generic.c +++ b/src/surf/surf_routing_generic.c @@ -28,8 +28,8 @@ AS_t model_generic_create_sized(size_t childsize) { generic_get_bypassroute; new_component->finalize = model_generic_finalize; - new_component->to_index = xbt_dict_new(); - new_component->bypassRoutes = xbt_dict_new(); + new_component->to_index = xbt_dict_new_homogeneous(xbt_free); + new_component->bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) generic_free_route); return new_component; } @@ -46,7 +46,7 @@ void generic_parse_PU(AS_t as, const char *name) xbt_dict_t _to_index; _to_index = as->to_index; *id = xbt_dict_length(_to_index); - xbt_dict_set(_to_index, name, id, xbt_free); + xbt_dict_set(_to_index, name, id, NULL); } void generic_parse_AS(AS_t as, const char *name) @@ -56,7 +56,7 @@ void generic_parse_AS(AS_t as, const char *name) xbt_dict_t _to_index; _to_index = as->to_index; *id = xbt_dict_length(_to_index); - xbt_dict_set(_to_index, name, id, xbt_free); + xbt_dict_set(_to_index, name, id, NULL); } void generic_parse_bypassroute(AS_t rc, @@ -80,8 +80,7 @@ void generic_parse_bypassroute(AS_t rc, xbt_dynar_free(&(e_route->link_list)); xbt_free(e_route); - xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, - (void (*)(void *)) generic_free_route); + xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, NULL); xbt_free(route_name); } diff --git a/src/surf/surf_routing_none.c b/src/surf/surf_routing_none.c index 85776de552..f605009fcb 100644 --- a/src/surf/surf_routing_none.c +++ b/src/surf/surf_routing_none.c @@ -47,7 +47,7 @@ AS_t model_none_create_sized(size_t childsize) { new_component->get_bypass_route = none_get_bypass_route; new_component->finalize = model_none_finalize; - new_component->routing_sons = xbt_dict_new(); + new_component->routing_sons = xbt_dict_new_homogeneous(NULL); return new_component; } diff --git a/src/surf/surf_routing_rulebased.c b/src/surf/surf_routing_rulebased.c index b9fb8c4c6e..bdefb70c96 100644 --- a/src/surf/surf_routing_rulebased.c +++ b/src/surf/surf_routing_rulebased.c @@ -74,8 +74,7 @@ static void model_rulebased_parse_PU(AS_t rc, const char *name) static void model_rulebased_parse_AS(AS_t rc, const char *name) { AS_rulebased_t routing = (AS_rulebased_t) rc; - xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1), - NULL); + xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1), NULL); } static void model_rulebased_parse_route(AS_t rc, @@ -397,8 +396,8 @@ AS_t model_rulebased_create(void) { new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route; new_component->generic_routing.finalize = rulebased_finalize; /* initialization of internal structures */ - new_component->dict_processing_units = xbt_dict_new(); - new_component->dict_autonomous_systems = xbt_dict_new(); + new_component->dict_processing_units = xbt_dict_new_homogeneous(NULL); + new_component->dict_autonomous_systems = xbt_dict_new_homogeneous(NULL); new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free); new_component->list_ASroute = xbt_dynar_new(sizeof(rule_route_extended_t), diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index aec18201b2..c1bcc922de 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -257,7 +257,7 @@ void STag_surfxml_host(void){ memset(&host,0,sizeof(host)); xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)"); - host.properties = current_property_set = xbt_dict_new(); + host.properties = current_property_set = xbt_dict_new_homogeneous(xbt_free_f); host.id = A_surfxml_host_id; host.power_peak = get_cpu_power(A_surfxml_host_power); @@ -367,7 +367,7 @@ void STag_surfxml_link(void){ memset(&link,0,sizeof(link)); xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)"); - link.properties = current_property_set = xbt_dict_new(); + link.properties = current_property_set = xbt_dict_new_homogeneous(xbt_free_f); link.id = A_surfxml_link_id; link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth); @@ -443,7 +443,7 @@ void STag_surfxml_bypassRoute(void){ void STag_surfxml_config(void){ XBT_DEBUG("START configuration name = %s",A_surfxml_config_id); xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)"); - current_property_set = xbt_dict_new(); + current_property_set = xbt_dict_new_homogeneous(xbt_free_f); } void ETag_surfxml_config(void){ @@ -572,9 +572,9 @@ static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list) void parse_properties(void) { if (!current_property_set) - current_property_set = xbt_dict_new(); // Maybe, it should raise an error + current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error - xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), free); + xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL); } diff --git a/src/surf/surfxml_parseplatf.c b/src/surf/surfxml_parseplatf.c index c8216efce5..57a766a4c2 100644 --- a/src/surf/surfxml_parseplatf.c +++ b/src/surf/surfxml_parseplatf.c @@ -102,25 +102,25 @@ static void parse_Stag_trace_connect(void) case A_surfxml_trace_connect_kind_HOST_AVAIL: xbt_dict_set(trace_connect_list_host_avail, A_surfxml_trace_connect_trace, - xbt_strdup(A_surfxml_trace_connect_element), free); + xbt_strdup(A_surfxml_trace_connect_element), NULL); break; case A_surfxml_trace_connect_kind_POWER: xbt_dict_set(trace_connect_list_power, A_surfxml_trace_connect_trace, - xbt_strdup(A_surfxml_trace_connect_element), free); + xbt_strdup(A_surfxml_trace_connect_element), NULL); break; case A_surfxml_trace_connect_kind_LINK_AVAIL: xbt_dict_set(trace_connect_list_link_avail, A_surfxml_trace_connect_trace, - xbt_strdup(A_surfxml_trace_connect_element), free); + xbt_strdup(A_surfxml_trace_connect_element), NULL); break; case A_surfxml_trace_connect_kind_BANDWIDTH: xbt_dict_set(trace_connect_list_bandwidth, A_surfxml_trace_connect_trace, - xbt_strdup(A_surfxml_trace_connect_element), free); + xbt_strdup(A_surfxml_trace_connect_element), NULL); break; case A_surfxml_trace_connect_kind_LATENCY: xbt_dict_set(trace_connect_list_latency, A_surfxml_trace_connect_trace, - xbt_strdup(A_surfxml_trace_connect_element), free); + xbt_strdup(A_surfxml_trace_connect_element), NULL); break; default: xbt_die("Cannot connect trace %s to %s: kind of trace unknown", @@ -150,12 +150,12 @@ void parse_platform_file(const char *file) if (!surfxml_bufferstack_stack) surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL); - traces_set_list = xbt_dict_new(); - trace_connect_list_host_avail = xbt_dict_new(); - trace_connect_list_power = xbt_dict_new(); - trace_connect_list_link_avail = xbt_dict_new(); - trace_connect_list_bandwidth = xbt_dict_new(); - trace_connect_list_latency = xbt_dict_new(); + traces_set_list = xbt_dict_new_homogeneous(NULL); + trace_connect_list_host_avail = xbt_dict_new_homogeneous(free); + trace_connect_list_power = xbt_dict_new_homogeneous(free); + trace_connect_list_link_avail = xbt_dict_new_homogeneous(free); + trace_connect_list_bandwidth = xbt_dict_new_homogeneous(free); + trace_connect_list_latency = xbt_dict_new_homogeneous(free); surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_Stag_trace); surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_Etag_trace); diff --git a/src/surf/trace_mgr.c b/src/surf/trace_mgr.c index ea18e1a9c4..c49bd7ca67 100644 --- a/src/surf/trace_mgr.c +++ b/src/surf/trace_mgr.c @@ -88,10 +88,9 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input, last_event->delta = periodicity; if (!trace_list) - trace_list = xbt_dict_new(); + trace_list = xbt_dict_new_homogeneous((void (*)(void *)) tmgr_trace_free); - xbt_dict_set(trace_list, id, (void *) trace, - (void (*)(void *)) tmgr_trace_free); + xbt_dict_set(trace_list, id, (void *) trace, NULL); xbt_dynar_free(&list); return trace; diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index b8ecc23cd8..217e63b4f2 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -454,7 +454,7 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, double latency = 0.0; if (ptask_parallel_task_link_set == NULL) - ptask_parallel_task_link_set = xbt_dict_new(); + ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL); xbt_dict_reset(ptask_parallel_task_link_set); diff --git a/src/xbt/backtrace_dummy.c b/src/xbt/backtrace_dummy.c index 68733532a6..f10eb04e7a 100644 --- a/src/xbt/backtrace_dummy.c +++ b/src/xbt/backtrace_dummy.c @@ -1,5 +1,3 @@ -/* $Id: ex_interface.h 3782 2007-07-14 09:11:06Z mquinson $ */ - /* backtrace_dummy -- stubs of this module for non-supported archs */ /* Copyright (c) 2008, 2009, 2010. The SimGrid Team. diff --git a/src/xbt/config.c b/src/xbt/config.c index c149aaa27c..39b4262834 100644 --- a/src/xbt/config.c +++ b/src/xbt/config.c @@ -64,7 +64,7 @@ static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, xbt_cfg_t xbt_cfg_new(void) { - return (xbt_cfg_t) xbt_dict_new(); + return (xbt_cfg_t) xbt_dict_new_homogeneous(&xbt_cfgelm_free); } /** \brief Copy an existing configuration set @@ -263,7 +263,7 @@ xbt_cfg_register(xbt_cfg_t * cfg, XBT_ERROR("%d is an invalide type code", type); } - xbt_dict_set((xbt_dict_t) * cfg, name, res, &xbt_cfgelm_free); + xbt_dict_set((xbt_dict_t) * cfg, name, res, NULL); } /** @brief Unregister an element from a config set. diff --git a/src/xbt/dict.c b/src/xbt/dict.c index b0a5031b97..e079770024 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -1,6 +1,6 @@ /* dict - a generic dictionary, variation over hash table */ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2004-2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -19,15 +19,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict, xbt, "Dictionaries provide the same functionalities than hash tables"); -/*####[ Private prototypes ]#################################################*/ - -static xbt_mallocator_t dict_mallocator = NULL; -static void *dict_mallocator_new_f(void); -#define dict_mallocator_free_f xbt_free_f -#define dict_mallocator_reset_f ((void_f_pvoid_t)NULL) - - -/*####[ Code ]###############################################################*/ /** * \brief Constructor @@ -35,16 +26,38 @@ static void *dict_mallocator_new_f(void); * \see xbt_dict_free() * * Creates and initialize a new dictionary with a default hashtable size. + * The dictionary is heterogeneous: each element can have a different free + * function. */ xbt_dict_t xbt_dict_new(void) +{ + xbt_dict_t dict = xbt_dict_new_homogeneous(NULL); + dict->homogeneous = 0; + + return dict; +} + +/** + * \brief Constructor + * \param free_ctn function to call with (\a data as argument) when + * \a data is removed from the dictionary + * \return pointer to the destination + * \see xbt_dict_new(), xbt_dict_free() + * + * Creates and initialize a new dictionary with a default hashtable size. + * The dictionary is homogeneous: each element share the same free function. + */ +xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn) { xbt_dict_t dict; - dict = xbt_mallocator_get(dict_mallocator); + dict = xbt_new(s_xbt_dict_t, 1); + dict->free_f = free_ctn; dict->table_size = 127; dict->table = xbt_new0(xbt_dictelm_t, dict->table_size + 1); dict->count = 0; dict->fill = 0; + dict->homogeneous = 1; return dict; } @@ -74,12 +87,12 @@ void xbt_dict_free(xbt_dict_t * dict) while (current != NULL) { previous = current; current = current->next; - xbt_dictelm_free(previous); + xbt_dictelm_free(*dict, previous); (*dict)->count--; } } xbt_free(table); - xbt_mallocator_release(dict_mallocator, *dict); + xbt_free(*dict); *dict = NULL; } } @@ -251,7 +264,7 @@ XBT_INLINE void xbt_dict_set_ext(xbt_dict_t dict, if (current == NULL) { /* this key doesn't exist yet */ - current = xbt_dictelm_new(key, key_len, hash_code, data, free_ctn); + current = xbt_dictelm_new(dict, key, key_len, hash_code, data, free_ctn); dict->count++; if (previous == NULL) { dict->table[hash_code & dict->table_size] = current; @@ -262,16 +275,11 @@ XBT_INLINE void xbt_dict_set_ext(xbt_dict_t dict, previous->next = current; } } else { - XBT_DEBUG("Replace %.*s by %.*s under key %.*s", key_len, (char *) current->content, key_len, (char *) data, key_len, (char *) key); /* there is already an element with the same key: overwrite it */ - if (current->content != NULL && current->free_f != NULL) { - current->free_f(current->content); - } - current->content = data; - current->free_f = free_ctn; + xbt_dictelm_set_data(dict, current, data, free_ctn); } } @@ -468,7 +476,7 @@ XBT_INLINE void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, if (!dict->table[hash_code & dict->table_size]) dict->fill--; - xbt_dictelm_free(current); + xbt_dictelm_free(dict, current); dict->count--; } @@ -499,45 +507,7 @@ XBT_INLINE void xbt_dict_remove(xbt_dict_t dict, const char *key) XBT_INLINE void xbt_dicti_set(xbt_dict_t dict, uintptr_t key, uintptr_t data) { - - unsigned int hash_code = - xbt_dict_hash_ext((void *) &key, sizeof(uintptr_t)); - - xbt_dictelm_t current, previous = NULL; - xbt_assert(dict); - - XBT_DEBUG("ADD %zu->%zu; hash = %d, size = %d, & = %d", key, data, - hash_code, dict->table_size, hash_code & dict->table_size); - current = dict->table[hash_code & dict->table_size]; - while (current != NULL && - (hash_code != current->hash_code - || sizeof(uintptr_t) != current->key_len - || (((uintptr_t) key) != ((uintptr_t) current->key)))) { - previous = current; - current = current->next; - } - - if (current == NULL) { - /* this key doesn't exist yet */ - current = xbt_dictielm_new(key, hash_code, data); - dict->count++; - if (previous == NULL) { - dict->table[hash_code & dict->table_size] = current; - dict->fill++; - if ((dict->fill * 100) / (dict->table_size + 1) > MAX_FILL_PERCENT) - xbt_dict_rehash(dict); - } else { - previous->next = current; - } - } else { - - /* there is already an element with the same key: overwrite it */ - if (current->content != NULL && current->free_f != NULL) { - current->free_f(current->content); - } - current->content = (void *) data; - current->free_f = NULL; - } + xbt_dict_set_ext(dict, (void *)&key, sizeof key, (void*)data, NULL); } /** @@ -551,59 +521,13 @@ XBT_INLINE void xbt_dicti_set(xbt_dict_t dict, */ XBT_INLINE uintptr_t xbt_dicti_get(xbt_dict_t dict, uintptr_t key) { - - unsigned int hash_code = - xbt_dict_hash_ext(((void *) &key), sizeof(uintptr_t)); - xbt_dictelm_t current; - - xbt_assert(dict); - - current = dict->table[hash_code & dict->table_size]; - while (current != NULL && - (hash_code != current->hash_code - || sizeof(uintptr_t) != current->key_len - || (((uintptr_t) key) != ((uintptr_t) current->key)))) { - current = current->next; - } - - if (current == NULL) - return 0; - - return (uintptr_t) (current->content); + return (uintptr_t)xbt_dict_get_or_null_ext(dict, (void *)&key, sizeof key); } /** Remove a uintptr_t key from the dict */ XBT_INLINE void xbt_dicti_remove(xbt_dict_t dict, uintptr_t key) { - - unsigned int hash_code = - xbt_dict_hash_ext(((void *) &key), sizeof(uintptr_t)); - xbt_dictelm_t current, previous = NULL; - - - current = dict->table[hash_code & dict->table_size]; - while (current != NULL && - (hash_code != current->hash_code - || sizeof(uintptr_t) != current->key_len - || (((uintptr_t) key) != ((uintptr_t) current->key)))) { - previous = current; /* save the previous node */ - current = current->next; - } - - if (current == NULL) - THROWF(not_found_error, 0, "key %zu not found", key); - - if (previous != NULL) { - previous->next = current->next; - } else { - dict->table[hash_code & dict->table_size] = current->next; - } - - if (!dict->table[hash_code & dict->table_size]) - dict->fill--; - - xbt_dictelm_free(current); - dict->count--; + xbt_dict_remove_ext(dict, (void *)&key, sizeof key); } @@ -627,7 +551,7 @@ void xbt_dict_reset(xbt_dict_t dict) while (current != NULL) { previous = current; current = current->next; - xbt_dictelm_free(previous); + xbt_dictelm_free(dict, previous); } dict->table[i] = NULL; } @@ -764,20 +688,20 @@ void xbt_dict_dump_sizes(xbt_dict_t dict) */ void xbt_dict_preinit(void) { - if (dict_mallocator != NULL) { + if (dict_elm_mallocator != NULL) { /* Already created. I guess we want to switch to MC mode, so kill the previously created mallocator */ - xbt_mallocator_free(dict_mallocator); xbt_mallocator_free(dict_elm_mallocator); + xbt_mallocator_free(dict_het_elm_mallocator); } - dict_mallocator = xbt_mallocator_new(256, - dict_mallocator_new_f, - dict_mallocator_free_f, - dict_mallocator_reset_f); dict_elm_mallocator = xbt_mallocator_new(256, dict_elm_mallocator_new_f, dict_elm_mallocator_free_f, dict_elm_mallocator_reset_f); + dict_het_elm_mallocator = xbt_mallocator_new(256, + dict_het_elm_mallocator_new_f, + dict_het_elm_mallocator_free_f, + dict_het_elm_mallocator_reset_f); } /** @@ -786,11 +710,11 @@ void xbt_dict_preinit(void) */ void xbt_dict_postexit(void) { - if (dict_mallocator != NULL) { - xbt_mallocator_free(dict_mallocator); - dict_mallocator = NULL; + if (dict_elm_mallocator != NULL) { xbt_mallocator_free(dict_elm_mallocator); dict_elm_mallocator = NULL; + xbt_mallocator_free(dict_het_elm_mallocator); + dict_het_elm_mallocator = NULL; } if (all_sizes) { unsigned int count; @@ -811,11 +735,6 @@ void xbt_dict_postexit(void) } } -static void *dict_mallocator_new_f(void) -{ - return xbt_new(s_xbt_dict_t, 1); -} - #ifdef SIMGRID_TEST #include "xbt.h" #include "xbt/ex.h" @@ -832,39 +751,41 @@ static void print_str(void *str) } static void debuged_add_ext(xbt_dict_t head, const char *key, - const char *data_to_fill) + const char *data_to_fill, void_f_pvoid_t free_f) { char *data = xbt_strdup(data_to_fill); xbt_test_log("Add %s under %s", PRINTF_STR(data_to_fill), PRINTF_STR(key)); - xbt_dict_set(head, key, data, &free); + xbt_dict_set(head, key, data, free_f); if (XBT_LOG_ISENABLED(xbt_dict, xbt_log_priority_debug)) { xbt_dict_dump(head, (void (*)(void *)) &printf); fflush(stdout); } } -static void debuged_add(xbt_dict_t head, const char *key) +static void debuged_add(xbt_dict_t head, const char *key, void_f_pvoid_t free_f) { - debuged_add_ext(head, key, key); + debuged_add_ext(head, key, key, free_f); } -static void fill(xbt_dict_t * head) +static void fill(xbt_dict_t * head, int homogeneous) { + void_f_pvoid_t free_f = homogeneous ? NULL : &free; + xbt_test_add("Fill in the dictionnary"); - *head = xbt_dict_new(); - debuged_add(*head, "12"); - debuged_add(*head, "12a"); - debuged_add(*head, "12b"); - debuged_add(*head, "123"); - debuged_add(*head, "123456"); + *head = homogeneous ? xbt_dict_new_homogeneous(&free) : xbt_dict_new(); + debuged_add(*head, "12", free_f); + debuged_add(*head, "12a", free_f); + debuged_add(*head, "12b", free_f); + debuged_add(*head, "123", free_f); + debuged_add(*head, "123456", free_f); /* Child becomes child of what to add */ - debuged_add(*head, "1234"); + debuged_add(*head, "1234", free_f); /* Need of common ancestor */ - debuged_add(*head, "123457"); + debuged_add(*head, "123457", free_f); } @@ -993,14 +914,15 @@ xbt_ex_t e; xbt_dict_t head = NULL; char *data; - -XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse") +static void basic_test(int homogeneous) { + void_f_pvoid_t free_f; + xbt_test_add("Traversal the null dictionary"); traverse(head); xbt_test_add("Traversal and search the empty dictionary"); - head = xbt_dict_new(); + head = homogeneous ? xbt_dict_new_homogeneous(&free) : xbt_dict_new(); traverse(head); TRY { debuged_remove(head, "12346"); @@ -1012,11 +934,13 @@ XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse } xbt_dict_free(&head); + free_f = homogeneous ? NULL : &free; + xbt_test_add("Traverse the full dictionary"); - fill(&head); + fill(&head, homogeneous); count_check_get_key(head, 7); - debuged_add_ext(head, "toto", "tutu"); + debuged_add_ext(head, "toto", "tutu", free_f); search_ext(head, "toto", "tutu"); debuged_remove(head, "toto"); @@ -1028,22 +952,22 @@ XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse xbt_dict_free(&head); /* CHANGING */ - fill(&head); + fill(&head, homogeneous); count_check_get_key(head, 7); xbt_test_add("Change 123 to 'Changed 123'"); - xbt_dict_set(head, "123", strdup("Changed 123"), &free); + xbt_dict_set(head, "123", strdup("Changed 123"), free_f); count_check_get_key(head, 7); xbt_test_add("Change 123 back to '123'"); - xbt_dict_set(head, "123", strdup("123"), &free); + xbt_dict_set(head, "123", strdup("123"), free_f); count_check_get_key(head, 7); xbt_test_add("Change 12a to 'Dummy 12a'"); - xbt_dict_set(head, "12a", strdup("Dummy 12a"), &free); + xbt_dict_set(head, "12a", strdup("Dummy 12a"), free_f); count_check_get_key(head, 7); xbt_test_add("Change 12a to '12a'"); - xbt_dict_set(head, "12a", strdup("12a"), &free); + xbt_dict_set(head, "12a", strdup("12a"), free_f); count_check_get_key(head, 7); xbt_test_add("Traverse the resulting dictionary"); @@ -1079,9 +1003,19 @@ XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse traverse(head); } -XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") +XBT_TEST_UNIT("basic (heterogeneous)", test_dict_basic_heterogeneous, "Basic usage: change, retrieve, traverse: heterogeneous dictionary") { - fill(&head); + basic_test(0); +} + +XBT_TEST_UNIT("basic (homogeneous)", test_dict_basic_homogeneous, "Basic usage: change, retrieve, traverse: homogeneous dictionary") +{ + basic_test(1); +} + +static void remove_test(int homogeneous) +{ + fill(&head, homogeneous); count(head, 7); xbt_test_add("Remove non existing data"); TRY { @@ -1098,7 +1032,7 @@ XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") xbt_test_add ("Remove each data manually (traversing the resulting dictionary each time)"); - fill(&head); + fill(&head, homogeneous); debuged_remove(head, "12a"); traverse(head); count(head, 6); @@ -1139,7 +1073,7 @@ XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") xbt_test_add ("Free dict, create new fresh one, and then reset the dict"); xbt_dict_free(&head); - fill(&head); + fill(&head, homogeneous); xbt_dict_reset(head); count(head, 0); traverse(head); @@ -1149,9 +1083,19 @@ XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") xbt_dict_free(&head); } +XBT_TEST_UNIT("remove (heterogeneous)", test_dict_remove_heterogeneous, "Removing some values: heterogeneous dictionary") +{ + remove_test(0); +} + +XBT_TEST_UNIT("remove (homogeneous)", test_dict_remove_homogeneous, "Removing some values: homogeneous dictionary") +{ + remove_test(1); +} + XBT_TEST_UNIT("nulldata", test_dict_nulldata, "NULL data management") { - fill(&head); + fill(&head, 1); xbt_test_add("Store NULL under 'null'"); xbt_dict_set(head, "null", NULL, NULL); diff --git a/src/xbt/dict_cursor.c b/src/xbt/dict_cursor.c index 8d78868393..a83c005d58 100644 --- a/src/xbt/dict_cursor.c +++ b/src/xbt/dict_cursor.c @@ -1,6 +1,6 @@ /* dict_cursor - iterators over dictionnaries */ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2004-2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -197,10 +197,5 @@ XBT_INLINE void xbt_dict_cursor_set_data(xbt_dict_cursor_t cursor, void_f_pvoid_t free_ctn) { __cursor_not_null(cursor); - if (cursor->current->free_f) - cursor->current->free_f(cursor->current->content); - - cursor->current->content = data; - cursor->current->free_f = free_ctn; - return; + xbt_dictelm_set_data(cursor->dict, cursor->current, data, free_ctn); } diff --git a/src/xbt/dict_elm.c b/src/xbt/dict_elm.c index 0591621117..a980fc0d0c 100644 --- a/src/xbt/dict_elm.c +++ b/src/xbt/dict_elm.c @@ -1,6 +1,6 @@ -/* dict - a generic dictionary, variation over the B-tree concept */ +/* dict - a generic dictionary, variation over hash table */ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2004-2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -22,62 +22,83 @@ XBT_LOG_NEW_SUBCATEGORY(xbt_dict_collapse, xbt_dict, "Dictionaries internals: post-removal cleanup"); xbt_mallocator_t dict_elm_mallocator = NULL; +xbt_mallocator_t dict_het_elm_mallocator = NULL; -xbt_dictelm_t xbt_dictelm_new(const char *key, - int key_len, - unsigned int hash_code, - void *content, void_f_pvoid_t free_f) +xbt_dictelm_t xbt_dictelm_new(xbt_dict_t dict, const char *key, int key_len, + unsigned int hash_code, void *content, + void_f_pvoid_t free_f) { - xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator); - - element->dictielem = 0; /* please free the key on free */ + xbt_dictelm_t element; + + if (dict->homogeneous) { + xbt_assert(!free_f, + "Cannot set an individual free function in homogeneous dicts."); + element = xbt_mallocator_get(dict_elm_mallocator); + } else { + xbt_het_dictelm_t het_element = xbt_mallocator_get(dict_het_elm_mallocator); + het_element->free_f = free_f; + element = &het_element->element; + } element->key = xbt_new(char, key_len + 1); - memcpy((void *) element->key, (void *) key, key_len); + memcpy(element->key, key, key_len); element->key[key_len] = '\0'; element->key_len = key_len; element->hash_code = hash_code; element->content = content; - element->free_f = free_f; element->next = NULL; return element; } -xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code, - uintptr_t content) +void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element) { - xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator); - - element->key = (void *) key; - - element->dictielem = 1; /* please DONT free the key on free */ - element->key_len = sizeof(uintptr_t); - element->hash_code = hash_code; - - element->content = (void *) content; - element->free_f = NULL; - element->next = NULL; + if (element) { + char *key = element->key; + void *content = element->content; + void_f_pvoid_t free_f; + if (dict->homogeneous) { + free_f = dict->free_f; + xbt_mallocator_release(dict_elm_mallocator, element); + } else { + xbt_het_dictelm_t het_element = (xbt_het_dictelm_t)element; + free_f = het_element->free_f; + xbt_mallocator_release(dict_het_elm_mallocator, het_element); + } - return element; + xbt_free(key); + if (free_f && content) + free_f(content); + } } -void xbt_dictelm_free(xbt_dictelm_t element) +void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element, + void *data, void_f_pvoid_t free_ctn) { - if (element != NULL) { - if (!element->dictielem) - xbt_free(element->key); + void_f_pvoid_t free_f; + if (dict->homogeneous) { + free_f = dict->free_f; + xbt_assert(!free_ctn, + "Cannot set an individual free function in homogeneous dicts."); + } else { + xbt_het_dictelm_t het_element = (xbt_het_dictelm_t)element; + free_f = het_element->free_f; + het_element->free_f = free_ctn; + } - if (element->free_f != NULL && element->content != NULL) { - element->free_f(element->content); - } + if (free_f && element->content) + free_f(element->content); - xbt_mallocator_release(dict_elm_mallocator, element); - } + element->content = data; } void *dict_elm_mallocator_new_f(void) { return xbt_new(s_xbt_dictelm_t, 1); } + +void *dict_het_elm_mallocator_new_f(void) +{ + return xbt_new(s_xbt_het_dictelm_t, 1); +} diff --git a/src/xbt/dict_private.h b/src/xbt/dict_private.h index 033500f2b8..490fe38cbb 100644 --- a/src/xbt/dict_private.h +++ b/src/xbt/dict_private.h @@ -1,7 +1,7 @@ /* dict_elm - elements of generic dictionnaries */ /* This file is not to be loaded from anywhere but dict.c */ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2004-2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -22,22 +22,27 @@ typedef struct s_xbt_dictelm *xbt_dictelm_t; #define MAX_FILL_PERCENT 80 typedef struct s_xbt_dictelm { - int dictielem:1; char *key; int key_len; unsigned int hash_code; void *content; - void_f_pvoid_t free_f; xbt_dictelm_t next; } s_xbt_dictelm_t; +typedef struct s_xbt_het_dictelm { + s_xbt_dictelm_t element; + void_f_pvoid_t free_f; +} s_xbt_het_dictelm_t, *xbt_het_dictelm_t; + typedef struct s_xbt_dict { + void_f_pvoid_t free_f; xbt_dictelm_t *table; int table_size; int count; int fill; + int homogeneous; } s_xbt_dict_t; typedef struct s_xbt_dict_cursor s_xbt_dict_cursor_t; @@ -47,12 +52,17 @@ extern void *dict_elm_mallocator_new_f(void); #define dict_elm_mallocator_free_f xbt_free_f #define dict_elm_mallocator_reset_f ((void_f_pvoid_t)NULL) +extern xbt_mallocator_t dict_het_elm_mallocator; +extern void *dict_het_elm_mallocator_new_f(void); +#define dict_het_elm_mallocator_free_f xbt_free_f +#define dict_het_elm_mallocator_reset_f ((void_f_pvoid_t)NULL) + /*####[ Function prototypes ]################################################*/ -xbt_dictelm_t xbt_dictelm_new(const char *key, int key_len, +xbt_dictelm_t xbt_dictelm_new(xbt_dict_t dict, const char *key, int key_len, unsigned int hash_code, void *content, void_f_pvoid_t free_f); -xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code, - uintptr_t content); -void xbt_dictelm_free(xbt_dictelm_t element); +void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element); +void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element, + void *data, void_f_pvoid_t free_ctn); #endif /* _XBT_DICT_PRIVATE_H_ */ diff --git a/src/xbt/graph.c b/src/xbt/graph.c index a56d008f66..e56e413938 100644 --- a/src/xbt/graph.c +++ b/src/xbt/graph.c @@ -561,7 +561,7 @@ static void __parse_graph_begin(void) else parsed_graph = xbt_graph_new_graph(0, NULL); - parsed_nodes = xbt_dict_new(); + parsed_nodes = xbt_dict_new_homogeneous(NULL); } static void __parse_graph_end(void) @@ -735,7 +735,7 @@ xbt_graph_t xbt_graph_load (const char *filename) file = fopen (filename, "r"); xbt_assert(file, "Failed to open %s \n", filename); - xbt_dict_t nodes_dict = xbt_dict_new (); + xbt_dict_t nodes_dict = xbt_dict_new_homogeneous(NULL); xbt_graph_t ret = xbt_graph_new_graph (0, NULL); //read the number of nodes diff --git a/src/xbt/lib.c b/src/xbt/lib.c index 1141f8d6a0..163c0deb9e 100644 --- a/src/xbt/lib.c +++ b/src/xbt/lib.c @@ -17,7 +17,7 @@ xbt_lib_t xbt_lib_new(void) { xbt_lib_t lib; lib = xbt_new(s_xbt_lib_t, 1); - lib->dict = xbt_dict_new(); + lib->dict = xbt_dict_new_homogeneous(xbt_free); lib->levels = 0; lib->free_f = NULL; return lib; @@ -60,7 +60,7 @@ void xbt_lib_set(xbt_lib_t lib, const char *key, int level, void *obj) void **elts = xbt_dict_get_or_null(lib->dict, key); if (!elts) { elts = xbt_new0(void *, lib->levels); - xbt_dict_set(lib->dict, key, elts, xbt_free); + xbt_dict_set(lib->dict, key, elts, NULL); } if (elts[level]) { XBT_DEBUG("Replace %p by %p element under key '%s:%d'", diff --git a/src/xbt/xbt_strbuff.c b/src/xbt/xbt_strbuff.c index 1db44325f6..688b4d9bd5 100644 --- a/src/xbt/xbt_strbuff.c +++ b/src/xbt/xbt_strbuff.c @@ -1,5 +1,3 @@ -/* $Id: buff.c 3483 2007-05-07 11:18:56Z mquinson $ */ - /* strbuff -- string buffers */ /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. @@ -309,14 +307,14 @@ static void mytest(const char *input, const char *patterns, char *str; /*foreach */ xbt_strbuff_t sb; /* what we test */ - p = xbt_dict_new(); + p = xbt_dict_new_homogeneous(free); dyn_patterns = xbt_str_split(patterns, " "); xbt_dynar_foreach(dyn_patterns, cpt, str) { xbt_dynar_t keyvals = xbt_str_split(str, "="); char *key = xbt_dynar_get_as(keyvals, 0, char *); char *val = xbt_dynar_get_as(keyvals, 1, char *); xbt_str_subst(key, '_', ' ', 0); // to put space in names without breaking the enclosing dynar_foreach - xbt_dict_set(p, key, xbt_strdup(val), free); + xbt_dict_set(p, key, xbt_strdup(val), NULL); xbt_dynar_free(&keyvals); } xbt_dynar_free(&dyn_patterns); diff --git a/teshsuite/gras/empty_main/empty_main.c b/teshsuite/gras/empty_main/empty_main.c index f2a9d00bd9..83e6d5cbf1 100644 --- a/teshsuite/gras/empty_main/empty_main.c +++ b/teshsuite/gras/empty_main/empty_main.c @@ -1,5 +1,3 @@ -/* $Id: gras.c 3859 2007-07-18 12:29:51Z donassbr $ */ - /* empty_main.c -- check what happens when the processes do nothing */ /* Thanks to Loris Marshal for reporting a problem in that case */ diff --git a/teshsuite/gras/msg_handle/msg_handle.c b/teshsuite/gras/msg_handle/msg_handle.c index af07a05271..6943fdbedc 100644 --- a/teshsuite/gras/msg_handle/msg_handle.c +++ b/teshsuite/gras/msg_handle/msg_handle.c @@ -1,5 +1,3 @@ -/* $Id: mmrpc.c 3399 2007-04-11 19:34:43Z cherierm $ */ - /* msg_handle - ensures the semantic of gras_msg_handle(i) for i<0,=0 or >0 */ /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. diff --git a/teshsuite/gras/small_sleep/small_sleep.c b/teshsuite/gras/small_sleep/small_sleep.c index 622565e35d..e5fd687af9 100644 --- a/teshsuite/gras/small_sleep/small_sleep.c +++ b/teshsuite/gras/small_sleep/small_sleep.c @@ -1,5 +1,3 @@ -/* $Id: gras.c 3859 2007-07-18 12:29:51Z donassbr $ */ - /* small_sleep.c -- check what happens when the processes do sleeps very shortly*/ /* Copyright (c) 2008, 2009, 2010. The SimGrid Team. diff --git a/tools/gras/gras_stub_generator.h b/tools/gras/gras_stub_generator.h index e50590ffd1..8fa5f45510 100644 --- a/tools/gras/gras_stub_generator.h +++ b/tools/gras/gras_stub_generator.h @@ -1,5 +1,3 @@ -/* $Id$ */ - /* gras_stub_generator - creates the main() to use a GRAS program */ /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */ diff --git a/tools/gras/stub_generator.c b/tools/gras/stub_generator.c index 5de317aa19..c8cda70a58 100644 --- a/tools/gras/stub_generator.c +++ b/tools/gras/stub_generator.c @@ -56,8 +56,7 @@ static s_process_t process; static void parse_process_init(void) { - xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, - NULL); + xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL); xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL); process.argc = 1; process.argv = xbt_new(char *, 1); @@ -96,9 +95,9 @@ int main(int argc, char *argv[]) int i; surf_init(&argc, argv); - process_function_set = xbt_dict_new(); + process_function_set = xbt_dict_new_homogeneous(NULL); process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free); - machine_set = xbt_dict_new(); + machine_set = xbt_dict_new_homogeneous(NULL); for (i = 1; i < argc; i++) { int need_removal = 0; diff --git a/tools/gras/unix_stub_generator.c b/tools/gras/unix_stub_generator.c index 42aabfc17d..87c087a355 100644 --- a/tools/gras/unix_stub_generator.c +++ b/tools/gras/unix_stub_generator.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* gras_stub_generator - creates the main() to use a GRAS program */ /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */ diff --git a/tools/gras/windows_stub_generator.c b/tools/gras/windows_stub_generator.c index 77a9fe9578..ddb4299fd0 100644 --- a/tools/gras/windows_stub_generator.c +++ b/tools/gras/windows_stub_generator.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* gras_stub_generator - creates the main() to use a GRAS program */ /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */ diff --git a/tools/tesh/run_context.c b/tools/tesh/run_context.c index 1eaaedfdc6..26221267f8 100644 --- a/tools/tesh/run_context.c +++ b/tools/tesh/run_context.c @@ -298,8 +298,10 @@ void rctx_pushline(const char *filepos, char kind, char *line) rctx->cmd = xbt_strdup(line); rctx->filepos = xbt_strdup(filepos); - if(option){ - rctx->cmd = bprintf("%s %s",rctx->cmd,option); + if (option){ + char *newcmd = bprintf("%s %s", rctx->cmd, option); + free(rctx->cmd); + rctx->cmd = newcmd; } XBT_INFO("[%s] %s%s", filepos, rctx->cmd, ((rctx->is_background) ? " (background command)" : "")); @@ -359,7 +361,7 @@ void rctx_pushline(const char *filepos, char kind, char *line) int len = strlen("setenv "); char *eq = strchr(line + len, '='); char *key = bprintf("%.*s", (int) (eq - line - len), line + len); - xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f); + xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL); free(key); rctx->env = realloc(rctx->env, ++(rctx->env_size) * sizeof(char *)); @@ -560,7 +562,9 @@ void rctx_start(void) int child_out[2]; XBT_DEBUG("Cmd before rewriting %s", rctx->cmd); - rctx->cmd = xbt_str_varsubst(rctx->cmd, env); + char *newcmd = xbt_str_varsubst(rctx->cmd, env); + free(rctx->cmd); + rctx->cmd = newcmd; XBT_VERB("Start %s %s", rctx->cmd, (rctx->is_background ? "(background job)" : "")); xbt_os_mutex_acquire(armageddon_mutex); @@ -643,20 +647,35 @@ void rctx_start(void) /* Helper function to sort the output */ static int cmpstringp(const void *p1, const void *p2) { - /* Sort only using the 19 first chars (date+pid) - * If the dates are the same, then, sort using pointer address (be stable wrt output of each process) + /* Sort only using the sort_len first chars + * If they are the same, then, sort using pointer address + * (be stable wrt output of each process) */ - const char *s1 = *((const char**) p1); - const char *s2 = *((const char**) p2); + const char **s1 = *(const char***)p1; + const char **s2 = *(const char***)p2; - XBT_DEBUG("Compare strings '%s' and '%s'", s1, s2); + XBT_DEBUG("Compare strings '%s' and '%s'", *s1, *s2); - int res = strncmp(s1, s2, sort_len); + int res = strncmp(*s1, *s2, sort_len); if (res == 0) - res = p1 > p2 ? 1 : (p1 < p2 ? -1 : 0); + res = s1 > s2 ? 1 : (s1 < s2 ? -1 : 0); return res; } +static void stable_sort(xbt_dynar_t a) +{ + unsigned long len = xbt_dynar_length(a); + void **b = xbt_new(void*, len); + unsigned long i; + for (i = 0 ; i < len ; i++) /* fill the array b with pointers to strings */ + b[i] = xbt_dynar_get_ptr(a, i); + qsort(b, len, sizeof *b, cmpstringp); /* sort it */ + for (i = 0 ; i < len ; i++) /* dereference the pointers to get the strings */ + b[i] = *(char**)b[i]; + for (i = 0 ; i < len ; i++) /* put everything in place */ + xbt_dynar_set_as(a, i, char*, b[i]); + xbt_free(b); +} /* Waits for the child to end (or to timeout), and check its ending conditions. This is launched from rctx_start but either in main @@ -720,7 +739,7 @@ void *rctx_wait(void *r) } if (rctx->output_sort) { - xbt_dynar_sort(b, cmpstringp); + stable_sort(b); /* If empty lines moved in first position, remove them */ while (!xbt_dynar_is_empty(b) && *xbt_dynar_getfirst_as(b, char*) == '\0') xbt_dynar_shift(b, NULL); diff --git a/tools/tesh/tesh.c b/tools/tesh/tesh.c index f23c3be90b..f865e45fb4 100644 --- a/tools/tesh/tesh.c +++ b/tools/tesh/tesh.c @@ -183,12 +183,12 @@ static void parse_environ() int i; char *eq = NULL; char *key = NULL; - env = xbt_dict_new(); + env = xbt_dict_new_homogeneous(xbt_free_f); for (i = 0; environ[i]; i++) { p = environ[i]; eq = strchr(p, '='); key = bprintf("%.*s", (int) (eq - p), p); - xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f); + xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL); free(key); } } @@ -234,7 +234,7 @@ int main(int argc, char *argv[]) char *eq = strchr(argv[i+1], '='); xbt_assert(eq,"The argument of --setenv must contain a '=' (got %s instead)",argv[i+1]); char *key = bprintf("%.*s", (int) (eq - argv[i+1]), argv[i+1]); - xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f); + xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL); XBT_INFO("setting environment variable '%s' to '%s'", key, eq+1); free(key); memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *)); @@ -245,10 +245,12 @@ int main(int argc, char *argv[]) XBT_ERROR("--cfg argument requires an argument"); exit(1); } - if(!option){ //if option is NULL + if (!option){ //if option is NULL option = bprintf("--cfg=%s",argv[i+1]); - }else{ - option = bprintf("%s --cfg=%s",option,argv[i+1]); + } else { + char *newoption = bprintf("%s --cfg=%s", option, argv[i+1]); + free(option); + option = newoption; } XBT_INFO("Add option \'--cfg=%s\' to command line",argv[i+1]); memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *)); @@ -300,6 +302,6 @@ int main(int argc, char *argv[]) rctx_exit(); xbt_dict_free(&env); - xbt_free_f(option); + free(option); return 0; }