| 1 |
/* Copyright 2025 Google Inc. All Rights Reserved. |
| 2 |
|
| 3 |
Distributed under MIT license. |
| 4 |
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "static_init.h" |
| 8 |
|
| 9 |
#include "../common/platform.h" |
| 10 |
#include "../common/static_init.h" |
| 11 |
|
| 12 |
#if (BROTLI_STATIC_INIT != BROTLI_STATIC_INIT_NONE) |
| 13 |
#include "../common/dictionary.h" |
| 14 |
#include "dictionary_hash.h" |
| 15 |
#include "static_dict_lut.h" |
| 16 |
#endif |
| 17 |
|
| 18 |
#if defined(__cplusplus) || defined(c_plusplus) |
| 19 |
extern "C" { |
| 20 |
#endif |
| 21 |
|
| 22 |
#if (BROTLI_STATIC_INIT != BROTLI_STATIC_INIT_NONE) |
| 23 |
static BROTLI_BOOL DoBrotliEncoderStaticInit(void) { |
| 24 |
const BrotliDictionary* dict = BrotliGetDictionary(); |
| 25 |
BROTLI_BOOL ok = BrotliEncoderInitStaticDictionaryLut( |
| 26 |
dict, kStaticDictionaryBuckets, kStaticDictionaryWords); |
| 27 |
if (!ok) return BROTLI_FALSE; |
| 28 |
ok = BrotliEncoderInitDictionaryHash(dict, kStaticDictionaryHashWords, |
| 29 |
kStaticDictionaryHashLengths); |
| 30 |
if (!ok) return BROTLI_FALSE; |
| 31 |
return BROTLI_TRUE; |
| 32 |
} |
| 33 |
#endif /* BROTLI_STATIC_INIT_NONE */ |
| 34 |
|
| 35 |
#if (BROTLI_STATIC_INIT == BROTLI_STATIC_INIT_EARLY) |
| 36 |
static BROTLI_BOOL kEarlyInitOk; |
| 37 |
static __attribute__((constructor)) void BrotliEncoderStaticInitEarly(void) { |
| 38 |
kEarlyInitOk = DoBrotliEncoderStaticInit(); |
| 39 |
} |
| 40 |
#elif (BROTLI_STATIC_INIT == BROTLI_STATIC_INIT_LAZY) |
| 41 |
static BROTLI_BOOL kLazyInitOk; |
| 42 |
void BrotliEncoderLazyStaticInitInner(void) { |
| 43 |
kLazyInitOk = DoBrotliEncoderStaticInit(); |
| 44 |
} |
| 45 |
#endif /* BROTLI_STATIC_INIT_EARLY */ |
| 46 |
|
| 47 |
BROTLI_BOOL BrotliEncoderEnsureStaticInit(void) { |
| 48 |
#if (BROTLI_STATIC_INIT == BROTLI_STATIC_INIT_NONE) |
| 49 |
return BROTLI_TRUE; |
| 50 |
#elif (BROTLI_STATIC_INIT == BROTLI_STATIC_INIT_EARLY) |
| 51 |
return kEarlyInitOk; |
| 52 |
#else |
| 53 |
return kLazyInitOk; |
| 54 |
#endif |
| 55 |
} |
| 56 |
|
| 57 |
#if defined(__cplusplus) || defined(c_plusplus) |
| 58 |
} /* extern "C" */ |
| 59 |
#endif |