[ python-Bugs-1274069 ] bz2module.c compiler warning
SourceForge.net
noreply at sourceforge.net
Sat Sep 3 09:50:45 CEST 2005
Bugs item #1274069, was opened at 2005-08-26 16:25
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1274069&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Extension Modules
Group: Python 2.5
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Tim Peters (tim_one)
Assigned to: Reinhold Birkenfeld (birkenfeld)
Summary: bz2module.c compiler warning
Initial Comment:
On Python HEAD, there's a new warning while
compiling bz2module.c (MSVC 7.1):
python\Modules\bz2module.c(1095) : warning
C4244: '=' :
conversion from 'Py_off_t' to 'int', possible loss of data
Looks like a legitimate complaint to me. The line in
question:
readsize = offset-bytesread;
Those have types int, Py_off_t, and int respectively. Is
it true that offset-bytesread _necessarily_ fits in an int?
If so, a comment should explain why, and a cast should
be added to squash the warning. Or If the difference
doesn't necessarily fit in an int, the code is wrong.
----------------------------------------------------------------------
>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-09-03 09:50
Message:
Logged In: YES
user_id=1188172
Applied the newest patch. The warnings should be gone now.
bz2module.c r1.26, 1.23.2.3.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-08-27 19:52
Message:
Logged In: YES
user_id=80475
The new patch works fine on this end.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2005-08-27 19:13
Message:
Logged In: YES
user_id=31435
Raymond, did you read the error output and verify that you're
not suffering from the sample3.bz2 problem it explains?
"""
All six of the fc's should find no differences.
If fc finds an error on sample3.bz2, this could be
because WinZip's 'TAR file smart CR/LF conversion'
is too clever for its own good. Disable this option.
The correct size for sample3.ref is 120,244. If it
is 150,251, WinZip has messed it up.
"""
Since the error you saw did come from sample3.bz2, that
would be a good thing to check ;-)
----------------------------------------------------------------------
Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-08-27 19:02
Message:
Logged In: YES
user_id=1188172
Tackled the two warnings (tell() should return a long int if
64 bits) with new patch.
I can't see the error in your output.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-08-27 18:31
Message:
Logged In: YES
user_id=80475
The latest patch gives me the following:
--------------------Configuration: bz2 - Win32
Debug--------------------
Compiling...
bz2module.c
C:\py25\Modules\bz2module.c(1143) : warning C4244:
'function' : conversion from '__int64 ' to 'long ', possible
loss of data
C:\py25\Modules\bz2module.c(1143) : warning C4761: integral
size mismatch in argument; conversion supplied
lib /out:libbz2.lib blocksort.obj huffman.obj
crctable.obj randtable.obj compress.obj
decompress.obj bzlib.obj
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
cl -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo -o bzip2
bzip2.c libbz2.lib setargv.obj
bzip2.c
cl -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo -o
bzip2recover bzip2recover.c
bzip2recover.c
type words1
Doing 6 tests (3 compress, 3 uncompress) ...
If there's a problem, things might stop at this point.
.\bzip2 -1 < sample1.ref > sample1.rb2
.\bzip2 -2 < sample2.ref > sample2.rb2
.\bzip2 -3 < sample3.ref > sample3.rb2
.\bzip2 -d < sample1.bz2 > sample1.tst
.\bzip2 -d < sample2.bz2 > sample2.tst
.\bzip2 -ds < sample3.bz2 > sample3.tst
All six of the fc's should find no differences.
If fc finds an error on sample3.bz2, this could be
because WinZip's 'TAR file smart CR/LF conversion'
is too clever for its own good. Disable this option.
The correct size for sample3.ref is 120,244. If it
is 150,251, WinZip has messed it up.
fc sample1.bz2 sample1.rb2
Comparing files sample1.bz2 and sample1.rb2
FC: no differences encountered
fc sample2.bz2 sample2.rb2
Comparing files sample2.bz2 and sample2.rb2
FC: no differences encountered
fc sample3.bz2 sample3.rb2
Comparing files sample3.bz2 and sample3.rb2
****** sample3.bz2
BZh31AY&SYºÍ3É
·ïuU©´`Û2 ªÉçI%@¯
¾àý£^1 ˯ðú£¦Çº)ëô·alèDh3H¯Ú\mIL´hiiÈB°Ró
****** sample3.rb2
BZh31AY&SYîÜ>
ò#
óAJ3ù²ªÔ©zÉêè7UÎ{ýÍC2
l
}ÛÀ
******
fc sample1.tst sample1.ref
Comparing files sample1.tst and sample1.ref
FC: no differences encountered
fc sample2.tst sample2.ref
Comparing files sample2.tst and sample2.ref
FC: no differences encountered
fc sample3.tst sample3.ref
Comparing files sample3.tst and sample3.ref
FC: no differences encountered
Linking...
bz2_d.pyd - 1 error(s), 2 warning(s)
----------------------------------------------------------------------
Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-08-27 16:36
Message:
Logged In: YES
user_id=1188172
Okay, next try. Someone with Windows should check this
before I check in.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2005-08-27 14:55
Message:
Logged In: YES
user_id=21627
As Tim says: the cast deserves a comment, explaining why it
cannot overflow. Even when readsize is size_t, it might
still overflow, since Py_off_t might be wider than size_t.
Apart from that, the patch looks good - but I can't check
whether it silences the warning on Windows.
----------------------------------------------------------------------
Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-08-27 14:27
Message:
Logged In: YES
user_id=1188172
Attaching patch for f->pos and f->size as Py_off_t.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2005-08-27 12:30
Message:
Logged In: YES
user_id=21627
Clearly, the difference is bound by buffersize (since, if it
is larger, readsize is set to buffersize). buffersize is
initialized to SMALLCHUNK, which is 8192, and never changed,
so yes, the difference fits to an int an all supported
platforms.
OTOH, the condition of the if statement is bogus:
if ((size_t)offset-bytesread > buffersize)
offset is of type Py_off_t, which is a 64-bit type on most
platforms. Casting it to size_t causes truncation on 32-bit
platforms.
Furthermore, I think self->pos should be of type Py_off_t,
as it will wrap around for files larger >2GB on 32-bit
platforms; the same for self->size.
----------------------------------------------------------------------
Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-08-26 17:05
Message:
Logged In: YES
user_id=1188172
I think declaring readsize as size_t should fix the problem.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1274069&group_id=5470
More information about the Python-bugs-list
mailing list