Skip to content
Advertisement

How to model struct that contains reference to it’s definition in python through ctypes?

trying to wrap struct the reference it’s definition as below

foo.c

JavaScript

how to model that, for example

foo.py

JavaScript

of course python doesn’t interpret that, I could use c_void_p instead of pointer(Foo), and cast it’s value as follow

JavaScript

but, is there a way to model that struct in a python class?

Advertisement

Answer

From [Python.Docs]: ctypes – Incomplete Types:

… . In ctypes, we can define the cell class and and set the _fields_ attribute later, after the class statement.

Applying that to the current problem, the code would look smth like:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement