Opened 11 years ago

Closed 11 years ago

#3460 closed defect (fixed)

cpl_hash_set.cpp:382: error: cast from 'const void*' to 'long unsigned int' loses precision

Reported by: jctilton Owned by: warmerdam
Priority: normal Milestone: 1.7.2
Component: ConfigBuild Version: unspecified
Severity: normal Keywords: hash
Cc: Even Rouault

Description (last modified by warmerdam)

Using the MinGW_w64 gcc compiler (based on gcc version 4.4.4), I get the following when I try to build GDAL:

...
libtool: compile:  x86_64-w64-mingw32-g++ -g -O2 -Wall -DOGR_ENABLED 
-I/home/JamesCTilton/Downloads/gdal-1.7.1/port -I/usr/local/include 
-I/usr/local/include/include -I/usr/local/include -I/usr/local/include/include 
-I../frmts/zlib -DHAVE_LIBZ -c cpl_hash_set.cpp  -DDLL_EXPORT -DPIC -o .libs/cpl_hash_set.o
cpl_hash_set.cpp: In function 'long unsigned int CPLHashSetHashPointer(const void*)':
cpl_hash_set.cpp:382: error: cast from 'const void*' to 'long unsigned int' loses precision
make[1]: *** [cpl_hash_set.lo] Error 1
make[1]: Leaving directory `/home/JamesCTilton/Downloads/gdal-1.7.1/port'
make: *** [port-target] Error 2

How can I get around this problem? Thanks!

I configured with the following command:

./configure CC=x86_64-w64-mingw32-gcc CPP=x86_64-w64-mingw32-cpp \ CXX=x86_64-w64-mingw32-g++ F77=x86_64-w64-mingw32-gfortran \ AR=x86_64-w64-mingw32-ar RANLIB=x86_64-w64-mingw32-ranlib \ STRIP=x86_64-w64-mingw32-strip AS=x86_64-w64-mingw32-as \ DLLTOOL=x86_64-w64-mingw32-dlltool LD=x86_64-w64-mingw32-ld \ NM=x86_64-w64-mingw32-nm OBJDUMP=x86_64-w64-mingw32-objdump \ LDFLAGS="-L /usr/local" --prefix=/usr/local \ --with-expat=/usr/local/include --with-libtiff=internal \ --with-jpeg=/usr/local/include --with-libz=/usr/local/include \ --with-png=/usr/local/include

Change History (9)

comment:1 Changed 11 years ago by warmerdam

Component: defaultConfigBuild
Description: modified (diff)
Keywords: hash added
Owner: changed from warmerdam to Even Rouault

Even,

I think you implemented the hash set? I do not believe it is a safe assumption that a long and a pointer are the same size. It would be somewhat safer to assume a GIntBig is big enough to hold a pointer.

comment:2 Changed 11 years ago by Even Rouault

jctilton,

could you try to substitute line 382 or port/cpl_hash_set.cpp with

return reinterpret_cast<unsigned long>(elt);

if it still doesn't work, try :

return reinterpret_cast<unsigned long>(const_cast<void*>( elt));

Please report which of those 2 work.

comment:3 Changed 11 years ago by jctilton

Thank you for the suggestions. I will try them out when I get back to my office Monday morning and let you know the results.

comment:4 Changed 11 years ago by jctilton

I tried out your suggestions, but ended up with the same error. (I also reconfigured my compilation environment so that I now don't have to explicitly specify my build tools to configure.) Configuring with:

./configure --prefix=/usr/local --with-expat=/usr/local --with-netcdf=/us r/local --with-libtiff=internal --with-jpeg=/usr/local --with-png=internal

make produces:

libtool: compile: g++ -g -O2 -Wall -DOGR_ENABLED -I/home/JamesCTilton/Downloads/gdal-1.7.1/port -I/usr/local -I/usr/local/include -I/usr/local -I/usr/local/include -I../frmts/zlib -DHAVE_LIBZ -c cpl_hash_set.cpp -DDLL_EXPORT -DPIC -o .libs/cpl_hash_set.o cpl_hash_set.cpp: In function 'long unsigned int CPLHashSetHashPointer(const void*)': cpl_hash_set.cpp:382: error: cast from 'const void*' to 'long unsigned int' loses precision make[1]: * [cpl_hash_set.lo] Error 1 make[1]: Leaving directory `/home/JamesCTilton/Downloads/gdal-1.7.1/port' make: * [port-target] Error 2

After editing line 382 of cpl_hash_set.cpp to read:

$ grep reinterpret_cast port/cpl_hash_set.cpp

return reinterpret_cast<unsigned long>(elt);

make produces: /bin/sh /home/JamesCTilton/Downloads/gdal-1.7.1/libtool --mode=compile --tag=CXX g++ -g -O2 -Wall -DOGR_ENABLED -I/home/JamesCTilton/Downloads/gdal-1.7.1/port

-I/usr/local -I/usr/local/include -I/usr/local -I/usr/local/include

-I../frmts/zlib -DHAVE_LIBZ -c -o cpl_hash_set.lo cpl_hash_set.cpp libtool: compile: g++ -g -O2 -Wall -DOGR_ENABLED -I/home/JamesCTilton/Downloads/gdal-1.7.1/port -I/usr/local -I/usr/local/include -I/usr/local -I/usr/local/include -I../frmts/zlib -DHAVE_LIBZ -c cpl_hash_set.cpp -DDLL_EXPORT -DPIC -o .libs/cpl_hash_set.o cpl_hash_set.cpp: In function 'long unsigned int CPLHashSetHashPointer(const void*)': cpl_hash_set.cpp:382: error: cast from 'const void*' to 'long unsigned int' loses precision make[1]: * [cpl_hash_set.lo] Error 1 make[1]: Leaving directory `/home/JamesCTilton/Downloads/gdal-1.7.1/port' make: * [port-target] Error 2

After editing line 382 of cpl_hash_set.cpp to read:

return reinterpret_cast<unsigned long>(const_cast<void*>( elt));

make produces: /bin/sh /home/JamesCTilton/Downloads/gdal-1.7.1/libtool --mode=compile --tag=CXX g++ -g -O2 -Wall -DOGR_ENABLED -I/home/JamesCTilton/Downloads/gdal-1.7.1/port

-I/usr/local -I/usr/local/include -I/usr/local -I/usr/local/include

-I../frmts/zlib -DHAVE_LIBZ -c -o cpl_hash_set.lo cpl_hash_set.cpp libtool: compile: g++ -g -O2 -Wall -DOGR_ENABLED -I/home/JamesCTilton/Downloads/gdal-1.7.1/port -I/usr/local -I/usr/local/include -I/usr/local -I/usr/local/include -I../frmts/zlib -DHAVE_LIBZ -c cpl_hash_set.cpp -DDLL_EXPORT -DPIC -o .libs/cpl_hash_set.o cpl_hash_set.cpp: In function 'long unsigned int CPLHashSetHashPointer(const void*)': cpl_hash_set.cpp:382: error: cast from 'void*' to 'long unsigned int' loses precision make[1]: * [cpl_hash_set.lo] Error 1 make[1]: Leaving directory `/home/JamesCTilton/Downloads/gdal-1.7.1/port' make: * [port-target] Error 2

comment:5 Changed 11 years ago by jctilton

Resolution: fixed
Status: newclosed

My compiler was happy with the following change to the function CPLHashSetHashPointer:

unsigned long CPLHashSetHashPointer(const void* elt) {

GUIntBig temp_Big;

temp_Big = (GUIntBig) elt; return (unsigned long) temp_Big;

}

I also subsequently encountered the same error in the function GDALDatasetHashFunc in gcore/gdaldataset.cpp, and also in the function ChunkAndWarpMulti? in gdalwarpoperation.cpp. I solved these in a similar way.

I'm sure this is not a clean solution - it is only proved to work in my compile environment.

I leave it to the experts to come up with a cleaned up solution.

But thanks for pointing the way. I took my lead from the comment "It would be somewhat safer to assume a GIntBig is big enough to hold a pointer."

comment:6 Changed 11 years ago by warmerdam

Resolution: fixed
Status: closedreopened

i have committed a similar change in trunk (r19040). Could you try this variation to ensure it will work? If so, I'll back port into 1.7 branch as well.

unsigned long CPLHashSetHashPointer(const void* elt)
{
    return (unsigned long)(GUIntBig) elt;
}

Could you be more specific about what lines in ChunkAndWarpMulti? caused problems?

comment:7 Changed 11 years ago by warmerdam

Cc: Even Rouault added
Owner: changed from Even Rouault to warmerdam
Status: reopenednew

comment:8 Changed 11 years ago by jctilton

I made the change as suggested in CLPHashSetHashPointer.

I also modified GDALDatasetHashFunc in gcore/gdaldataset.cpp to be:

static unsigned long GDALDatasetHashFunc(const void* elt) {

DatasetCtxt?* psStruct = (DatasetCtxt?*) elt;

return (unsigned long)(GUIntBig) psStruct->poDS;

}

Finally, I also modified line 861 in alg/gdalwarpoperation.cpp to be:

eErr = (CPLErr) (long)(GIntBig) papThreadDataList[iThread*3+2];

My compiler accepted all the above changes as valid.

My build now continues on to near completion. I have encountered another problem, having to do with libjasper - but this is unrelated to this particular bug report. I hope to solve my libjasper problem by (re)installing libjasper.

Thanks for all of your help!!!

comment:9 Changed 11 years ago by Even Rouault

Milestone: 1.7.2
Resolution: fixed
Status: newclosed

Based on jctilton latest feedback :

r19065 /trunk/gdal/ (alg/gdalwarpoperation.cpp gcore/gdaldataset.cpp): Additional fixes for build problems on systems with 64bit pointer and 32bit long (#3460)

r19066 /branches/1.7/gdal/ (3 files in 3 dirs): fixes for build problems on systems with 64bit pointer and 32bit long - backport of r19040 and r19065 (#3460)

Note: See TracTickets for help on using tickets.