fiddley 0.0.4 → 0.0.5

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: bf2d272d2170487e17fb8f3c96e70076228361f6
4
- data.tar.gz: c1a3515ec44871af8a51f0e482f1bcc0352903f0
3
+ metadata.gz: 89adacb7382de9ea109dda5d0a9aa9a0126a3198
4
+ data.tar.gz: f8e12868b55cddad59d0981a01690d41b23888dc
5
5
  SHA512:
6
- metadata.gz: 8679a00557727ed2d2590f82f7d85f9977c415f5001338d4463653f28d407b0270dbd24b6e51a20a42ee4139e2cfa7c8de197a4b371b519cabd49a1e1e88b270
7
- data.tar.gz: 538b0728b44e29d737fbfb6a3f0d8ff0f572049853ed45a2a4cdd554eaec1ddc95528659b648dde7a8d65b5e6a4cee1d4e321631801b879cff6159b978067fb5
6
+ metadata.gz: 1e455169f82ace8c779056efe3c6eda4f88ab6a5d13012a9d3bea5c59246876278e9cabccd73f72dab79e7151687a9af96493f7f97bc55bbcd45d922c8d8b829
7
+ data.tar.gz: 03bc837b03cf53ccbe543efe6432596a34e158646bf91894ac7282c392cb14401cddc8f7f3c9516ede054a6194891ed3cc7d347bc5f61fc36c503fad30dc034d
@@ -1,5 +1,5 @@
1
1
  module Fiddley
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
4
4
 
5
5
  require "fiddley/function"
@@ -1,4 +1,5 @@
1
1
  require "fiddle/import"
2
+ require "fiddley/struct"
2
3
  require "fiddley/utils"
3
4
 
4
5
  module Fiddley
@@ -45,13 +46,12 @@ module Fiddley
45
46
  cname = rname
46
47
  end
47
48
  extern "#{type2str(ret)} #{cname}(#{params.map{|e| type2str(e)}.join(', ')})", @convention
48
- if ret == :string
49
- tname = (cname.to_s + '+').to_sym
50
- instance_eval <<-end
51
- alias #{tname.inspect} #{cname.inspect}
52
- end
53
- define_singleton_method(cname) do |*args|
54
- __send__(tname, *args).to_s
49
+ case ret
50
+ when :string
51
+ wrap_function(cname, &:to_s)
52
+ when :pointer
53
+ wrap_function(cname) do |result|
54
+ Fiddley::MemoryPointer.new(ret, result)
55
55
  end
56
56
  end
57
57
  if cname != rname
@@ -61,6 +61,16 @@ module Fiddley
61
61
  end
62
62
  end
63
63
 
64
+ private def wrap_function(cname, &blk)
65
+ tname = (cname.to_s + '+').to_sym
66
+ instance_eval <<-end
67
+ alias #{tname.inspect} #{cname.inspect}
68
+ end
69
+ define_singleton_method(cname) do |*args|
70
+ blk.call(__send__(tname, *args))
71
+ end
72
+ end
73
+
64
74
  case RUBY_PLATFORM
65
75
  when /cygwin/
66
76
  libprefix = "cyg"
@@ -10,8 +10,13 @@ module Fiddley
10
10
  include Fiddley::Utils
11
11
 
12
12
  def initialize(type, num = 1, clear = true)
13
- @size = type2size(type) * num
14
- @ptr = Fiddle::Pointer.malloc(@size)
13
+ if num.is_a?(Fiddle::Pointer)
14
+ @ptr = num
15
+ @size = @ptr.size
16
+ else
17
+ @size = type2size(type) * num
18
+ @ptr = Fiddle::Pointer.malloc(@size)
19
+ end
15
20
  end
16
21
 
17
22
  attr_reader :size
@@ -90,12 +95,12 @@ module Fiddley
90
95
  end
91
96
  end
92
97
 
93
- def put_bytes(offset, str, len = nil)
94
- @ptr[offset, len ? len : str.bytesize] = len ? str[0, len] : str
98
+ def put_bytes(offset, str, idx = 0, len = str.bytesize - idx)
99
+ @ptr[offset, len] = str[idx, len]
95
100
  end
96
101
 
97
- def write_bytes(str, len = nil)
98
- put_bytes(0, str, len)
102
+ def write_bytes(str, idx = 0, len = nil)
103
+ put_bytes(0, str, idx, len)
99
104
  end
100
105
 
101
106
  def get_bytes(offset, len)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiddley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - U.Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-01 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Use Fiddle instead of Ruby-FFI !!!
14
14
  email: