xxhash 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/xxhash/xxhash.c CHANGED
@@ -67,13 +67,30 @@ VALUE xxhash_xxh32(VALUE mod, VALUE input, VALUE seed)
67
67
  return ULL2NUM(XXH32(StringValuePtr(input), (size_t)RSTRING_LEN(input), (unsigned int)NUM2ULL(seed)));
68
68
  }
69
69
 
70
- void xxhash32_streaming_hash_free(xxhash_xxh32_t* storage)
70
+ static void xxhash32_streaming_hash_free(void *ptr)
71
71
  {
72
+ xxhash_xxh32_t* storage = (xxhash_xxh32_t*)ptr;
72
73
  // Digest frees the memory.
73
74
  XXH32_freeState(storage->state);
74
75
  xfree(storage);
75
76
  }
76
77
 
78
+ static size_t xxhash32_streaming_hash_memsize(const void *ptr)
79
+ {
80
+ // Ideally we'd include sizeof(XXH32_state_t) too, but the type is opaque.
81
+ return sizeof(xxhash_xxh32_t);
82
+ }
83
+
84
+ static const rb_data_type_t xxhash_xxh32_type = {
85
+ .wrap_struct_name = "xxhash/xxhash32_streaming_hash",
86
+ .function = {
87
+ .dmark = NULL,
88
+ .dfree = xxhash32_streaming_hash_free,
89
+ .dsize = xxhash32_streaming_hash_memsize,
90
+ },
91
+ .flags = RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
92
+ };
93
+
77
94
  VALUE xxhash32_streaming_hash_new(VALUE klass, VALUE seed)
78
95
  {
79
96
  XXH_errorcode code;
@@ -86,14 +103,14 @@ VALUE xxhash32_streaming_hash_new(VALUE klass, VALUE seed)
86
103
  rb_raise(rb_eRuntimeError, "Error during reset.");
87
104
  return Qnil;
88
105
  }
89
- return Data_Wrap_Struct(klass, 0, xxhash32_streaming_hash_free, storage);
106
+ return TypedData_Wrap_Struct(klass, &xxhash_xxh32_type, storage);
90
107
  }
91
108
 
92
109
  VALUE xxhash32_streaming_hash_reset(VALUE self)
93
110
  {
94
111
  XXH_errorcode code;
95
112
  xxhash_xxh32_t* storage;
96
- Data_Get_Struct(self, xxhash_xxh32_t, storage);
113
+ TypedData_Get_Struct(self, xxhash_xxh32_t, &xxhash_xxh32_type, storage);
97
114
 
98
115
  code = XXH32_reset(storage->state, storage->seed);
99
116
  if(code != XXH_OK) {
@@ -107,7 +124,7 @@ VALUE xxhash32_streaming_hash_update(VALUE self, VALUE data)
107
124
  {
108
125
  XXH_errorcode code;
109
126
  xxhash_xxh32_t* storage;
110
- Data_Get_Struct(self, xxhash_xxh32_t, storage);
127
+ TypedData_Get_Struct(self, xxhash_xxh32_t, &xxhash_xxh32_type, storage);
111
128
 
112
129
  code = XXH32_update(storage->state, StringValuePtr(data), (size_t)RSTRING_LEN(data));
113
130
  if(code != XXH_OK) {
@@ -119,7 +136,7 @@ VALUE xxhash32_streaming_hash_update(VALUE self, VALUE data)
119
136
  VALUE xxhash32_streaming_hash_digest(VALUE self)
120
137
  {
121
138
  xxhash_xxh32_t* storage;
122
- Data_Get_Struct(self, xxhash_xxh32_t, storage);
139
+ TypedData_Get_Struct(self, xxhash_xxh32_t, &xxhash_xxh32_type, storage);
123
140
 
124
141
  // Do not free memory now.
125
142
  return ULL2NUM(XXH32_digest(storage->state));
@@ -130,13 +147,30 @@ VALUE xxhash_xxh64(VALUE mod, VALUE input, VALUE seed)
130
147
  return ULL2NUM(XXH64(StringValuePtr(input), (size_t)RSTRING_LEN(input), (unsigned int)NUM2ULL(seed)));
131
148
  }
132
149
 
133
- void xxhash64_streaming_hash_free(xxhash_xxh64_t* storage)
150
+ static void xxhash64_streaming_hash_free(void *ptr)
134
151
  {
152
+ xxhash_xxh64_t* storage = (xxhash_xxh64_t*)ptr;
135
153
  // Digest frees the memory.
136
154
  XXH64_freeState(storage->state);
137
155
  xfree(storage);
138
156
  }
139
157
 
158
+ static size_t xxhash64_streaming_hash_memsize(const void *ptr)
159
+ {
160
+ // Ideally we'd include sizeof(XXH64_state_t) too, but the type is opaque.
161
+ return sizeof(xxhash_xxh64_t);
162
+ }
163
+
164
+ static const rb_data_type_t xxhash_xxh64_type = {
165
+ .wrap_struct_name = "xxhash/xxhash64_streaming_hash",
166
+ .function = {
167
+ .dmark = NULL,
168
+ .dfree = xxhash64_streaming_hash_free,
169
+ .dsize = xxhash64_streaming_hash_memsize,
170
+ },
171
+ .flags = RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
172
+ };
173
+
140
174
  VALUE xxhash64_streaming_hash_new(VALUE klass, VALUE seed)
141
175
  {
142
176
  XXH_errorcode code;
@@ -150,14 +184,14 @@ VALUE xxhash64_streaming_hash_new(VALUE klass, VALUE seed)
150
184
  rb_raise(rb_eRuntimeError, "Error during reset.");
151
185
  return Qnil;
152
186
  }
153
- return Data_Wrap_Struct(klass, 0, xxhash64_streaming_hash_free, storage);
187
+ return TypedData_Wrap_Struct(klass, &xxhash_xxh64_type, storage);
154
188
  }
155
189
 
156
190
  VALUE xxhash64_streaming_hash_reset(VALUE self)
157
191
  {
158
192
  XXH_errorcode code;
159
193
  xxhash_xxh64_t* storage;
160
- Data_Get_Struct(self, xxhash_xxh64_t, storage);
194
+ TypedData_Get_Struct(self, xxhash_xxh64_t, &xxhash_xxh64_type, storage);
161
195
 
162
196
  code = XXH64_reset(storage->state, storage->seed);
163
197
  if(code != XXH_OK) {
@@ -170,7 +204,7 @@ VALUE xxhash64_streaming_hash_update(VALUE self, VALUE data)
170
204
  {
171
205
  XXH_errorcode code;
172
206
  xxhash_xxh64_t* storage;
173
- Data_Get_Struct(self, xxhash_xxh64_t, storage);
207
+ TypedData_Get_Struct(self, xxhash_xxh64_t, &xxhash_xxh64_type, storage);
174
208
 
175
209
  code = XXH64_update(storage->state, StringValuePtr(data), (size_t)RSTRING_LEN(data));
176
210
  if(code != XXH_OK) {
@@ -182,7 +216,7 @@ VALUE xxhash64_streaming_hash_update(VALUE self, VALUE data)
182
216
  VALUE xxhash64_streaming_hash_digest(VALUE self)
183
217
  {
184
218
  xxhash_xxh64_t* storage;
185
- Data_Get_Struct(self, xxhash_xxh64_t, storage);
219
+ TypedData_Get_Struct(self, xxhash_xxh64_t, &xxhash_xxh64_type, storage);
186
220
 
187
221
  // Do not free memory now.
188
222
  return ULL2NUM(XXH64_digest(storage->state));
@@ -209,6 +243,7 @@ void Init_xxhash(void)
209
243
  rb_define_singleton_method(mInternal, "xxh64_file", (ruby_method*) &xxhash_xxh64_file, 2);
210
244
 
211
245
  cStreamingHash = rb_define_class_under(mInternal, "StreamingHash32", rb_cObject);
246
+ rb_undef_alloc_func(cStreamingHash);
212
247
 
213
248
  rb_define_singleton_method(cStreamingHash, "new", (ruby_method*) &xxhash32_streaming_hash_new, 1);
214
249
  rb_define_method(cStreamingHash, "update", (ruby_method*) &xxhash32_streaming_hash_update, 1);
@@ -216,6 +251,7 @@ void Init_xxhash(void)
216
251
  rb_define_method(cStreamingHash, "reset", (ruby_method*) &xxhash32_streaming_hash_reset, 0);
217
252
 
218
253
  cStreamingHash64 = rb_define_class_under(mInternal, "StreamingHash64", rb_cObject);
254
+ rb_undef_alloc_func(cStreamingHash64);
219
255
 
220
256
  rb_define_singleton_method(cStreamingHash64, "new", (ruby_method*) &xxhash64_streaming_hash_new, 1);
221
257
  rb_define_method(cStreamingHash64, "update", (ruby_method*) &xxhash64_streaming_hash_update, 1);
data/ext/xxhash/xxhash.h CHANGED
@@ -19,14 +19,12 @@ typedef VALUE (ruby_method)();
19
19
 
20
20
  VALUE xxhash_xxh32(VALUE mod, VALUE input, VALUE seed);
21
21
  VALUE xxhash_xxh32_file(VALUE mod, VALUE filename, VALUE seed);
22
- void xxhash32_streaming_hash_free(xxhash_xxh32_t* state);
23
22
  VALUE xxhash32_streaming_hash_new(VALUE klass, VALUE seed);
24
23
  VALUE xxhash32_streaming_hash_update(VALUE self, VALUE data);
25
24
  VALUE xxhash32_streaming_hash_reset(VALUE self);
26
25
  VALUE xxhash32_streaming_hash_digest(VALUE self);
27
26
  VALUE xxhash_xxh64(VALUE mod, VALUE input, VALUE seed);
28
27
  VALUE xxhash_xxh64_file(VALUE mod, VALUE filename, VALUE seed);
29
- void xxhash64_streaming_hash_free(xxhash_xxh64_t* state);
30
28
  VALUE xxhash64_streaming_hash_new(VALUE klass, VALUE seed);
31
29
  VALUE xxhash64_streaming_hash_update(VALUE self, VALUE data);
32
30
  VALUE xxhash64_streaming_hash_reset(VALUE self);
@@ -1,3 +1,3 @@
1
1
  module XXhash
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xxhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliy Ermolovich
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-28 00:00:00.000000000 Z
11
+ date: 2024-12-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby wrapper for xxHash lib
14
14
  email:
@@ -39,7 +39,7 @@ homepage: http://github.com/nashby/xxhash
39
39
  licenses:
40
40
  - MIT
41
41
  metadata: {}
42
- post_install_message:
42
+ post_install_message:
43
43
  rdoc_options: []
44
44
  require_paths:
45
45
  - lib
@@ -54,8 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubygems_version: 3.0.9
58
- signing_key:
57
+ rubygems_version: 3.5.16
58
+ signing_key:
59
59
  specification_version: 4
60
60
  summary: Ruby wrapper for xxHash lib
61
61
  test_files: