Skip to content

Commit 57040c9

Browse files
committed
fix: Handle member structure pointers inside a structure
Signed-off-by: shubham kumar <shubham.kumar@intel.com>
1 parent 51aa747 commit 57040c9

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

bindings/sysman/python/test/validate_structures.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ def parse_python_structure(
101101
fields_str = match.group(1)
102102
fields = []
103103

104-
# Parse each field tuple
105-
field_pattern = r'\(\s*"([^"]+)"\s*,\s*([^\)]+?)\s*\)'
106-
107-
for field_match in re.finditer(field_pattern, fields_str):
108-
field_name = field_match.group(1).strip()
109-
field_type = field_match.group(2).strip().rstrip(",")
110-
fields.append((field_name, field_type))
104+
# Parse line by line to handle nested parentheses like POINTER(...)
105+
for line in fields_str.split('\n'):
106+
# Match: ("field_name", field_type), with optional comment
107+
field_match = re.match(r'\s*\(\s*"([^"]+)"\s*,\s*(.+?)\s*\)\s*,?\s*(?:#.*)?$', line)
108+
if field_match:
109+
field_name = field_match.group(1)
110+
field_type = field_match.group(2).strip().rstrip(',')
111+
fields.append((field_name, field_type))
111112

112113
return fields if fields else None
113114

@@ -126,6 +127,18 @@ def normalize_c_type(c_type: str) -> str:
126127
python_base = C_TO_PYTHON_TYPE_MAP.get(base_type, base_type)
127128
return f"{python_base} * {size}"
128129

130+
# Handle pointers to custom structures: zes_power_limit_ext_desc_t* -> POINTER(zes_power_limit_ext_desc_t)
131+
if c_type.endswith("*"):
132+
# Check if it's a mapped type first (like void*, const void*)
133+
if c_type in C_TO_PYTHON_TYPE_MAP:
134+
return C_TO_PYTHON_TYPE_MAP[c_type]
135+
136+
# Otherwise, it's a pointer to a custom type
137+
base_type = c_type[:-1].strip() # Remove * and trailing spaces
138+
# Check if base type is in map (unlikely for pointers, but be safe)
139+
python_base = C_TO_PYTHON_TYPE_MAP.get(base_type, base_type)
140+
return f"POINTER({python_base})"
141+
129142
# Map type if in dictionary, otherwise keep as-is
130143
return C_TO_PYTHON_TYPE_MAP.get(c_type, c_type)
131144

0 commit comments

Comments
 (0)