From fae474869c563e27e3624ae56cfab4b5f16994c7 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Wed, 5 Aug 2020 16:00:49 +0100 Subject: [PATCH] Remove external destroy method OpenMC will call delete directly on the CustomSource. --- .../parameterized_source_ring.cpp | 7 ------- include/openmc/source.h | 1 - src/source.cpp | 8 +++----- .../parameterized_source_sampling.cpp | 6 ------ 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/examples/parameterized_custom_source/parameterized_source_ring.cpp b/examples/parameterized_custom_source/parameterized_source_ring.cpp index 7b0089090..bd7bb1f6f 100644 --- a/examples/parameterized_custom_source/parameterized_source_ring.cpp +++ b/examples/parameterized_custom_source/parameterized_source_ring.cpp @@ -65,10 +65,3 @@ class ParameterizedSource : public openmc::CustomSource { extern "C" ParameterizedSource* create(const char* parameters) { return ParameterizedSource::from_string(parameters); } - -// A function to destroy a pointer to an instance of this class when generated -// via a plugin call using dlopen/dlsym. -// You must have external C linkage here otherwise dlopen will not find the file -extern "C" void destroy(ParameterizedSource* source) { - delete source; -} diff --git a/include/openmc/source.h b/include/openmc/source.h index 2492cb2b7..5bc2901b4 100644 --- a/include/openmc/source.h +++ b/include/openmc/source.h @@ -67,7 +67,6 @@ class CustomSource { }; typedef CustomSource* create_custom_source_t(const char* parameters); -typedef void destroy_custom_source_t(CustomSource*); //============================================================================== // Functions diff --git a/src/source.cpp b/src/source.cpp index fc184dc4e..4ddd3eb2a 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -50,7 +50,6 @@ sample_t custom_source_function; std::string custom_source_parameters; CustomSource* custom_source; -destroy_custom_source_t* destroy_custom_source; } @@ -380,9 +379,8 @@ void load_custom_source_library() using sample_t = Particle::Bank (*)(uint64_t* seed); custom_source_function = reinterpret_cast(dlsym(custom_source_library, "sample_source")); } else { - // get the functions to create and destroy the CustomSource from the library + // get the function to create the CustomSource from the library create_custom_source_t* create_custom_source = (create_custom_source_t*) dlsym(custom_source_library, "create"); - destroy_custom_source = (destroy_custom_source_t*) dlsym(custom_source_library, "destroy"); // create a pointer to an instance of the CustomSource custom_source = create_custom_source(custom_source_parameters.c_str()); @@ -404,8 +402,8 @@ void load_custom_source_library() void close_custom_source_library() { if (custom_source) { - // destroy the CustomSource if it exists - destroy_custom_source(custom_source); + // delete the CustomSource if it exists + delete custom_source; } #ifdef HAS_DYNAMIC_LINKING diff --git a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp index b50c9d284..3eda071e8 100644 --- a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp +++ b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp @@ -58,9 +58,3 @@ class ParameterizedSource : public openmc::CustomSource { extern "C" ParameterizedSource* create(const char* parameters) { return ParameterizedSource::from_string(parameters); } - -// you must have external C linkage here otherwise -// dlopen will not find the file -extern "C" void destroy(ParameterizedSource* source) { - delete source; -}