Skip to content

Commit e1cefcf

Browse files
schema: use ly_array_iter for SLeafList defaults API
It is way clearer this way. Closes: #119 Signed-off-by: Stefan Gula <[email protected]> Signed-off-by: Samuel Gauthier <[email protected]>
1 parent 2fc312b commit e1cefcf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

libyang/schema.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,15 +1414,12 @@ def type(self) -> Type:
14141414
def defaults(self) -> Iterator[Union[None, bool, int, str, float]]:
14151415
if self.cdata_leaflist.dflts == ffi.NULL:
14161416
return
1417-
arr_length = ffi.cast("uint64_t *", self.cdata_leaflist.dflts)[-1]
1418-
for i in range(arr_length):
1419-
val = lib.lyd_value_get_canonical(
1420-
self.context.cdata, self.cdata_leaflist.dflts[i]
1421-
)
1417+
for dflt in ly_array_iter(self.cdata_leaflist.dflts):
1418+
val = lib.lyd_value_get_canonical(self.context.cdata, dflt)
14221419
if not val:
14231420
yield None
14241421
val = c2str(val)
1425-
val_type = Type(self.context, self.cdata_leaflist.dflts[i].realtype, None)
1422+
val_type = Type(self.context, dflt.realtype, None)
14261423
if val_type == Type.BOOL:
14271424
yield val == "true"
14281425
elif val_type in Type.NUM_TYPES:

0 commit comments

Comments
 (0)