Issue577728

classification
Title: struct.java now accepts 64bits ints
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: bckfnn, pjosselin
Priority: normal Keywords: patch

Created on 2002-07-05.10:06:53 by pjosselin, last changed 2002-10-29.12:06:32 by bckfnn.

Files
File name Uploaded Description Edit Remove
structPatch.diff pjosselin, 2002-07-05.10:06:53 The Patch !
testStruct.py pjosselin, 2002-07-05.10:20:32 Test script for the patch
Messages
msg2238 (view) Author: Josselin PUJO (pjosselin) Date: 2002-07-05.10:06:53
In CPython, the struct module can manage 64 bits
integers in unsigned and signed form with the 'Q' or
'q' format code.

This patch duplicates this missing functionnality in
Jython.

Patch as attached file, simple test script folows

from struct import *

#unsigned long check
try:
	pack('<Q',-1)
	print 'Error: unsigned long should not work'
except error:
	pass
	
try:
	pack('>Q',-1)
	print 'Error: unsigned long should not work'
except error:
	pass

big_long=0x10000000000000000L
#oversized unsigned long check
try:
	print pack('<Q',big_long)
	print 'Error, should not try to pack >64bits ints'
except OverflowError:
	pass
	
try:
	print pack('>Q',big_long)
	print 'Error, should not try to pack >64bits ints'
except OverflowError:
	pass

#oversized positive signed long check
try:
	print pack('<q',big_long)
	print 'Error, should not try to pack >64bits ints'
except OverflowError:
	pass
	
try:
	print pack('>q',big_long)
	print 'Error, should not try to pack >64bits ints'
except OverflowError:
	pass

#oversized negative signed long check
big_long=-big_long
try:
	print pack('<q',big_long)
	print 'Error, should not try to pack >64bits ints'
except OverflowError:
	pass
	
try:
	print pack('>q',big_long)
	print 'Error, should not try to pack >64bits ints'
except OverflowError:
	pass

u_data=(0x1L,0x10000L,0x100000000L)
s_data=(0x1L,-0x10000L,0x0FFFFFFFFL,-0x100000000L)
#internal pack-unpack coherence check

s=pack('<QQQ',u_data[0],u_data[1],u_data[2])
if u_data!=unpack('<QQQ',s):
	print "internal coherence error:		%s ==> %s ==>
%s"%(`u_data`,`s`,`unpack('<QQQ',s)`)


s=pack('>QQQ',u_data[0],u_data[1],u_data[2])
if u_data!=unpack('>QQQ',s):
	print "internal coherence error:		%s ==> %s ==>
%s"%(`u_data`,`s`,`unpack('>QQQ',s)`)

s=pack('<qqqq',s_data[0],s_data[1],s_data[2],s_data[3])
if s_data!=unpack('<qqqq',s):
	print "internal coherence error:		%s ==> %s ==>
%s"%(`s_data`,`s`,`unpack('<qqqq',s)`)

s=pack('>qqqq',s_data[0],s_data[1],s_data[2],s_data[3])
if s_data!=unpack('>qqqq',s):
	print "internal coherence error:		%s ==> %s ==>
%s"%(`s_data`,`s`,`unpack('>qqqq',s)`)

#external unpack coherence check
string_from_CPython='\x00\x00\x00\x00\x00\x01\x11p\xff\xff\xff\xff\xff\xfe\xc7\x80\xff\xff\xff\xff\xff\xff\xff\xfb\x00\x00\x00\x00\x00\x018\x80'
if
(70000,-80000,-5,80000)!=unpack('!Qqqq',string_from_CPython):
	print 'Error unpacking from CPython !'
msg2239 (view) Author: Josselin PUJO (pjosselin) Date: 2002-07-05.10:20:32
Logged In: YES 
user_id=289277

Grr, my python test file did NOT like sourceforge
formatting, resent attached 
msg2240 (view) Author: Finn Bock (bckfnn) Date: 2002-10-29.11:07:51
Logged In: YES 
user_id=4201

Added as struct.java: 2.7;

The patch is a step in the right direction, but it does not
implement
the funtionallity correctly. For example, the test_struct
still fails
for some long values. If you want to, an other patch that
allows dist/test/test_struct.py to complete will be very
welcome.
msg2241 (view) Author: Finn Bock (bckfnn) Date: 2002-10-29.12:06:32
Logged In: YES 
user_id=4201

Added as struct.java: 2.7;

The patch is a step in the right direction, but it does not
implement
the funtionallity correctly. For example, the test_struct
still fails
for some long values. If you want to, an other patch that
allows dist/test/test_struct.py to complete will be very
welcome.
History
Date User Action Args
2002-07-05 10:06:53pjosselincreate