[Python-Dev] [docs] undocumented argtypes magic in ctypes? (original) (raw)
Eli Bendersky eliben at gmail.com
Wed Mar 6 18:19:23 CET 2013
- Previous message: [Python-Dev] Difference in RE between 3.2 and 3.3 (or Aaron Swartz memorial)
- Next message: [Python-Dev] [docs] undocumented argtypes magic in ctypes?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Mar 6, 2013 at 8:33 AM, Andrew Svetlov <andrew.svetlov at gmail.com>wrote:
Looks like bug for me.
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
Eli
On Tue, Mar 5, 2013 at 4:26 PM, Eli Bendersky <eliben at gmail.com> wrote: > Hello, > > While playing with ctypes a bit, I noticed a feature that doesn't appear to > be documented. Suppose I import the readdirr function (assuming DIRENT is a > correctly declared ctypes.Structure): > > DIRp = cvoidp > DIRENTp = POINTER(DIRENT) > DIRENTpp = POINTER(DIRENTp) > > readdirr = lib.readdirr > readdirr.argtypes = [DIRp, DIRENTp, DIRENTpp] > readdirr.restype = cint > > It seems that I can then call it as follows: > > dirent = DIRENT() > result = DIRENTp() > > readdirr(dirfd, dirent, result) > > Note that while readdirr takes DIRENTp and DIRENTpp as its second and > third args, I pass in just DIRENT and DIRENTp, accordingly. What I should > have done is use byref() on both, but ctypes seems to have some magic > applied when argtypes declares pointer types. If I use byref, it still > works. However, if I keep the same call and comment out the argtypes > declaration, I get a segfault. > > So, is it a feature that should be documented, explicitly discouraged or is > it a bug? > > Eli > > _> ________________________ > docs mailing list > docs at python.org > http://mail.python.org/mailman/listinfo/docs >
-- Thanks, Andrew Svetlov -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130306/d87ac147/attachment.html>
- Previous message: [Python-Dev] Difference in RE between 3.2 and 3.3 (or Aaron Swartz memorial)
- Next message: [Python-Dev] [docs] undocumented argtypes magic in ctypes?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]