Showing content from http://mail.python.org/pipermail/python-dev/attachments/20130306/d87ac147/attachment.html below:
<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 6, 2013 at 8:33 AM, Andrew Svetlov <span dir="ltr"><<a href="mailto:andrew.svetlov@gmail.com" target="_blank">andrew.svetlov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Looks like bug for me.<br></blockquote><div><br></div><div>ctypes seems to auto-convert arguments when argtypes is specified. This fact is documented. However, I'm not sure whether this auto-conversion is advanced enough to apply byref. Because otherwise, DIRENT is certainly not convertible to DIRENT_p<br>
<br>Eli<br><br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5"><br>
On Tue, Mar 5, 2013 at 4:26 PM, Eli Bendersky <<a href="mailto:eliben@gmail.com">eliben@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> While playing with ctypes a bit, I noticed a feature that doesn't appear to<br>
> be documented. Suppose I import the readdir_r function (assuming DIRENT is a<br>
> correctly declared ctypes.Structure):<br>
><br>
> DIR_p = c_void_p<br>
> DIRENT_p = POINTER(DIRENT)<br>
> DIRENT_pp = POINTER(DIRENT_p)<br>
><br>
> readdir_r = lib.readdir_r<br>
> readdir_r.argtypes = [DIR_p, DIRENT_p, DIRENT_pp]<br>
> readdir_r.restype = c_int<br>
><br>
> It seems that I can then call it as follows:<br>
><br>
> dirent = DIRENT()<br>
> result = DIRENT_p()<br>
><br>
> readdir_r(dir_fd, dirent, result)<br>
><br>
> Note that while readdir_r takes DIRENT_p and DIRENT_pp as its second and<br>
> third args, I pass in just DIRENT and DIRENT_p, accordingly. What I should<br>
> have done is use byref() on both, but ctypes seems to have some magic<br>
> applied when argtypes declares pointer types. If I use byref, it still<br>
> works. However, if I keep the same call and comment out the argtypes<br>
> declaration, I get a segfault.<br>
><br>
> So, is it a feature that should be documented, explicitly discouraged or is<br>
> it a bug?<br>
><br>
> Eli<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> docs mailing list<br>
> <a href="mailto:docs@python.org">docs@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/docs" target="_blank">http://mail.python.org/mailman/listinfo/docs</a><br>
><br>
<br>
<br>
<br>
--<br>
Thanks,<br>
Andrew Svetlov<br>
</blockquote></div><br></div></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4