Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error reporting in tiledb_subarray_alloc #3220

Merged
merged 4 commits into from Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions tiledb/sm/c_api/api_argument_validator.h
Expand Up @@ -134,6 +134,17 @@ inline void action_invalid_object(const std::string& type_name) {
throw CAPIStatusException(std::string("Invalid TileDB object: ") + type_name);
}

/**
* Returns after successfully validating an array.
*
* @param array Possibly-valid pointer to array
*/
inline void ensure_array_is_valid(const tiledb_array_t* array) {
if (array == nullptr) {
action_invalid_object("array");
}
}

/**
* Returns after successfully validating a filter list.
*
Expand Down
32 changes: 10 additions & 22 deletions tiledb/sm/c_api/tiledb.cc
Expand Up @@ -3529,54 +3529,42 @@ int32_t tiledb_query_get_subarray_t(
/* SUBARRAY */
/* ****************************** */

int32_t tiledb_subarray_alloc(
capi_return_t tiledb_subarray_alloc(
tiledb_ctx_t* ctx,
const tiledb_array_t* array,
tiledb_subarray_t** subarray) {
// Sanity check
if (sanity_check(ctx) == TILEDB_ERR || sanity_check(ctx, array) == TILEDB_ERR)
return TILEDB_ERR;
api::ensure_array_is_valid(array);
api::ensure_output_pointer_is_valid(subarray);

// Error if array is not open
if (!array->array_->is_open()) {
auto st = Status_Error("Cannot create subarray; array is not open");
*subarray = nullptr;
LOG_STATUS(st);
save_error(ctx, st);
return TILEDB_ERR;
throw api::CAPIStatusException("Cannot create subarray; array is not open");
}

// Create a buffer struct
*subarray = new (std::nothrow) tiledb_subarray_t;
*subarray = new tiledb_subarray_t;
if (*subarray == nullptr) {
bekadavis9 marked this conversation as resolved.
Show resolved Hide resolved
auto st = Status_Error("Failed to allocate TileDB subarray object");
LOG_STATUS(st);
save_error(ctx, st);
return TILEDB_OOM;
throw api::CAPIStatusException(
"Failed to allocate TileDB subarray wrapper");
} else {
(*subarray)->subarray_ = nullptr;
}

// Create a new subarray object
try {
(*subarray)->subarray_ = new (std::nothrow) tiledb::sm::Subarray(
(*subarray)->subarray_ = new tiledb::sm::Subarray(
array->array_.get(),
(tiledb::sm::stats::Stats*)nullptr,
ctx->ctx_->storage_manager()->logger(),
true,
ctx->ctx_->storage_manager());
(*subarray)->is_allocated_ = true;
} catch (...) {
}
if ((*subarray)->subarray_ == nullptr) {
delete *subarray;
auto st = Status_Error("Failed to allocate TileDB subarray object");
LOG_STATUS(st);
save_error(ctx, st);
return TILEDB_OOM;
*subarray = nullptr;
throw api::CAPIStatusException("Failed to create subarray");
}

// Success
return TILEDB_OK;
}

Expand Down