From 45c2d7ce0ce350c4cc27acb6089885de1dce9b19 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 15 Sep 2019 10:31:18 +0200 Subject: [PATCH] document existing coding convention in C, and stick to it --- ChangeLog | 4 ++-- README.coding | 2 ++ .../simdag/scheduling/sd_scheduling.c | 18 +++++++++--------- include/simgrid/actor.h | 4 ++-- include/simgrid/host.h | 10 +++++----- src/msg/msg_legacy.cpp | 4 ++-- src/s4u/s4u_Actor.cpp | 4 ++-- src/s4u/s4u_Host.cpp | 4 ++-- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1e5a2a232..c0f5b21694 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,8 +16,8 @@ S4U: - on_simulation_end: after simulation, before cleanups - on_deadlock: as the name implies. - C bindings: - - sg_{host,actor}_{set,get}_data() now all exist. - Use them to attach user data to the object. + - sg_{actor,host,link}_{data,data_set}() now all exist. + Use them to attach user data to the object and retrieve it. MSG: - convert a new set of functions to the S4U C interface and move the old MSG diff --git a/README.coding b/README.coding index 6b3d048dde..44414b90f2 100644 --- a/README.coding +++ b/README.coding @@ -35,6 +35,8 @@ SimGrid4 will follow the these rules: - Example: src/kernel/activity/Activity.cpp include/simgrid/activity/Activity.hpp C + - Field getters are named sg_object_field() eg sg_link_name() + Field setters are named sg_object_field_set() eg sg_link_data_set() - variables and functions are in snake_case() - typedefs do not hide the pointers, ie * must be explicit char * sg_host_get_name(sg_host_t * host); diff --git a/examples/deprecated/simdag/scheduling/sd_scheduling.c b/examples/deprecated/simdag/scheduling/sd_scheduling.c index be2963af31..17972b6512 100644 --- a/examples/deprecated/simdag/scheduling/sd_scheduling.c +++ b/examples/deprecated/simdag/scheduling/sd_scheduling.c @@ -24,26 +24,26 @@ struct _HostAttribute { static double sg_host_get_available_at(sg_host_t host) { - HostAttribute attr = (HostAttribute)sg_host_get_data(host); + HostAttribute attr = (HostAttribute)sg_host_data(host); return attr->available_at; } static void sg_host_set_available_at(sg_host_t host, double time) { - HostAttribute attr = (HostAttribute)sg_host_get_data(host); + HostAttribute attr = (HostAttribute)sg_host_data(host); attr->available_at = time; - sg_host_set_data(host, attr); + sg_host_data_set(host, attr); } static SD_task_t sg_host_get_last_scheduled_task( sg_host_t host){ - HostAttribute attr = (HostAttribute)sg_host_get_data(host); + HostAttribute attr = (HostAttribute)sg_host_data(host); return attr->last_scheduled_task; } static void sg_host_set_last_scheduled_task(sg_host_t host, SD_task_t task){ - HostAttribute attr = (HostAttribute)sg_host_get_data(host); + HostAttribute attr = (HostAttribute)sg_host_data(host); attr->last_scheduled_task=task; - sg_host_set_data(host, attr); + sg_host_data_set(host, attr); } static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax) @@ -159,7 +159,7 @@ int main(int argc, char **argv) sg_host_t *hosts = sg_host_list(); for (cursor = 0; cursor < total_nhosts; cursor++) - sg_host_set_data(hosts[cursor], xbt_new0(struct _HostAttribute, 1)); + sg_host_data_set(hosts[cursor], xbt_new0(struct _HostAttribute, 1)); /* load the DAX file */ xbt_dynar_t dax = SD_daxload(argv[2]); @@ -246,8 +246,8 @@ int main(int argc, char **argv) xbt_dynar_free_container(&dax); for (cursor = 0; cursor < total_nhosts; cursor++) { - free(sg_host_get_data(hosts[cursor])); - sg_host_set_data(hosts[cursor], NULL); + free(sg_host_data(hosts[cursor])); + sg_host_data_set(hosts[cursor], NULL); } xbt_free(hosts); diff --git a/include/simgrid/actor.h b/include/simgrid/actor.h index ba67224273..9b38ab555a 100644 --- a/include/simgrid/actor.h +++ b/include/simgrid/actor.h @@ -49,8 +49,8 @@ XBT_PUBLIC const char* sg_actor_self_get_name(); XBT_PUBLIC void sg_actor_self_execute(double flops); XBT_PUBLIC void sg_actor_ref(sg_actor_t actor); XBT_PUBLIC void sg_actor_unref(sg_actor_t actor); -XBT_PUBLIC void* sg_actor_get_data(sg_actor_t actor); -XBT_PUBLIC void sg_actor_set_data(sg_actor_t actor, void* userdata); +XBT_PUBLIC void* sg_actor_data(sg_actor_t actor); +XBT_PUBLIC void sg_actor_data_set(sg_actor_t actor, void* userdata); SG_END_DECL() diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 30db249aeb..fad40cd22f 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -49,16 +49,16 @@ XBT_PUBLIC const char* sg_host_get_name(sg_host_t host); * * This functions returns the user data associated to @a host if any. */ -XBT_PUBLIC void* sg_host_get_data(sg_host_t host); -XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_get_data()") XBT_PUBLIC void* sg_host_user(sg_host_t host); +XBT_PUBLIC void* sg_host_data(sg_host_t host); +XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_data()") XBT_PUBLIC void* sg_host_user(sg_host_t host); /** @brief Set the user data of a #sg_host_t. * * This functions attach @a data to @a host. */ -XBT_PUBLIC void sg_host_set_data(sg_host_t host, void* userdata); -XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_set_data()") XBT_PUBLIC +XBT_PUBLIC void sg_host_data_set(sg_host_t host, void* userdata); +XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_data_set()") XBT_PUBLIC void sg_host_user_set(sg_host_t host, void* userdata); -XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_set_data(h, NULL)") XBT_PUBLIC void sg_host_user_destroy(sg_host_t host); +XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_data_set(h, NULL)") XBT_PUBLIC void sg_host_user_destroy(sg_host_t host); // ========= storage related functions ============ /** @brief Return the list of mount point names on an host. diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index 04567739bb..cd258f3cd1 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -282,11 +282,11 @@ const char* MSG_host_get_name(sg_host_t host) } void* MSG_host_get_data(sg_host_t host) { - return sg_host_get_data(host); + return sg_host_data(host); } void MSG_host_set_data(sg_host_t host, void* data) { - return sg_host_set_data(host, data); + return sg_host_data_set(host, data); } xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host) { diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 64ce673799..7187920c3b 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -742,12 +742,12 @@ void sg_actor_unref(sg_actor_t actor) } /** @brief Return the user data of a #sg_actor_t */ -void* sg_actor_get_data(sg_actor_t actor) +void* sg_actor_data(sg_actor_t actor) { return actor->get_data(); } /** @brief Set the user data of a #sg_actor_t */ -void sg_actor_set_data(sg_actor_t actor, void* userdata) +void sg_actor_data_set(sg_actor_t actor, void* userdata) { actor->set_data(userdata); } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 0453276114..5e90311284 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -385,11 +385,11 @@ xbt_dynar_t sg_hosts_as_dynar() // ========= Layering madness ==============* // ========== User data Layer ========== -void* sg_host_get_data(sg_host_t host) +void* sg_host_data(sg_host_t host) { return host->get_data(); } -void sg_host_set_data(sg_host_t host, void* userdata) +void sg_host_data_set(sg_host_t host, void* userdata) { host->set_data(userdata); } -- 2.20.1