Add a separate internal function to initialize the CRC32

table, which is used also by LZ encoder. This was needed
because calling lzma_crc32() and ignoring the result is
a no-op due to lzma_attr_pure.
This commit is contained in:
Lasse Collin 2009-02-08 18:24:50 +02:00
parent ae1ad9af54
commit 0e27028d74
3 changed files with 12 additions and 3 deletions

View File

@ -61,6 +61,7 @@ typedef struct {
/// the array two-dimensional. /// the array two-dimensional.
#ifdef HAVE_SMALL #ifdef HAVE_SMALL
extern uint32_t lzma_crc32_table[1][256]; extern uint32_t lzma_crc32_table[1][256];
extern void lzma_crc32_init(void);
#else #else
extern const uint32_t lzma_crc32_table[8][256]; extern const uint32_t lzma_crc32_table[8][256];
extern const uint64_t lzma_crc64_table[4][256]; extern const uint64_t lzma_crc64_table[4][256];

View File

@ -38,10 +38,18 @@ crc32_init(void)
} }
extern void
lzma_crc32_init(void)
{
mythread_once(crc32_init);
return;
}
extern LZMA_API(uint32_t) extern LZMA_API(uint32_t)
lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc) lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
{ {
mythread_once(crc32_init); lzma_crc32_init();
crc = ~crc; crc = ~crc;

View File

@ -20,6 +20,7 @@
#include "lz_encoder.h" #include "lz_encoder.h"
#include "lz_encoder_hash.h" #include "lz_encoder_hash.h"
#include "check.h"
struct lzma_coder_s { struct lzma_coder_s {
@ -488,8 +489,7 @@ lzma_lz_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
{ {
#ifdef HAVE_SMALL #ifdef HAVE_SMALL
// We need that the CRC32 table has been initialized. // We need that the CRC32 table has been initialized.
// This is enough to do it. lzma_crc32_init();
lzma_crc32(NULL, 0, 0);
#endif #endif
// Allocate and initialize the base data structure. // Allocate and initialize the base data structure.