Skip to content

Commit 38bf2ad

Browse files
authored
Fix tuple.value not set in OGTupleWithBuffer (#135)
* Fix tuple.value not set in OGTupleWithBuffer * Update TupleTypeCompatibilityTests.swift
1 parent 6aceaa1 commit 38bf2ad

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Sources/OpenGraph_SPI/Runtime/OGTupleType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ void OGTupleWithBuffer(OGTupleType tuple_type, size_t count, const void (* funct
243243
if (buffer_size <= 0x1000) {
244244
char buffer[buffer_size];
245245
bzero(buffer, buffer_size);
246+
tuple.value = buffer;
246247
// NOTE: If you use buffer out of the scope, the stack may be malformed.
247248
// So we need to call function in this scope.
248249
function(tuple, context);

Tests/OpenGraphCompatibilityTests/Runtime/TupleTypeCompatibilityTests.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ struct UnsafeMutableTupleCompatibilityTests {
151151
}
152152

153153
@Test
154-
func buffer() {
154+
func stackBuffer() {
155+
// size <= 0x1000
155156
withUnsafeTuple(of: TupleType([T1.self, T2.self]), count: 1) { mutableTuple in
156157
let ref = T1()
157158
ref.a = 1
@@ -162,6 +163,26 @@ struct UnsafeMutableTupleCompatibilityTests {
162163
let t1 = tuple[0] as T1
163164
let t2 = tuple[1] as T2
164165

166+
#expect(t1 === ref)
167+
#expect(t1.a == 1)
168+
#expect(t2.a == 2)
169+
}
170+
171+
}
172+
173+
@Test
174+
func heapBuffer() {
175+
// size > 0x1000
176+
withUnsafeTuple(of: TupleType([T1.self, T2.self]), count: 512) { mutableTuple in
177+
let ref = T1()
178+
ref.a = 1
179+
mutableTuple.initialize(at: 0, to: ref)
180+
mutableTuple.initialize(at: 1, to: T2(a: 2))
181+
182+
let tuple = UnsafeTuple(type: mutableTuple.type, value: mutableTuple.value)
183+
let t1 = tuple[0] as T1
184+
let t2 = tuple[1] as T2
185+
165186
#expect(t1 === ref)
166187
#expect(t1.a == 1)
167188
#expect(t2.a == 2)

0 commit comments

Comments
 (0)