Skip to content

Commit e60bdda

Browse files
authored
Update compareValues API (#132)
1 parent 83bedb9 commit e60bdda

File tree

14 files changed

+208
-75
lines changed

14 files changed

+208
-75
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/OpenGraph/Attribute/Attribute/External.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct External<Value> {
1313
// MARK: - _AttributeBody
1414

1515
extension External: _AttributeBody {
16-
public static var comparisonMode: OGComparisonMode { ._3 }
16+
public static var comparisonMode: ComparisonMode { .equatableAlways }
1717

1818
public static var flags: OGAttributeTypeFlags { [] }
1919

Sources/OpenGraph/Attribute/Body/AttributeBody.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public protocol _AttributeBody {
1111
static func _destroySelf(_ pointer: UnsafeMutableRawPointer)
1212
static var _hasDestroySelf: Bool { get }
1313
static func _updateDefault(_ pointer: UnsafeMutableRawPointer)
14-
static var comparisonMode: OGComparisonMode { get }
14+
static var comparisonMode: ComparisonMode { get }
1515
static var flags: OGAttributeTypeFlags { get }
1616
}
1717

@@ -21,7 +21,7 @@ extension _AttributeBody {
2121
public static func _destroySelf(_ pointer: UnsafeMutableRawPointer) {}
2222
public static var _hasDestroySelf: Bool { false }
2323
public static func _updateDefault(_ pointer: UnsafeMutableRawPointer) {}
24-
public static var comparisonMode: OGComparisonMode { ._2 }
24+
public static var comparisonMode: ComparisonMode { .equatableUnlessPOD }
2525
public static var flags: OGAttributeTypeFlags { .mainThread }
2626
}
2727

Sources/OpenGraph/Runtime/CompareValues.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ private func OGCompareValues(
1212
lhs: UnsafeRawPointer,
1313
rhs: UnsafeRawPointer,
1414
type: Any.Type,
15-
options: OGComparisonOptions
15+
options: ComparisonOptions
1616
) -> Bool
1717

18-
public func compareValues<Value>(_ lhs: Value, _ rhs: Value, mode: OGComparisonMode = ._3) -> Bool {
19-
compareValues(lhs, rhs, options: OGComparisonOptions(mode: mode))
18+
public func compareValues<Value>(_ lhs: Value, _ rhs: Value, mode: ComparisonMode = .equatableAlways) -> Bool {
19+
compareValues(lhs, rhs, options: [.init(mode: mode), .copyOnWrite])
2020
}
2121

22-
public func compareValues<Value>(_ lhs: Value, _ rhs: Value, options: OGComparisonOptions) -> Bool {
22+
public func compareValues<Value>(_ lhs: Value, _ rhs: Value, options: ComparisonOptions) -> Bool {
2323
withUnsafePointer(to: lhs) { p1 in
2424
withUnsafePointer(to: rhs) { p2 in
25-
OGCompareValues(lhs: p1, rhs: p2, type: Value.self, options: .init(rawValue: options.rawValue | 0x100))
25+
OGCompareValues(lhs: p1, rhs: p2, type: Value.self, options: options)
2626
}
2727
}
2828
}
2929

30-
extension OGComparisonOptions {
31-
public init(mode: OGComparisonMode) {
32-
self.init(rawValue: mode.rawValue)
30+
extension ComparisonOptions {
31+
public init(mode: ComparisonMode) {
32+
self.init(rawValue: numericCast(mode.rawValue))
3333
}
3434
}

Sources/OpenGraphShims/GraphShims.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public typealias OGAttributeType = AGAttributeType
1010
public typealias OGAttributeTypeFlags = AGAttributeTypeFlags
1111
public typealias OGCachedValueOptions = AGCachedValueOptions
1212
public typealias OGChangedValueFlags = AGChangedValueFlags
13-
public typealias OGComparisonMode = AGComparisonMode
14-
public typealias OGComparisonOptions = AGComparisonOptions
1513
public typealias OGCounterQueryType = AGCounterQueryType
1614
public typealias OGDebugServer = AGDebugServer
1715
public typealias OGInputOptions = AGInputOptions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// OGCompareValues.cpp
3+
// OpenGraph_SPI
4+
5+
#include "OGComparison.h"
6+
#include "OGComparisonPrivate.h"
7+
8+
const void *OGComparisonStateGetDestination(OGComparisonState state) {
9+
return state->destination;
10+
}
11+
12+
const void *OGComparisonStateGetSource(OGComparisonState state) {
13+
return state->source;
14+
}
15+
16+
OGFieldRange OGComparisonStateGetFieldRange(OGComparisonState state) {
17+
return state->field_range;
18+
}
19+
20+
OGTypeID OGComparisonStateGetFieldType(OGComparisonState state) {
21+
return state->field_type;
22+
}
23+
24+
bool OGCompareValues(const void *lhs, const void *rhs, OGTypeID type, OGComparisonOptions options) {
25+
// TODO
26+
return false;
27+
}
28+
29+
const unsigned char *_Nullable OGPrefetchCompareValues(OGTypeID type_id,
30+
OGComparisonOptions options,
31+
uint32_t priority) {
32+
// TODO
33+
return nullptr;
34+
}
35+
36+
void OGOverrideComparisonForTypeDescriptor(void *descriptor, OGComparisonMode mode) {
37+
// TODO
38+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// OGComparisonPrivate.h
3+
// OpenGraph_SPI
4+
//
5+
// Audited for 6.5.4
6+
// Status: Complete
7+
//
8+
// Modified based on Compute project: https://github.com/jcmosc/Compute/blob/main/Sources/ComputeCxx/Comparison/AGComparison-Private.h
9+
// Copyright (c) 2025 James Moschou
10+
//
11+
// Permission is hereby granted, free of charge, to any person obtaining a copy
12+
// of this software and associated documentation files (the "Software"), to deal
13+
// in the Software without restriction, including without limitation the rights
14+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
// copies of the Software, and to permit persons to whom the Software is
16+
// furnished to do so, subject to the following conditions:
17+
//
18+
// The above copyright notice and this permission notice shall be included in all
19+
// copies or substantial portions of the Software.
20+
//
21+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMOGES OR OTHER
25+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
// SOFTWARE.
28+
29+
#ifndef OGComparisonPrivate_h
30+
#define OGComparisonPrivate_h
31+
32+
#include "OGBase.h"
33+
#include "OGComparison.h"
34+
#include "OGTypeID.h"
35+
36+
OG_ASSUME_NONNULL_BEGIN
37+
38+
OG_EXTERN_C_BEGIN
39+
40+
typedef struct OGComparisonStateStorage {
41+
const void *destination;
42+
const void *source;
43+
OGFieldRange field_range;
44+
OGTypeID field_type;
45+
} OGComparisonStateStorage;
46+
47+
OG_EXTERN_C_END
48+
49+
OG_ASSUME_NONNULL_END
50+
51+
#endif /* OGComparisonPrivate_h */
52+

Sources/OpenGraph_SPI/Runtime/OGCompareValues.cpp

Lines changed: 0 additions & 13 deletions
This file was deleted.

Sources/OpenGraph_SPI/include/OGCompareValues.h

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// OGComparison.h
3+
// OpenGraph_SPI
4+
//
5+
// Audited for 6.5.4
6+
// Status: Complete
7+
8+
//
9+
// Modified based on Compute project: https://github.com/jcmosc/Compute/blob/main/Sources/ComputeCxx/Comparison/AGComparison.h
10+
// Copyright (c) 2025 James Moschou
11+
//
12+
// Permission is hereby granted, free of charge, to any person obtaining a copy
13+
// of this software and associated documentation files (the "Software"), to deal
14+
// in the Software without restriction, including without limitation the rights
15+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
// copies of the Software, and to permit persons to whom the Software is
17+
// furnished to do so, subject to the following conditions:
18+
//
19+
// The above copyright notice and this permission notice shall be included in all
20+
// copies or substantial portions of the Software.
21+
//
22+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMOGES OR OTHER
26+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
// SOFTWARE.
29+
30+
#ifndef OGComparison_h
31+
#define OGComparison_h
32+
33+
#include "OGBase.h"
34+
#include "OGTypeID.h"
35+
36+
OG_ASSUME_NONNULL_BEGIN
37+
38+
OG_EXTERN_C_BEGIN
39+
40+
typedef struct OGFieldRange {
41+
size_t offset;
42+
size_t size;
43+
} OGFieldRange;
44+
45+
typedef struct OGComparisonStateStorage *OGComparisonState;
46+
47+
OG_EXPORT
48+
OG_REFINED_FOR_SWIFT
49+
const void *OGComparisonStateGetDestination(OGComparisonState state);
50+
51+
OG_EXPORT
52+
OG_REFINED_FOR_SWIFT
53+
const void *OGComparisonStateGetSource(OGComparisonState state);
54+
55+
OG_EXPORT
56+
OG_REFINED_FOR_SWIFT
57+
OGFieldRange OGComparisonStateGetFieldRange(OGComparisonState state);
58+
59+
OG_EXPORT
60+
OG_REFINED_FOR_SWIFT
61+
OGTypeID OGComparisonStateGetFieldType(OGComparisonState state);
62+
63+
typedef OG_ENUM(uint8_t, OGComparisonMode) {
64+
OGComparisonModeBitwise = 0,
65+
OGComparisonModeIndirect = 1,
66+
OGComparisonModeEquatableUnlessPOD = 2,
67+
OGComparisonModeEquatableAlways = 3,
68+
} OG_SWIFT_NAME(ComparisonMode);
69+
70+
typedef OG_OPTIONS(uint32_t, OGComparisonOptions) {
71+
OGComparisonOptionsComparisonModeBitwise = 0,
72+
OGComparisonOptionsComparisonModeIndirect = 1,
73+
OGComparisonOptionsComparisonModeEquatableUnlessPOD = 2,
74+
OGComparisonOptionsComparisonModeEquatableAlways = 3,
75+
OGComparisonOptionsComparisonModeMask = 0xff,
76+
77+
OGComparisonOptionsCopyOnWrite = 1 << 8,
78+
OGComparisonOptionsFetchLayoutsSynchronously = 1 << 9,
79+
OGComparisonOptionsReportFailures = 1ul << 31, // -1 signed int
80+
} OG_SWIFT_NAME(ComparisonOptions);
81+
82+
OG_EXPORT
83+
OG_REFINED_FOR_SWIFT
84+
bool OGCompareValues(const void *lhs,
85+
const void *rhs,
86+
OGTypeID type_id,
87+
OGComparisonOptions options);
88+
89+
OG_EXPORT
90+
OG_REFINED_FOR_SWIFT
91+
const unsigned char *_Nullable OGPrefetchCompareValues(OGTypeID type_id,
92+
OGComparisonOptions options,
93+
uint32_t priority);
94+
95+
OG_EXPORT
96+
OG_REFINED_FOR_SWIFT
97+
void OGOverrideComparisonForTypeDescriptor(void *descriptor, OGComparisonMode mode);
98+
99+
OG_EXTERN_C_END
100+
101+
OG_ASSUME_NONNULL_END
102+
103+
#endif /* OGComparison_h */

0 commit comments

Comments
 (0)