[Py++] ctypes generator ignores bit fields
Hello, The ctypes code generator translates the struct struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io : 1; unsigned int keep_cache : 1; unsigned int flush : 1; unsigned int padding : 29; uint64_t fh; uint64_t lock_owner; }; into fuse_file_info._fields_ = [ #class fuse_file_info ("flags", ctypes.c_int), ("fh_old", ctypes.c_ulong), ("writepage", ctypes.c_int), ("direct_io", ctypes.c_uint), ("keep_cache", ctypes.c_uint), ("flush", ctypes.c_uint), ("padding", ctypes.c_uint), ("fh", ctypes.c_ulonglong), ("lock_owner", ctypes.c_ulonglong), ] but this is wrong, the correct translation is: fuse_file_info._fields_ = [ ('flags', ctypes.c_int), ('fh_old', ctypes.c_ulong), ('writepage', ctypes.c_int), ('direct_io', ctypes.c_uint, 1), ('keep_cache', ctypes.c_uint, 1), ('flush', ctypes.c_uint, 1), ('padding', ctypes.c_uint, 29), ('fh', ctypes.c_uint64), ('lock_owner', ctypes.c_uint64)] Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
Thanks. I will try to fix the problems you reported this evening and will let you know. On Sat, Dec 26, 2009 at 2:26 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
Hello,
The ctypes code generator translates the struct
struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io : 1; unsigned int keep_cache : 1; unsigned int flush : 1; unsigned int padding : 29; uint64_t fh; uint64_t lock_owner; };
into
fuse_file_info._fields_ = [ #class fuse_file_info ("flags", ctypes.c_int), ("fh_old", ctypes.c_ulong), ("writepage", ctypes.c_int), ("direct_io", ctypes.c_uint), ("keep_cache", ctypes.c_uint), ("flush", ctypes.c_uint), ("padding", ctypes.c_uint), ("fh", ctypes.c_ulonglong), ("lock_owner", ctypes.c_ulonglong), ]
but this is wrong, the correct translation is:
fuse_file_info._fields_ = [ ('flags', ctypes.c_int), ('fh_old', ctypes.c_ulong), ('writepage', ctypes.c_int), ('direct_io', ctypes.c_uint, 1), ('keep_cache', ctypes.c_uint, 1), ('flush', ctypes.c_uint, 1), ('padding', ctypes.c_uint, 29), ('fh', ctypes.c_uint64), ('lock_owner', ctypes.c_uint64)]
Best,
-Nikolaus
-- »Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
-- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
On Sat, Dec 26, 2009 at 10:57 AM, Roman Yakovenko <roman.yakovenko@gmail.com> wrote:
Thanks. I will try to fix the problems you reported this evening and will let you know.
Nikolaus, I fixed both issues you reported: * http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1784&view=rev * http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1785&view=rev Thanks for a good bug reports. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
Roman Yakovenko <roman.yakovenko@gmail.com> writes:
On Sat, Dec 26, 2009 at 10:57 AM, Roman Yakovenko <roman.yakovenko@gmail.com> wrote:
Thanks. I will try to fix the problems you reported this evening and will let you know.
Nikolaus, I fixed both issues you reported: * http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1784&view=rev * http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1785&view=rev
Hi, Thanks for looking into this. I'm afraid the fix for the CFUNCTYPE vs POINTER(CFUNCTYPE) issue is not completely working though. The small testcase that I send around indeed generates correct code with the new version. However, if you try the same code on a more complex header (like the attached one, needs fuse headers to be installed) it still produces the wrong result: fuse_lowlevel_ops._fields_ = [ #class fuse_lowlevel_ops ("init", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p, ctypes.POINTER( fuse_conn_info ) ) )), ("destroy", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p ) )), [...] Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
On Sun, Dec 27, 2009 at 2:46 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
Hi,
Thanks for looking into this. I'm afraid the fix for the CFUNCTYPE vs POINTER(CFUNCTYPE) issue is not completely working though.
The small testcase that I send around indeed generates correct code with the new version. However, if you try the same code on a more complex header (like the attached one, needs fuse headers to be installed) it still produces the wrong result:
fuse_lowlevel_ops._fields_ = [ #class fuse_lowlevel_ops ("init", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p, ctypes.POINTER( fuse_conn_info ) ) )), ("destroy", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p ) )), [...]
:-(. I will take a look on this today. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
On Sun, Dec 27, 2009 at 10:10 AM, Roman Yakovenko <roman.yakovenko@gmail.com> wrote:
On Sun, Dec 27, 2009 at 2:46 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
Hi,
Thanks for looking into this. I'm afraid the fix for the CFUNCTYPE vs POINTER(CFUNCTYPE) issue is not completely working though.
The small testcase that I send around indeed generates correct code with the new version. However, if you try the same code on a more complex header (like the attached one, needs fuse headers to be installed) it still produces the wrong result:
fuse_lowlevel_ops._fields_ = [ #class fuse_lowlevel_ops ("init", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p, ctypes.POINTER( fuse_conn_info ) ) )), ("destroy", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p ) )), [...]
:-(. I will take a look on this today.
Nikolaus, unfortunately I can't reproduce the error. I attached the generated file and the "source" file. Can you investigate a little bit more? Thanks. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
Roman Yakovenko <roman.yakovenko@gmail.com> writes:
On Sun, Dec 27, 2009 at 10:10 AM, Roman Yakovenko <roman.yakovenko@gmail.com> wrote:
On Sun, Dec 27, 2009 at 2:46 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
Hi,
Thanks for looking into this. I'm afraid the fix for the CFUNCTYPE vs POINTER(CFUNCTYPE) issue is not completely working though.
The small testcase that I send around indeed generates correct code with the new version. However, if you try the same code on a more complex header (like the attached one, needs fuse headers to be installed) it still produces the wrong result:
fuse_lowlevel_ops._fields_ = [ #class fuse_lowlevel_ops ("init", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p, ctypes.POINTER( fuse_conn_info ) ) )), ("destroy", ctypes.POINTER( ctypes.CFUNCTYPE( None, ctypes.c_void_p ) )), [...]
:-(. I will take a look on this today.
Nikolaus, unfortunately I can't reproduce the error. I attached the generated file and the "source" file.
Can you investigate a little bit more?
You are right. The reason why it didn't work for me at first was the monkeypatching that I did to get POINTER(c_char) instead of c_char_p. Luckily enough, with your other commit I don't need that patching anymore either. Thanks again! Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
participants (2)
-
Nikolaus Rath -
Roman Yakovenko