:: commit 07ca4fa4c2dd8d19c40307ed70933bda05699c61

Kamila Szewczyk <kspalaiologos@gmail.com> — 2022-09-05 07:00

parents: fb45d93645

apply suggested fix to #46

diff --git a/include/common.h b/include/common.h
index e59978b..5dcd72b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -46,8 +46,6 @@ static void write_neutral_s32(u8 * data, s32 value) {
     data[3] = (value >> 24) & 0xFF;
 }
 
-#define PUBLIC_API
-
 #if defined(__GNUC__) || defined(__clang__)
     #define RESTRICT __restrict__
 #elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
diff --git a/include/libbz3.h b/include/libbz3.h
index a5ac58a..c0e272c 100644
--- a/include/libbz3.h
+++ b/include/libbz3.h
@@ -22,6 +22,10 @@
 
 #include <stdint.h>
 
+#ifndef BZIP3_API
+    #define BZIP3_API
+#endif
+
 #define BZ3_OK 0
 #define BZ3_ERR_OUT_OF_BOUNDS -1
 #define BZ3_ERR_BWT -2
@@ -35,31 +39,31 @@ struct bz3_state;
 /**
  * @brief Get the last error number associated with a given state.
  */
-int8_t bz3_last_error(struct bz3_state * state);
+BZIP3_API int8_t bz3_last_error(struct bz3_state * state);
 
 /**
  * @brief Return a user-readable message explaining the cause of the last error.
  */
-const char * bz3_strerror(struct bz3_state * state);
+BZIP3_API const char * bz3_strerror(struct bz3_state * state);
 
 /**
  * @brief Construct a new block encoder state, which will encode blocks as big as the given block size.
  * The decoder will be able to decode blocks at most as big as the given block size.
  * Returns NULL in case allocation fails or the block size is not between 65K and 511M
  */
-struct bz3_state * bz3_new(int32_t block_size);
+BZIP3_API struct bz3_state * bz3_new(int32_t block_size);
 
 /**
  * @brief Free the memory occupied by a block encoder state.
  */
-void bz3_free(struct bz3_state * state);
+BZIP3_API void bz3_free(struct bz3_state * state);
 
 /**
  * @brief Encode a single block. Returns the amount of bytes written to `buffer'.
  * `buffer' must be able to hold at least `size + size / 50 + 32' bytes. The size must not
  * exceed the block size associated with the state.
  */
-int32_t bz3_encode_block(struct bz3_state * state, uint8_t * buffer, int32_t size);
+BZIP3_API int32_t bz3_encode_block(struct bz3_state * state, uint8_t * buffer, int32_t size);
 
 /**
  * @brief Decode a single block.
@@ -68,7 +72,7 @@ int32_t bz3_encode_block(struct bz3_state * state, uint8_t * buffer, int32_t siz
  * @param size The size of the compressed data in `buffer'
  * @param orig_size The original size of the data before compression.
  */
-int32_t bz3_decode_block(struct bz3_state * state, uint8_t * buffer, int32_t size, int32_t orig_size);
+BZIP3_API int32_t bz3_decode_block(struct bz3_state * state, uint8_t * buffer, int32_t size, int32_t orig_size);
 
 /**
  * @brief Encode `n' blocks, all in parallel.
@@ -80,13 +84,13 @@ int32_t bz3_decode_block(struct bz3_state * state, uint8_t * buffer, int32_t siz
  *
  * Present in the shared library only if -lpthread was present during building.
  */
-void bz3_encode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[], int32_t n);
+BZIP3_API void bz3_encode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[], int32_t n);
 
 /**
  * @brief Decode `n' blocks, all in parallel.
  * Same specifics as `bz3_encode_blocks', but doesn't overwrite `sizes'.
  */
-void bz3_decode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[], int32_t orig_sizes[],
-                       int32_t n);
+BZIP3_API void bz3_decode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[],
+                                 int32_t orig_sizes[], int32_t n);
 
 #endif
diff --git a/src/libbz3.c b/src/libbz3.c
index 58108f2..9847e98 100644
--- a/src/libbz3.c
+++ b/src/libbz3.c
@@ -453,9 +453,9 @@ struct bz3_state {
     s8 last_error;
 };
 
-PUBLIC_API s8 bz3_last_error(struct bz3_state * state) { return state->last_error; }
+BZIP3_API s8 bz3_last_error(struct bz3_state * state) { return state->last_error; }
 
-PUBLIC_API const char * bz3_strerror(struct bz3_state * state) {
+BZIP3_API const char * bz3_strerror(struct bz3_state * state) {
     switch (state->last_error) {
         case BZ3_OK:
             return "No error";
@@ -476,7 +476,7 @@ PUBLIC_API const char * bz3_strerror(struct bz3_state * state) {
     }
 }
 
-PUBLIC_API struct bz3_state * bz3_new(s32 block_size) {
+BZIP3_API struct bz3_state * bz3_new(s32 block_size) {
     if (block_size < KiB(65) || block_size > MiB(511)) {
         return NULL;
     }
@@ -511,7 +511,7 @@ PUBLIC_API struct bz3_state * bz3_new(s32 block_size) {
     return bz3_state;
 }
 
-PUBLIC_API void bz3_free(struct bz3_state * state) {
+BZIP3_API void bz3_free(struct bz3_state * state) {
     free(state->swap_buffer);
     free(state->sais_array);
     free(state->cm_state);
@@ -526,7 +526,7 @@ PUBLIC_API void bz3_free(struct bz3_state * state) {
         y = tmp;      \
     }
 
-PUBLIC_API s32 bz3_encode_block(struct bz3_state * state, u8 * buffer, s32 data_size) {
+BZIP3_API s32 bz3_encode_block(struct bz3_state * state, u8 * buffer, s32 data_size) {
     u8 *b1 = buffer, *b2 = state->swap_buffer;
 
     if (data_size > state->block_size) {
@@ -597,7 +597,7 @@ PUBLIC_API s32 bz3_encode_block(struct bz3_state * state, u8 * buffer, s32 data_
     return data_size + overhead * 4 + 1;
 }
 
-PUBLIC_API s32 bz3_decode_block(struct bz3_state * state, u8 * buffer, s32 data_size, s32 orig_size) {
+BZIP3_API s32 bz3_decode_block(struct bz3_state * state, u8 * buffer, s32 data_size, s32 orig_size) {
     // Read the header.
     u32 crc32 = read_neutral_s32(buffer);
     s32 bwt_idx = read_neutral_s32(buffer + 4);
@@ -738,7 +738,7 @@ static void * bz3_init_decode_thread(void * _msg) {
     return NULL;  // unreachable
 }
 
-PUBLIC_API void bz3_encode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[], int32_t n) {
+BZIP3_API void bz3_encode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[], int32_t n) {
     encode_thread_msg messages[n];
     pthread_t threads[n];
     for (int32_t i = 0; i < n; i++) {
@@ -751,8 +751,8 @@ PUBLIC_API void bz3_encode_blocks(struct bz3_state * states[], uint8_t * buffers
     for (int32_t i = 0; i < n; i++) sizes[i] = messages[i].size;
 }
 
-PUBLIC_API void bz3_decode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[],
-                                  int32_t orig_sizes[], int32_t n) {
+BZIP3_API void bz3_decode_blocks(struct bz3_state * states[], uint8_t * buffers[], int32_t sizes[],
+                                 int32_t orig_sizes[], int32_t n) {
     decode_thread_msg messages[n];
     pthread_t threads[n];
     for (int32_t i = 0; i < n; i++) {
tab: 248 wrap: offon