From 23cafa4d7bfad1c5b6c8e1f33cf9e9c4b16158fb Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 20 Oct 2025 02:58:22 +0530 Subject: [PATCH] Expose classes and perform struct conversion in __init__ --- __init__.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d679661 --- /dev/null +++ b/__init__.py @@ -0,0 +1,41 @@ +import logging +from .pylibbpf import ( + BpfObject as _BpfObject, # C++ object (internal) + BpfProgram, + BpfMap, + PerfEventArray, + StructParser, + BpfException, +) +from .wrappers import BpfObjectWrapper +from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs + +logger = logging.getLogger(__name__) + + +class BpfObject(BpfObjectWrapper): + """BpfObject with automatic struct conversion""" + + def __init__(self, object_path: str, structs=None): + """Create a BPF object""" + if structs is None: + structs = {} + elif is_pythonbpf_structs(structs): + logger.info(f"Auto-converting {len(structs)} PythonBPF structs to ctypes") + structs = convert_structs_to_ctypes(structs) + + # Create C++ BpfObject with converted structs + cpp_obj = _BpfObject(object_path, structs) + + # Initialize wrapper + super().__init__(cpp_obj) + + +__all__ = [ + "BpfObject", + "BpfProgram", + "BpfMap", + "PerfEventArray", + "StructParser", + "BpfException", +]