Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <sstream>
#include <stdexcept>
 
#include "api.h"
 
#define RETURN_IF_ERROR(fn)    \
  do {                         \
    OrtStatus* _status = (fn); \
    if (_status != nullptr) {  \
      return _status;          \
    }                          \
  } while (0)
 
#define RETURN_IF(cond, ort_api, msg)                    \
  do {                                                   \
    if ((cond)) {                                        \
      return (ort_api).CreateStatus(ORT_EP_FAIL, (msg)); \
    }                                                    \
  } while (0)
 
// see ORT_ENFORCE for implementations that also capture a stack trace and work in builds with exceptions disabled
// NOTE: In this simplistic implementation you must provide an argument, even it if's an empty string
#define EP_ENFORCE(condition, ...)                       \
  do {                                                   \
    if (!(condition)) {                                  \
      std::ostringstream oss;                            \
      oss << "EP_ENFORCE failed: " << #condition << " "; \
      oss << __VA_ARGS__;                                \
      throw std::runtime_error(oss.str());               \
    }                                                    \
  } while (false)
 
// Ignores an OrtStatus* while taking ownership of it so that it does not get leaked.
#define IGNORE_ORTSTATUS(status_expr)   \
  do {                                  \
    OrtStatus* _status = (status_expr); \
    Ort::Status _ignored{_status};      \
  } while (false)
 
// Helper macros to convert exceptions to OrtStatus* return values.
// Usage:
//   EXCEPTION_TO_RETURNED_STATUS_BEGIN
//     ... code that may throw ...
//   EXCEPTION_TO_RETURNED_STATUS_END
#define EXCEPTION_TO_RETURNED_STATUS_BEGIN try {
#define EXCEPTION_TO_RETURNED_STATUS_END                  \
  }                                                       \
  catch (const Ort::Exception& ex) {                      \
    Ort::Status status(ex);                               \
    return status.release();                              \
  }                                                       \
  catch (const std::exception& ex) {                      \
    Ort::Status status(ex.what(), ORT_EP_FAIL);           \
    return status.release();                              \
  }                                                       \
  catch (...) {                                           \
    Ort::Status status("Unknown exception", ORT_EP_FAIL); \
    return status.release();                              \
  }