Skip to content

Commit ddbbce4

Browse files
committed
Use c_char type for Int8 arrays in ir_to_ctypes
1 parent c580aab commit ddbbce4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pylibbpf/ir_to_ctypes.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ def ir_type_to_ctypes(ir_type):
2222

2323
elif isinstance(ir_type, ir.ArrayType):
2424
count = ir_type.count
25-
element_type = ir_type_to_ctypes(ir_type.element)
26-
return element_type * count
27-
25+
element_type_ir = ir_type.element
26+
27+
if isinstance(element_type_ir, ir.IntType) and element_type_ir.width == 8:
28+
# Use c_char for string fields (will have .decode())
29+
return ctypes.c_char * count
30+
else:
31+
element_type = ir_type_to_ctypes(element_type_ir)
32+
return element_type * count
2833
elif isinstance(ir_type, ir.PointerType):
2934
return ctypes.c_void_p
3035

0 commit comments

Comments
 (0)