From 62dceedf62ca9df19fd3afee1458e21d9f211c5a Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 4 Feb 2020 13:21:51 +0100 Subject: [PATCH] Clearly state that we don't care about the return code of actors Earlier, the actor had the exact same prototype than the C main() function. In particular, it was supposed to return an integer. But that value is ignored in simgrid since years (or maybe since ever). So, change the expected return code to 'void' to make this clear and reduce the clutter in user code. The deprecation code should be in place until v3.30 for s4u code. The MSG clients are not modified, and the MSG implementation is only slightly modified with a crude cast (that mandates the -Wno-error=cast-function-type flag on the command line when compiling MSG). --- examples/c/actor-create/actor-create.c | 6 ++-- examples/c/async-waitany/async-waitany.c | 6 ++-- .../s4u/actor-create/s4u-actor-create.cpp | 3 +- examples/s4u/async-ready/s4u-async-ready.cpp | 3 +- examples/s4u/async-wait/s4u-async-wait.cpp | 6 ++-- .../async-waituntil/s4u-async-waituntil.cpp | 6 ++-- .../s4u/dht-kademlia/s4u-dht-kademlia.cpp | 35 +++++++++---------- .../s4u/io-file-remote/s4u-io-file-remote.cpp | 3 +- .../s4u-platform-failures.cpp | 6 ++-- .../smpi/replay_multiple/replay_multiple.c | 4 +-- .../masterslave_mailbox_smpi.cpp | 6 ++-- include/simgrid/engine.h | 4 +-- include/simgrid/msg.h | 10 +++--- include/simgrid/s4u/Engine.hpp | 10 ++++-- include/xbt/function_types.h | 2 +- src/bindings/java/jmsg.cpp | 30 ++++++++-------- src/kernel/EngineImpl.cpp | 12 +++++++ src/kernel/EngineImpl.hpp | 2 ++ src/msg/msg_legacy.cpp | 8 ++--- src/msg/msg_process.cpp | 12 +++---- src/s4u/s4u_Engine.cpp | 17 ++++++--- teshsuite/smpi/gh-139/gh-139.c | 3 +- tools/cmake/MakeLib.cmake | 5 +++ 23 files changed, 106 insertions(+), 93 deletions(-) diff --git a/examples/c/actor-create/actor-create.c b/examples/c/actor-create/actor-create.c index 044d4463c3..9715ea0f4f 100644 --- a/examples/c/actor-create/actor-create.c +++ b/examples/c/actor-create/actor-create.c @@ -32,7 +32,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_create, "The logging channel used in this * * One 'receiver' actor is instantiated within the simulation later in this file. */ -static int receiver(int argc, char** argv) +static void receiver(int argc, char** argv) { xbt_assert(argc == 2, "This actor expects a single argument: the mailbox on which to get messages"); sg_mailbox_t mailbox = sg_mailbox_by_name(argv[1]); @@ -44,11 +44,10 @@ static int receiver(int argc, char** argv) const char* msg3 = sg_mailbox_get(mailbox); XBT_INFO("I received '%s', '%s' and '%s'", msg1, msg2, msg3); XBT_INFO("I'm done. See you."); - return 0; } /* Our second class of actors, in charge of sending stuff */ -static int sender(int argc, char** argv) +static void sender(int argc, char** argv) { xbt_assert(argc == 3, "Actor 'sender' requires 2 parameters (mailbox and data to send), but got only %d", argc - 1); XBT_INFO("Hello s4u, I have something to send"); @@ -57,7 +56,6 @@ static int sender(int argc, char** argv) sg_mailbox_put(mailbox, xbt_strdup(sent_data), strlen(sent_data)); XBT_INFO("I'm done. See you."); - return 0; } /* Here comes the main function of your program */ diff --git a/examples/c/async-waitany/async-waitany.c b/examples/c/async-waitany/async-waitany.c index 73eaae32fd..3871f00ec1 100644 --- a/examples/c/async-waitany/async-waitany.c +++ b/examples/c/async-waitany/async-waitany.c @@ -16,7 +16,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(async_waitany, "Messages specific for this example"); -static int sender(int argc, char* argv[]) +static void sender(int argc, char* argv[]) { xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc); long messages_count = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s"); @@ -77,10 +77,9 @@ static int sender(int argc, char* argv[]) free(mboxes); XBT_INFO("Goodbye now!"); - return 0; } -static int receiver(int argc, char* argv[]) +static void receiver(int argc, char* argv[]) { xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc); int id = xbt_str_parse_int(argv[1], "ID should be numerical, not %s"); @@ -99,7 +98,6 @@ static int receiver(int argc, char* argv[]) } XBT_INFO("I'm done. See you!"); - return 0; } int main(int argc, char* argv[]) diff --git a/examples/s4u/actor-create/s4u-actor-create.cpp b/examples/s4u/actor-create/s4u-actor-create.cpp index 9809d5f14d..bff3790308 100644 --- a/examples/s4u/actor-create/s4u-actor-create.cpp +++ b/examples/s4u/actor-create/s4u-actor-create.cpp @@ -44,7 +44,7 @@ static void receiver(const std::string& mailbox_name) } /* Our second class of actors is also a function */ -static int forwarder(int argc, char** argv) +static void forwarder(int argc, char** argv) { xbt_assert(argc >= 3, "Actor forwarder requires 2 parameters, but got only %d", argc - 1); simgrid::s4u::Mailbox* in = simgrid::s4u::Mailbox::by_name(argv[1]); @@ -52,7 +52,6 @@ static int forwarder(int argc, char** argv) std::string* msg = static_cast(in->get()); XBT_INFO("Forward '%s'.", msg->c_str()); out->put(msg, msg->size()); - return 0; } /* Declares a third class of actors which sends a message to the mailbox 'mb42'. diff --git a/examples/s4u/async-ready/s4u-async-ready.cpp b/examples/s4u/async-ready/s4u-async-ready.cpp index 8bebb5087b..6745ee3b0b 100644 --- a/examples/s4u/async-ready/s4u-async-ready.cpp +++ b/examples/s4u/async-ready/s4u-async-ready.cpp @@ -25,7 +25,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_ready, "Messages specific for this s4u example"); -static int peer(int argc, char** argv) +static void peer(int argc, char** argv) { xbt_assert(argc == 5, "Expecting 4 parameters from the XML deployment file but got %d", argc); int my_id = std::stoi(argv[1]); /* - my id */ @@ -90,7 +90,6 @@ static int peer(int argc, char** argv) simgrid::s4u::Comm::wait_all(&pending_comms); XBT_INFO("Goodbye now!"); - return 0; } diff --git a/examples/s4u/async-wait/s4u-async-wait.cpp b/examples/s4u/async-wait/s4u-async-wait.cpp index 8dec9667cb..03da3fd142 100644 --- a/examples/s4u/async-wait/s4u-async-wait.cpp +++ b/examples/s4u/async-wait/s4u-async-wait.cpp @@ -18,7 +18,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_wait, "Messages specific for this s4u example"); -static int sender(int argc, char** argv) +static void sender(int argc, char** argv) { xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc); long messages_count = std::stol(argv[1]); /* - number of tasks */ @@ -63,11 +63,10 @@ static int sender(int argc, char** argv) } XBT_INFO("Goodbye now!"); - return 0; } /* Receiver actor expects 1 argument: its ID */ -static int receiver(int argc, char** argv) +static void receiver(int argc, char** argv) { xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc); simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(std::string("receiver-") + argv[1]); @@ -80,7 +79,6 @@ static int receiver(int argc, char** argv) cont = false; // If it's a finalize message, we're done. delete received; } - return 0; } int main(int argc, char *argv[]) diff --git a/examples/s4u/async-waituntil/s4u-async-waituntil.cpp b/examples/s4u/async-waituntil/s4u-async-waituntil.cpp index ae9039f4fa..bce6ec6309 100644 --- a/examples/s4u/async-waituntil/s4u-async-waituntil.cpp +++ b/examples/s4u/async-waituntil/s4u-async-waituntil.cpp @@ -17,7 +17,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_waituntil, "Messages specific for this s4u example"); -static int sender(int argc, char** argv) +static void sender(int argc, char** argv) { xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc); long messages_count = std::stol(argv[1]); /* - number of tasks */ @@ -61,11 +61,10 @@ static int sender(int argc, char** argv) } XBT_INFO("Goodbye now!"); - return 0; } /* Receiver actor expects 1 argument: its ID */ -static int receiver(int argc, char** argv) +static void receiver(int argc, char** argv) { xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc); simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(std::string("receiver-") + argv[1]); @@ -78,7 +77,6 @@ static int receiver(int argc, char** argv) cont = false; // If it's a finalize message, we're done. delete received; } - return 0; } int main(int argc, char* argv[]) diff --git a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp index 50349e1b88..ac5231cf8a 100644 --- a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp +++ b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp @@ -17,53 +17,53 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(kademlia, "Messages specific for this example"); * @param the ID of the person I know in the system (or not) * @param Time before I leave the system because I'm bored */ -static int node(int argc, char* argv[]) +static void node(int argc, char* argv[]) { bool join_success = true; double deadline; xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments"); /* Node initialization */ unsigned int node_id = strtoul(argv[1], nullptr, 0); - kademlia::Node* node = new kademlia::Node(node_id); + kademlia::Node node(node_id); if (argc == 4) { - XBT_INFO("Hi, I'm going to join the network with id %u", node->getId()); + XBT_INFO("Hi, I'm going to join the network with id %u", node.getId()); unsigned int known_id = strtoul(argv[2], NULL, 0); - join_success = node->join(known_id); + join_success = node.join(known_id); deadline = std::stod(argv[3]); } else { deadline = std::stod(argv[2]); - XBT_INFO("Hi, I'm going to create the network with id %u", node->getId()); - node->routingTableUpdate(node->getId()); + XBT_INFO("Hi, I'm going to create the network with id %u", node.getId()); + node.routingTableUpdate(node.getId()); } if (join_success) { - XBT_VERB("Ok, I'm joining the network with id %u", node->getId()); + XBT_VERB("Ok, I'm joining the network with id %u", node.getId()); // We start the main loop double next_lookup_time = simgrid::s4u::Engine::get_clock() + RANDOM_LOOKUP_INTERVAL; XBT_VERB("Main loop start"); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(node->getId())); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(node.getId())); while (simgrid::s4u::Engine::get_clock() < deadline) { - if (node->receive_comm == nullptr) - node->receive_comm = mailbox->get_async(&node->received_msg); + if (node.receive_comm == nullptr) + node.receive_comm = mailbox->get_async(&node.received_msg); - if (node->receive_comm->test()) { + if (node.receive_comm->test()) { // There has been a message, we need to handle it ! - const kademlia::Message* msg = static_cast(node->received_msg); + const kademlia::Message* msg = static_cast(node.received_msg); if (msg) { - node->handleFindNode(msg); + node.handleFindNode(msg); delete msg->answer_; delete msg; - node->receive_comm = nullptr; + node.receive_comm = nullptr; } else simgrid::s4u::this_actor::sleep_for(1); } else { /* We search for a pseudo random node */ if (simgrid::s4u::Engine::get_clock() >= next_lookup_time) { - node->randomLookup(); + node.randomLookup(); next_lookup_time += RANDOM_LOOKUP_INTERVAL; } else { // Didn't get a message: sleep for a while... @@ -75,10 +75,7 @@ static int node(int argc, char* argv[]) XBT_INFO("I couldn't join the network :("); } XBT_DEBUG("I'm leaving the network"); - XBT_INFO("%u/%u FIND_NODE have succeeded", node->find_node_success, node->find_node_success + node->find_node_failed); - delete node; - - return 0; + XBT_INFO("%u/%u FIND_NODE have succeeded", node.find_node_success, node.find_node_success + node.find_node_failed); } /** @brief Main function */ diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp index 7994ee00b7..a3b2fd919f 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp @@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example"); -static int host(int argc, char* argv[]) +static void host(int argc, char* argv[]) { simgrid::s4u::File file(argv[1], nullptr); const char* filename = file.get_path(); @@ -32,7 +32,6 @@ static int host(int argc, char* argv[]) file.remote_copy(simgrid::s4u::Host::by_name(argv[2]), argv[3]); } } - return 0; } int main(int argc, char** argv) diff --git a/examples/s4u/platform-failures/s4u-platform-failures.cpp b/examples/s4u/platform-failures/s4u-platform-failures.cpp index e33bdbd201..68a2211610 100644 --- a/examples/s4u/platform-failures/s4u-platform-failures.cpp +++ b/examples/s4u/platform-failures/s4u-platform-failures.cpp @@ -22,7 +22,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); -static int master(int argc, char* argv[]) +static void master(int argc, char* argv[]) { xbt_assert(argc == 5, "Expecting one parameter"); @@ -67,10 +67,9 @@ static int master(int argc, char* argv[]) } XBT_INFO("Goodbye now!"); - return 0; } -static int worker(int argc, char* argv[]) +static void worker(int argc, char* argv[]) { xbt_assert(argc == 2, "Expecting one parameter"); long id = xbt_str_parse_int(argv[1], "Invalid argument %s"); @@ -96,7 +95,6 @@ static int worker(int argc, char* argv[]) XBT_INFO("Mmh. Something went wrong. Nevermind. Let's keep going!"); } } - return 0; } int main(int argc, char* argv[]) diff --git a/examples/smpi/replay_multiple/replay_multiple.c b/examples/smpi/replay_multiple/replay_multiple.c index 6bf7d76f3a..7ad646ea34 100644 --- a/examples/smpi/replay_multiple/replay_multiple.c +++ b/examples/smpi/replay_multiple/replay_multiple.c @@ -13,7 +13,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); -static int smpi_replay(int argc, char *argv[]) { +static void smpi_replay(int argc, char* argv[]) +{ const char* instance_id = argv[1]; int rank = xbt_str_parse_int(argv[2], "Cannot parse rank '%s'"); const char* trace_filename = argv[3]; @@ -24,7 +25,6 @@ static int smpi_replay(int argc, char *argv[]) { } smpi_replay_run(instance_id, rank, start_delay_flops, trace_filename); - return 0; } int main(int argc, char *argv[]){ diff --git a/examples/smpi/smpi_s4u_masterslave/masterslave_mailbox_smpi.cpp b/examples/smpi/smpi_s4u_masterslave/masterslave_mailbox_smpi.cpp index 79039ffc1e..a786889f33 100644 --- a/examples/smpi/smpi_s4u_masterslave/masterslave_mailbox_smpi.cpp +++ b/examples/smpi/smpi_s4u_masterslave/masterslave_mailbox_smpi.cpp @@ -61,7 +61,7 @@ static void worker(std::vector args) XBT_INFO("Exiting now."); } -static int master_mpi(int argc, char* argv[]) +static void master_mpi(int argc, char* argv[]) { MPI_Init(&argc, &argv); @@ -78,10 +78,9 @@ static int master_mpi(int argc, char* argv[]) MPI_Finalize(); XBT_INFO("After finalize %d %d", rank, test[0]); - return 0; } -static int alltoall_mpi(int argc, char* argv[]) +static void alltoall_mpi(int argc, char* argv[]) { MPI_Init(&argc, &argv); @@ -96,7 +95,6 @@ static int alltoall_mpi(int argc, char* argv[]) XBT_INFO("after alltoall %d", rank); MPI_Finalize(); - return 0; } int main(int argc, char* argv[]) diff --git a/include/simgrid/engine.h b/include/simgrid/engine.h index 736ba3b770..95b9ae48ca 100644 --- a/include/simgrid/engine.h +++ b/include/simgrid/engine.h @@ -29,13 +29,13 @@ XBT_PUBLIC void simgrid_load_deployment(const char* filename); /** Run the simulation after initialization */ XBT_PUBLIC void simgrid_run(); /** Registers the main function of an actor that will be launched from the deployment file */ -XBT_PUBLIC void simgrid_register_function(const char* name, int (*code)(int, char**)); +XBT_PUBLIC void simgrid_register_function(const char* name, void (*code)(int, char**)); /** Registers a function as the default main function of actors * * It will be used as fallback when the function requested from the deployment file was not registered. * It is used for trace-based simulations (see examples/s4u/replay-comms and similar). */ -XBT_PUBLIC void simgrid_register_default(int (*code)(int, char**)); +XBT_PUBLIC void simgrid_register_default(void (*code)(int, char**)); /** Retrieve the simulation time (in seconds) */ XBT_PUBLIC double simgrid_get_clock(); /** Retrieve the number of actors in the simulation */ diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 70bc569741..a9b2830b20 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -300,7 +300,7 @@ XBT_PUBLIC msg_error_t MSG_main(); * @param code the function (must have the same prototype than the main function of any C program: int ..(int argc, char * *argv[])) */ -XBT_PUBLIC void MSG_function_register(const char* name, xbt_main_func_t code); +XBT_PUBLIC void MSG_function_register(const char* name, int (*code)(int, char**)); /** @brief Registers a code function as being the default value. * * This function will get used by MSG_launch_application() when there is no registered function of the requested name @@ -309,7 +309,7 @@ XBT_PUBLIC void MSG_function_register(const char* name, xbt_main_func_t code); * @param code the function (must have the same prototype than the main function of any C program: int ..(int argc, char * *argv[])) */ -XBT_PUBLIC void MSG_function_register_default(xbt_main_func_t code); +XBT_PUBLIC void MSG_function_register_default(int (*code)(int, char**)); /** @brief Creates a new platform, including hosts, links and the routing_table */ XBT_PUBLIC void MSG_create_environment(const char* file); /** @brief Creates the application described in the provided file */ @@ -327,10 +327,10 @@ XBT_PUBLIC double MSG_get_clock(); XBT_PUBLIC unsigned long int MSG_get_sent_msg(); /************************** Process handling *********************************/ -XBT_PUBLIC msg_process_t MSG_process_create(const char* name, xbt_main_func_t code, void* data, msg_host_t host); -XBT_PUBLIC msg_process_t MSG_process_create_with_arguments(const char* name, xbt_main_func_t code, void* data, +XBT_PUBLIC msg_process_t MSG_process_create(const char* name, int (*code)(int, char**), void* data, msg_host_t host); +XBT_PUBLIC msg_process_t MSG_process_create_with_arguments(const char* name, int (*code)(int, char**), void* data, msg_host_t host, int argc, char** argv); -XBT_PUBLIC msg_process_t MSG_process_create_with_environment(const char* name, xbt_main_func_t code, void* data, +XBT_PUBLIC msg_process_t MSG_process_create_with_environment(const char* name, int (*code)(int, char**), void* data, msg_host_t host, int argc, char** argv, xbt_dict_t properties); diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 6cc8c60a2f..f62b955895 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -48,9 +48,15 @@ public: void load_platform(const std::string& platf); - void register_function(const std::string& name, int (*code)(int, char**)); + XBT_ATTRIB_DEPRECATED_v330("Please change the return code of your actors to void") void register_function( + const std::string& name, int (*code)(int, char**)); + + void register_function(const std::string& name, void (*code)(int, char**)); void register_function(const std::string& name, void (*code)(std::vector)); - void register_default(int (*code)(int, char**)); + + XBT_ATTRIB_DEPRECATED_v330("Please change the return code of your actors to void") void register_default( + int (*code)(int, char**)); + void register_default(void (*code)(int, char**)); template void register_actor(const std::string& name) { diff --git a/include/xbt/function_types.h b/include/xbt/function_types.h index 9bd7432906..4fb25ef779 100644 --- a/include/xbt/function_types.h +++ b/include/xbt/function_types.h @@ -21,7 +21,7 @@ typedef int (*int_f_int_pvoid_t)(int, void*); typedef int (*int_f_pvoid_pvoid_t) (void *, void *); typedef int (*int_f_cpvoid_cpvoid_t) (const void *, const void *); -typedef int (*xbt_main_func_t) (int argc, char *argv[]); +typedef void (*xbt_main_func_t)(int argc, char* argv[]); SG_END_DECL #endif /* XBT_FUNCTION_TYPE_H */ diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 9533b5f4ad..2f1d5d75a8 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -82,12 +82,12 @@ void jmsg_throw_status(JNIEnv *env, msg_error_t status) { * Unsortable functions * ***************************************************************************************/ -JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls) +JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Msg_getClock(JNIEnv*, jclass) { return (jdouble) MSG_get_clock(); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv* env, jclass, jobjectArray jargs) { env->GetJavaVM(&__java_vm); @@ -131,7 +131,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j JAVA_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr); } -JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) +JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv* env, jclass) { /* Run everything */ XBT_DEBUG("Ready to run MSG_MAIN"); @@ -162,7 +162,7 @@ JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass env->CallStaticVoidMethod(clsProcess, idDebug); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls, jstring jplatformFile) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv* env, jclass, jstring jplatformFile) { const char *platformFile = env->GetStringUTFChars(jplatformFile, 0); @@ -171,7 +171,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, env->ReleaseStringUTFChars(jplatformFile, platformFile); } -JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv * env, jclass cls) +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv* env, jclass) { msg_netzone_t as = MSG_zone_get_root(); jobject jas = jnetzone_new_instance(env); @@ -189,52 +189,51 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNI return (jobject) jas; } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_debug(JNIEnv * env, jclass cls, jstring js) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_debug(JNIEnv* env, jclass, jstring js) { const char *s = env->GetStringUTFChars(js, 0); XBT_DEBUG("%s", s); env->ReleaseStringUTFChars(js, s); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_verb(JNIEnv * env, jclass cls, jstring js) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_verb(JNIEnv* env, jclass, jstring js) { const char *s = env->GetStringUTFChars(js, 0); XBT_VERB("%s", s); env->ReleaseStringUTFChars(js, s); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_info(JNIEnv* env, jclass, jstring js) { const char *s = env->GetStringUTFChars(js, 0); XBT_INFO("%s", s); env->ReleaseStringUTFChars(js, s); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_warn(JNIEnv * env, jclass cls, jstring js) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_warn(JNIEnv* env, jclass, jstring js) { const char *s = env->GetStringUTFChars(js, 0); XBT_WARN("%s", s); env->ReleaseStringUTFChars(js, s); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_error(JNIEnv * env, jclass cls, jstring js) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_error(JNIEnv* env, jclass, jstring js) { const char *s = env->GetStringUTFChars(js, 0); XBT_ERROR("%s", s); env->ReleaseStringUTFChars(js, s); } -JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_critical(JNIEnv * env, jclass cls, jstring js) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_critical(JNIEnv* env, jclass, jstring js) { const char *s = env->GetStringUTFChars(js, 0); XBT_CRITICAL("%s", s); env->ReleaseStringUTFChars(js, s); } -static int java_main(int argc, char *argv[]); +static void java_main(int argc, char* argv[]); -JNIEXPORT void JNICALL -Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, jstring jdeploymentFile) +JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_deployApplication(JNIEnv* env, jclass, jstring jdeploymentFile) { const char *deploymentFile = env->GetStringUTFChars(jdeploymentFile, 0); @@ -282,7 +281,7 @@ static void run_jprocess(JNIEnv *env, jobject jprocess) } /** Create a Java org.simgrid.msg.Process with the arguments and run it */ -static int java_main(int argc, char *argv[]) +static void java_main(int argc, char* argv[]) { JNIEnv *env = get_current_thread_env(); simgrid::kernel::context::JavaContext* context = @@ -321,7 +320,6 @@ static int java_main(int argc, char *argv[]) jprocess_bind(jprocess, process, env); run_jprocess(env, context->jprocess_); - return 0; } namespace simgrid { diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 07e5ab61e5..e8c223566d 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -48,6 +48,12 @@ void EngineImpl::load_deployment(const std::string& file) surf_parse(); surf_parse_close(); } +void EngineImpl::register_function(const std::string& name, int (*code)(int, char**)) // deprecated +{ + simix_global->registered_functions[name] = [code](std::vector args) { + return xbt::wrap_main(code, std::move(args)); + }; +} void EngineImpl::register_function(const std::string& name, xbt_main_func_t code) { simix_global->registered_functions[name] = [code](std::vector args) { @@ -62,6 +68,12 @@ void EngineImpl::register_function(const std::string& name, void (*code)(std::ve }; } +void EngineImpl::register_default(int (*code)(int, char**)) // deprecated +{ + simix_global->default_function = [code](std::vector args) { + return xbt::wrap_main(code, std::move(args)); + }; +} void EngineImpl::register_default(xbt_main_func_t code) { simix_global->default_function = [code](std::vector args) { diff --git a/src/kernel/EngineImpl.hpp b/src/kernel/EngineImpl.hpp index 386e921edb..cf4828ff1c 100644 --- a/src/kernel/EngineImpl.hpp +++ b/src/kernel/EngineImpl.hpp @@ -27,8 +27,10 @@ public: virtual ~EngineImpl(); void load_deployment(const std::string& file); + void register_function(const std::string& name, int (*code)(int, char**)); // deprecated void register_function(const std::string& name, xbt_main_func_t code); void register_function(const std::string& name, void (*code)(std::vector)); + void register_default(int (*code)(int, char**)); // deprecated void register_default(xbt_main_func_t code); routing::NetZoneImpl* netzone_root_ = nullptr; diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index da208dd5a5..93d126e2d9 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -23,13 +23,13 @@ msg_error_t MSG_main() simgrid_run(); return MSG_OK; } -void MSG_function_register(const char* name, xbt_main_func_t code) +void MSG_function_register(const char* name, int (*code)(int, char**)) { - simgrid_register_function(name, code); + simgrid_register_function(name, (void (*)(int, char**))code); } -void MSG_function_register_default(xbt_main_func_t code) +void MSG_function_register_default(int (*code)(int, char**)) { - simgrid_register_default(code); + simgrid_register_default((void (*)(int, char**))code); } double MSG_get_clock() { diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index fc52b04fbf..9b53e16a7f 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -14,7 +14,7 @@ * Does exactly the same as #MSG_process_create_with_arguments but without providing standard arguments * (@a argc, @a argv, @a start_time, @a kill_time). */ -msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host) +msg_process_t MSG_process_create(const char* name, int (*code)(int, char**), void* data, msg_host_t host) { return MSG_process_create_with_environment(name == nullptr ? "" : name, code, data, host, 0, nullptr, nullptr); } @@ -32,8 +32,8 @@ msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *d * @param argv second argument passed to @a code */ -msg_process_t MSG_process_create_with_arguments(const char *name, xbt_main_func_t code, void *data, msg_host_t host, - int argc, char **argv) +msg_process_t MSG_process_create_with_arguments(const char* name, int (*code)(int, char**), void* data, msg_host_t host, + int argc, char** argv) { return MSG_process_create_with_environment(name, code, data, host, argc, argv, nullptr); } @@ -55,8 +55,8 @@ msg_process_t MSG_process_create_with_arguments(const char *name, xbt_main_func_ * @see msg_process_t * @return The new corresponding object. */ -msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host, - int argc, char **argv, xbt_dict_t properties) +msg_process_t MSG_process_create_with_environment(const char* name, int (*code)(int, char**), void* data, + msg_host_t host, int argc, char** argv, xbt_dict_t properties) { xbt_assert(host != nullptr, "Invalid parameters: host param must not be nullptr"); sg_actor_t actor = sg_actor_init(std::move(name), host); @@ -70,7 +70,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun xbt_dict_foreach (properties, cursor, key, value) actor->set_property(key, value); } - sg_actor_start(actor, code, argc, argv); + sg_actor_start(actor, (void (*)(int, char**))code, argc, argv); } catch (simgrid::HostFailureException const&) { xbt_die("Could not launch a new process on failed host %s.", host->get_cname()); } diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 6b00aa9695..78e4b4b00e 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -90,8 +90,17 @@ void Engine::load_platform(const std::string& platf) XBT_DEBUG("PARSE TIME: %g", (end - start)); } +void Engine::register_function(const std::string& name, int (*code)(int, char**)) // deprecated +{ + pimpl->register_function(name, code); +} +void Engine::register_default(int (*code)(int, char**)) // deprecated +{ + pimpl->register_default(code); +} + /** Registers the main function of an actor that will be launched from the deployment file */ -void Engine::register_function(const std::string& name, int (*code)(int, char**)) +void Engine::register_function(const std::string& name, void (*code)(int, char**)) { pimpl->register_function(name, code); } @@ -106,7 +115,7 @@ void Engine::register_function(const std::string& name, void (*code)(std::vector * It will be used as fallback when the function requested from the deployment file was not registered. * It is used for trace-based simulations (see examples/s4u/replay-comms and similar). */ -void Engine::register_default(int (*code)(int, char**)) +void Engine::register_default(void (*code)(int, char**)) { pimpl->register_default(code); } @@ -403,11 +412,11 @@ void simgrid_run() { simgrid::s4u::Engine::get_instance()->run(); } -void simgrid_register_function(const char* name, int (*code)(int, char**)) +void simgrid_register_function(const char* name, void (*code)(int, char**)) { simgrid::s4u::Engine::get_instance()->register_function(name, code); } -void simgrid_register_default(int (*code)(int, char**)) +void simgrid_register_default(void (*code)(int, char**)) { simgrid::s4u::Engine::get_instance()->register_default(code); } diff --git a/teshsuite/smpi/gh-139/gh-139.c b/teshsuite/smpi/gh-139/gh-139.c index 69a127f8bd..6a9d436aa8 100644 --- a/teshsuite/smpi/gh-139/gh-139.c +++ b/teshsuite/smpi/gh-139/gh-139.c @@ -27,7 +27,7 @@ void* req_wait(void* bar); // Thread creation helper -static int thread_create_wrapper(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) +static void thread_create_wrapper(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) { int the_global_rank = global_rank; struct threadwrap* t = (struct threadwrap*)sg_actor_self_data(); @@ -37,7 +37,6 @@ static int thread_create_wrapper(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED c t->f(t->param); sg_actor_self_data_set(NULL); free(t); - return 0; } static void mpi_thread_create(const char* name, void* (*f)(void*), void* param) diff --git a/tools/cmake/MakeLib.cmake b/tools/cmake/MakeLib.cmake index b29b5921d7..38890f4d1c 100644 --- a/tools/cmake/MakeLib.cmake +++ b/tools/cmake/MakeLib.cmake @@ -24,6 +24,11 @@ set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version}) set_property(TARGET simgrid APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") +# Don't complain when we cast (int (*)(int,char**)) into (void(*)(int,char**)) +# This will stop when MSG goes away +set_property(SOURCE ${CMAKE_HOME_DIRECTORY}/src/msg/msg_legacy.cpp PROPERTY COMPILE_FLAGS -Wno-error=cast-function-type) +set_property(SOURCE ${CMAKE_HOME_DIRECTORY}/src/msg/msg_process.cpp PROPERTY COMPILE_FLAGS -Wno-error=cast-function-type) + add_dependencies(simgrid maintainer_files) if(enable_model-checking) -- 2.20.1