Gregory Ewing at 2018/4/15 PM 08:20 wrote:
Jach Fong wrote:
 >>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0))
 >>> pvoid.contents
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'c_void_p' object has no attribute 'contents'

I think the 'contents' attribute only applies to pointers that are
pointing at part of another Python object. Your c_void_p instance
is not that kind of pointer.

I must say the ctypes documentation is rather confusing when it
comes to these kinds of details. It doesn't help that the "Pointers
and Arrays" section is marked as "Not yet written". Does anyone
have any plans to finish it?

>>> pt = ctypes.cast(buf0, ctypes.POINTER(ctypes.c_void_p))
>>> type(pt)
<class '__main__.LP_c_void_p'>
>>> pt.contents
c_void_p(1835102323)

From the API point of view, I think it's better not to dive into the ocean of "type" too deeply, especially when foreign language was involved. You may get totally confused. (unless you want to write code like in the IOCCC contest:-)

I have to admit that the ctypes' document was written pretty well. Most of my problems were caused by that I didn't read it thoughtfully:-(

--Jach

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to