]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
chd: make LZMA and inline helpers portable
authorStefan Reinauer <stefan.reinauer@coreboot.org>
Thu, 21 May 2026 23:11:14 +0000 (16:11 -0700)
committerStefan Reinauer <stefan.reinauer@coreboot.org>
Mon, 1 Jun 2026 03:16:20 +0000 (20:16 -0700)
Use the public LZMA property writer to build decoder properties
instead of the MAME-only allocator helper. This keeps the CHD LZMA
path compatible with the stock SDK interface.

Make ATTR_FORCE_INLINE produce inline definitions on GCC and Clang so
header-defined helpers can be included safely by multiple translation
units. Define PTR64 from CPU_64_BIT when the build has not already
provided it.

archivers/chd/chdcodec.cpp
archivers/chd/chdtypes.h
archivers/chd/osdcomm.h

index fdc7c1cb5e8b9291a28c0fb07896ded0f408dd8c..35efdd212895f79452ba5c9f05843de9a07b89ab 100644 (file)
@@ -1133,15 +1133,25 @@ chd_lzma_decompressor::chd_lzma_decompressor(chd_file &chd, UINT32 hunkbytes, bo
        CLzmaEncProps encoder_props;
        chd_lzma_compressor::configure_properties(encoder_props, hunkbytes);
 
-       // convert to decoder properties
-       CLzmaProps decoder_props;
-       decoder_props.lc = encoder_props.lc;
-       decoder_props.lp = encoder_props.lp;
-       decoder_props.pb = encoder_props.pb;
-       decoder_props.dicSize = encoder_props.dictSize;
+       CLzmaEncHandle encoder = LzmaEnc_Create(&m_allocator);
+       if (!encoder)
+               throw CHDERR_DECOMPRESSION_ERROR;
+       if (LzmaEnc_SetProps(encoder, &encoder_props) != SZ_OK)
+       {
+               LzmaEnc_Destroy(encoder, &m_allocator, &m_allocator);
+               throw CHDERR_DECOMPRESSION_ERROR;
+       }
+       Byte decoder_props[LZMA_PROPS_SIZE];
+       SizeT props_size = sizeof(decoder_props);
+       if (LzmaEnc_WriteProperties(encoder, decoder_props, &props_size) != SZ_OK)
+       {
+               LzmaEnc_Destroy(encoder, &m_allocator, &m_allocator);
+               throw CHDERR_DECOMPRESSION_ERROR;
+       }
+       LzmaEnc_Destroy(encoder, &m_allocator, &m_allocator);
 
        // do memory allocations
-       SRes res = LzmaDec_Allocate_MAME(&m_decoder, &decoder_props, &m_allocator);
+       SRes res = LzmaDec_Allocate(&m_decoder, decoder_props, LZMA_PROPS_SIZE, &m_allocator);
        if (res != SZ_OK)
                throw CHDERR_DECOMPRESSION_ERROR;
 }
index 941caf5ea31f498b9076da82476c503da6893f1e..39da1155eec3d7c7e367ade4e2fcd850aaa713b6 100644 (file)
 #define CLIB_DECL __cdecl
 #define FLAC_API_EXPORTS
 
+#if defined(CPU_64_BIT) && !defined(PTR64)
+#define PTR64 1
+#endif
+
 /* Macros for normalizing data into big or little endian formats */
 #define FLIPENDIAN_INT16(x)    (((((UINT16) (x)) >> 8) | ((x) << 8)) & 0xffff)
 #define FLIPENDIAN_INT32(x)    ((((UINT32) (x)) << 24) | (((UINT32) (x)) >> 24) | \
index 4c7835579acdb2353f770ce470aac11d769f82c2..efee862822d2c18b4dfed3b3d0a56c6f0295037b 100644 (file)
@@ -36,7 +36,7 @@
 #define ATTR_MALLOC             __attribute__((malloc))
 #define ATTR_PURE               __attribute__((pure))
 #define ATTR_CONST              __attribute__((const))
-#define ATTR_FORCE_INLINE       __attribute__((always_inline))
+#define ATTR_FORCE_INLINE       inline __attribute__((always_inline))
 #define ATTR_NONNULL(...)       __attribute__((nonnull(__VA_ARGS__)))
 #define ATTR_DEPRECATED         __attribute__((deprecated))
 /* not supported in GCC prior to 4.4.x */