Python 1.5.2 and large files (Solaris 7)

Charles G Waldman cgw at fnal.gov
Thu May 27 13:12:58 EDT 1999


Interesting that this topic should come up at this time - I've just
found one of our server programs here at Fermilab that broke when we
upgraded from 1.5.1 to 1.5.2 (at my suggestion, no less!) due to the
fact that os.stat(...)[ST_SIZE] is a Long int on some platforms and a
regular int on others.

We're reading and writing files in "cpio" format; and instead of
forking off a separate process to run cpio, we have our own cpio
module implemented in Python.

In some of this code, data has to get padded to a block boundary.

We have some code that looks like this:

	...

        size = size + len(trailer)
        padt = 512-(size%512) 

        return("\0"*int(padd) +
               head_crc + hex8(data_crc) + "\0"*int(padc) +
               trailer + "\0"*int(padt) )

	...

"size" is coming from an os.stat call.

This code works on platforms where os.stat(...)[ST_SIZE] is an int,
but on our SGI boxes the size is a long and we get a 

 TypeError: can't multiply sequence with non-int

This was getting people quite confused, because the code "used to
work" and they started to suspect that something was wrong with 1.5.2.

Fortunately, since this topic had just been discussed on the list, I
was able to troubleshoot it and fix it quickly.

Despite this little spot of trouble, I still think it's good for
integer-yielding file ops to return Longs on systems that support
large filesystems.  However the inability to multiply a string by a
Long is kind of unpleasant - I think that Long ints are "second-class" 
citizens in Python in a lot of ways, and agree with Tim that it would
be really great to eliminate the user-visible distinction between
regular ints and Longs.  

Up to now,  people wouldn't really have to deal with the distinction
that much - if you're doing number theory or crypto and use Longs, you 
presumably know what you're doing, and for most other purposes the
existence of Longs could be more or less ignored.  However, if
integer-yielding file ops are going to return Longs, then people may
be getting Longs when they don't expect them.  Worse still, the code
may run without errors on one type of system (without large filesystem 
support) and unexpectedly break on another system.





More information about the Python-list mailing list