Skip to content

Commit b8ca549

Browse files
authored
Add ctx to CurrentDomain CAPI, adjust CPPAPI. (#5219)
This adds a ctx parameter to all CurrentDomain CAPI calls so that internal exceptions are propagated correctly through the capi handle layer. I also adjusted the CPP CurrentDomain API, the only current user of these calls. --- TYPE: C_API | CPP_API DESC: Add ctx to CurrentDomain CAPI, adjust CPPAPI.
1 parent 58dbc08 commit b8ca549

File tree

10 files changed

+96
-78
lines changed

10 files changed

+96
-78
lines changed

examples/c_api/current_domain.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void create_array() {
7474
tiledb_ndrectangle_set_range_for_name(ctx, ndrect, "d1", &range);
7575

7676
// Assign the rectangle to the current domain
77-
tiledb_current_domain_set_ndrectangle(current_domain, ndrect);
77+
tiledb_current_domain_set_ndrectangle(ctx, current_domain, ndrect);
7878

7979
// Create a single attribute "a" so each cell can store an integer
8080
tiledb_attribute_t* a;
@@ -119,21 +119,21 @@ void print_current_domain() {
119119

120120
// Check if current domain is empty
121121
uint32_t is_empty;
122-
tiledb_current_domain_get_is_empty(current_domain, &is_empty);
122+
tiledb_current_domain_get_is_empty(ctx, current_domain, &is_empty);
123123

124124
if (is_empty) {
125125
printf("Current domain: empty\n");
126126
} else {
127127
// Get current domain type
128128
tiledb_current_domain_type_t current_domain_type;
129-
tiledb_current_domain_get_type(current_domain, &current_domain_type);
129+
tiledb_current_domain_get_type(ctx, current_domain, &current_domain_type);
130130

131131
if (current_domain_type == TILEDB_NDRECTANGLE) {
132132
printf("Current domain type: NDRECTANGLE\n");
133133

134134
// Get the ND rectangle
135135
tiledb_ndrectangle_t* ndrect;
136-
tiledb_current_domain_get_ndrectangle(current_domain, &ndrect);
136+
tiledb_current_domain_get_ndrectangle(ctx, current_domain, &ndrect);
137137

138138
tiledb_range_t range;
139139
tiledb_ndrectangle_get_range_from_name(ctx, ndrect, "d1", &range);
@@ -203,7 +203,7 @@ void expand_current_domain() {
203203
tiledb_ndrectangle_set_range_for_name(ctx, ndrect, "d1", &range);
204204

205205
// Set the rectangle to the current domain
206-
tiledb_current_domain_set_ndrectangle(new_current_domain, ndrect);
206+
tiledb_current_domain_set_ndrectangle(ctx, new_current_domain, ndrect);
207207

208208
// Expand the current domain
209209
tiledb_array_schema_evolution_expand_current_domain(

test/src/unit-capi-array_schema.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,8 @@ TEST_CASE_METHOD(
25032503
tiledb_array_schema_get_current_domain(ctx_, schema, &crd) == TILEDB_OK);
25042504

25052505
uint32_t is_empty = 0;
2506-
REQUIRE(tiledb_current_domain_get_is_empty(crd, &is_empty) == TILEDB_OK);
2506+
REQUIRE(
2507+
tiledb_current_domain_get_is_empty(ctx_, crd, &is_empty) == TILEDB_OK);
25072508
CHECK(is_empty == 1);
25082509

25092510
REQUIRE(tiledb_current_domain_free(&crd) == TILEDB_OK);
@@ -2537,7 +2538,7 @@ TEST_CASE_METHOD(
25372538

25382539
tiledb_ndrectangle_t* ndr = nullptr;
25392540
REQUIRE(tiledb_ndrectangle_alloc(ctx_, domain, &ndr) == TILEDB_OK);
2540-
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
2541+
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_, crd, ndr) == TILEDB_OK);
25412542

25422543
REQUIRE(
25432544
tiledb_array_schema_set_current_domain(ctx_, schema, crd) == TILEDB_OK);
@@ -2604,7 +2605,7 @@ TEST_CASE_METHOD(
26042605
REQUIRE(
26052606
tiledb_array_schema_get_current_domain(ctx_, schema, &crd) == TILEDB_OK);
26062607

2607-
REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
2608+
REQUIRE(tiledb_current_domain_get_ndrectangle(ctx_, crd, &ndr) == TILEDB_OK);
26082609
tiledb_range_t outrange;
26092610
REQUIRE(
26102611
tiledb_ndrectangle_get_range_from_name(ctx_, ndr, "d1", &outrange) ==
@@ -2672,7 +2673,7 @@ TEST_CASE_METHOD(
26722673
REQUIRE(
26732674
tiledb_ndrectangle_set_range_for_name(ctx_, ndr, "d1", &range) ==
26742675
TILEDB_OK);
2675-
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
2676+
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_, crd, ndr) == TILEDB_OK);
26762677
REQUIRE(
26772678
tiledb_array_schema_set_current_domain(ctx_, schema, crd) == TILEDB_OK);
26782679

@@ -2712,7 +2713,7 @@ TEST_CASE_METHOD(
27122713
REQUIRE(
27132714
tiledb_ndrectangle_set_range_for_name(ctx_, ndr, "d1", &range) ==
27142715
TILEDB_OK);
2715-
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
2716+
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_, crd, ndr) == TILEDB_OK);
27162717

27172718
REQUIRE(
27182719
tiledb_array_schema_evolution_expand_current_domain(ctx_, evo, crd) ==
@@ -2752,7 +2753,7 @@ TEST_CASE_METHOD(
27522753
REQUIRE(
27532754
tiledb_array_schema_get_current_domain(ctx_, schema, &crd) == TILEDB_OK);
27542755

2755-
REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
2756+
REQUIRE(tiledb_current_domain_get_ndrectangle(ctx_, crd, &ndr) == TILEDB_OK);
27562757
tiledb_range_t outrange;
27572758
REQUIRE(
27582759
tiledb_ndrectangle_get_range_from_name(ctx_, ndr, "d1", &outrange) ==

test/src/unit-current-domain-rest.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void RestCurrentDomainFx::create_sparse_array(const std::string& array_name) {
128128
tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d2", &range_var) ==
129129
TILEDB_OK);
130130

131-
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
131+
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_c_, crd, ndr) == TILEDB_OK);
132132
REQUIRE(
133133
tiledb_array_schema_set_current_domain(ctx_c_, array_schema, crd) ==
134134
TILEDB_OK);
@@ -169,7 +169,8 @@ TEST_CASE_METHOD(
169169
tiledb_array_schema_get_current_domain(ctx_c_, schema, &crd) ==
170170
TILEDB_OK);
171171

172-
REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
172+
REQUIRE(
173+
tiledb_current_domain_get_ndrectangle(ctx_c_, crd, &ndr) == TILEDB_OK);
173174
tiledb_range_t outrange;
174175
tiledb_range_t outrange_var;
175176
REQUIRE(
@@ -239,7 +240,7 @@ TEST_CASE_METHOD(
239240
tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d2", &range_var) ==
240241
TILEDB_OK);
241242

242-
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
243+
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_c_, crd, ndr) == TILEDB_OK);
243244
REQUIRE(
244245
tiledb_array_schema_evolution_expand_current_domain(ctx_c_, evo, crd) ==
245246
TILEDB_OK);
@@ -262,7 +263,8 @@ TEST_CASE_METHOD(
262263
tiledb_array_schema_get_current_domain(ctx_c_, schema, &crd) ==
263264
TILEDB_OK);
264265

265-
REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
266+
REQUIRE(
267+
tiledb_current_domain_get_ndrectangle(ctx_c_, crd, &ndr) == TILEDB_OK);
266268
tiledb_range_t outrange;
267269
REQUIRE(
268270
tiledb_ndrectangle_get_range_from_name(ctx_c_, ndr, "d1", &outrange) ==

tiledb/api/c_api/current_domain/current_domain_api.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ capi_return_t tiledb_current_domain_get_type(
106106

107107
} // namespace tiledb::api
108108

109+
using tiledb::api::api_entry_context;
109110
using tiledb::api::api_entry_plain;
110111
using tiledb::api::api_entry_with_context;
111112

@@ -124,32 +125,36 @@ CAPI_INTERFACE(current_domain_free, tiledb_current_domain_t** current_domain) {
124125

125126
CAPI_INTERFACE(
126127
current_domain_set_ndrectangle,
128+
tiledb_ctx_t* ctx,
127129
tiledb_current_domain_t* current_domain,
128130
tiledb_ndrectangle_t* ndr) {
129-
return api_entry_plain<tiledb::api::tiledb_current_domain_set_ndrectangle>(
130-
current_domain, ndr);
131+
return api_entry_context<tiledb::api::tiledb_current_domain_set_ndrectangle>(
132+
ctx, current_domain, ndr);
131133
}
132134

133135
CAPI_INTERFACE(
134136
current_domain_get_ndrectangle,
137+
tiledb_ctx_t* ctx,
135138
tiledb_current_domain_t* current_domain,
136139
tiledb_ndrectangle_t** ndr) {
137-
return api_entry_plain<tiledb::api::tiledb_current_domain_get_ndrectangle>(
138-
current_domain, ndr);
140+
return api_entry_context<tiledb::api::tiledb_current_domain_get_ndrectangle>(
141+
ctx, current_domain, ndr);
139142
}
140143

141144
CAPI_INTERFACE(
142145
current_domain_get_is_empty,
146+
tiledb_ctx_t* ctx,
143147
tiledb_current_domain_t* current_domain,
144148
uint32_t* is_empty) {
145-
return api_entry_plain<tiledb::api::tiledb_current_domain_get_is_empty>(
146-
current_domain, is_empty);
149+
return api_entry_context<tiledb::api::tiledb_current_domain_get_is_empty>(
150+
ctx, current_domain, is_empty);
147151
}
148152

149153
CAPI_INTERFACE(
150154
current_domain_get_type,
155+
tiledb_ctx_t* ctx,
151156
tiledb_current_domain_t* current_domain,
152157
tiledb_current_domain_type_t* type) {
153-
return api_entry_plain<tiledb::api::tiledb_current_domain_get_type>(
154-
current_domain, type);
158+
return api_entry_context<tiledb::api::tiledb_current_domain_get_type>(
159+
ctx, current_domain, type);
155160
}

tiledb/api/c_api/current_domain/current_domain_api_external_experimental.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,19 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_free(
106106
* range.max_size = sizeof(max);
107107
* tiledb_ndrectangle_set_range_for_name(ctx, ndr, "dim", &range);
108108
*
109-
* tiledb_current_domain_set_ndrectangle(current_domain, ndr);
109+
* tiledb_current_domain_set_ndrectangle(ctx, current_domain, ndr);
110110
*
111111
* tiledb_ndrectangle_free(&ndr);
112112
* tiledb_current_domain_free(&current_domain);
113113
* @endcode
114114
*
115+
* @param ctx A TileDB context
115116
* @param current_domain The current domain to modify
116117
* @param ndr The N-dimensional rectangle to be set
117118
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
118119
*/
119120
TILEDB_EXPORT capi_return_t tiledb_current_domain_set_ndrectangle(
121+
tiledb_ctx_t* ctx,
120122
tiledb_current_domain_t* current_domain,
121123
tiledb_ndrectangle_t* ndr) TILEDB_NOEXCEPT;
122124

@@ -131,14 +133,16 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_set_ndrectangle(
131133
*
132134
* @code{.c}
133135
* tiledb_ndrectangle_t *ndr;
134-
* tiledb_current_domain_get_ndrectangle(current_domain, &ndr);
136+
* tiledb_current_domain_get_ndrectangle(ctx, current_domain, &ndr);
135137
* @endcode
136138
*
139+
* @param ctx A TileDB context
137140
* @param current_domain The current domain to query
138141
* @param ndr The N-dimensional rectangle of the current domain
139142
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
140143
*/
141144
TILEDB_EXPORT capi_return_t tiledb_current_domain_get_ndrectangle(
145+
tiledb_ctx_t* ctx,
142146
tiledb_current_domain_t* current_domain,
143147
tiledb_ndrectangle_t** ndr) TILEDB_NOEXCEPT;
144148

@@ -149,14 +153,16 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_get_ndrectangle(
149153
*
150154
* @code{.c}
151155
* uint32_t empty = 0;
152-
* tiledb_current_domain_get_is_empty(current_domain, &empty);
156+
* tiledb_current_domain_get_is_empty(ctx, current_domain, &empty);
153157
* @endcode
154158
*
159+
* @param ctx A TileDB context
155160
* @param current_domain The current domain to query
156161
* @param is_empty True if nothing is set on the current domain
157162
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
158163
*/
159164
TILEDB_EXPORT capi_return_t tiledb_current_domain_get_is_empty(
165+
tiledb_ctx_t* ctx,
160166
tiledb_current_domain_t* current_domain,
161167
uint32_t* is_empty) TILEDB_NOEXCEPT;
162168

@@ -167,14 +173,16 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_get_is_empty(
167173
*
168174
* @code{.c}
169175
* tiledb_current_domain_type_t type;
170-
* tiledb_current_domain_get_type(current_domain, &type);
176+
* tiledb_current_domain_get_type(ctx, current_domain, &type);
171177
* @endcode
172178
*
179+
* @param ctx A TileDB context
173180
* @param current_domain The current domain to query
174181
* @param type The type of representation set on the current domain
175182
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
176183
*/
177184
TILEDB_EXPORT capi_return_t tiledb_current_domain_get_type(
185+
tiledb_ctx_t* ctx,
178186
tiledb_current_domain_t* current_domain,
179187
tiledb_current_domain_type_t* type) TILEDB_NOEXCEPT;
180188

tiledb/api/c_api/current_domain/test/compile_capi_current_domain_main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
int main() {
3333
tiledb_current_domain_create(nullptr, nullptr);
3434
tiledb_current_domain_free(nullptr);
35-
tiledb_current_domain_set_ndrectangle(nullptr, nullptr);
36-
tiledb_current_domain_get_ndrectangle(nullptr, nullptr);
37-
tiledb_current_domain_get_is_empty(nullptr, nullptr);
38-
tiledb_current_domain_get_type(nullptr, nullptr);
35+
tiledb_current_domain_set_ndrectangle(nullptr, nullptr, nullptr);
36+
tiledb_current_domain_get_ndrectangle(nullptr, nullptr, nullptr);
37+
tiledb_current_domain_get_is_empty(nullptr, nullptr, nullptr);
38+
tiledb_current_domain_get_type(nullptr, nullptr, nullptr);
3939

4040
return 0;
4141
}

tiledb/api/c_api/current_domain/test/unit_capi_current_domain.cc

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,34 @@ TEST_CASE_METHOD(
100100
crd = nullptr;
101101
CHECK(tiledb_current_domain_create(ctx, &crd) == TILEDB_OK);
102102

103-
CHECK(tiledb_current_domain_set_ndrectangle(nullptr, nullptr) == TILEDB_ERR);
104-
CHECK(tiledb_current_domain_set_ndrectangle(crd, nullptr) == TILEDB_ERR);
103+
CHECK(
104+
tiledb_current_domain_set_ndrectangle(nullptr, nullptr, nullptr) ==
105+
TILEDB_INVALID_CONTEXT);
106+
CHECK(
107+
tiledb_current_domain_set_ndrectangle(ctx, nullptr, nullptr) ==
108+
TILEDB_ERR);
109+
CHECK(tiledb_current_domain_set_ndrectangle(ctx, crd, nullptr) == TILEDB_ERR);
105110

106-
CHECK(tiledb_current_domain_get_ndrectangle(nullptr, nullptr) == TILEDB_ERR);
107-
CHECK(tiledb_current_domain_get_ndrectangle(crd, nullptr) == TILEDB_ERR);
111+
CHECK(
112+
tiledb_current_domain_get_ndrectangle(nullptr, nullptr, nullptr) ==
113+
TILEDB_INVALID_CONTEXT);
114+
CHECK(
115+
tiledb_current_domain_get_ndrectangle(ctx, nullptr, nullptr) ==
116+
TILEDB_ERR);
117+
CHECK(tiledb_current_domain_get_ndrectangle(ctx, crd, nullptr) == TILEDB_ERR);
108118

109-
CHECK(tiledb_current_domain_get_is_empty(nullptr, nullptr) == TILEDB_ERR);
110-
CHECK(tiledb_current_domain_get_is_empty(crd, nullptr) == TILEDB_ERR);
119+
CHECK(
120+
tiledb_current_domain_get_is_empty(nullptr, nullptr, nullptr) ==
121+
TILEDB_INVALID_CONTEXT);
122+
CHECK(
123+
tiledb_current_domain_get_is_empty(ctx, nullptr, nullptr) == TILEDB_ERR);
124+
CHECK(tiledb_current_domain_get_is_empty(ctx, crd, nullptr) == TILEDB_ERR);
111125

112-
CHECK(tiledb_current_domain_get_type(nullptr, nullptr) == TILEDB_ERR);
113-
CHECK(tiledb_current_domain_get_type(crd, nullptr) == TILEDB_ERR);
126+
CHECK(
127+
tiledb_current_domain_get_type(nullptr, nullptr, nullptr) ==
128+
TILEDB_INVALID_CONTEXT);
129+
CHECK(tiledb_current_domain_get_type(ctx, nullptr, nullptr) == TILEDB_ERR);
130+
CHECK(tiledb_current_domain_get_type(ctx, crd, nullptr) == TILEDB_ERR);
114131

115132
tiledb_current_domain_free(&crd);
116133
}
@@ -126,22 +143,23 @@ TEST_CASE_METHOD(
126143
REQUIRE(tiledb_ndrectangle_alloc(ctx, domain_, &ndr) == TILEDB_OK);
127144

128145
uint32_t is_empty = 0;
129-
REQUIRE(tiledb_current_domain_get_is_empty(crd, &is_empty) == TILEDB_OK);
146+
REQUIRE(tiledb_current_domain_get_is_empty(ctx, crd, &is_empty) == TILEDB_OK);
130147
CHECK(is_empty == 1);
131148

132149
tiledb_current_domain_type_t type;
133-
CHECK(tiledb_current_domain_get_type(crd, &type) == TILEDB_ERR);
150+
CHECK(tiledb_current_domain_get_type(ctx, crd, &type) == TILEDB_ERR);
134151

135-
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
152+
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx, crd, ndr) == TILEDB_OK);
136153

137-
REQUIRE(tiledb_current_domain_get_is_empty(crd, &is_empty) == TILEDB_OK);
154+
REQUIRE(tiledb_current_domain_get_is_empty(ctx, crd, &is_empty) == TILEDB_OK);
138155
CHECK(is_empty == 0);
139156

140-
REQUIRE(tiledb_current_domain_get_type(crd, &type) == TILEDB_OK);
157+
REQUIRE(tiledb_current_domain_get_type(ctx, crd, &type) == TILEDB_OK);
141158
CHECK(type == TILEDB_NDRECTANGLE);
142159

143160
tiledb_ndrectangle_t* out_ndr = nullptr;
144-
REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &out_ndr) == TILEDB_OK);
161+
REQUIRE(
162+
tiledb_current_domain_get_ndrectangle(ctx, crd, &out_ndr) == TILEDB_OK);
145163
CHECK(out_ndr != nullptr);
146164

147165
// Verify that they point to the same tiledb::sm::NDRectangle instance.

0 commit comments

Comments
 (0)