Skip to content

Commit 9198210

Browse files
committed
[[ Bug 21333 ]] Allow aggregates to contain nullptrs
1 parent 899cd79 commit 9198210

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LiveCode Builder Language
2+
## Nullable aggregate fields
3+
* Aggregate fields of Pointer type can now contain `nothing`,
4+
i.e. null pointers

libfoundation/src/foundation-foreign.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,16 @@ static bool _aggregate_export(const MCForeignTypeDescriptor* desc, MCValueRef p_
12941294
const MCForeignTypeDescriptor *t_field_desc = MCForeignTypeInfoGetDescriptor(t_field_type);
12951295
if (t_element_type == t_field_desc->bridgetype)
12961296
{
1297-
if (!t_field_desc->doexport(t_field_desc, t_element, false, t_ptr))
1297+
if (t_element_type == kMCNullTypeInfo)
12981298
{
1299-
t_success = false;
1299+
MCMemoryClear(t_ptr, t_size);
1300+
}
1301+
else
1302+
{
1303+
if (!t_field_desc->doexport(t_field_desc, t_element, false, t_ptr))
1304+
{
1305+
t_success = false;
1306+
}
13001307
}
13011308
}
13021309
else if (MCTypeInfoIsForeign(t_element_type))

tests/lcb/vm/foreign-aggregate.lcb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,18 @@ public handler TestForeignAggregate_Roundtrip()
2626
end repeat
2727
end handler
2828

29+
public foreign type AggregateWithPointer binds to "MCAggregateTypeInfo:r"
30+
constant kAggregateWithNullPointer is [nothing]
31+
32+
public handler TestForeignAggregateNullPointerRoundTrip()
33+
variable tAggregate as AggregateWithPointer
34+
put kAggregateWithNullPointer into tAggregate
35+
36+
variable tList as List
37+
put tAggregate into tList
38+
39+
test "aggregate containing null pointer roundtrips" when \
40+
tList[1] is kAggregateWithNullPointer[1]
41+
end handler
42+
2943
end module

0 commit comments

Comments
 (0)