Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylibfdt/libfdt.i: fix backwards compatibility of return values #160

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pylibfdt/libfdt.i
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ def check_err_null(val, quiet=()):
FdtException if val indicates an error was reported and the error
is not in @quiet.
"""
# Normally a list is returned which contains the data and its length.
# If we get just an integer error code, it means the function failed.
# Compatibility for SWIG v4.2 and earlier. SWIG 4.2 would drop the first
# item from the list if it was None, returning only the second item.
if not isinstance(val, list):
if -val not in quiet:
raise FdtException(val)
val = [None, val]

if val[0] is None:
if -val[1] not in quiet:
raise FdtException(val[1])
return val

class FdtRo(object):
Expand Down Expand Up @@ -395,8 +398,8 @@ class FdtRo(object):
"""
pdata = check_err_null(
fdt_get_property_by_offset(self._fdt, prop_offset), quiet)
if isinstance(pdata, (int)):
return pdata
if pdata[0] is None:
return pdata[1]
return Property(pdata[0], pdata[1])

def getprop(self, nodeoffset, prop_name, quiet=()):
Expand All @@ -417,8 +420,8 @@ class FdtRo(object):
"""
pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name),
quiet)
if isinstance(pdata, (int)):
return pdata
if pdata[0] is None:
return pdata[1]
return Property(prop_name, bytearray(pdata[0]))

def hasprop(self, nodeoffset, prop_name, quiet=()):
Expand All @@ -444,10 +447,10 @@ class FdtRo(object):
"""
pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name),
quiet + (NOTFOUND,))
if isinstance(pdata, (int)):
if pdata == -NOTFOUND:
if pdata[0] is None:
if pdata[1] == -NOTFOUND:
return False
return pdata
return pdata[1]
return True

def get_phandle(self, nodeoffset):
Expand Down
Loading