Skip to content

Commit

Permalink
fix nullptr dereferencing warning
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Jan 12, 2025
1 parent 5e89f23 commit d8c3a0a
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 33 deletions.
12 changes: 11 additions & 1 deletion core/include/detray/builders/surface_factory_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@

#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"
#include "detray/definitions/geometry.hpp"

// System include(s)
#include <memory>
#include <stdexcept>
#include <tuple>
#include <vector>

Expand Down Expand Up @@ -160,7 +166,11 @@ class factory_decorator : public surface_factory_interface<detector_t> {
explicit factory_decorator(
std::unique_ptr<surface_factory_interface<detector_t>> 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
Expand Down
2 changes: 0 additions & 2 deletions core/include/detray/core/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 0 additions & 1 deletion io/include/detray/io/backend/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

// Project include(s)
#include "detray/builders/detector_builder.hpp"
#include "detray/utils/type_traits.hpp"

// System include(s)
#include <concepts>
Expand Down
6 changes: 3 additions & 3 deletions io/include/detray/io/backend/detail/type_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ get_id() {
}

/// Infer the IO material id from the material type - homogeneous material
template <concepts::homogeneous_material material_t>
template <detray::concepts::homogeneous_material material_t>
constexpr io::material_id get_id() {
using scalar_t = typename material_t::scalar_type;

Expand All @@ -67,7 +67,7 @@ constexpr io::material_id get_id() {
}

/// Infer the IO material id from the material type - material maps
template <concepts::material_map material_t>
template <detray::concepts::material_map material_t>
constexpr io::material_id get_id() {

using map_frame_t = typename material_t::local_frame_type;
Expand All @@ -88,7 +88,7 @@ constexpr io::material_id get_id() {
}

/// Infer the grid id from its coordinate system
template <concepts::surface_grid grid_t>
template <detray::concepts::surface_grid grid_t>
constexpr io::accel_id get_id() {

using frame_t = typename grid_t::local_frame_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class detector_components_writer final {

/// Create a new writer of type @tparam writer_t
template <class writer_t>
/*requires std::is_base_of_v<writer_interface<detector_t>, writer_t>*/ void
requires std::is_base_of_v<writer_interface<detector_t>, writer_t> void
add() {
add(std::make_unique<writer_t>());
}
Expand Down
2 changes: 1 addition & 1 deletion io/include/detray/io/frontend/impl/json_readers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions io/include/detray/io/frontend/impl/json_writers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,8 +31,6 @@ void add_json_writers(detector_components_writer<detector_t>& writers,
// Always needed
using json_geometry_writer = json_converter<detector_t, geometry_writer>;

static_assert(
io::concepts::writer_backend<detector_t, io::geometry_writer>);
writers.template add<json_geometry_writer>();

// Find other writers, depending on the detector type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <array>
Expand Down
10 changes: 5 additions & 5 deletions io/include/detray/io/json/json_io.hpp
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 4 additions & 5 deletions tests/integration_tests/io/io_json_detector_roundtrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -195,7 +194,7 @@ GTEST_TEST(io, json_toy_geometry) {
auto [toy_det, names] = build_toy_detector<test_algebra>(host_mr, toy_cfg);

// Write the detector
io::json_writer<detector_t, io::geometry_writer> geo_writer;
io::json_converter<detector_t, io::geometry_writer> geo_writer;
auto file_name = geo_writer.write(
toy_det, names, std::ios::out | std::ios::binary | std::ios::trunc);

Expand All @@ -204,7 +203,7 @@ GTEST_TEST(io, json_toy_geometry) {

// Read the detector back in
detector_builder<metadata_t> toy_builder;
io::json_reader<detector_t, io::geometry_reader> geo_reader;
io::json_converter<detector_t, io::geometry_reader> geo_reader;
geo_reader.read(toy_builder, volume_name_map, file_name);
auto det = toy_builder.build(host_mr);

Expand All @@ -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<default_metadata_t> comp_builder;
io::json_reader<detector<default_metadata_t>, io::geometry_reader>
io::json_converter<detector<default_metadata_t>, 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);
Expand Down
10 changes: 5 additions & 5 deletions tests/unit_tests/io/io_json_detector_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -69,7 +69,7 @@ GTEST_TEST(io, json_telescope_geometry_writer) {
auto [det, names] = build_telescope_detector<test_algebra>(
host_mr, tel_cfg.positions(positions));

io::json_writer<detector_t, io::geometry_writer> geo_writer;
io::json_converter<detector_t, io::geometry_writer> geo_writer;
geo_writer.write(det, names);
}

Expand All @@ -84,7 +84,7 @@ GTEST_TEST(io, json_telescope_material_writer) {
auto [det, names] = build_telescope_detector<test_algebra>(
host_mr, tel_cfg.positions(positions));

io::json_writer<detector_t, io::homogeneous_material_writer> mat_writer;
io::json_converter<detector_t, io::homogeneous_material_writer> mat_writer;
mat_writer.write(det, names);
}

Expand All @@ -99,7 +99,7 @@ GTEST_TEST(io, json_toy_material_maps_writer) {
toy_cfg.use_material_maps(true);
auto [det, names] = build_toy_detector<test_algebra>(host_mr, toy_cfg);

io::json_writer<detector_t, io::material_map_writer> map_writer;
io::json_converter<detector_t, io::material_map_writer> map_writer;
map_writer.write(det, names,
std::ios::out | std::ios::binary | std::ios::trunc);
}
Expand All @@ -113,7 +113,7 @@ GTEST_TEST(io, json_toy_grid_writer) {
vecmem::host_memory_resource host_mr;
auto [det, names] = build_toy_detector<test_algebra>(host_mr);

io::json_writer<detector_t, io::surface_grid_writer> grid_writer;
io::json_converter<detector_t, io::surface_grid_writer> grid_writer;
grid_writer.write(det, names,
std::ios::out | std::ios::binary | std::ios::trunc);
}
Expand Down

0 comments on commit d8c3a0a

Please sign in to comment.