[Python-Dev] struct.pack() on 64bit machine

Aleksander Piotrowski aleksander.piotrowski at nic.com.pl
Sat Mar 20 10:40:44 EST 2004


Hi

I'm running python on OpenBSD/sparc64 (SUN Ultra 10) and have question
about struct module.

On this machine struct.pack() gives me:

>>> struct.pack('l', 1)
'\x00\x00\x00\x00\x00\x00\x00\x01'
>>> struct.pack('i', 1)
'\x00\x00\x00\x01'

On i386 box I have:

>>> struct.pack('l', 1)
'\x01\x00\x00\x00'
>>> struct.pack('i', 1)
'\x01\x00\x00\x00'

Because of this, OpenBSD port have following patch:

$OpenBSD: patch-Lib_test_test_fcntl_py,v 1.1.1.1 2003/12/31 17:38:33 sturm Exp $
--- Lib/test/test_fcntl.py.orig	2003-12-31 12:13:00.000000000 +0100
+++ Lib/test/test_fcntl.py	2003-12-31 12:14:14.000000000 +0100
@@ -22,9 +22,13 @@ if sys.platform.startswith('atheos'):
 
 if sys.platform in ('netbsd1', 'Darwin1.2', 'darwin',
                     'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
-                    'bsdos2', 'bsdos3', 'bsdos4',
-                    'openbsd', 'openbsd2', 'openbsd3'):
+                    'bsdos2', 'bsdos3', 'bsdos4'):
     lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, fcntl.F_WRLCK, 0)
+elif sys.platform in ['openbsd', 'openbsd2', 'openbsd3']:
+    if sys.maxint == 2147483647:
+        lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, fcntl.F_WRLCK, 0)
+    else:
+        lockdata = struct.pack('ixxxxixxxxihh', 0, 0, 0, fcntl.F_WRLCK, 0)
 elif sys.platform in ['aix3', 'aix4', 'hp-uxB', 'unixware7']:
     lockdata = struct.pack('hhlllii', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
 elif sys.platform in ['os2emx']:


Is it OK? It should work like this on 64bit machine, right?

Thanks,

Alek
-- 
- Spokojnie, Petro. Odzyskam nasze dzieci - obiecał Groszek. - I zabiję
Achillesa przy okazji. Niedługo, skarbie. Zanim umrę.
- To świetnie - pochwaliła go. - Bo potem byłoby ci o wiele trudniej.
 -- Orson Scott Card, Teatr Cieni



More information about the Python-Dev mailing list