Skip to content

Commit

Permalink
fixed header size declaration (noreturn is possible)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-aladev committed Jan 5, 2022
1 parent 0cd2388 commit 57e0f37
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ext/zstds_ext/dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down Expand Up @@ -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 --

Expand Down
8 changes: 8 additions & 0 deletions ext/zstds_ext/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions ext/zstds_ext/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 57e0f37

Please sign in to comment.