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 +4 -4
- data/ext/fiddle/function.c +2 -1
- data/ext/fiddle/memory_view.c +72 -3
- data/ext/fiddle/pointer.c +1 -0
- data/lib/fiddle/function.rb +6 -0
- data/lib/fiddle/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05f04e2fc988a1635621c537e5836231c2ae496ed45990523be623b44c8557be
|
4
|
+
data.tar.gz: b81aec1d67a6a08413245b483c6aed84052df7f5b907e8111bf1b8a47c2e69bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1c8640fb5a93f6b8c36eb3062f7b795cc10160176fe6d8e3f1370c5ce4ffd2e3036581ed4a3842a8eeb6d595219e8ee370c9c0d996e6213dfcb400fea10c58
|
7
|
+
data.tar.gz: fcd3f9cf4d08f760065770d2529f95c17dc8c95f889d691824f98bad1cb03fbeee20dcf005493b4bc9b66850b7fecdf022b13aaa6c359949a2266696a313619f
|
data/ext/fiddle/function.c
CHANGED
@@ -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
|
-
|
384
|
+
ULONG2NUM(error));
|
384
385
|
rb_funcall(mFiddle, rb_intern("win32_last_socket_error="), 1,
|
385
386
|
INT2NUM(socket_error));
|
386
387
|
#endif
|
data/ext/fiddle/memory_view.c
CHANGED
@@ -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
|
-
|
39
|
+
fiddle_memview_release(struct memview_data *data)
|
39
40
|
{
|
40
|
-
|
41
|
+
if (NIL_P(data->view.obj)) return;
|
42
|
+
|
41
43
|
rb_memory_view_release(&data->view);
|
42
|
-
|
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){
|
data/lib/fiddle/function.rb
CHANGED
data/lib/fiddle/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2021-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|