Hirokazu Yamamoto <ocean-c...@m2.ccsnet.ne.jp> added the comment:

Here is at least better, simple patch. But ideally,
mask should be created from variable type. "short" mask
should be created for "short" variable, "long long" mask
for "long long" variable, vise verse.

I'll create such patch next. I hope it's final solution.

////////////////////////////////////////
// This works on attached patch.

from __future__ import print_function
import ctypes
class Blah(ctypes.Structure):
    _fields_ = [("a", ctypes.c_uint64, 64),
                ("b", ctypes.c_uint16, 16),
                ("c", ctypes.c_uint8, 8),
                ("d", ctypes.c_uint8, 8)]

x = Blah(0xFEDCBA9876543210,0xBEEF,0x44,0x12)
print(Blah.a, hex(x.a))
print(Blah.b, hex(x.b))
print(Blah.c, hex(x.c))
print(Blah.d, hex(x.d))

----------
versions:  -Python 2.6
Added file: http://bugs.python.org/file19120/py3k_fix_ctypes_cfields.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6493>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to