Menu

#8 Compiler Warnings for default typecast

None
closed
nobody
None
5
2016-07-12
2016-07-11
Ben Webb
No

Change the following to no longer have the compiler produce C4244 and C4267 warnings

File: Objects.hxx

long hashValue() const
{
return PyObject_Hash( p );
}

should be

long hashValue() const
{
return (long)PyObject_Hash( p );
}

void extend( const Object &ob )
{
setSlice( size(), size(), ob );
}

should be

void extend( const Object &ob )
{
setSlice( (int)size(), (int)size(), ob );
}

int length() const
{
return PyMapping_Length( ptr() );
}

should be

int length() const
{
return PyMapping_Length( ptr() );
}

Discussion

  • Ben Webb

    Ben Webb - 2016-07-11

    Forgot to add the typecast to the last method, should be

    int length() const
    {
    return (int)PyMapping_Length( ptr() );
    }

     
  • Barry Alan Scott

    I think the right fix is to return Py_ssize_t for the length calls, which is signed not size_t that is unsigned.
    At least on linux hash() is a long and should not need casting.

    I have committed changes from the work on linux to change to use Py_ssize_t.
    I will update with feedback from vc2015 testing in a bit.

     
  • Barry Alan Scott

    • status: open --> closed
    • Group: -->
     
  • Barry Alan Scott

    r353 should fix the compiler warnings and fix the bugs that they point to.
    Namely lose of precision, turning 64 bit values into 32 bit values.

    tested on python 2.7 and python 3.5 32 and 64 bit windows, mac and linux

    You may need to fix calling code to use Py_ssize_t and Py_hash_t to avoid truncation.

     

Log in to post a comment.