narray_ffi 1.1.0 → 1.1.1

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
  SHA1:
3
- metadata.gz: 1d1fd3b17183842cb75ec77fef2754c7fc9266a8
4
- data.tar.gz: d652418d88d7ce7df105336d628f2a0cdbf6619e
3
+ metadata.gz: 510a401c952751ea163855b174e72a2f871c25d4
4
+ data.tar.gz: 9e81c0380bc8e31ec91a82c5f72b4df4344b0516
5
5
  SHA512:
6
- metadata.gz: 362cab7657d9a7a00a1b84933a1c436395694c68a244904b8eb5fa9af4edb71191852f23578fb13c713554729a21d07b5fb03b061469f1f3aa407dfbd8df7e1f
7
- data.tar.gz: 91d3336406830ddee1a4c1c458cd5df888a73666522ea56ac970c40306cfb1a92fa3a5555cc1013dc05fb46284d7953215a5e20b107696b9acb51ce207764d26
6
+ metadata.gz: 5ef3e44b7ad2999b1cee2146a63d4f34828d27e588d2952bfdff3120e62d17588e7d11dad16801f6c2de80a2db8f96ce5dcef71d759200bba7b0e8083f512282
7
+ data.tar.gz: 85840bd05ac8574a205185d5a4f2582161b8135df5870d0e6a7a33dfbb0c1fb7c871a7dbf5c852da9a721951f334b6b27f6a02f4c63a927de192f11e4eaa66c2
@@ -14,6 +14,31 @@ static VALUE
14
14
  return ret;
15
15
  }
16
16
 
17
+ static VALUE
18
+ na_to_ptr(VALUE self)
19
+ {
20
+ struct NARRAY *ary;
21
+ VALUE mod;
22
+ VALUE klass;
23
+ VALUE ret;
24
+ VALUE address;
25
+ long length;
26
+
27
+ GetNArray(self,ary);
28
+ mod = rb_const_get(rb_cObject, rb_intern("FFI"));
29
+ klass = rb_const_get(mod, rb_intern("Pointer"));
30
+ if ( ary->ref != Qnil ) {
31
+ if ( rb_funcall(ary->ref, rb_intern("kind_of?"), 1, klass) == Qtrue ) {
32
+ return ary->ref;
33
+ }
34
+ }
35
+
36
+ length = na_sizeof[ary->type] * ary->total;
37
+ ret = rb_funcall(klass, rb_intern("new"), 1, na_address(self));
38
+ ret = rb_funcall(ret, rb_intern("slice"), 2, LONG2NUM(0), LONG2NUM(length));
39
+ return ret;
40
+ }
41
+
17
42
  static struct NARRAY*
18
43
  na_alloc_struct_empty(int type, int rank, int *shape)
19
44
  {
@@ -153,11 +178,9 @@ static VALUE
153
178
  rb_raise(rb_eArgError, "Argument is required");
154
179
  }
155
180
  mod = rb_const_get(rb_cObject, rb_intern("FFI"));
156
- if (mod != Qnil) {
157
- klass_p = rb_const_get(mod, rb_intern("Pointer"));
158
- if ( rb_funcall(argv[0], rb_intern("kind_of?"), 1, klass_p) == Qtrue ){
159
- return na_pointer_to_na(argc-1,argv+1,argv[0]);
160
- }
181
+ klass_p = rb_const_get(mod, rb_intern("Pointer"));
182
+ if ( rb_funcall(argv[0], rb_intern("kind_of?"), 1, klass_p) == Qtrue ){
183
+ return na_pointer_to_na(argc-1,argv+1,argv[0]);
161
184
  }
162
185
  rb_funcall2(klass, rb_intern("to_na_old"), argc, argv);
163
186
  }
@@ -168,6 +191,8 @@ void Init_narray_ffi_c() {
168
191
  id = rb_intern("NArray");
169
192
  klass = rb_const_get(rb_cObject, id);
170
193
  rb_define_private_method(klass, "address", na_address, 0);
194
+ rb_define_method(klass, "to_ptr", na_to_ptr, 0);
195
+ rb_define_alias(rb_singleton_class(klass), "to_na_old", "to_na");
171
196
  rb_define_singleton_method(klass, "to_na", na_s_to_na_pointer, -1);
172
197
  rb_define_singleton_method(klass, "to_narray", na_s_to_na_pointer, -1);
173
198
  }
data/lib/narray_ffi.rb CHANGED
@@ -1,14 +1,3 @@
1
1
  require "narray"
2
2
  require "ffi"
3
- class NArray
4
- class << self
5
- alias to_na_old to_na
6
- end
7
- end
8
3
  require "narray_ffi_c.so"
9
-
10
- class NArray
11
- def to_ptr
12
- return FFI::Pointer::new( address() ).slice(0, size*element_size)
13
- end
14
- end
data/narray_ffi.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'narray_ffi'
3
- s.version = "1.1.0"
3
+ s.version = "1.1.1"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "brice.videau@imag.fr"
6
6
  s.homepage = "https://forge.imag.fr/projects/opencl-ruby/"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: narray_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice Videau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2015-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: narray