From cf40826f7a7dd4fe681451a647673253fdd1e0e7 Mon Sep 17 00:00:00 2001 From: Dark-detsixE Date: Fri, 25 Jul 2025 11:21:16 +0800 Subject: [PATCH 1/2] Fix tuple.value not set in OGTupleWithBuffer --- Sources/OpenGraph_SPI/Runtime/OGTupleType.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/OpenGraph_SPI/Runtime/OGTupleType.cpp b/Sources/OpenGraph_SPI/Runtime/OGTupleType.cpp index 6cdecc8d..22b95809 100644 --- a/Sources/OpenGraph_SPI/Runtime/OGTupleType.cpp +++ b/Sources/OpenGraph_SPI/Runtime/OGTupleType.cpp @@ -243,6 +243,7 @@ void OGTupleWithBuffer(OGTupleType tuple_type, size_t count, const void (* funct if (buffer_size <= 0x1000) { char buffer[buffer_size]; bzero(buffer, buffer_size); + tuple.value = buffer; // NOTE: If you use buffer out of the scope, the stack may be malformed. // So we need to call function in this scope. function(tuple, context); From 6d2dfd09c3ef7bc642972c43ccf0010bf9ce4954 Mon Sep 17 00:00:00 2001 From: Dark-detsixE Date: Mon, 28 Jul 2025 15:05:21 +0800 Subject: [PATCH 2/2] Update TupleTypeCompatibilityTests.swift --- .../Runtime/TupleTypeCompatibilityTests.swift | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Tests/OpenGraphCompatibilityTests/Runtime/TupleTypeCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Runtime/TupleTypeCompatibilityTests.swift index 838d0707..ad81905c 100644 --- a/Tests/OpenGraphCompatibilityTests/Runtime/TupleTypeCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Runtime/TupleTypeCompatibilityTests.swift @@ -151,7 +151,8 @@ struct UnsafeMutableTupleCompatibilityTests { } @Test - func buffer() { + func stackBuffer() { + // size <= 0x1000 withUnsafeTuple(of: TupleType([T1.self, T2.self]), count: 1) { mutableTuple in let ref = T1() ref.a = 1 @@ -162,6 +163,26 @@ struct UnsafeMutableTupleCompatibilityTests { let t1 = tuple[0] as T1 let t2 = tuple[1] as T2 + #expect(t1 === ref) + #expect(t1.a == 1) + #expect(t2.a == 2) + } + + } + + @Test + func heapBuffer() { + // size > 0x1000 + withUnsafeTuple(of: TupleType([T1.self, T2.self]), count: 512) { mutableTuple in + let ref = T1() + ref.a = 1 + mutableTuple.initialize(at: 0, to: ref) + mutableTuple.initialize(at: 1, to: T2(a: 2)) + + let tuple = UnsafeTuple(type: mutableTuple.type, value: mutableTuple.value) + let t1 = tuple[0] as T1 + let t2 = tuple[1] as T2 + #expect(t1 === ref) #expect(t1.a == 1) #expect(t2.a == 2)