diff --git a/ext/zstds_ext/dictionary.c b/ext/zstds_ext/dictionary.c index c069015..960efe7 100644 --- a/ext/zstds_ext/dictionary.c +++ b/ext/zstds_ext/dictionary.c @@ -9,7 +9,6 @@ #include "zstds_ext/buffer.h" #include "zstds_ext/error.h" #include "zstds_ext/gvl.h" -#include "zstds_ext/macro.h" #include "zstds_ext/option.h" // -- initialization -- @@ -153,22 +152,23 @@ VALUE zstds_ext_get_dictionary_buffer_id(VALUE ZSTDS_EXT_UNUSED(self), VALUE buf return UINT2NUM(id); } -VALUE zstds_ext_get_dictionary_header_size(VALUE ZSTDS_EXT_UNUSED(self), VALUE buffer) -{ #if defined(HAVE_ZDICT_HEADER_SIZE) +VALUE zstds_ext_get_dictionary_header_size(VALUE self, VALUE buffer) +{ zstds_result_t result = ZDICT_getDictHeaderSize(RSTRING_PTR(buffer), RSTRING_LEN(buffer)); if (ZDICT_isError(result)) { zstds_ext_raise_error(zstds_ext_get_error(ZSTD_getErrorCode(result))); } return SIZET2NUM(result); +} #else +ZSTDS_EXT_NORETURN VALUE zstds_ext_get_dictionary_header_size(VALUE self, VALUE buffer) +{ zstds_ext_raise_error(ZSTDS_EXT_ERROR_NOT_IMPLEMENTED); - - return SIZET2NUM(0); +}; #endif -} // -- exports -- diff --git a/ext/zstds_ext/dictionary.h b/ext/zstds_ext/dictionary.h index 164ba26..0e78216 100644 --- a/ext/zstds_ext/dictionary.h +++ b/ext/zstds_ext/dictionary.h @@ -6,11 +6,19 @@ #include "ruby.h" +#include "zstds_ext/macro.h" + #define ZSTDS_EXT_DEFAULT_DICTIONARY_CAPACITY (1 << 17); // 128 KB VALUE zstds_ext_train_dictionary_buffer(VALUE self, VALUE samples, VALUE options); VALUE zstds_ext_get_dictionary_buffer_id(VALUE self, VALUE buffer); +#if defined(HAVE_ZDICT_HEADER_SIZE) +VALUE zstds_ext_get_dictionary_header_size(VALUE self, VALUE buffer); +#else +ZSTDS_EXT_NORETURN VALUE zstds_ext_get_dictionary_header_size(VALUE self, VALUE buffer); +#endif + void zstds_ext_dictionary_exports(VALUE root_module); #endif // ZSTDS_EXT_DICTIONARY_H diff --git a/ext/zstds_ext/macro.h b/ext/zstds_ext/macro.h index 2e8dc86..fed697b 100644 --- a/ext/zstds_ext/macro.h +++ b/ext/zstds_ext/macro.h @@ -10,4 +10,10 @@ #define ZSTDS_EXT_UNUSED(x) x #endif +#if defined(__GNUC__) +#define ZSTDS_EXT_NORETURN __attribute__((__noreturn__)) +#else +#define ZSTDS_EXT_NORETURN +#endif + #endif // ZSTDS_EXT_MACRO_H