From: Stefan Reinauer Date: Thu, 21 May 2026 23:11:14 +0000 (-0700) Subject: chd: make LZMA and inline helpers portable X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=ffa7d7496b59c828168d7913f2caea81b7c196dd;p=francis%2Fwinuae.git chd: make LZMA and inline helpers portable 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. --- diff --git a/archivers/chd/chdcodec.cpp b/archivers/chd/chdcodec.cpp index fdc7c1cb..35efdd21 100644 --- a/archivers/chd/chdcodec.cpp +++ b/archivers/chd/chdcodec.cpp @@ -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; } diff --git a/archivers/chd/chdtypes.h b/archivers/chd/chdtypes.h index 941caf5e..39da1155 100644 --- a/archivers/chd/chdtypes.h +++ b/archivers/chd/chdtypes.h @@ -31,6 +31,10 @@ #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) | \ diff --git a/archivers/chd/osdcomm.h b/archivers/chd/osdcomm.h index 4c783557..efee8628 100644 --- a/archivers/chd/osdcomm.h +++ b/archivers/chd/osdcomm.h @@ -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 */