Source: grfcodec
Version: 6.0.6-6
Tags: patch
User: debian-cr...@lists.debian.org
Usertags: ftcbfs

grfcodec cannot be cross built from source due to the way it deals with
endianess (checking for it at build time). While that approach is quite
portable for native builds, it completely breaks cross builds.

Let me propose a different way. The check about endianess is basically
used for two related choices.

 * BYTE_OFSL/BYTE_OFSH
 * BE_SWAP16/BE_SWAP32

The former can be eliminated using type punning. Such type punning is
safe in this setting due to the union ensuring proper alignment. With a
little code modification, we can get rid of the need in a portable way.

For the latter, I am wondering whether you'd be ok with using

    #include <endian.h>

in order to redefine those macros as follows.

    #define BE_SWAP16 le16toh
    #define BE_SWAP32 le32toh

Once converted, src/endian_check.cpp can be deleted with no replacement,
which would help cross building.

Is that something you'd be ok with?

I'm attaching a patch to get rid of BYTE_OFSL/BYTE_OFSH as it is so
simple. If you agree, I can also send a patch for getting rid of
BE_SWAP* in the projected way.

Helmut
--- grfcodec-6.0.6.orig/src/sprites.cpp
+++ grfcodec-6.0.6/src/sprites.cpp
@@ -599,8 +599,8 @@
 			if (!*lastcodepos)	// there's a zero length verbatim chunk -> delete it
 				outpos--;
 
-			ofsl = chunk.u8[BYTE_OFSL];
-			ofsh = chunk.u8[BYTE_OFSH];
+			ofsl = chunk.u16[0] & 0xff;
+			ofsh = chunk.u16[0] >> 8;
 			overlap = chunk.u8[2];
 
 			out[outpos++] = (-overlap << 3) | ofsh;
--- grfcodec-6.0.6.orig/src/typesize.h
+++ grfcodec-6.0.6/src/typesize.h
@@ -153,13 +153,9 @@
 #ifdef GRFCODEC_BIG_ENDIAN
 #	define BE_SWAP16(b) (*((U8*)(&b))+(*(((U8*)(&b))+1)<<8))
 #	define BE_SWAP32(b) (*((U8*)(&b))+(*(((U8*)(&b))+1)<<8)+(*(((U8*)(&b))+2)<<16)+(*(((U8*)(&b))+3)<<24))
-#	define BYTE_OFSL 1
-#	define BYTE_OFSH 0
 #elif defined(GRFCODEC_LITTLE_ENDIAN)
 #	define BE_SWAP16(b) (b)
 #	define BE_SWAP32(b) (b)
-#	define BYTE_OFSL 0
-#	define BYTE_OFSH 1
 #else
 # error "Endianness not defined!"
 #endif

Reply via email to