Create a ctypes Structure subclass dynamically.
(sdef: StructDef, known: dict[str, type])
| 178 | |
| 179 | |
| 180 | def _make_struct(sdef: StructDef, known: dict[str, type]) -> type: |
| 181 | """Create a ctypes Structure subclass dynamically.""" |
| 182 | fields = [] |
| 183 | for f in sdef.fields: |
| 184 | ct = _resolve_type(f.c_type, known) |
| 185 | if ct is None: |
| 186 | ct = c_void_p |
| 187 | if f.bitfield is not None: |
| 188 | fields.append((f.name, ct, f.bitfield)) |
| 189 | else: |
| 190 | fields.append((f.name, ct)) # type: ignore[arg-type] |
| 191 | |
| 192 | cls = type(sdef.name, (Structure,), {"_fields_": fields}) |
| 193 | return cls |
| 194 | |
| 195 | |
| 196 | # ============================================================================ |
no test coverage detected