Skip to content

Commit

Permalink
Fixes to previous commits as found the code didn't link under optimis…
Browse files Browse the repository at this point in the history
…ation.
  • Loading branch information
ned14 committed Jul 17, 2024
1 parent 6279aff commit 5bf34fb
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 159 deletions.
6 changes: 3 additions & 3 deletions include/outcome/detail/revision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Distributed under the Boost Software License, Version 1.0.
*/

// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define OUTCOME_PREVIOUS_COMMIT_REF 10eb45ca7d11a35df14e0fa89939a3e3185c0aa9
#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-16 20:39:50 +00:00"
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 10eb45ca
#define OUTCOME_PREVIOUS_COMMIT_REF 6279affbf2fee17dbe2a564165b8815409565b10
#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 14:25:30 +00:00"
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 6279affb
66 changes: 51 additions & 15 deletions include/outcome/experimental/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ Distributed under the Boost Software License, Version 1.0.
#define OUTCOME_C_INLINE
#endif

#ifndef OUTCOME_C_NODISCARD
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 202000L
#define OUTCOME_C_NODISCARD [[nodiscard]]
#elif defined(__GNUC__) || defined(__clang__)
#define OUTCOME_C_NODISCARD __attribute__((warn_unused_result))
#else
#define OUTCOME_C_NODISCARD
#endif
#endif

#include "../outcome_gdb.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -105,7 +115,7 @@ extern "C"
pun.c = v; \
return std::move(pun.cpp); \
} \
inline cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result<R> v) \
inline OUTCOME_C_NODISCARD cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result<R> v) \
{ \
union type_punner_t \
{ \
Expand All @@ -132,20 +142,20 @@ extern "C"
unsigned flags; \
S error; \
}; \
static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \
static OUTCOME_C_INLINE OUTCOME_C_NODISCARD struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \
{ \
struct cxx_result_status_code_##ident ret; \
outcome_make_result_status_code_success((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), (const void *) &value, \
sizeof(value)); \
return ret; \
} \
static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_posix(int errcode) \
static OUTCOME_C_INLINE OUTCOME_C_NODISCARD struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_posix(int errcode) \
{ \
struct cxx_result_status_code_##ident ret; \
outcome_make_result_status_code_failure_posix((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \
return ret; \
} \
static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_system(intptr_t errcode) \
static OUTCOME_C_INLINE OUTCOME_C_NODISCARD struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_system(intptr_t errcode) \
{ \
struct cxx_result_status_code_##ident ret; \
outcome_make_result_status_code_failure_system((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \
Expand Down Expand Up @@ -223,7 +233,7 @@ extern "C"
#ifndef __cplusplus
// Declares the function in C, needs to occur at least once in a C++ source file to get implemented
#define CXX_DECLARE_RESULT_SYSTEM_FROM_ENUM(ident, enum_name, uuid, ...) \
extern struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v);
extern OUTCOME_C_NODISCARD struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v);
#else
}

Expand All @@ -241,8 +251,25 @@ extern "C"
#include <algorithm>
#include <cstring>

#ifndef OUTCOME_C_WEAK
#ifdef _MSC_VER
#define OUTCOME_C_WEAK inline
#else
#define OUTCOME_C_WEAK __attribute__((weak))
#endif
#endif

#ifndef OUTCOME_C_MSVC_FORCE_EMIT
#ifdef _MSC_VER
#define OUTCOME_C_MSVC_FORCE_EMIT(x) extern "C" __declspec(selectany) void *x##_emit = x;
#else
#define OUTCOME_C_MSVC_FORCE_EMIT(x)
#endif
#endif


// You need to include this C header in at least one C++ source file to have these C helper functions be implemented
extern "C" inline void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes)
extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes)
{
union type_punner_t
{
Expand All @@ -267,8 +294,9 @@ extern "C" inline void outcome_make_result_status_code_success(void *out, size_t
memcpy(out, toset, tosetbytes);
memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy);
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_success)

extern "C" inline void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode)
extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode)
{
using value_type = OUTCOME_V2_NAMESPACE::experimental::posix_code::value_type;
union type_punner_t
Expand All @@ -294,8 +322,9 @@ extern "C" inline void outcome_make_result_status_code_failure_posix(void *out,
memcpy(out, (void *) &pun.c, sizeof(value_type));
memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy);
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_posix)

extern "C" inline void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode)
extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode)
{
using value_type = OUTCOME_V2_NAMESPACE::experimental::system_code::value_type;
union type_punner_t
Expand All @@ -315,9 +344,9 @@ extern "C" inline void outcome_make_result_status_code_failure_system(void *out,
~type_punner_t() {}
} pun{
#ifdef _WIN32
OUTCOME_V2_NAMESPACE::experimental::win32_code(errcode)
OUTCOME_V2_NAMESPACE::experimental::win32_code((OUTCOME_V2_NAMESPACE::experimental::win32::DWORD) errcode)
#else
OUTCOME_V2_NAMESPACE::experimental::posix_code(errcode)
OUTCOME_V2_NAMESPACE::experimental::posix_code((int) errcode)
#endif
};
static_assert(sizeof(pun.cpp) == sizeof(pun.c), "");
Expand All @@ -327,27 +356,31 @@ extern "C" inline void outcome_make_result_status_code_failure_system(void *out,
memcpy(out, (void *) &pun.c, sizeof(value_type));
memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy);
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_system)

extern "C" inline int outcome_status_code_equal(const void *_a, const void *_b)
extern "C" OUTCOME_C_WEAK int outcome_status_code_equal(const void *_a, const void *_b)
{
const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a;
const auto *b = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _b;
return *a == *b;
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal)

extern "C" inline int outcome_status_code_equal_generic(const void *_a, int errcode)
extern "C" OUTCOME_C_WEAK int outcome_status_code_equal_generic(const void *_a, int errcode)
{
const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a;
return *a == (SYSTEM_ERROR2_NAMESPACE::errc) errcode;
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal_generic)

extern "C" inline const char *outcome_status_code_message(const void *_a)
extern "C" OUTCOME_C_WEAK const char *outcome_status_code_message(const void *_a)
{
static thread_local SYSTEM_ERROR2_NAMESPACE::system_code::string_ref msg((const char *) nullptr, 0);
const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a;
msg = a->message();
return msg.c_str();
}
OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_message)

OUTCOME_V2_NAMESPACE_BEGIN
namespace experimental
Expand Down Expand Up @@ -402,10 +435,13 @@ OUTCOME_V2_NAMESPACE_END
} \
}; \
SYSTEM_ERROR2_NAMESPACE_END \
extern "C" inline struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v) \
extern "C" OUTCOME_C_WEAK OUTCOME_C_NODISCARD struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name( \
enum enum_name v) \
{ \
return OUTCOME_V2_NAMESPACE::experimental::detail::outcome_make_result_failure_system_enum<struct cxx_result_status_code_system_##ident>(v); \
}
} \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_system_enum_##enum_name)


#endif

Expand Down
Loading

0 comments on commit 5bf34fb

Please sign in to comment.