fiddle 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f60ecd26479775fa123a883a89a39ebae034c408e99bd0bc33a4d802cc04c648
4
- data.tar.gz: 7466888aaca2242fd13af7c6663212d4c7404c4e5336626baea9c2519a068c7f
3
+ metadata.gz: 05f04e2fc988a1635621c537e5836231c2ae496ed45990523be623b44c8557be
4
+ data.tar.gz: b81aec1d67a6a08413245b483c6aed84052df7f5b907e8111bf1b8a47c2e69bd
5
5
  SHA512:
6
- metadata.gz: bd4349a30d8aa6b0113261cb3f53e2dee46b56b1ea72617abfbf921f31b13161897f39277358aa8e1bf3d6329d41b4b260f198ac850916eb677e7a46a21ee299
7
- data.tar.gz: 99dd69a25bb75de362d244ebc0d4d338710b93195ce417356e44e9d7415ec7a1c0e553da2406a3ae3c5d907d705ad40e9bb9ab46eb7c95fc2ddd0aee7ea42df5
6
+ metadata.gz: 7b1c8640fb5a93f6b8c36eb3062f7b795cc10160176fe6d8e3f1370c5ce4ffd2e3036581ed4a3842a8eeb6d595219e8ee370c9c0d996e6213dfcb400fea10c58
7
+ data.tar.gz: fcd3f9cf4d08f760065770d2529f95c17dc8c95f889d691824f98bad1cb03fbeee20dcf005493b4bc9b66850b7fecdf022b13aaa6c359949a2266696a313619f
@@ -378,9 +378,10 @@ function_call(int argc, VALUE argv[], VALUE self)
378
378
  {
379
379
  int errno_keep = errno;
380
380
  #if defined(_WIN32)
381
+ DWORD error = WSAGetLastError();
381
382
  int socket_error = WSAGetLastError();
382
383
  rb_funcall(mFiddle, rb_intern("win32_last_error="), 1,
383
- INT2NUM(errno_keep));
384
+ ULONG2NUM(error));
384
385
  rb_funcall(mFiddle, rb_intern("win32_last_socket_error="), 1,
385
386
  INT2NUM(socket_error));
386
387
  #endif
@@ -1,5 +1,6 @@
1
1
  #include <stdbool.h>
2
2
  #include <ruby/ruby.h>
3
+ #include <ruby/encoding.h>
3
4
 
4
5
  #ifdef HAVE_RUBY_MEMORY_VIEW_H
5
6
  # include <ruby/memory_view.h>
@@ -35,12 +36,25 @@ fiddle_memview_mark(void *ptr)
35
36
  }
36
37
 
37
38
  static void
38
- fiddle_memview_free(void *ptr)
39
+ fiddle_memview_release(struct memview_data *data)
39
40
  {
40
- struct memview_data *data = ptr;
41
+ if (NIL_P(data->view.obj)) return;
42
+
41
43
  rb_memory_view_release(&data->view);
42
- if (data->members)
44
+ data->view.obj = Qnil;
45
+ data->view.byte_size = 0;
46
+ if (data->members) {
43
47
  xfree(data->members);
48
+ data->members = NULL;
49
+ data->n_members = 0;
50
+ }
51
+ }
52
+
53
+ static void
54
+ fiddle_memview_free(void *ptr)
55
+ {
56
+ struct memview_data *data = ptr;
57
+ fiddle_memview_release(data);
44
58
  xfree(ptr);
45
59
  }
46
60
 
@@ -62,11 +76,32 @@ rb_fiddle_memview_s_allocate(VALUE klass)
62
76
  struct memview_data *data;
63
77
  VALUE obj = TypedData_Make_Struct(klass, struct memview_data, &fiddle_memview_data_type, data);
64
78
  data->view.obj = Qnil;
79
+ data->view.byte_size = 0;
65
80
  data->members = NULL;
66
81
  data->n_members = 0;
67
82
  return obj;
68
83
  }
69
84
 
85
+ static VALUE
86
+ rb_fiddle_memview_release(VALUE obj)
87
+ {
88
+ struct memview_data *data;
89
+ TypedData_Get_Struct(obj, struct memview_data, &fiddle_memview_data_type, data);
90
+
91
+ if (NIL_P(data->view.obj)) return Qnil;
92
+ fiddle_memview_release(data);
93
+ return Qnil;
94
+ }
95
+
96
+ static VALUE
97
+ rb_fiddle_memview_s_export(VALUE klass, VALUE target)
98
+ {
99
+ ID id_new;
100
+ CONST_ID(id_new, "new");
101
+ VALUE memview = rb_funcall(klass, id_new, 1, target);
102
+ return rb_ensure(rb_yield, memview, rb_fiddle_memview_release, memview);
103
+ }
104
+
70
105
  static VALUE
71
106
  rb_fiddle_memview_initialize(VALUE obj, VALUE target)
72
107
  {
@@ -74,6 +109,7 @@ rb_fiddle_memview_initialize(VALUE obj, VALUE target)
74
109
  TypedData_Get_Struct(obj, struct memview_data, &fiddle_memview_data_type, data);
75
110
 
76
111
  if (!rb_memory_view_get(target, &data->view, 0)) {
112
+ data->view.obj = Qnil;
77
113
  rb_raise(rb_eArgError, "Unable to get a memory view from %+"PRIsVALUE, target);
78
114
  }
79
115
 
@@ -233,12 +269,44 @@ rb_fiddle_memview_aref(int argc, VALUE *argv, VALUE obj)
233
269
  return rb_memory_view_extract_item_members(ptr, data->members, data->n_members);
234
270
  }
235
271
 
272
+ static VALUE
273
+ rb_fiddle_memview_to_s(VALUE self)
274
+ {
275
+ struct memview_data *data;
276
+ const char *raw_data;
277
+ long byte_size;
278
+ VALUE string;
279
+
280
+ TypedData_Get_Struct(self,
281
+ struct memview_data,
282
+ &fiddle_memview_data_type,
283
+ data);
284
+
285
+ if (NIL_P(data->view.obj)) {
286
+ raw_data = NULL;
287
+ byte_size = 0;
288
+ } else {
289
+ raw_data = data->view.data;
290
+ byte_size = data->view.byte_size;
291
+ }
292
+
293
+ string = rb_enc_str_new_static(raw_data, byte_size, rb_ascii8bit_encoding());
294
+ {
295
+ ID id_memory_view;
296
+ CONST_ID(id_memory_view, "memory_view");
297
+ rb_ivar_set(string, id_memory_view, self);
298
+ }
299
+ return rb_obj_freeze(string);
300
+ }
301
+
236
302
  void
237
303
  Init_fiddle_memory_view(void)
238
304
  {
239
305
  rb_cMemoryView = rb_define_class_under(mFiddle, "MemoryView", rb_cObject);
240
306
  rb_define_alloc_func(rb_cMemoryView, rb_fiddle_memview_s_allocate);
307
+ rb_define_singleton_method(rb_cMemoryView, "export", rb_fiddle_memview_s_export, 1);
241
308
  rb_define_method(rb_cMemoryView, "initialize", rb_fiddle_memview_initialize, 1);
309
+ rb_define_method(rb_cMemoryView, "release", rb_fiddle_memview_release, 0);
242
310
  rb_define_method(rb_cMemoryView, "obj", rb_fiddle_memview_get_obj, 0);
243
311
  rb_define_method(rb_cMemoryView, "byte_size", rb_fiddle_memview_get_byte_size, 0);
244
312
  rb_define_method(rb_cMemoryView, "readonly?", rb_fiddle_memview_get_readonly, 0);
@@ -249,6 +317,7 @@ Init_fiddle_memory_view(void)
249
317
  rb_define_method(rb_cMemoryView, "strides", rb_fiddle_memview_get_strides, 0);
250
318
  rb_define_method(rb_cMemoryView, "sub_offsets", rb_fiddle_memview_get_sub_offsets, 0);
251
319
  rb_define_method(rb_cMemoryView, "[]", rb_fiddle_memview_aref, -1);
320
+ rb_define_method(rb_cMemoryView, "to_s", rb_fiddle_memview_to_s, 0);
252
321
  }
253
322
 
254
323
  #endif /* FIDDLE_MEMORY_VIEW */
data/ext/fiddle/pointer.c CHANGED
@@ -770,6 +770,7 @@ rb_fiddle_ptr_s_to_ptr(VALUE self, VALUE val)
770
770
  }
771
771
  else if (RTEST(rb_obj_is_kind_of(val, rb_cString))){
772
772
  char *str = StringValuePtr(val);
773
+ wrap = val;
773
774
  ptr = rb_fiddle_ptr_new(str, RSTRING_LEN(val), NULL);
774
775
  }
775
776
  else if ((vptr = rb_check_funcall(val, id_to_ptr, 0, 0)) != Qundef){
@@ -19,5 +19,11 @@ module Fiddle
19
19
  def to_i
20
20
  ptr.to_i
21
21
  end
22
+
23
+ # Turn this function in to a proc
24
+ def to_proc
25
+ this = self
26
+ lambda { |*args| this.call(*args) }
27
+ end
22
28
  end
23
29
  end
@@ -1,3 +1,3 @@
1
1
  module Fiddle
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-04-19 00:00:00.000000000 Z
12
+ date: 2021-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler