From e3e659ca834411bd56bb288223f64e7f978575b1 Mon Sep 17 00:00:00 2001 From: stchaker Date: Tue, 4 Apr 2023 16:58:28 -0400 Subject: [PATCH 1/2] avoid python C API segfault on intel mac --- include/openmc/settings.h | 7 ++++++- src/initialize.cpp | 1 + src/settings.cpp | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 806288efe..9cd2f7c2d 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -68,7 +68,12 @@ extern std::string path_input; //!< directory where main .xml files resides extern std::string path_output; //!< directory where output files are written extern std::string path_particle_restart; //!< path to a particle restart file extern std::string path_sourcepoint; //!< path to a source file -extern "C" std::string path_statepoint; //!< path to a statepoint file +extern std::string path_statepoint; //!< path to a statepoint file + +// This is required because the c_str() may not be the first thing in +// std::string. Sometimes it is, but it seems libc++ may not be like that +// on some computers, like the intel Mac. +extern "C" char const* path_statepoint_c; //!< C pointer to statepoint file name extern "C" int32_t n_inactive; //!< number of inactive batches extern "C" int32_t max_lost_particles; //!< maximum number of lost particles diff --git a/src/initialize.cpp b/src/initialize.cpp index 6383af64e..da35d4ff6 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -193,6 +193,7 @@ int parse_command_line(int argc, char* argv[]) // Set path and flag for type of run if (filetype == "statepoint") { settings::path_statepoint = argv[i]; + settings::path_statepoint_c = settings::path_statepoint.c_str(); settings::restart_run = true; } else if (filetype == "particle restart") { settings::path_particle_restart = argv[i]; diff --git a/src/settings.cpp b/src/settings.cpp index 2f8fbd1d0..cf678d404 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -82,6 +82,8 @@ std::string path_output; std::string path_particle_restart; std::string path_sourcepoint; std::string path_statepoint; +std::string empty_string = ""; +char const* path_statepoint_c {empty_string.c_str()}; int32_t n_inactive {0}; int32_t max_lost_particles {10}; From 5713ef700cd06f0059489f7ff304eeebe2c07135 Mon Sep 17 00:00:00 2001 From: stchaker Date: Thu, 20 Apr 2023 12:21:10 -0400 Subject: [PATCH 2/2] update mac segfault fix format, fix python settings name --- include/openmc/settings.h | 2 +- openmc/lib/settings.py | 2 +- src/settings.cpp | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 9cd2f7c2d..f6cbe3138 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -73,7 +73,7 @@ extern std::string path_statepoint; //!< path to a statepoint file // This is required because the c_str() may not be the first thing in // std::string. Sometimes it is, but it seems libc++ may not be like that // on some computers, like the intel Mac. -extern "C" char const* path_statepoint_c; //!< C pointer to statepoint file name +extern "C" const char* path_statepoint_c; //!< C pointer to statepoint file name extern "C" int32_t n_inactive; //!< number of inactive batches extern "C" int32_t max_lost_particles; //!< maximum number of lost particles diff --git a/openmc/lib/settings.py b/openmc/lib/settings.py index 2e9dd18df..9225c2d4e 100644 --- a/openmc/lib/settings.py +++ b/openmc/lib/settings.py @@ -56,7 +56,7 @@ class _Settings: @property def path_statepoint(self): - path = c_char_p.in_dll(_dll, 'path_statepoint').value + path = c_char_p.in_dll(_dll, 'path_statepoint_c').value return path.decode() @property diff --git a/src/settings.cpp b/src/settings.cpp index cf678d404..b0848b3b5 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -82,8 +82,7 @@ std::string path_output; std::string path_particle_restart; std::string path_sourcepoint; std::string path_statepoint; -std::string empty_string = ""; -char const* path_statepoint_c {empty_string.c_str()}; +const char* path_statepoint_c {path_statepoint.c_str()}; int32_t n_inactive {0}; int32_t max_lost_particles {10};