Skip to content

Commit 723ce72

Browse files
committed
Fix size_flags for the zero-flags case
Resolves #75
1 parent f065ad3 commit 723ce72

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

design/mvp/CanonicalABI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def size_variant(cases):
180180

181181
def size_flags(labels):
182182
n = len(labels)
183+
if n == 0: return 0
183184
if n <= 8: return 1
184185
if n <= 16: return 2
185186
return 4 * num_i32_flags(labels)

design/mvp/canonical-abi/definitions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def size_variant(cases):
183183

184184
def size_flags(labels):
185185
n = len(labels)
186+
if n == 0: return 0
186187
if n <= 8: return 1
187188
if n <= 16: return 2
188189
return 4 * num_i32_flags(labels)

design/mvp/canonical-abi/run_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def test_name():
9595
test(Unit(), [], {})
9696
test(Record([Field('x',U8()), Field('y',U16()), Field('z',U32())]), [1,2,3], {'x':1,'y':2,'z':3})
9797
test(Tuple([Tuple([U8(),U8()]),U8()]), [1,2,3], {'0':{'0':1,'1':2},'1':3})
98+
t = Flags([])
99+
test(t, [], {})
98100
t = Flags(['a','b'])
99101
test(t, [0], {'a':False,'b':False})
100102
test(t, [2], {'a':False,'b':True})
@@ -283,6 +285,12 @@ def test_heap(t, expect, args, byte_array):
283285
[1,0xff,5,0,6,0xff,7,0xff, 0,0xff,8,0xff,0xff,0xff,9,0xff])
284286
test_heap(List(Union([U8()])), [{'0':6},{'0':7},{'0':8}], [0,3],
285287
[0,6, 0,7, 0,8])
288+
t = List(Flags([]))
289+
test_heap(t, [{},{},{}], [0,3],
290+
[])
291+
t = List(Tuple([Flags([]), U8()]))
292+
test_heap(t, [mk_tup({}, 42), mk_tup({}, 43), mk_tup({}, 44)], [0,3],
293+
[42,43,44])
286294
t = List(Flags(['a','b']))
287295
test_heap(t, [{'a':False,'b':False},{'a':False,'b':True},{'a':True,'b':True}], [0,3],
288296
[0,2,3])

0 commit comments

Comments
 (0)