homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author higstar
Recipients higstar, theller
Date 2009年05月21日.00:43:40
SpamBayes Score 9.1797156e-05
Marked as misclassified No
Message-id <1242866623.03.0.42045536953.issue6069@psf.upfronthosting.co.za>
In-reply-to
Content
After reading the documentation for ctypes (specifically "Bit fields are
only possible for integer fields" from section 16.15.1.12) I've updated
the test.
---
import ctypes
import time
class uint(ctypes.BigEndianStructure):
 _pack_ = 1 # aligned to 8 bits, not ctypes default of 32
 _fields_ = [
 ("Data0", ctypes.c_uint, 31),
 ("Data1", ctypes.c_uint, 32),
 ]
class ulonglong(ctypes.BigEndianStructure):
 _pack_ = 1 # aligned to 8 bits, not ctypes default of 32
 _fields_ = [
 ("Data0", ctypes.c_ulonglong, 31),
 ("Data1", ctypes.c_ulonglong, 32),
 ]
size_of_structures_in_bytes = 8
def castbytes(type):
 buffer = (ctypes.c_byte * size_of_structures_in_bytes)()
 for index in range(size_of_structures_in_bytes):
 buffer[index] = 0x55
 return ctypes.cast(ctypes.pointer(buffer),
ctypes.POINTER(type)).contents
def print_members(test):
 print("Data0 is 0x%X, Data1 is 0x%X for %s"%(test.Data0, test.Data1,
test.__class__.__name__))
test_classes = [ uint, ulonglong]
Failed = False
tests = [castbytes(type) for type in test_classes]
for test in tests:
 print_members(test)
if not tests[0].Data0 == tests[1].Data0 == 0x2AAAAAAA:
 Failed = True
 print("Data0 failed")
if not tests[0].Data1 == tests[1].Data1 == 0xAAAAAAAA:
 Failed = True
 print("Data1 failed")
if not Failed:
 print("Passed")
History
Date User Action Args
2009年05月21日 00:43:43higstarsetrecipients: + higstar, theller
2009年05月21日 00:43:43higstarsetmessageid: <1242866623.03.0.42045536953.issue6069@psf.upfronthosting.co.za>
2009年05月21日 00:43:41higstarlinkissue6069 messages
2009年05月21日 00:43:40higstarcreate

AltStyle によって変換されたページ (->オリジナル) /