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 2162356
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 162 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
70 changes: 52 additions & 18 deletions include/outcome/experimental/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,31 @@ Distributed under the Boost Software License, Version 1.0.

#include "../detail/try.h"

#if __STDC_VERSION__ >= 199900L
#define OUTCOME_C_INLINE inline
#ifndef OUTCOME_C_WEAK
#ifdef _MSC_VER
#define OUTCOME_C_WEAK inline
#else
#define OUTCOME_C_INLINE
#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


#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"
Expand Down Expand Up @@ -105,7 +126,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) \
OUTCOME_C_NODISCARD inline cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result<R> v) \
{ \
union type_punner_t \
{ \
Expand All @@ -132,25 +153,28 @@ extern "C"
unsigned flags; \
S error; \
}; \
static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \
OUTCOME_C_NODISCARD extern OUTCOME_C_WEAK 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) \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_success) \
OUTCOME_C_NODISCARD extern OUTCOME_C_WEAK 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) \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_posix) \
OUTCOME_C_NODISCARD extern OUTCOME_C_WEAK 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); \
return ret; \
} \
OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_system) \
CXX_DECLARE_RESULT_STATUS_CODE_CXX(ident, R, S)

#define CXX_RESULT_STATUS_CODE(ident) struct cxx_result_status_code_##ident
Expand Down Expand Up @@ -223,7 +247,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 +265,9 @@ extern "C"
#include <algorithm>
#include <cstring>


// 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 +292,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 +320,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 +342,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 +354,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 +433,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_NODISCARD OUTCOME_C_WEAK 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 2162356

Please sign in to comment.