On Wed, Mar 6, 2013 at 8:33 AM, Andrew Svetlov <andrew.svet...@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 <eli...@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 readdir_r function (assuming DIRENT > is a > > correctly declared ctypes.Structure): > > > > DIR_p = c_void_p > > DIRENT_p = POINTER(DIRENT) > > DIRENT_pp = POINTER(DIRENT_p) > > > > readdir_r = lib.readdir_r > > readdir_r.argtypes = [DIR_p, DIRENT_p, DIRENT_pp] > > readdir_r.restype = c_int > > > > It seems that I can then call it as follows: > > > > dirent = DIRENT() > > result = DIRENT_p() > > > > readdir_r(dir_fd, dirent, result) > > > > Note that while readdir_r takes DIRENT_p and DIRENT_pp as its second and > > third args, I pass in just DIRENT and DIRENT_p, 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 > > d...@python.org > > http://mail.python.org/mailman/listinfo/docs > > > > > > -- > Thanks, > Andrew Svetlov >
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com