HearthSim / decrunch

Python wrapper around Crunch DXTc decompressor
https://hearthsim.info
zlib License
14 stars 23 forks source link

Error building, loses precision #6

Open Sembiance opened 7 years ago

Sembiance commented 7 years ago
sembiance@riverbend ~/decrunch $ python setup.py install --user
running install
running bdist_egg
running egg_info
creating decrunch.egg-info
writing decrunch.egg-info/PKG-INFO
writing top-level names to decrunch.egg-info/top_level.txt
writing dependency_links to decrunch.egg-info/dependency_links.txt
writing manifest file 'decrunch.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'decrunch.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
building 'decrunch' extension
creating build
creating build/temp.linux-x86_64-2.7
x86_64-pc-linux-gnu-g++ -pthread -fPIC -Icrunch -I/usr/include/python2.7 -c crn_decomp.cpp -o build/temp.linux-x86_64-2.7/crn_decomp.o
In file included from crn_decomp.cpp:10:0:
crunch/crn_decomp.h: In function ‘void* crnd::crnd_malloc(size_t, size_t*)’:
crunch/crn_decomp.h:2536:28: error: cast from ‘crnd::uint8* {aka unsigned char*}’ to ‘crnd::uint32 {aka unsigned int}’ loses precision [-fpermissive]
       CRND_ASSERT(((uint32)p_new & (CRND_MIN_ALLOC_ALIGNMENT - 1)) == 0);
                            ^
crunch/crn_decomp.h:435:39: note: in definition of macro ‘CRND_ASSERT’
 #define CRND_ASSERT(_exp) (void)( (!!(_exp)) || (crnd::crnd_assert(#_exp, __FILE__, __LINE__), 0) )
                                       ^
crunch/crn_decomp.h: In function ‘void* crnd::crnd_realloc(void*, size_t, size_t*, bool)’:
crunch/crn_decomp.h:2561:28: error: cast from ‘void*’ to ‘crnd::uint32 {aka unsigned int}’ loses precision [-fpermissive]
       CRND_ASSERT(((uint32)p_new & (CRND_MIN_ALLOC_ALIGNMENT - 1)) == 0);
                            ^
crunch/crn_decomp.h:435:39: note: in definition of macro ‘CRND_ASSERT’
 #define CRND_ASSERT(_exp) (void)( (!!(_exp)) || (crnd::crnd_assert(#_exp, __FILE__, __LINE__), 0) )
                                       ^
error: command 'x86_64-pc-linux-gnu-g++' failed with exit status 1
>sembiance@riverbend ~/decrunch $ x86_64-pc-linux-gnu-g++ --version
x86_64-pc-linux-gnu-g++ (Gentoo 5.4.0-r3 p1.3, pie-0.6.5) 5.4.0
sembiance@riverbend ~/decrunch $ python --version
Python 2.7.13
sembiance@riverbend ~/decrunch $ uname -a
Linux riverbend 4.10.9 1 SMP PREEMPT Tue Apr 11 10:30:30 EDT 2017 x86_64 Intel(R) Core(TM) i7-4960X CPU @ 3.60GHz GenuineIntel GNU/Linux

It builds if I change the (uint32) cast to (long) (a temporary, unadvised cheat I learned from http://stackoverflow.com/questions/1640423/error-cast-from-void-to-int-loses-precision#1640448)

Note: Using Python 3.4 doesn't fix this error.

yiyuezhuo commented 6 years ago

Thanks to the issue since I try to use UnityPack and build the module. In my Windows 64 plateform, the (uint32) should cast to (long long) (It's mentioned in same stackoverflow link) to get the build done.

jleclanche commented 5 years ago

Is this still an issue in 0.4.0?

Sembiance commented 5 years ago

Still happening with the very latest github master version with python 3.6. And yes, changing the casts on line 2347 and 2369 from (uint32) to (long long) fixes it.

sembiance@lostcrag ~/tmp/decrunch $ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing decrunch.egg-info/PKG-INFO
writing dependency_links to decrunch.egg-info/dependency_links.txt
writing top-level names to decrunch.egg-info/top_level.txt
reading manifest template 'MANIFEST.in'
writing manifest file 'decrunch.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
building 'decrunch' extension
x86_64-pc-linux-gnu-g++ -pthread -fPIC -Icrunch -I/usr/include/python3.6m -c decrunch.cpp -o build/temp.linux-x86_64-3.6/decrunch.o -std=c++11
x86_64-pc-linux-gnu-g++ -pthread -fPIC -Icrunch -I/usr/include/python3.6m -c crn_decomp.cpp -o build/temp.linux-x86_64-3.6/crn_decomp.o -std=c++11
In file included from crn_decomp.cpp:18:
crunch/crn_decomp.h: In function ‘void* crnd::crnd_malloc(size_t, size_t*)’:
crunch/crn_decomp.h:2347:23: error: cast from ‘crnd::uint8*’ {aka ‘unsigned char*’} to ‘crnd::uint32’ {aka ‘unsigned int’} loses precision [-fpermissive]
 2347 |  CRND_ASSERT(((uint32)p_new & (CRND_MIN_ALLOC_ALIGNMENT - 1)) == 0);
      |                       ^~~~~
crunch/crn_decomp.h:468:13: note: in definition of macro ‘CRND_ASSERT’
  468 |  (void)((!!(_exp)) || (crnd::crnd_assert(#_exp, __FILE__, __LINE__), 0))
      |             ^~~~
crunch/crn_decomp.h: In function ‘void* crnd::crnd_realloc(void*, size_t, size_t*, bool)’:
crunch/crn_decomp.h:2369:23: error: cast from ‘void*’ to ‘crnd::uint32’ {aka ‘unsigned int’} loses precision [-fpermissive]
 2369 |  CRND_ASSERT(((uint32)p_new & (CRND_MIN_ALLOC_ALIGNMENT - 1)) == 0);
      |                       ^~~~~
crunch/crn_decomp.h:468:13: note: in definition of macro ‘CRND_ASSERT’
  468 |  (void)((!!(_exp)) || (crnd::crnd_assert(#_exp, __FILE__, __LINE__), 0))
      |             ^~~~
error: command 'x86_64-pc-linux-gnu-g++' failed with exit status 1
sembiance@lostcrag ~/tmp/decrunch $ x86_64-pc-linux-gnu-g++ --version
x86_64-pc-linux-gnu-g++ (Gentoo 9.1.0-r1 p1.1) 9.1.0
sembiance@lostcrag ~/tmp/decrunch $ python --version
Python 3.6.8