From cb595d9b1991269731c5ffa48d448b7db05b68fa Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 24 Feb 2024 23:00:03 +0800 Subject: [PATCH 1/3] Fix OGSubgraph.current crash in CFRelease --- Sources/_OpenGraph/Graph/Graph.cpp | 13 +++++++++++++ Sources/_OpenGraph/Graph/Graph.hpp | 2 ++ Sources/_OpenGraph/Graph/OGSubgraph.cpp | 9 ++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Sources/_OpenGraph/Graph/Graph.cpp b/Sources/_OpenGraph/Graph/Graph.cpp index e55f063..d103817 100644 --- a/Sources/_OpenGraph/Graph/Graph.cpp +++ b/Sources/_OpenGraph/Graph/Graph.cpp @@ -6,5 +6,18 @@ // #include "Graph.hpp" +#include +#include +#include "Subgraph.hpp" pthread_key_t OG::Graph::_current_update_key; + +OG::Graph::Graph() OG_NOEXCEPT { + // TODO + static dispatch_once_t make_keys; + dispatch_once_f(&make_keys, nullptr, [](void *context){ + pthread_key_create(&_current_update_key, nullptr); + OG::Subgraph::make_current_subgraph_key(); + }); + // TODO +} diff --git a/Sources/_OpenGraph/Graph/Graph.hpp b/Sources/_OpenGraph/Graph/Graph.hpp index 155ee88..1180036 100644 --- a/Sources/_OpenGraph/Graph/Graph.hpp +++ b/Sources/_OpenGraph/Graph/Graph.hpp @@ -33,6 +33,8 @@ class Graph final { return _current_update_key; } + Graph() OG_NOEXCEPT; + class Context final { private: Graph *_graph; diff --git a/Sources/_OpenGraph/Graph/OGSubgraph.cpp b/Sources/_OpenGraph/Graph/OGSubgraph.cpp index cc7c8c5..0bb5e21 100644 --- a/Sources/_OpenGraph/Graph/OGSubgraph.cpp +++ b/Sources/_OpenGraph/Graph/OGSubgraph.cpp @@ -67,7 +67,7 @@ OGSubgraphRef OGSubgraphCreate2(OGGraphRef cf_graph, OGAttribute attribute) { return cf_subgrah; } -OGSubgraphRef OGSubgraphGetCurrent() { +_Nullable OGSubgraphRef OGSubgraphGetCurrent() { OG::Subgraph* subgraph = (OG::Subgraph*)pthread_getspecific(OG::Subgraph::current_key()); if (subgraph == nullptr) { return nullptr; @@ -75,7 +75,7 @@ OGSubgraphRef OGSubgraphGetCurrent() { return subgraph->to_cf(); } -void OGSubgraphSetCurrent(OGSubgraphRef cf_subgraph) { +void OGSubgraphSetCurrent(_Nullable OGSubgraphRef cf_subgraph) { OG::Subgraph* oldSubgraph = (OG::Subgraph*)pthread_getspecific(OG::Subgraph::current_key()); if (cf_subgraph == nullptr) { pthread_setspecific(OG::Subgraph::current_key(), nullptr); @@ -86,7 +86,10 @@ void OGSubgraphSetCurrent(OGSubgraphRef cf_subgraph) { } } if (oldSubgraph != nullptr) { - CFRelease(oldSubgraph->to_cf()); + OGSubgraphRef cf_oldSubgraph = oldSubgraph->to_cf(); + if (cf_oldSubgraph) { + CFRelease(cf_oldSubgraph); + } } } From 257f8b3db2ee5965a4ef7ba54d4044308b3f035a Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 24 Feb 2024 23:37:07 +0800 Subject: [PATCH 2/3] Add OGTargetConditionals --- Sources/_OpenGraph/Debug/OGDebugServer.cpp | 2 +- Sources/_OpenGraph/Debug/OGDebugServer.h | 2 +- Sources/_OpenGraph/Debug/og-debug-server.hpp | 4 +- Sources/_OpenGraph/Debug/og-debug-server.mm | 4 +- Sources/_OpenGraph/Graph/OGGraph.cpp | 2 +- Sources/_OpenGraph/Graph/OGSubgraph.cpp | 2 +- Sources/_OpenGraph/OGBase.h | 16 +- Sources/_OpenGraph/OGTargetConditionals.h | 277 ++++++++++++++++++ Sources/_OpenGraph/Private/CFRuntime.h | 4 +- .../_OpenGraph/Runtime/OGTypeDescription.cpp | 4 +- .../_OpenGraph/Runtime/OGTypeDescription.h | 4 +- Sources/_OpenGraph/Util/assert.cpp | 8 +- Sources/_OpenGraph/Util/log.cpp | 4 +- Sources/_OpenGraph/Util/log.hpp | 4 +- Sources/_OpenGraph/Util/realloc_vector.cpp | 4 +- .../_OpenGraph/include/OGTargetConditionals.h | 1 + 16 files changed, 305 insertions(+), 37 deletions(-) create mode 100644 Sources/_OpenGraph/OGTargetConditionals.h create mode 120000 Sources/_OpenGraph/include/OGTargetConditionals.h diff --git a/Sources/_OpenGraph/Debug/OGDebugServer.cpp b/Sources/_OpenGraph/Debug/OGDebugServer.cpp index 268d05a..8765561 100644 --- a/Sources/_OpenGraph/Debug/OGDebugServer.cpp +++ b/Sources/_OpenGraph/Debug/OGDebugServer.cpp @@ -8,7 +8,7 @@ #include "OGDebugServer.h" #include "og-debug-server.hpp" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN // MARK: - Exported C functions diff --git a/Sources/_OpenGraph/Debug/OGDebugServer.h b/Sources/_OpenGraph/Debug/OGDebugServer.h index 3a82db7..2b32988 100644 --- a/Sources/_OpenGraph/Debug/OGDebugServer.h +++ b/Sources/_OpenGraph/Debug/OGDebugServer.h @@ -14,7 +14,7 @@ typedef struct OG_BRIDGED_TYPE(id) OGDebugServerStorage * OGDebugServerRef; struct OGDebugServerStorage; -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN OG_ASSUME_NONNULL_BEGIN diff --git a/Sources/_OpenGraph/Debug/og-debug-server.hpp b/Sources/_OpenGraph/Debug/og-debug-server.hpp index 1666cfd..6301a5c 100644 --- a/Sources/_OpenGraph/Debug/og-debug-server.hpp +++ b/Sources/_OpenGraph/Debug/og-debug-server.hpp @@ -9,7 +9,7 @@ #define og_debug_server_hpp #include "OGBase.h" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN #include "OGDebugServer.h" #include "../Util/vector.hpp" #include @@ -65,5 +65,5 @@ struct OGDebugServerStorage { OG_ASSUME_NONNULL_END -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ #endif /* og_debug_server_ hpp */ diff --git a/Sources/_OpenGraph/Debug/og-debug-server.mm b/Sources/_OpenGraph/Debug/og-debug-server.mm index 4458b91..a34b5c9 100644 --- a/Sources/_OpenGraph/Debug/og-debug-server.mm +++ b/Sources/_OpenGraph/Debug/og-debug-server.mm @@ -6,7 +6,7 @@ // Audited for 2021 Release #include "og-debug-server.hpp" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN #include "../Util/log.hpp" #include "../Util/assert.hpp" @@ -332,4 +332,4 @@ bool blocking_write(int descriptor, void *buf, unsigned long count) { return; } -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ diff --git a/Sources/_OpenGraph/Graph/OGGraph.cpp b/Sources/_OpenGraph/Graph/OGGraph.cpp index 6328064..b7b45cc 100644 --- a/Sources/_OpenGraph/Graph/OGGraph.cpp +++ b/Sources/_OpenGraph/Graph/OGGraph.cpp @@ -15,7 +15,7 @@ OGGraphRef OGGraphCreate() { OGGraphRef OGGraphCreateShared(OGGraphRef storage) { const CFIndex extraSize = sizeof(OGGraphStorage)-sizeof(CFRuntimeBase); - #if TARGET_CPU_WASM32 + #if OG_TARGET_CPU_WASM32 // FIXME: extraSize will be 8 on WASM. Investate later. static_assert(extraSize == 0x8); #else diff --git a/Sources/_OpenGraph/Graph/OGSubgraph.cpp b/Sources/_OpenGraph/Graph/OGSubgraph.cpp index 0bb5e21..c314abc 100644 --- a/Sources/_OpenGraph/Graph/OGSubgraph.cpp +++ b/Sources/_OpenGraph/Graph/OGSubgraph.cpp @@ -53,7 +53,7 @@ OGSubgraphRef OGSubgraphCreate(OGGraphRef cf_graph) { OGSubgraphRef OGSubgraphCreate2(OGGraphRef cf_graph, OGAttribute attribute) { OG::Graph::Context &context = OG::Graph::Context::from_cf(cf_graph); const CFIndex extraSize = sizeof(OGSubgraphStorage)-sizeof(CFRuntimeBase); - #if TARGET_CPU_WASM32 + #if OG_TARGET_CPU_WASM32 // FIXME: extraSize will always be 8 thus it will fail on WASM. Investate later. static_assert(extraSize == 8); #else diff --git a/Sources/_OpenGraph/OGBase.h b/Sources/_OpenGraph/OGBase.h index 1a73a30..252622c 100644 --- a/Sources/_OpenGraph/OGBase.h +++ b/Sources/_OpenGraph/OGBase.h @@ -44,17 +44,7 @@ #include #include #include -#ifdef __APPLE__ -#include -#ifndef TARGET_OS_DARWIN -#define TARGET_OS_DARWIN TARGET_OS_MAC -#endif -#ifndef TARGET_CPU_WASM32 -#define TARGET_CPU_WASM32 0 -#endif -#else -#include -#endif +#include "OGTargetConditionals.h" #define OG_OPTIONS CF_OPTIONS #define OG_EXTERN_C_BEGIN CF_EXTERN_C_BEGIN @@ -66,10 +56,10 @@ #define OG_SWIFT_NAME CF_SWIFT_NAME #define OG_BRIDGED_TYPE CF_BRIDGED_TYPE -#if TARGET_OS_DARWIN && __OBJC__ +#if OG_TARGET_OS_DARWIN && __OBJC__ #define OG_OBJC_FOUNDATION 1 #else #define OG_OBJC_FOUNDATION 0 -#endif /* TARGET_OS_DARWIN && __OBJC__ */ +#endif /* OG_TARGET_OS_DARWIN && __OBJC__ */ #endif /* OGBase_h */ diff --git a/Sources/_OpenGraph/OGTargetConditionals.h b/Sources/_OpenGraph/OGTargetConditionals.h new file mode 100644 index 0000000..d969162 --- /dev/null +++ b/Sources/_OpenGraph/OGTargetConditionals.h @@ -0,0 +1,277 @@ +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// + +/* + File: OGTargetConditionals.h + + Contains: Autoconfiguration of TARGET_ conditionals for Mac OS X and iPhone + + Note: OpenSwiftUITargetConditionals.h in 3.4 Universal Interfaces works + with all compilers. This header only recognizes compilers + known to run on Mac OS X. + +*/ + +#ifndef __OPENGRAPHTARGETCONDITIONALS__ +#define __OPENGRAPHTARGETCONDITIONALS__ +/**************************************************************************************************** + + TARGET_CPU_* + These conditionals specify which microprocessor instruction set is being + generated. At most one of these is true, the rest are false. + + TARGET_CPU_PPC - Compiler is generating PowerPC instructions for 32-bit mode + TARGET_CPU_PPC64 - Compiler is generating PowerPC instructions for 64-bit mode + TARGET_CPU_68K - Compiler is generating 680x0 instructions + TARGET_CPU_X86 - Compiler is generating x86 instructions + TARGET_CPU_ARM - Compiler is generating ARM instructions + TARGET_CPU_MIPS - Compiler is generating MIPS instructions + TARGET_CPU_SPARC - Compiler is generating Sparc instructions + TARGET_CPU_ALPHA - Compiler is generating Dec Alpha instructions + TARGET_CPU_WASM32 - Compiler is generating WebAssembly instructions for 32-bit mode + + + TARGET_OS_* + These conditionals specify in which Operating System the generated code will + run. Indention is used to show which conditionals are evolutionary subclasses. + + The MAC/WIN32/UNIX conditionals are mutually exclusive. + The IOS/TV/WATCH conditionals are mutually exclusive. + + + TARGET_OS_WIN32 - Generated code will run under 32-bit Windows + TARGET_OS_UNIX - Generated code will run under some Unix (not OSX) + TARGET_OS_CYGWIN - Generated code will run under 64-bit Cygwin + TARGET_OS_WASI - Generated code will run under WebAssembly System Interface + TARGET_OS_MAC - Generated code will run under Mac OS X variant + TARGET_OS_IPHONE - Generated code for firmware, devices, or simulator + TARGET_OS_IOS - Generated code will run under iOS + TARGET_OS_TV - Generated code will run under Apple TV OS + TARGET_OS_WATCH - Generated code will run under Apple Watch OS + TARGET_OS_SIMULATOR - Generated code will run under a simulator + TARGET_OS_EMBEDDED - Generated code for firmware + + TARGET_IPHONE_SIMULATOR - DEPRECATED: Same as TARGET_OS_SIMULATOR + TARGET_OS_NANO - DEPRECATED: Same as TARGET_OS_WATCH + + TARGET_RT_* + These conditionals specify in which runtime the generated code will + run. This is needed when the OS and CPU support more than one runtime + (e.g. Mac OS X supports CFM and mach-o). + + TARGET_RT_LITTLE_ENDIAN - Generated code uses little endian format for integers + TARGET_RT_BIG_ENDIAN - Generated code uses big endian format for integers + TARGET_RT_64_BIT - Generated code uses 64-bit pointers + TARGET_RT_MAC_CFM - TARGET_OS_MAC is true and CFM68K or PowerPC CFM (TVectors) are used + TARGET_RT_MAC_MACHO - TARGET_OS_MAC is true and Mach-O/dlyd runtime is used + + +****************************************************************************************************/ + +#if __APPLE__ +#define OG_TARGET_OS_DARWIN 1 +#define OG_TARGET_OS_LINUX 0 +#define OG_TARGET_OS_WINDOWS 0 +#define OG_TARGET_OS_BSD 0 +#define OG_TARGET_OS_ANDROID 0 +#define OG_TARGET_OS_CYGWIN 0 +#define OG_TARGET_OS_WASI 0 +#elif __ANDROID__ +#define OG_TARGET_OS_DARWIN 0 +#define OG_TARGET_OS_LINUX 1 +#define OG_TARGET_OS_WINDOWS 0 +#define OG_TARGET_OS_BSD 0 +#define OG_TARGET_OS_ANDROID 1 +#define OG_TARGET_OS_CYGWIN 0 +#define OG_TARGET_OS_WASI 0 +#elif __linux__ +#define OG_TARGET_OS_DARWIN 0 +#define OG_TARGET_OS_LINUX 1 +#define OG_TARGET_OS_WINDOWS 0 +#define OG_TARGET_OS_BSD 0 +#define OG_TARGET_OS_ANDROID 0 +#define OG_TARGET_OS_CYGWIN 0 +#define OG_TARGET_OS_WASI 0 +#elif __CYGWIN__ +#define OG_TARGET_OS_DARWIN 0 +#define OG_TARGET_OS_LINUX 1 +#define OG_TARGET_OS_WINDOWS 0 +#define OG_TARGET_OS_BSD 0 +#define OG_TARGET_OS_ANDROID 0 +#define OG_TARGET_OS_CYGWIN 1 +#define OG_TARGET_OS_WASI 0 +#elif _WIN32 || _WIN64 +#define OG_TARGET_OS_DARWIN 0 +#define OG_TARGET_OS_LINUX 0 +#define OG_TARGET_OS_WINDOWS 1 +#define OG_TARGET_OS_BSD 0 +#define OG_TARGET_OS_ANDROID 0 +#define OG_TARGET_OS_CYGWIN 0 +#define OG_TARGET_OS_WASI 0 +#elif __unix__ +#define OG_TARGET_OS_DARWIN 0 +#define OG_TARGET_OS_LINUX 0 +#define OG_TARGET_OS_WINDOWS 0 +#define OG_TARGET_OS_BSD 1 +#define OG_TARGET_OS_ANDROID 0 +#define OG_TARGET_OS_CYGWIN 0 +#define OG_TARGET_OS_WASI 0 +#elif __wasi__ +#define OG_TARGET_OS_DARWIN 0 +#define OG_TARGET_OS_LINUX 0 +#define OG_TARGET_OS_WINDOWS 0 +#define OG_TARGET_OS_BSD 0 +#define OG_TARGET_OS_ANDROID 0 +#define OG_TARGET_OS_CYGWIN 0 +#define OG_TARGET_OS_WASI 1 +#else +#error unknown operating system +#endif + +#define OG_TARGET_OS_WIN32 OG_TARGET_OS_WINDOWS +#define OG_TARGET_OS_MAC OG_TARGET_OS_DARWIN +#define OG_TARGET_OS_OSX OG_TARGET_OS_DARWIN + +// iOS, watchOS, and tvOS are not supported +#define OG_TARGET_OS_IPHONE 0 +#define OG_TARGET_OS_IOS 0 +#define OG_TARGET_OS_WATCH 0 +#define OG_TARGET_OS_TV 0 + +#if __x86_64__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 1 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __arm64__ || __aarch64__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 1 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __mips64__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 1 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __powerpc64__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 1 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __i386__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 1 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __arm__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 1 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __mips__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 1 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __powerpc__ +#define OG_TARGET_CPU_PPC 1 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 0 +#elif __s390x__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 1 +#define OG_TARGET_CPU_WASM32 0 +#elif __wasm32__ +#define OG_TARGET_CPU_PPC 0 +#define OG_TARGET_CPU_PPC64 0 +#define OG_TARGET_CPU_X86 0 +#define OG_TARGET_CPU_X86_64 0 +#define OG_TARGET_CPU_ARM 0 +#define OG_TARGET_CPU_ARM64 0 +#define OG_TARGET_CPU_MIPS 0 +#define OG_TARGET_CPU_MIPS64 0 +#define OG_TARGET_CPU_S390X 0 +#define OG_TARGET_CPU_WASM32 1 +#else +#error unknown architecture +#endif + +#if __LITTLE_ENDIAN__ +#define OG_TARGET_RT_LITTLE_ENDIAN 1 +#define OG_TARGET_RT_BIG_ENDIAN 0 +#elif __BIG_ENDIAN__ +#define OG_TARGET_RT_LITTLE_ENDIAN 0 +#define OG_TARGET_RT_BIG_ENDIAN 1 +#else +#error unknown endian +#endif + +#if __LP64__ || __LLP64__ || __POINTER_WIDTH__-0 == 64 +#define OG_TARGET_RT_64_BIT 1 +#else +#define OG_TARGET_RT_64_BIT 0 +#endif + +#endif /* __OPENGRAPHTARGETCONDITIONALS__ */ diff --git a/Sources/_OpenGraph/Private/CFRuntime.h b/Sources/_OpenGraph/Private/CFRuntime.h index 0701782..958c9d8 100644 --- a/Sources/_OpenGraph/Private/CFRuntime.h +++ b/Sources/_OpenGraph/Private/CFRuntime.h @@ -1,5 +1,5 @@ #include "OGBase.h" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN // Copied from https://github.com/apple/swift-corelibs-foundation/blob/d8e8a8b92b3a8af8381a11155328c1bba1c6bd2c/CoreFoundation/Base.subproj/CFRuntime.h /* CFRuntime.h Copyright (c) 1999-2019, Apple Inc. All rights reserved. @@ -283,4 +283,4 @@ CF_EXTERN_C_END #endif /* ! __COREFOUNDATION_CFRUNTIME__ */ #else #include -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ diff --git a/Sources/_OpenGraph/Runtime/OGTypeDescription.cpp b/Sources/_OpenGraph/Runtime/OGTypeDescription.cpp index 2f708f2..52476e8 100644 --- a/Sources/_OpenGraph/Runtime/OGTypeDescription.cpp +++ b/Sources/_OpenGraph/Runtime/OGTypeDescription.cpp @@ -7,11 +7,11 @@ #include "OGTypeDescription.h" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN CFStringRef OGTypeDescription(OGTypeID id) { CFMutableStringRef ref = CFStringCreateMutable(CFAllocatorGetDefault(), 0); // OG::swift::metadata::append_description(__CFString*) const // cast id into metadata and call append_description return ref; } -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ diff --git a/Sources/_OpenGraph/Runtime/OGTypeDescription.h b/Sources/_OpenGraph/Runtime/OGTypeDescription.h index ec9c28a..0c9b4d1 100644 --- a/Sources/_OpenGraph/Runtime/OGTypeDescription.h +++ b/Sources/_OpenGraph/Runtime/OGTypeDescription.h @@ -13,7 +13,7 @@ OG_ASSUME_NONNULL_BEGIN -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN OG_EXTERN_C_BEGIN OG_EXPORT @@ -22,7 +22,7 @@ CFStringRef OGTypeDescription(OGTypeID type); OG_EXTERN_C_END -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ OG_ASSUME_NONNULL_END diff --git a/Sources/_OpenGraph/Util/assert.cpp b/Sources/_OpenGraph/Util/assert.cpp index a8d9101..6fd3b04 100644 --- a/Sources/_OpenGraph/Util/assert.cpp +++ b/Sources/_OpenGraph/Util/assert.cpp @@ -21,9 +21,9 @@ void precondition_failure(const char *format, ...) { vasprintf(&s, format, va); va_end(va); if (s != nullptr) { - #if TARGET_OS_DARWIN + #if OG_TARGET_OS_DARWIN os_log_error(error_log(), "precondition failure: %s", s); - #endif /* TARGET_OS_DARWIN */ + #endif /* OG_TARGET_OS_DARWIN */ // 2023 release addition // OG::Graph::trace_assertion_failure(true, "precondition failure: %s", s) if (error_message == nullptr) { @@ -41,9 +41,9 @@ void non_fatal_precondition_failure(const char *format, ...) { vasprintf(&s, format, va); va_end(va); if (s != nullptr) { - #if TARGET_OS_DARWIN + #if OG_TARGET_OS_DARWIN os_log_fault(error_log(), "precondition failure: %s", s); - #endif /* TARGET_OS_DARWIN */ + #endif /* OG_TARGET_OS_DARWIN */ free(s); } return; diff --git a/Sources/_OpenGraph/Util/log.cpp b/Sources/_OpenGraph/Util/log.cpp index 33adcb5..ea52f1e 100644 --- a/Sources/_OpenGraph/Util/log.cpp +++ b/Sources/_OpenGraph/Util/log.cpp @@ -7,7 +7,7 @@ #include "log.hpp" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN namespace OG { os_log_t misc_log() { @@ -20,4 +20,4 @@ os_log_t error_log() { } } /* OG */ -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ diff --git a/Sources/_OpenGraph/Util/log.hpp b/Sources/_OpenGraph/Util/log.hpp index f56985e..e661d66 100644 --- a/Sources/_OpenGraph/Util/log.hpp +++ b/Sources/_OpenGraph/Util/log.hpp @@ -10,7 +10,7 @@ #include "OGBase.h" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN #include @@ -19,6 +19,6 @@ os_log_t misc_log(); os_log_t error_log(); } /* OG */ -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ #endif /* log_hpp */ diff --git a/Sources/_OpenGraph/Util/realloc_vector.cpp b/Sources/_OpenGraph/Util/realloc_vector.cpp index e0935c8..2dff26d 100644 --- a/Sources/_OpenGraph/Util/realloc_vector.cpp +++ b/Sources/_OpenGraph/Util/realloc_vector.cpp @@ -8,11 +8,11 @@ #include "realloc_vector.hpp" #include "assert.hpp" -#if TARGET_OS_DARWIN +#if OG_TARGET_OS_DARWIN #include #else #include -#endif /* TARGET_OS_DARWIN */ +#endif /* OG_TARGET_OS_DARWIN */ template void *_Nullable OG::details::realloc_vector(void* ptr, T& size, T new_size) { diff --git a/Sources/_OpenGraph/include/OGTargetConditionals.h b/Sources/_OpenGraph/include/OGTargetConditionals.h new file mode 120000 index 0000000..b9f963b --- /dev/null +++ b/Sources/_OpenGraph/include/OGTargetConditionals.h @@ -0,0 +1 @@ +../OGTargetConditionals.h \ No newline at end of file From 9519417c8218733e6508a56f3f56653cd3fe702f Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 24 Feb 2024 23:37:24 +0800 Subject: [PATCH 3/3] Disable dispatch in WASI support --- Sources/_OpenGraph/Graph/Graph.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/_OpenGraph/Graph/Graph.cpp b/Sources/_OpenGraph/Graph/Graph.cpp index d103817..1b21e91 100644 --- a/Sources/_OpenGraph/Graph/Graph.cpp +++ b/Sources/_OpenGraph/Graph/Graph.cpp @@ -6,18 +6,27 @@ // #include "Graph.hpp" +#include "Subgraph.hpp" + +#if !OG_TARGET_OS_WASI #include +#endif #include -#include "Subgraph.hpp" pthread_key_t OG::Graph::_current_update_key; OG::Graph::Graph() OG_NOEXCEPT { // TODO + + // libdispatch is not supported on WASI + // Tracked via https://github.com/swiftwasm/swift/issues/5565 + #if !OG_TARGET_OS_WASI static dispatch_once_t make_keys; dispatch_once_f(&make_keys, nullptr, [](void *context){ pthread_key_create(&_current_update_key, nullptr); OG::Subgraph::make_current_subgraph_key(); }); + #endif + // TODO }