From edf51a444164709afd8df9a2f875e0bbfd1c8037 Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Mon, 13 Jan 2025 07:06:28 -0400 Subject: [PATCH] DevSpecp.yy: Fix mirror list use of std::move()d objects We were building a list of mirrored items filled with the memory pointed to by unique_ptrs which had already been std::move()d into other unique_ptrs. --- hcore/deviceManager/deviceSpecp.yy | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/hcore/deviceManager/deviceSpecp.yy b/hcore/deviceManager/deviceSpecp.yy index 74424aa..8c862e7 100644 --- a/hcore/deviceManager/deviceSpecp.yy +++ b/hcore/deviceManager/deviceSpecp.yy @@ -7,6 +7,7 @@ #include #include #include +#include #include #ifndef yylex @@ -33,6 +34,32 @@ void yyerror(const char *message) + std::string(message)); } +void mirrorDeviceSpecs() { + for (const auto& interoSpec : DeviceManager::interoceptorDeviceSpecs) { + auto it = std::find_if( + DeviceManager::senseDeviceSpecs.begin(), + DeviceManager::senseDeviceSpecs.end(), + [&interoSpec](const SenseDeviceSpec& spec) { + return spec == *interoSpec; + }); + if (it == DeviceManager::senseDeviceSpecs.end()) { + DeviceManager::senseDeviceSpecs.push_back(*interoSpec); + } + } + + for (const auto& extroSpec : DeviceManager::extrospectorDeviceSpecs) { + auto it = std::find_if( + DeviceManager::senseDeviceSpecs.begin(), + DeviceManager::senseDeviceSpecs.end(), + [&extroSpec](const SenseDeviceSpec& spec) { + return spec == *extroSpec; + }); + if (it == DeviceManager::senseDeviceSpecs.end()) { + DeviceManager::senseDeviceSpecs.push_back(*extroSpec); + } + } +} + %} %union { @@ -57,7 +84,7 @@ void yyerror(const char *message) %% file: /* NOTHING */ - | sensor_specs + | sensor_specs { mirrorDeviceSpecs(); } ; sensor_specs: @@ -77,7 +104,6 @@ interoceptor_spec: spec->sensorType = $1; DeviceManager::interoceptorDeviceSpecs.push_back(std::move(spec)); - DeviceManager::senseDeviceSpecs.push_back(*spec); delete $3; } ; @@ -89,7 +115,6 @@ extrospector_spec: spec->sensorType = $1; DeviceManager::extrospectorDeviceSpecs.push_back(std::move(spec)); - DeviceManager::senseDeviceSpecs.push_back(*spec); delete $3; } ;