Skip to content

Commit 9643764

Browse files
committed
dtschema: Rework int array to matrix fixups
Using _is_int_schema to match int arrays doesn't work if we have a list of 'items' with just descriptions as that looks the same as a string or phandle list. To fix this, let's also look for a $ref to a 'uint*-array' type in addition to integer keywords. As part of this, _fixup_int_array becomes redundant and can be removed. The items size fixup needs to be done after all the other fixups and after all the recursion. Otherwise, we miss some instances. Signed-off-by: Rob Herring <[email protected]>
1 parent 6463dcb commit 9643764

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

dtschema/lib.py

+28-32
Original file line numberDiff line numberDiff line change
@@ -146,48 +146,45 @@ def _fixup_string_to_array(subschema):
146146
subschema['items'] = [ _extract_single_schemas(subschema) ]
147147

148148
def _fixup_int_array_to_matrix(subschema):
149-
is_int = False
149+
if 'allOf' in subschema.keys() and '$ref' in subschema['allOf'][0].keys():
150+
if not re.match('.*uint(8|16|32)-array', subschema['allOf'][0]['$ref']):
151+
return
150152

151-
if not 'items' in subschema.keys():
152-
return
153+
# Find 'items'. It may be under the 'allOf' or at the same level
154+
for item in subschema['allOf']:
155+
if isinstance(item, dict) and 'items' in item.keys():
156+
subschema = item
157+
break
153158

154-
if (not isinstance(subschema['items'],dict)) or 'items' in subschema['items'].keys():
155-
return
159+
if not 'items' in subschema.keys():
160+
return
156161

157-
if not _is_int_schema(subschema['items']):
162+
elif not 'items' in subschema.keys() or \
163+
(isinstance(subschema['items'],list) and not _is_int_schema(subschema['items'][0])) or \
164+
(isinstance(subschema['items'],dict) and not _is_int_schema(subschema['items'])):
158165
return
159166

160-
subschema['items'] = copy.deepcopy(subschema)
161-
# Don't copy 'allOf'
162-
subschema['items'].pop('allOf', None)
163-
for k in list(subschema.keys()):
164-
if k == 'items' or k == 'allOf':
165-
continue
166-
subschema.pop(k)
167-
167+
if isinstance(subschema['items'],dict) and not 'items' in subschema['items'].keys():
168+
subschema['items'] = copy.deepcopy(subschema)
169+
# Don't copy 'allOf'
170+
subschema['items'].pop('allOf', None)
171+
for k in list(subschema.keys()):
172+
if k == 'items' or k == 'allOf':
173+
continue
174+
subschema.pop(k)
175+
176+
if isinstance(subschema['items'],list) and not \
177+
('items' in subschema['items'][0].keys() or \
178+
'minItems' in subschema['items'][0].keys() or \
179+
'maxitems' in subschema['items'][0].keys()):
180+
subschema['items'] = [ {'items': subschema['items']} ]
168181

169182
def _fixup_scalar_to_array(subschema):
170183
if not _is_int_schema(subschema):
171184
return
172185

173186
subschema['items'] = { 'items': _extract_single_schemas(subschema) }
174187

175-
def _fixup_int_array(subschema):
176-
177-
if not 'items' in subschema.keys():
178-
return
179-
180-
# A string list or already a matrix?
181-
for l in subschema['items']:
182-
if isinstance(l, dict) and 'items' in l.keys():
183-
return
184-
if _is_int_schema(l):
185-
break
186-
else:
187-
return
188-
189-
subschema['items'] = [ {'items': subschema['items']} ]
190-
191188
def _fixup_items_size(schema):
192189
# Make items list fixed size-spec
193190
if isinstance(schema, list):
@@ -218,10 +215,8 @@ def fixup_vals(schema):
218215
# Now we should be a the schema level to do actual fixups
219216
# print(schema)
220217
_fixup_int_array_to_matrix(schema)
221-
_fixup_int_array(schema)
222218
_fixup_string_to_array(schema)
223219
_fixup_scalar_to_array(schema)
224-
_fixup_items_size(schema)
225220
# print(schema)
226221

227222
def walk_conditionals(schema):
@@ -456,6 +451,7 @@ def process_schema(filename):
456451

457452
# Add any implicit properties
458453
fixup_node_props(schema)
454+
_fixup_items_size(schema)
459455

460456
add_select_schema(schema)
461457
if not 'select' in schema.keys():

0 commit comments

Comments
 (0)