This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, python-dev, steve.dower, tim.golden, zach.ware
Date 2015-03-25.23:43:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427327006.44.0.62112861975.issue23765@psf.upfronthosting.co.za>
In-reply-to
Content
> So the repr that's there for c_char_p is currently::
>    "%s(%s)" % (self.__class__.__name__, cast(self, c_void_p).value)

I suggested switching to using from_buffer:

    c_void_p.from_buffer(self).value 

from_buffer is more efficient. cast() is imlemented as an FFI call. There's also another approach using the buffer protocol:

    int.from_bytes(self, sys.byteorder)

> I prefer the former (remove c_char_p.__repr__ completely), but 
> the latter is clearly there for some reason. Any opinions?

It's there for same reason I suggested overriding c_wchar_p.__repr__. Getting the repr of an object shouldn't segfault the interpreter. The existing check with IsBadStringPtrA is bogus in a multithreaded environment. The repr should just show the address. At least that won't crash.

A topic for another discussion is disabling the SEH handler because it's not used consistently anyway (e.g. to guard pointer and CData base pointer access). To compensate, the faulthandler could be enhanced. It could call the CRT's __pxcptinfoptrs (not documented, but it should be) to get the Windows EXCEPTION_POINTERS record. This would enable at least an improved error message, e.g. "Segmentation fault reading [addr]" and "Segmentation fault writing [addr]". The funny thing is the current faulthandler example uses ctypes.string_at, which, because it's implemented as an FFI call guarded by the SEH handler, just raises OSError on Windows.
History
Date User Action Args
2015-03-25 23:43:26eryksunsetrecipients: + eryksun, tim.golden, python-dev, zach.ware, steve.dower
2015-03-25 23:43:26eryksunsetmessageid: <1427327006.44.0.62112861975.issue23765@psf.upfronthosting.co.za>
2015-03-25 23:43:26eryksunlinkissue23765 messages
2015-03-25 23:43:26eryksuncreate