Skip to content

Commit 8d7cf78

Browse files
committed
Fix for 64-bit architectures.
1 parent 6820130 commit 8d7cf78

4 files changed

Lines changed: 54 additions & 32 deletions

File tree

NEWS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11

2+
* Version 0.6 29 Dec 2000
3+
4+
** Fix to make python-xlib work on 64-bytes architectures.
5+
6+
The struct and array modules uses sizeof(long) to determine the number
7+
of bytes used when representing the type code 'l'. On Intel and VAX,
8+
this is 32 bits as expected. On Alpha, it's 64 bits. python-xlib now
9+
probes how large each type code is to avoid this problem.
10+
11+
212
* Version 0.5 28 Dec 2000
313

414
** Functions implemented to get and set all ICCCM WM properties on

Xlib/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: __init__.py,v 1.6 2000-12-22 13:23:34 petli Exp $
1+
# $Id: __init__.py,v 1.7 2000-12-29 16:16:54 petli Exp $
22
#
33
# Xlib.__init__ -- glue for Xlib package
44
#
@@ -33,5 +33,4 @@
3333
'xobject',
3434
]
3535

36-
__version__ = (0, 5)
37-
36+
__version__ = (0, 6)

Xlib/protocol/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Fri Dec 29 17:05:02 2000 Peter Liljenberg <petli@cendio.se>
2+
3+
* rq.py: Alpha forces us to probe how many bytes each struct code
4+
in 'bhil' represents, instead of being able to assume that b is 1,
5+
h is 2 and l is 4.
6+
17
2000-12-21 <petli@cendio.se>
28

39
* request.py (SetClipRectangles): Fixed typo (attribute was

Xlib/protocol/rq.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rq.py,v 1.8 2000-12-22 13:23:34 petli Exp $
1+
# $Id: rq.py,v 1.9 2000-12-29 16:17:02 petli Exp $
22
#
33
# Xlib.protocol.rq -- structure primitives for request, events and errors
44
#
@@ -33,16 +33,23 @@
3333

3434
class BadDataError(Exception): pass
3535

36-
unsigned_codes = { 1: 'b',
37-
2: 'h',
38-
4: 'l'
39-
}
4036

41-
unsigned_codes = { 1: 'B',
42-
2: 'H',
43-
4: 'L'
44-
}
37+
# Thanks to buggy behaviour of struct and array on 64-bit architectures,
38+
# we have to probe which format codes to use for 8, 16 and 32-bit values
4539

40+
signed_codes = { }
41+
unsigned_codes = { }
42+
43+
for c in 'bhil':
44+
signed_codes[struct.calcsize('=' + c)] = c
45+
unsigned_codes[struct.calcsize('=' + c)] = string.upper(c)
46+
47+
sb_code = signed_codes[1]
48+
ub_code = unsigned_codes[1]
49+
sw_code = signed_codes[2]
50+
uw_code = unsigned_codes[2]
51+
sl_code = signed_codes[4]
52+
ul_code = unsigned_codes[4]
4653

4754
class Field:
4855
"""Field objects represent the data fields of a Struct.
@@ -152,7 +159,7 @@ def get_binary_value(self, keys):
152159

153160

154161
class Opcode(ConstantField):
155-
structcode = 'B'
162+
structcode = ub_code
156163
structvalues = 1
157164

158165

@@ -278,27 +285,27 @@ def pack_value(self, value):
278285
return val
279286

280287
class Int8(ValueField):
281-
structcode = 'b'
288+
structcode = sb_code
282289
structvalues = 1
283290

284291
class Int16(ValueField):
285-
structcode = 'h'
292+
structcode = sw_code
286293
structvalues = 1
287294

288295
class Int32(ValueField):
289-
structcode = 'l'
296+
structcode = sl_code
290297
structvalues = 1
291298

292299
class Card8(ValueField):
293-
structcode = 'B'
300+
structcode = ub_code
294301
structvalues = 1
295302

296303
class Card16(ValueField):
297-
structcode = 'H'
304+
structcode = uw_code
298305
structvalues = 1
299306

300307
class Card32(ValueField):
301-
structcode = 'L'
308+
structcode = ul_code
302309
structvalues = 1
303310

304311

@@ -361,7 +368,7 @@ class Cursor(Resource):
361368

362369
class Bool(ValueField):
363370
structvalues = 1
364-
structcode = 'B'
371+
structcode = ub_code
365372

366373
def check_value(self, value):
367374
return not not value
@@ -441,15 +448,15 @@ def pack_value(self, val):
441448
else:
442449
pad = ''
443450

444-
return apply(struct.pack, ('>' + 'H' * slen, ) + tuple(val)) + pad, slen
451+
return apply(struct.pack, ('>' + uw_code * slen, ) + tuple(val)) + pad, slen
445452

446453
def parse_binary_value(self, data, display, length, format):
447454
if self.pad:
448455
slen = length + (length % 2)
449456
else:
450457
slen = length
451458

452-
return struct.unpack('>' + 'H' * length, data[:length]), data[slen:]
459+
return struct.unpack('>' + uw_code * length, data[:length]), data[slen:]
453460

454461

455462

@@ -596,11 +603,11 @@ def parse_binary_value(self, data, display, length, format):
596603
data = data[length + ((4 - length % 4) % 4):]
597604

598605
elif format == 16:
599-
ret = (16, array.array('H', data[:2 * length]))
606+
ret = (16, array.array(uw_code, data[:2 * length]))
600607
data = data[2 * (length + length % 2):]
601608

602609
elif format == 32:
603-
ret = (32, array.array('L', data[:4 * length]))
610+
ret = (32, array.array(ul_code, data[:4 * length]))
604611
data = data[4 * length:]
605612

606613
return ret, data
@@ -725,7 +732,7 @@ def parse_binary_value(self, data, display, length, format):
725732
else:
726733
dlen = length * format
727734

728-
a = array.array('L', data[:dlen])
735+
a = array.array(ul_code, data[:dlen])
729736

730737
ret = []
731738
for i in range(0, len(a), format):
@@ -738,7 +745,7 @@ def pack_value(self, value):
738745
for v in value:
739746
keycodes = max(keycodes, len(v))
740747

741-
a = array.array('L')
748+
a = array.array(ul_code)
742749

743750
for v in value:
744751
for k in v:
@@ -753,7 +760,7 @@ class ModifierMapping(ValueField):
753760
structcode = None
754761

755762
def parse_binary_value(self, data, display, length, format):
756-
a = array.array('B', data[:8 * format])
763+
a = array.array(ub_code, data[:8 * format])
757764

758765
ret = []
759766
for i in range(0, 8):
@@ -769,7 +776,7 @@ def pack_value(self, value):
769776
for v in value:
770777
keycodes = max(keycodes, len(v))
771778

772-
a = array.array('B')
779+
a = array.array(ub_code)
773780

774781
for v in value:
775782
for k in v:
@@ -802,12 +809,12 @@ def __init__(self, code):
802809
def parse_value(self, value, display):
803810
return value
804811

805-
Card8Obj = ScalarObj('B')
806-
Card16Obj = ScalarObj('H')
807-
Card32Obj = ScalarObj('L')
812+
Card8Obj = ScalarObj(ub_code)
813+
Card16Obj = ScalarObj(uw_code)
814+
Card32Obj = ScalarObj(ul_code)
808815

809816
class ResourceObj:
810-
structcode = 'L'
817+
structcode = ul_code
811818
structvalues = 1
812819

813820
def __init__(self, class_name):

0 commit comments

Comments
 (0)