[issue22552] ctypes.CDLL returns singleton objects, resulting in usage conflicts

Ivan Pozdeev report at bugs.python.org
Sun Oct 5 03:33:11 CEST 2014


Ivan Pozdeev added the comment:

@R. David Murray: haha, the reverse change that introduced this problem in the first place! issue 14201's problem is exactly why I was going to suggest to also make _FuncPtr's compare equal if they point to the same function.

@eryksun: Packages do this because it's the natural thing to do - there's no apparent way to clone a pointer, there's not even a notion they _need_ to be cloned. https://docs.python.org/2/library/ctypes.html#loading-shared-libraries only documents __getattr__() and behavior of a LibraryLoader, not of a CDLL . 

Bottom line: ctypes currently leaves a trap for users to fall into. While Python's paradigm is "make right things easy, make wrong things hard".

So, he optimal way seems to require to clone function pointers to set attributes. I'm going to add a guard attribute and a `clone' method to _FuncPtr. It's discussable whether to make cloned/altered pointers compare equal to the originals.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22552>
_______________________________________


More information about the Python-bugs-list mailing list