Skip to content

Commit fcdf03b

Browse files
committed
add std::expected
1 parent ae4c40c commit fcdf03b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

runtime-light/k2-platform/k2-api.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <cerrno>
88
#include <cstddef>
99
#include <cstdint>
10+
#include <expected>
1011
#include <memory>
11-
#include <optional>
1212
#include <sys/utsname.h>
1313
#include <tuple>
1414
#include <utility>
@@ -17,6 +17,8 @@
1717
#include "runtime-light/k2-platform/k2-header.h"
1818
#undef K2_API_HEADER_H
1919

20+
#include "runtime-common/core/utils/kphp-assert-core.h"
21+
2022
namespace k2 {
2123

2224
namespace k2_impl_ {
@@ -228,15 +230,16 @@ inline int32_t iconv(size_t* result, void* iconv_cd, char** inbuf, size_t* inbyt
228230
}
229231

230232
inline auto resolve_symbol(void* addr) {
231-
using return_type =
232-
std::optional<std::tuple<std::unique_ptr<char, decltype(std::addressof(k2::free))>, std::unique_ptr<char, decltype(std::addressof(k2::free))>, uint32_t>>;
233+
using symbol_info_t =
234+
std::tuple<std::unique_ptr<char, decltype(std::addressof(k2::free))>, std::unique_ptr<char, decltype(std::addressof(k2::free))>, uint32_t>;
235+
using return_type = std::expected<symbol_info_t, int32_t>;
233236
size_t name_len{};
234237
if (auto error_code{k2_symbol_name_len(addr, &name_len)}; error_code != k2::errno_ok) {
235-
return return_type{};
238+
return return_type{std::unexpected{error_code}};
236239
}
237240
size_t filename_len{};
238241
if (auto error_code{k2_symbol_filename_len(addr, &filename_len)}; error_code != k2::errno_ok) {
239-
return return_type{};
242+
return return_type{std::unexpected{error_code}};
240243
}
241244

242245
// +1 since we get non-null-terminated strings from platform and we want to null-terminate them on our side
@@ -246,7 +249,7 @@ inline auto resolve_symbol(void* addr) {
246249

247250
SymbolInfo symbolInfo{.name = name, .filename = filename, .lineno = 0};
248251
if (auto error_code{k2_resolve_symbol(addr, &symbolInfo)}; error_code != k2::errno_ok) {
249-
return return_type{};
252+
return return_type{std::unexpected{error_code}};
250253
}
251254

252255
// null-terminate

0 commit comments

Comments
 (0)