This calling of the wrapper functions and assignment to the instance on every new point instantiation just looks bad. It is not that bad, as the wrapped functions are not new objects, but it remakes the assignment to the unique func in the ctypes wrapper for the library (although it would still have a major impact would one write actual Python code dealing with a couple hundred of Point instances)
I'd suggest just making the wrap call once, on top level code, would be much more elegant here:
class Point(...):
...
def move(self):
Point._move_point_func(self)
# These assignments must be after class body, due to the needed referenc to the class itself.
Point._move_point_func = wrap_function(lib, 'move_point', None, [Point])
...
(I am not sure if the functions wrapped by ctypes have a proper __get__. If they have, you might not even need the intermediate move method)
ctypes_example/tutorial2/testWrappedPoint.py
Line 29 in 07e89a1
This calling of the wrapper functions and assignment to the instance on every new point instantiation just looks bad. It is not that bad, as the wrapped functions are not new objects, but it remakes the assignment to the unique
funcin the ctypes wrapper for the library (although it would still have a major impact would one write actual Python code dealing with a couple hundred of Point instances)I'd suggest just making the wrap call once, on top level code, would be much more elegant here:
(I am not sure if the functions wrapped by ctypes have a proper
__get__. If they have, you might not even need the intermediatemovemethod)