Skip to content

Commit

Permalink
more fun with DALI_ENFORCE
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Lecki <[email protected]>
  • Loading branch information
klecki committed Mar 22, 2024
1 parent d63f66e commit f30eff7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions dali/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int PopCurrBatchSize(batch_size_map_t *batch_size_map, int max_batch_size,
*/
dali::InputOperatorNoCopyMode GetExternalSourceCopyMode(unsigned int flags) {
dali::InputOperatorNoCopyMode no_copy_mode = dali::InputOperatorNoCopyMode::DEFAULT;
DALI_ENFORCE(!((flags & DALI_ext_force_copy) && (flags & DALI_ext_force_no_copy)),
dali::DALI_ENFORCE(!((flags & DALI_ext_force_copy) && (flags & DALI_ext_force_no_copy)),
"External Source cannot be forced to use DALI_ext_force_copy and "
"DALI_ext_force_no_copy at the same time.");
if (flags & DALI_ext_force_copy) {
Expand Down Expand Up @@ -722,7 +722,7 @@ void daliLoadLibrary(const char* lib_path) {

void daliGetReaderMetadata(daliPipelineHandle_t pipe_handle, const char *reader_name,
daliReaderMetadata* meta) {
DALI_ENFORCE(meta, "Provided pointer to meta cannot be NULL.");
dali::DALI_ENFORCE(meta, "Provided pointer to meta cannot be NULL.");
dali::Pipeline* pipeline = (*pipe_handle)->pipeline.get();
dali::ReaderMeta returned_meta = pipeline->GetReaderMeta(reader_name);
meta->epoch_size = returned_meta.epoch_size;
Expand Down Expand Up @@ -827,7 +827,7 @@ void daliGetSerializedCheckpoint(
daliPipelineHandle_t pipe_handle,
const daliExternalContextCheckpoint *external_context,
char **checkpoint, size_t *n) {
DALI_ENFORCE(external_context, "Provided pointer to external context cannot be NULL.");
dali::DALI_ENFORCE(external_context, "Provided pointer to external context cannot be NULL.");
auto &pipeline = (*pipe_handle)->pipeline;
dali::ExternalContextCheckpoint ctx{};
if (external_context->pipeline_data.data) {
Expand All @@ -845,7 +845,7 @@ void daliGetSerializedCheckpoint(
std::string cpt = pipeline->SerializedCheckpoint(ctx);
*n = cpt.size();
*checkpoint = reinterpret_cast<char *>(daliAlloc(cpt.size()));
DALI_ENFORCE(*checkpoint, "Failed to allocate memory");
dali::DALI_ENFORCE(*checkpoint, "Failed to allocate memory");
memcpy(*checkpoint, cpt.c_str(), *n);
}

Expand All @@ -862,7 +862,7 @@ void daliRestoreFromSerializedCheckpoint(
daliPipelineHandle *pipe_handle,
const char *checkpoint, size_t n,
daliExternalContextCheckpoint *external_context) {
DALI_ENFORCE(external_context != nullptr,
dali::DALI_ENFORCE(external_context != nullptr,
"Null external context provided.");
auto &pipeline = (*pipe_handle)->pipeline;
auto ctx = pipeline->RestoreFromSerializedCheckpoint({checkpoint, n});
Expand Down
1 change: 1 addition & 0 deletions dali/pipeline/operator/op_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class DLL_PUBLIC OpSpec {
*/
DLL_PUBLIC inline void EnforceNoAliasWithDeprecated(const string& arg_name) {
auto set_through = set_through_deprecated_arguments_.find(arg_name);
// TODO: OMG - lazy evaluation of when this is macro ):
DALI_ENFORCE(
set_through == set_through_deprecated_arguments_.end(),
make_string("Operator ", SchemaName(), " got an unexpected '", set_through->second,
Expand Down
2 changes: 1 addition & 1 deletion include/dali/core/error_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ inline dali::string GetStacktrace() {
// #define DALI_ENFORCE(...) GET_MACRO(__VA_ARGS__, ENFRC_2, ENFRC_1)(__VA_ARGS__)

template <typename T>
void DALI_ENFORCE(T condition, const std::string &error_string = "",
void DALI_ENFORCE(const T &condition, const std::string &error_string = "",
source_location loc = source_location::current()) {
if (!condition) {
throw DALIException(error_string, make_string("[", loc.source_file(), ":", loc.line(), "]"),
Expand Down

0 comments on commit f30eff7

Please sign in to comment.