[Patches] fix simple 64-bit warnings/errors in signalmodule.c and bufferobject.c

Trent Mick trentm@activestate.com
Tue, 6 Jun 2000 13:32:28 -0700


On Tue, Jun 06, 2000 at 12:38:57PM -0700, Greg Stein wrote:
> On Tue, 6 Jun 2000, Trent Mick wrote:
> >...
> > > If keeping the decl
> > > "int" is important, then the warning is thoroughly appropriate!  Casting
> > > sizeof's result to int is a bad but expedient wormaround.  Defining a
> > > SAFE_DOWNCAST macro (that checks that the downcast doesn't lose info in
> > > DEBUG mode, and does the downcast without checking in non-DEBUG mode) is a
> > > better (but still sucky) wormaround.  C is simply a pain in the ass here.
> > > 
> > 
> > *Is* there a way to express that the downcast is safe that is not sucky?
> 
> I think that Tim means something like the following:
> 
> #ifdef DEBUG
> #  define SAFE_DOWNCAST(v) ((v) <= INT_MAX ? (int)(v) : abort())
> #else
> #  define SAFE_DOWNCAST(v) ((int)(v))
> #endif
> 
> My INT_MAX check probably isn't right, but this might be what he is
> getting at. Of course, you would also need other variants for different
> downcasts.

Sure, but then my compiler will still generate a warning on the int downcast
that you have there, hence still filling the compile output with junk.

> 
> 
> IMO, you *really* should not need to downcast all that often. I see it
> when I/O occurs (to fit something into a specific size), but type/size
> mismatches are usually indicative of design/specification errors.
>

Right. The main "design error" is in Include/object.h:

#define PyObject_VAR_HEAD \
    PyObject_HEAD \
	int ob_size; /* Number of items in variable part */
		

This is 'int' where it should be 'size_t'. We all agree. But this is not
going to chagne for Python 1.6 (maybe not until 2.0 or 3000). Yes, hopefully
all these warnings will then go away and clean up the Win64 build. Good
enough Tim?

Yes, I presume that there is a "right" answer to fix most of these warnings.
It is just that the "right" answer is going to have to wait for a little bit.
Until then the Win64 build is going to have gobs of downcast warnings.


> IMO #2, you should not tell the compiler to ignore certain
> warnings/errors (e.g. using pragmas). That is the worst scenario of all.
> That hides things even worse than a cast.

Agreeably yours,
Trent

-- 
Trent Mick
trentm@activestate.com