Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include "core/common/status.h"
#include "core/common/exceptions.h"
#include "core/common/make_string.h"
#include "core/session/onnxruntime_c_api.h"
 
namespace onnxruntime {
 
// Convert onnxruntime::common::Status to OrtStatus*.
_Ret_notnull_ OrtStatus* ToOrtStatus(const onnxruntime::common::Status& st);
 
// Convert OrtStatus* to onnxruntime::common::Status and release the OrtStatus*.
Status ToStatusAndRelease(OrtStatus* ort_status,
                          common::StatusCategory category = common::StatusCategory::ONNXRUNTIME);
};  // namespace onnxruntime
 
#ifndef ORT_NO_EXCEPTIONS
#define API_IMPL_BEGIN try {
#define API_IMPL_END                                                               \
  }                                                                                \
  catch (const onnxruntime::OnnxRuntimeException& ex) {                            \
    return OrtApis::CreateStatus(static_cast<OrtErrorCode>(ex.Code()), ex.what()); \
  }                                                                                \
  catch (const onnxruntime::NotImplementedException& ex) {                         \
    return OrtApis::CreateStatus(ORT_NOT_IMPLEMENTED, ex.what());                  \
  }                                                                                \
  catch (const std::exception& ex) {                                               \
    return OrtApis::CreateStatus(ORT_RUNTIME_EXCEPTION, ex.what());                \
  }                                                                                \
  catch (...) {                                                                    \
    return OrtApis::CreateStatus(ORT_FAIL, "Unknown Exception");                   \
  }
 
#else
#define API_IMPL_BEGIN {
#define API_IMPL_END }
#endif
 
// Check condition. If met, return an OrtStatus* error with the given OrtErrorCode.
#define ORT_API_RETURN_IF(condition, ort_error_code, ...)                                           \
  do {                                                                                              \
    if (condition) {                                                                                \
      return OrtApis::CreateStatus(ort_error_code, ::onnxruntime::MakeString(__VA_ARGS__).c_str()); \
    }                                                                                               \
  } while (false)
 
// Return the OrtStatus if it indicates an error
#define ORT_API_RETURN_IF_ERROR(expr) \
  do {                                \
    auto _status = (expr);            \
    if (_status)                      \
      return _status;                 \
  } while (0)
 
// Convert internal onnxruntime::Status to OrtStatus and return if there's an error
#define ORT_API_RETURN_IF_STATUS_NOT_OK(expr)   \
  do {                                          \
    auto _status = (expr);                      \
    if (!_status.IsOK())                        \
      return onnxruntime::ToOrtStatus(_status); \
  } while (0)
 
// Check condition. If met, return an OrtStatus* error with the given OrtErrorCode.
#define ORT_API_RETURN_IF(condition, ort_error_code, ...)                                           \
  do {                                                                                              \
    if (condition) {                                                                                \
      return OrtApis::CreateStatus(ort_error_code, ::onnxruntime::MakeString(__VA_ARGS__).c_str()); \
    }                                                                                               \
  } while (false)