YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/common/ybc-internal.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
#include "yb/common/ybc-internal.h"
13
14
#include "yb/util/status.h"
15
#include "yb/util/status_format.h"
16
17
namespace yb {
18
19
namespace {
20
YBCPAllocFn g_palloc_fn = nullptr;
21
YBCCStringToTextWithLenFn g_cstring_to_text_with_len_fn = nullptr;
22
}  // anonymous namespace
23
24
8.09k
void YBCSetPAllocFn(YBCPAllocFn palloc_fn) {
25
8.09k
  CHECK_NOTNULL(palloc_fn);
26
8.09k
  g_palloc_fn = palloc_fn;
27
8.09k
}
28
29
122k
void* YBCPAlloc(size_t size) {
30
122k
  CHECK_NOTNULL(g_palloc_fn);
31
122k
  return g_palloc_fn(size);
32
122k
}
33
34
8.09k
void YBCSetCStringToTextWithLenFn(YBCCStringToTextWithLenFn fn) {
35
8.09k
  CHECK_NOTNULL(fn);
36
8.09k
  g_cstring_to_text_with_len_fn = fn;
37
8.09k
}
38
39
43.2M
void* YBCCStringToTextWithLen(const char* c, int size) {
40
43.2M
  CHECK_NOTNULL(g_cstring_to_text_with_len_fn);
41
43.2M
  return g_cstring_to_text_with_len_fn(c, size);
42
43.2M
}
43
44
8.09k
YBCStatus ToYBCStatus(const Status& status) {
45
8.09k
  return status.RetainStruct();
46
8.09k
}
47
48
224M
YBCStatus ToYBCStatus(Status&& status) {
49
224M
  return status.DetachStruct();
50
224M
}
51
52
121k
void FreeYBCStatus(YBCStatus status) {
53
  // Create Status object that receives control over provided status, so it will be destoyed with
54
  // yb_status.
55
121k
  Status yb_status(status, AddRef::kFalse);
56
121k
}
57
58
85.2M
YBCStatus YBCStatusOK() {
59
85.2M
  return nullptr;
60
85.2M
}
61
62
2
YBCStatus YBCStatusNotSupport(const string& feature_name) {
63
2
  if (feature_name.empty()) {
64
2
    return ToYBCStatus(STATUS(NotSupported, "Feature is not supported"));
65
2
  } else {
66
0
    return ToYBCStatus(STATUS_FORMAT(NotSupported, "Feature '$0' not supported", feature_name));
67
0
  }
68
2
}
69
70
66
const char* YBCPAllocStdString(const std::string& s) {
71
66
  const size_t len = s.size();
72
66
  char* result = reinterpret_cast<char*>(YBCPAlloc(len + 1));
73
66
  memcpy(result, s.c_str(), len);
74
66
  result[len] = 0;
75
66
  return result;
76
66
}
77
78
} // namespace yb