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 d2f2234
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 164 deletions.
2 changes: 2 additions & 0 deletions cmake/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(outcome_HEADERS
"include/outcome/detail/version.hpp"
"include/outcome/experimental/coroutine_support.hpp"
"include/outcome/experimental/result.h"
"include/outcome/experimental/status-code/example/outcome-experimental.hpp"
"include/outcome/experimental/status-code/include/status-code/boost_error_code.hpp"
"include/outcome/experimental/status-code/include/status-code/com_code.hpp"
"include/outcome/experimental/status-code/include/status-code/config.hpp"
Expand All @@ -50,6 +51,7 @@ set(outcome_HEADERS
"include/outcome/experimental/status-code/include/status-code/system_code_from_exception.hpp"
"include/outcome/experimental/status-code/include/status-code/system_error2.hpp"
"include/outcome/experimental/status-code/include/status-code/win32_code.hpp"
"include/outcome/experimental/status-code/single-header/system_error2-nowindows.hpp"
"include/outcome/experimental/status-code/single-header/system_error2.hpp"
"include/outcome/experimental/status_outcome.hpp"
"include/outcome/experimental/status_result.hpp"
Expand Down
3 changes: 2 additions & 1 deletion doc/src/content/experimental/c-api/from-c/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ The C macro API header `<outcome/experimental/result.h>` has some macros for wor
<dd>Declares to C a <code>basic_result<T, E></code> type uniquely
identified by <code>ident</code>. <code>T</code> is available at the
member variable <code>.value</code>, and <code>E</code> is available
at the member variable <code>.error</code>.
at the member variable <code>.error</code>. If you call this from within
C++, make SURE it is not within a <code>extern "C"</code> block!

<dt><code>CXX_RESULT(ident)</code>
<dd>A reference to a previously declared <code>result</code> type with
Expand Down
3 changes: 2 additions & 1 deletion doc/src/content/experimental/c-api/from-c/system_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ identified by <code>ident</code>. <code>T</code> is available at the
member variable <code>.value</code>, and <code>struct cxx_status_code_system</code>
is available at the member variable <code>.error</code>. If in C++,
implements C extern functions for making successful and failure results
of this type.
of this type. If you call this from within
C++, make SURE it is not within a <code>extern "C"</code> block!

<dt><code>CXX_RESULT_SYSTEM(ident)</code>
<dd>A reference to a previously declared <code>status_result</code> type with
Expand Down
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 216235604bcd6b595bc69bd8d97cc50bf41d86fe
#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 19:25:24 +00:00"
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 21623560
84 changes: 66 additions & 18 deletions include/outcome/experimental/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,43 @@ 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 __STDC_VERSION__ >= 202000L || __cplusplus >= 201700L
#define OUTCOME_C_NODISCARD [[nodiscard]]
#ifdef __cplusplus
#define OUTCOME_C_NODISCARD_EXTERN_C extern "C" [[nodiscard]]
#else
#define OUTCOME_C_NODISCARD_EXTERN_C [[nodiscard]] extern
#endif
#elif defined(__GNUC__) || defined(__clang__)
#define OUTCOME_C_NODISCARD __attribute__((warn_unused_result))
#ifdef __cplusplus
#define OUTCOME_C_NODISCARD_EXTERN_C \
extern "C" __attribute__((warn_unused_result))
#else
#define OUTCOME_C_NODISCARD_EXTERN_C \
extern __attribute__((warn_unused_result))
#endif
#else
#define OUTCOME_C_NODISCARD
#endif
#endif

#include "../outcome_gdb.h"
Expand Down Expand Up @@ -105,7 +138,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 +165,29 @@ 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_C 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_C 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_C 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 +260,8 @@ 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);
OUTCOME_C_NODISCARD_EXTERN_C 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 +279,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 +306,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 +334,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 +356,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 +368,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 +447,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
7 changes: 7 additions & 0 deletions include/outcome/outcome_gdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Distributed under the Boost Software License, Version 1.0.

#ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS
#if defined(__ELF__)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverlength-strings"
#endif
__asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte 4 /* Python Text */\n"
".ascii \"gdb.inlined-script\\n\"\n"
Expand Down Expand Up @@ -149,6 +153,9 @@ __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"

".byte 0\n"
".popsection\n");
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
#endif

Expand Down
Loading

0 comments on commit d2f2234

Please sign in to comment.