From d8c3a0a3bcd89a0bf393ae3c6aa9826fe8f383e3 Mon Sep 17 00:00:00 2001 From: Joana Niermann Date: Sun, 12 Jan 2025 16:07:30 +0100 Subject: [PATCH] fix nullptr dereferencing warning --- .../detray/builders/surface_factory_interface.hpp | 12 +++++++++++- core/include/detray/core/detail/type_traits.hpp | 2 -- io/CMakeLists.txt | 1 + io/include/detray/io/backend/concepts.hpp | 1 - io/include/detray/io/backend/detail/type_info.hpp | 6 +++--- .../frontend/detail/detector_components_writer.hpp | 2 +- io/include/detray/io/frontend/impl/json_readers.hpp | 2 +- io/include/detray/io/frontend/impl/json_writers.hpp | 4 +--- .../detray/io/json/{ => detail}/json_algebra_io.hpp | 0 .../detray/io/json/{ => detail}/json_common_io.hpp | 0 .../detray/io/json/{ => detail}/json_geometry_io.hpp | 6 +++--- .../detray/io/json/{ => detail}/json_grids_io.hpp | 4 ++-- .../detray/io/json/{ => detail}/json_material_io.hpp | 2 +- io/include/detray/io/json/json_io.hpp | 10 +++++----- .../io/io_json_detector_roundtrip.cpp | 9 ++++----- tests/unit_tests/io/io_json_detector_writer.cpp | 10 +++++----- 16 files changed, 38 insertions(+), 33 deletions(-) rename io/include/detray/io/json/{ => detail}/json_algebra_io.hpp (100%) rename io/include/detray/io/json/{ => detail}/json_common_io.hpp (100%) rename io/include/detray/io/json/{ => detail}/json_geometry_io.hpp (96%) rename io/include/detray/io/json/{ => detail}/json_grids_io.hpp (97%) rename io/include/detray/io/json/{ => detail}/json_material_io.hpp (98%) diff --git a/core/include/detray/builders/surface_factory_interface.hpp b/core/include/detray/builders/surface_factory_interface.hpp index b7d592236..c4685bed7 100644 --- a/core/include/detray/builders/surface_factory_interface.hpp +++ b/core/include/detray/builders/surface_factory_interface.hpp @@ -7,6 +7,11 @@ #pragma once +// TODO: Remove this when gcc fixes their false positives. +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic warning "-Wnull-dereference" +#endif + // Project include(s). #include "detray/definitions/detail/indexing.hpp" #include "detray/definitions/detail/qualifiers.hpp" @@ -14,6 +19,7 @@ // System include(s) #include +#include #include #include @@ -160,7 +166,11 @@ class factory_decorator : public surface_factory_interface { explicit factory_decorator( std::unique_ptr> factory) : m_factory(std::move(factory)) { - assert(m_factory != nullptr); + if (m_factory == nullptr || m_factory.get() == nullptr) { + throw std::runtime_error( + "Surface factory decorator constructed with invalid base " + "factory"); + } } /// @returns access to the underlying factory - const diff --git a/core/include/detray/core/detail/type_traits.hpp b/core/include/detray/core/detail/type_traits.hpp index feddd771b..9c5fd96f3 100644 --- a/core/include/detray/core/detail/type_traits.hpp +++ b/core/include/detray/core/detail/type_traits.hpp @@ -8,8 +8,6 @@ #pragma once // Project include(s) -#include "detray/core/detail/type_traits.hpp" -#include "detray/definitions/detail/indexing.hpp" #include "detray/materials/detail/concepts.hpp" #include "detray/materials/material_rod.hpp" #include "detray/materials/material_slab.hpp" diff --git a/io/CMakeLists.txt b/io/CMakeLists.txt index ac7868399..08962d49f 100644 --- a/io/CMakeLists.txt +++ b/io/CMakeLists.txt @@ -28,6 +28,7 @@ file( "include/detray/io/frontend/detail/*.hpp" "include/detray/io/frontend/impl/*.hpp" "include/detray/io/json/*.hpp" + "include/detray/io/json/detail/*.hpp" ) detray_add_library( detray_io io ${_detray_io_public_headers} diff --git a/io/include/detray/io/backend/concepts.hpp b/io/include/detray/io/backend/concepts.hpp index f9f0d2549..c0eb944d1 100644 --- a/io/include/detray/io/backend/concepts.hpp +++ b/io/include/detray/io/backend/concepts.hpp @@ -9,7 +9,6 @@ // Project include(s) #include "detray/builders/detector_builder.hpp" -#include "detray/utils/type_traits.hpp" // System include(s) #include diff --git a/io/include/detray/io/backend/detail/type_info.hpp b/io/include/detray/io/backend/detail/type_info.hpp index 7310279e6..e4480ab96 100644 --- a/io/include/detray/io/backend/detail/type_info.hpp +++ b/io/include/detray/io/backend/detail/type_info.hpp @@ -48,7 +48,7 @@ get_id() { } /// Infer the IO material id from the material type - homogeneous material -template +template constexpr io::material_id get_id() { using scalar_t = typename material_t::scalar_type; @@ -67,7 +67,7 @@ constexpr io::material_id get_id() { } /// Infer the IO material id from the material type - material maps -template +template constexpr io::material_id get_id() { using map_frame_t = typename material_t::local_frame_type; @@ -88,7 +88,7 @@ constexpr io::material_id get_id() { } /// Infer the grid id from its coordinate system -template +template constexpr io::accel_id get_id() { using frame_t = typename grid_t::local_frame_type; diff --git a/io/include/detray/io/frontend/detail/detector_components_writer.hpp b/io/include/detray/io/frontend/detail/detector_components_writer.hpp index e621a5158..3d2289fff 100644 --- a/io/include/detray/io/frontend/detail/detector_components_writer.hpp +++ b/io/include/detray/io/frontend/detail/detector_components_writer.hpp @@ -39,7 +39,7 @@ class detector_components_writer final { /// Create a new writer of type @tparam writer_t template - /*requires std::is_base_of_v, writer_t>*/ void + requires std::is_base_of_v, writer_t> void add() { add(std::make_unique()); } diff --git a/io/include/detray/io/frontend/impl/json_readers.hpp b/io/include/detray/io/frontend/impl/json_readers.hpp index 49cd50a8f..23dbbab01 100644 --- a/io/include/detray/io/frontend/impl/json_readers.hpp +++ b/io/include/detray/io/frontend/impl/json_readers.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/io/backend/concepts.hpp" +#include "detray/core/concepts.hpp" #include "detray/io/backend/geometry_reader.hpp" #include "detray/io/backend/homogeneous_material_reader.hpp" #include "detray/io/backend/material_map_reader.hpp" diff --git a/io/include/detray/io/frontend/impl/json_writers.hpp b/io/include/detray/io/frontend/impl/json_writers.hpp index 1e46dcfb5..c7fbaba58 100644 --- a/io/include/detray/io/frontend/impl/json_writers.hpp +++ b/io/include/detray/io/frontend/impl/json_writers.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/io/backend/concepts.hpp" +#include "detray/core/concepts.hpp" #include "detray/io/backend/geometry_writer.hpp" #include "detray/io/backend/homogeneous_material_writer.hpp" #include "detray/io/backend/material_map_writer.hpp" @@ -31,8 +31,6 @@ void add_json_writers(detector_components_writer& writers, // Always needed using json_geometry_writer = json_converter; - static_assert( - io::concepts::writer_backend); writers.template add(); // Find other writers, depending on the detector type diff --git a/io/include/detray/io/json/json_algebra_io.hpp b/io/include/detray/io/json/detail/json_algebra_io.hpp similarity index 100% rename from io/include/detray/io/json/json_algebra_io.hpp rename to io/include/detray/io/json/detail/json_algebra_io.hpp diff --git a/io/include/detray/io/json/json_common_io.hpp b/io/include/detray/io/json/detail/json_common_io.hpp similarity index 100% rename from io/include/detray/io/json/json_common_io.hpp rename to io/include/detray/io/json/detail/json_common_io.hpp diff --git a/io/include/detray/io/json/json_geometry_io.hpp b/io/include/detray/io/json/detail/json_geometry_io.hpp similarity index 96% rename from io/include/detray/io/json/json_geometry_io.hpp rename to io/include/detray/io/json/detail/json_geometry_io.hpp index ac9dd423e..d003bc983 100644 --- a/io/include/detray/io/json/json_geometry_io.hpp +++ b/io/include/detray/io/json/detail/json_geometry_io.hpp @@ -9,10 +9,10 @@ // Project include(s) #include "detray/io/frontend/payloads.hpp" +#include "detray/io/json/detail/json_algebra_io.hpp" +#include "detray/io/json/detail/json_common_io.hpp" +#include "detray/io/json/detail/json_grids_io.hpp" #include "detray/io/json/json.hpp" -#include "detray/io/json/json_algebra_io.hpp" -#include "detray/io/json/json_common_io.hpp" -#include "detray/io/json/json_grids_io.hpp" // System include(s) #include diff --git a/io/include/detray/io/json/json_grids_io.hpp b/io/include/detray/io/json/detail/json_grids_io.hpp similarity index 97% rename from io/include/detray/io/json/json_grids_io.hpp rename to io/include/detray/io/json/detail/json_grids_io.hpp index 43bd2c41b..e8870ba1b 100644 --- a/io/include/detray/io/json/json_grids_io.hpp +++ b/io/include/detray/io/json/detail/json_grids_io.hpp @@ -10,9 +10,9 @@ // Project include(s). #include "detray/definitions/grid_axis.hpp" #include "detray/io/frontend/payloads.hpp" +#include "detray/io/json/detail/json_algebra_io.hpp" +#include "detray/io/json/detail/json_common_io.hpp" #include "detray/io/json/json.hpp" -#include "detray/io/json/json_algebra_io.hpp" -#include "detray/io/json/json_common_io.hpp" // System include(s). #include diff --git a/io/include/detray/io/json/json_material_io.hpp b/io/include/detray/io/json/detail/json_material_io.hpp similarity index 98% rename from io/include/detray/io/json/json_material_io.hpp rename to io/include/detray/io/json/detail/json_material_io.hpp index b4b45a11c..eddc8a656 100644 --- a/io/include/detray/io/json/json_material_io.hpp +++ b/io/include/detray/io/json/detail/json_material_io.hpp @@ -9,8 +9,8 @@ // Project include(s) #include "detray/io/frontend/payloads.hpp" +#include "detray/io/json/detail/json_common_io.hpp" #include "detray/io/json/json.hpp" -#include "detray/io/json/json_common_io.hpp" // System include(s) #include diff --git a/io/include/detray/io/json/json_io.hpp b/io/include/detray/io/json/json_io.hpp index f16f865cf..0b54937da 100644 --- a/io/include/detray/io/json/json_io.hpp +++ b/io/include/detray/io/json/json_io.hpp @@ -1,13 +1,13 @@ /** Detray library, part of the ACTS project (R&D line) * - * (c) 2022-2023 CERN for the benefit of the ACTS project + * (c) 2022-2025 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ #pragma once -#include "detray/io/json/json_algebra_io.hpp" -#include "detray/io/json/json_geometry_io.hpp" -#include "detray/io/json/json_grids_io.hpp" -#include "detray/io/json/json_material_io.hpp" +#include "detray/io/json/detail/json_algebra_io.hpp" +#include "detray/io/json/detail/json_geometry_io.hpp" +#include "detray/io/json/detail/json_grids_io.hpp" +#include "detray/io/json/detail/json_material_io.hpp" diff --git a/tests/integration_tests/io/io_json_detector_roundtrip.cpp b/tests/integration_tests/io/io_json_detector_roundtrip.cpp index 5d0fb54b0..dedf46d11 100644 --- a/tests/integration_tests/io/io_json_detector_roundtrip.cpp +++ b/tests/integration_tests/io/io_json_detector_roundtrip.cpp @@ -13,8 +13,7 @@ #include "detray/io/backend/geometry_writer.hpp" #include "detray/io/frontend/detector_reader.hpp" #include "detray/io/frontend/detector_writer.hpp" -#include "detray/io/json/json_reader.hpp" -#include "detray/io/json/json_writer.hpp" +#include "detray/io/json/json_converter.hpp" // Detray test include(s) #include "detray/test/cpu/toy_detector_test.hpp" @@ -195,7 +194,7 @@ GTEST_TEST(io, json_toy_geometry) { auto [toy_det, names] = build_toy_detector(host_mr, toy_cfg); // Write the detector - io::json_writer geo_writer; + io::json_converter geo_writer; auto file_name = geo_writer.write( toy_det, names, std::ios::out | std::ios::binary | std::ios::trunc); @@ -204,7 +203,7 @@ GTEST_TEST(io, json_toy_geometry) { // Read the detector back in detector_builder toy_builder; - io::json_reader geo_reader; + io::json_converter geo_reader; geo_reader.read(toy_builder, volume_name_map, file_name); auto det = toy_builder.build(host_mr); @@ -214,7 +213,7 @@ GTEST_TEST(io, json_toy_geometry) { // Read the toy detector into the default detector type using default_metadata_t = test::default_metadata; detector_builder comp_builder; - io::json_reader, io::geometry_reader> + io::json_converter, io::geometry_reader> comp_geo_reader; comp_geo_reader.read(comp_builder, volume_name_map, file_name); auto comp_det = comp_builder.build(host_mr); diff --git a/tests/unit_tests/io/io_json_detector_writer.cpp b/tests/unit_tests/io/io_json_detector_writer.cpp index 3d28a95c0..8e9926e24 100644 --- a/tests/unit_tests/io/io_json_detector_writer.cpp +++ b/tests/unit_tests/io/io_json_detector_writer.cpp @@ -17,7 +17,7 @@ #include "detray/io/backend/material_map_writer.hpp" #include "detray/io/backend/surface_grid_writer.hpp" #include "detray/io/frontend/detector_writer.hpp" -#include "detray/io/json/json_writer.hpp" +#include "detray/io/json/json_converter.hpp" // Detray test include(s) #include "detray/test/utils/detectors/build_telescope_detector.hpp" @@ -69,7 +69,7 @@ GTEST_TEST(io, json_telescope_geometry_writer) { auto [det, names] = build_telescope_detector( host_mr, tel_cfg.positions(positions)); - io::json_writer geo_writer; + io::json_converter geo_writer; geo_writer.write(det, names); } @@ -84,7 +84,7 @@ GTEST_TEST(io, json_telescope_material_writer) { auto [det, names] = build_telescope_detector( host_mr, tel_cfg.positions(positions)); - io::json_writer mat_writer; + io::json_converter mat_writer; mat_writer.write(det, names); } @@ -99,7 +99,7 @@ GTEST_TEST(io, json_toy_material_maps_writer) { toy_cfg.use_material_maps(true); auto [det, names] = build_toy_detector(host_mr, toy_cfg); - io::json_writer map_writer; + io::json_converter map_writer; map_writer.write(det, names, std::ios::out | std::ios::binary | std::ios::trunc); } @@ -113,7 +113,7 @@ GTEST_TEST(io, json_toy_grid_writer) { vecmem::host_memory_resource host_mr; auto [det, names] = build_toy_detector(host_mr); - io::json_writer grid_writer; + io::json_converter grid_writer; grid_writer.write(det, names, std::ios::out | std::ios::binary | std::ios::trunc); }