Skip to content

Commit 41eb1cc

Browse files
Fix crash in current domain triggered by incorrect function selection. (#5199)
Fix crash in current domain triggered by incorrect function selection for range() in the cpp api `range<std::string>` now selects the correct specialization. [[sc-51234]](https://app.shortcut.com/tiledb-inc/story/51234) --- TYPE: NO_HISTORY DESC: Fix crash in current domain triggered by incorrect function selection. --------- Co-authored-by: Luc Rancourt <[email protected]>
1 parent 6bad3ac commit 41eb1cc

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

test/src/test-cppapi-current-domain.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ TEST_CASE_METHOD(
118118
ndrect.set_range(1, std::string("b"), std::string("db"));
119119

120120
// Get and check ranges
121-
std::array<std::string, 2> range = ndrect.range(0);
121+
std::array<std::string, 2> range = ndrect.range<std::string>(0);
122122
CHECK(range[0] == "a");
123123
CHECK(range[1] == "c");
124-
range = ndrect.range(1);
124+
range = ndrect.range<std::string>(1);
125125
CHECK(range[0] == "b");
126126
CHECK(range[1] == "db");
127127

@@ -134,10 +134,10 @@ TEST_CASE_METHOD(
134134
auto rect = current_domain.ndrectangle();
135135

136136
// Get and check ranges
137-
range = ndrect.range(0);
137+
range = ndrect.range<std::string>(0);
138138
CHECK(range[0] == "a");
139139
CHECK(range[1] == "c");
140-
range = ndrect.range(1);
140+
range = ndrect.range<std::string>(1);
141141
CHECK(range[0] == "b");
142142
CHECK(range[1] == "db");
143143
}

tiledb/sm/cpp_api/ndrectangle.h

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -225,47 +225,6 @@ class NDRectangle {
225225
return *this;
226226
}
227227

228-
/**
229-
* Retrieves a range for a given variable length string dimension index and
230-
* range id.
231-
*
232-
* @param dim_idx The dimension index.
233-
* @param range_idx The range index.
234-
* @return A pair of the form (start, end).
235-
*/
236-
std::array<std::string, 2> range(unsigned dim_idx) {
237-
auto& ctx = ctx_.get();
238-
tiledb_range_t range;
239-
240-
ctx.handle_error(tiledb_ndrectangle_get_range(
241-
ctx.ptr().get(), ndrect_.get(), dim_idx, &range));
242-
243-
std::string start_str(static_cast<const char*>(range.min), range.min_size);
244-
std::string end_str(static_cast<const char*>(range.max), range.max_size);
245-
246-
return {std::move(start_str), std::move(end_str)};
247-
}
248-
249-
/**
250-
* Retrieves a range for a given variable length string dimension index and
251-
* range id.
252-
*
253-
* @param dim_name The dimension name.
254-
* @param range_idx The range index.
255-
* @return A pair of the form (start, end).
256-
*/
257-
std::array<std::string, 2> range(const std::string& dim_name) {
258-
auto& ctx = ctx_.get();
259-
tiledb_range_t range;
260-
ctx.handle_error(tiledb_ndrectangle_get_range_from_name(
261-
ctx.ptr().get(), ndrect_.get(), dim_name.c_str(), &range));
262-
263-
std::string start_str(static_cast<const char*>(range.min), range.min_size);
264-
std::string end_str(static_cast<const char*>(range.max), range.max_size);
265-
266-
return {std::move(start_str), std::move(end_str)};
267-
}
268-
269228
/**
270229
* Retrieves a range for a given dimension name. The template datatype must be
271230
* the same as that of the underlying array.
@@ -326,6 +285,50 @@ class NDRectangle {
326285
impl::Deleter deleter_;
327286
};
328287

288+
/**
289+
* Retrieves a range for a given variable length string dimension index and
290+
* range id.
291+
*
292+
* @param dim_name The dimension name.
293+
* @param range_idx The range index.
294+
* @return A pair of the form (start, end).
295+
*/
296+
template <>
297+
inline std::array<std::string, 2> NDRectangle::range<std::string>(
298+
const std::string& dim_name) {
299+
auto& ctx = ctx_.get();
300+
tiledb_range_t range;
301+
ctx.handle_error(tiledb_ndrectangle_get_range_from_name(
302+
ctx.ptr().get(), ndrect_.get(), dim_name.c_str(), &range));
303+
304+
std::string start_str(static_cast<const char*>(range.min), range.min_size);
305+
std::string end_str(static_cast<const char*>(range.max), range.max_size);
306+
307+
return {std::move(start_str), std::move(end_str)};
308+
}
309+
310+
/**
311+
* Retrieves a range for a given variable length string dimension index and
312+
* range id.
313+
*
314+
* @param dim_idx The dimension index.
315+
* @param range_idx The range index.
316+
* @return A pair of the form (start, end).
317+
*/
318+
template <>
319+
inline std::array<std::string, 2> NDRectangle::range(unsigned dim_idx) {
320+
auto& ctx = ctx_.get();
321+
tiledb_range_t range;
322+
323+
ctx.handle_error(tiledb_ndrectangle_get_range(
324+
ctx.ptr().get(), ndrect_.get(), dim_idx, &range));
325+
326+
std::string start_str(static_cast<const char*>(range.min), range.min_size);
327+
std::string end_str(static_cast<const char*>(range.max), range.max_size);
328+
329+
return {std::move(start_str), std::move(end_str)};
330+
}
331+
329332
} // namespace tiledb
330333

331334
#endif // TILEDB_CPP_API_NDRECTANGLE_H

0 commit comments

Comments
 (0)