Skip to content

Commit 7cdcdc7

Browse files
committed
Fix debug assertions (fixes #126, fixes #127)
1 parent 55f6243 commit 7cdcdc7

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

api/common/src/attribute.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ void processAttribute(const std::string& attrname, // input, attribute name
4545
if (valtype == matlab::data::ArrayType::DOUBLE) {
4646
matlab::data::TypedArray<double> attrvalue_mda = attrvalue;
4747
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
48-
nostd::span<const double>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
48+
nostd::span<const double>{&(*attrvalue_mda.cbegin()), attrvalue_mda.getNumberOfElements()}));
4949
} else if (valtype == matlab::data::ArrayType::INT32) {
5050
matlab::data::TypedArray<int32_t> attrvalue_mda = attrvalue;
5151
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
52-
nostd::span<const int32_t>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
52+
nostd::span<const int32_t>{&(*attrvalue_mda.cbegin()), attrvalue_mda.getNumberOfElements()}));
5353
} else if (valtype == matlab::data::ArrayType::UINT32) {
5454
matlab::data::TypedArray<uint32_t> attrvalue_mda = attrvalue;
5555
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
56-
nostd::span<const uint32_t>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
56+
nostd::span<const uint32_t>{&(*attrvalue_mda.cbegin()), attrvalue_mda.getNumberOfElements()}));
5757
} else if (valtype == matlab::data::ArrayType::INT64) {
5858
matlab::data::TypedArray<int64_t> attrvalue_mda = attrvalue;
5959
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
60-
nostd::span<const int64_t>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
60+
nostd::span<const int64_t>{&(*attrvalue_mda.cbegin()), attrvalue_mda.getNumberOfElements()}));
6161
} else if (valtype == matlab::data::ArrayType::LOGICAL) {
6262
matlab::data::TypedArray<bool> attrvalue_mda = attrvalue;
6363
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
64-
nostd::span<const bool>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
64+
nostd::span<const bool>{&(*attrvalue_mda.cbegin()), attrvalue_mda.getNumberOfElements()}));
6565
} else if (valtype == matlab::data::ArrayType::MATLAB_STRING) { // string
6666
matlab::data::StringArray attrvalue_mda = attrvalue;
6767
std::vector<nostd::string_view> strarray_attr;
@@ -73,7 +73,7 @@ void processAttribute(const std::string& attrname, // input, attribute name
7373
}
7474
attrs.StringViewBuffer.push_back(strarray_attr);
7575
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
76-
nostd::span<const nostd::string_view>{&(*attrs.StringViewBuffer.back().cbegin()), &(*attrs.StringViewBuffer.back().cend())}));
76+
nostd::span<const nostd::string_view>{&(*attrs.StringViewBuffer.back().cbegin()), attrvalue_mda.getNumberOfElements()}));
7777
} else { // ignore all other types
7878
return;
7979
}
@@ -85,8 +85,7 @@ void processAttribute(const std::string& attrname, // input, attribute name
8585
}
8686
attrs.DimensionsBuffer.push_back(attrvalue_dims_buffer);
8787
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(sizeattr,
88-
nostd::span<const double>{&(*attrs.DimensionsBuffer.back().cbegin()),
89-
&(*attrs.DimensionsBuffer.back().cend())}));
88+
nostd::span<const double>{attrs.DimensionsBuffer.back().data(), attrvalue_dims_buffer.size()}));
9089
}
9190
}
9291
} // namespace

api/metrics/src/AsynchronousInstrumentProxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ void AsynchronousInstrumentProxy::removeCallback(libmexclass::proxy::method::Con
2626
double idx = idx_mda[0] - 1; // adjust index from 1-based in MATLAB to 0-based in C++
2727
auto iter = CallbackInputs.begin();
2828
std::advance(iter, idx);
29-
CallbackInputs.erase(iter);
3029
CppInstrument->RemoveCallback(MeasurementFetcher::Fetcher, static_cast<void*>(&(*iter)));
30+
CallbackInputs.erase(iter);
3131
}
3232

3333
} // namespace libmexclass::opentelemetry

0 commit comments

Comments
 (0)