libui 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a70af9cdc5c6bdd0ff971474bfc3e7c7facaf9e3cd04af4375d40953e3827b7d
4
- data.tar.gz: 19b9c62a9003a5a097ff1643a783fa3a9bb72d36c06e1eb65f361d7679f51398
3
+ metadata.gz: 02ee9e67a91414cbea40a50448a58bbb320f8962f34a35fa9c26d7ed0019878d
4
+ data.tar.gz: cfde88b2432abbf23f9dd0d195db0258c143bfd1ff339f51b3112ccaf4742af2
5
5
  SHA512:
6
- metadata.gz: 9df4e5b0fb7a71c02b9b8715ebecf02cf0367829448d959ed1bd89fca65fd40fa51db37ee38b58546d60edb33c03719a183116f64fd95149081de711d095b9cb
7
- data.tar.gz: 27daac95b0cc02f44ca94b9ea11e3f91ef983806a1bef3319689d4dc60596f600d0673369fe165fe6e01470dae61dcf4ba6f6c80fd0cc5df5cf26c291a547466
6
+ metadata.gz: cb131ab13e11e6573058c0ec611c7467557756904b49d4121541f4075518958d3fdf2adc74e21d52f0f433c537faeffd6a77ab4162f7d42321fdec75437d1be0
7
+ data.tar.gz: 0dc6139433b79bec3e0a096f376db6af7eedc6b989ccab25bf4d3a1123afc75d053d43625d5302122952b2a527a8a17665ec9bc1472c1574f5ae4262bef80197
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # libui
1
+ # LibUI
2
2
 
3
3
  ![build](https://github.com/kojix2/libui/workflows/build/badge.svg)
4
4
  [![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)
@@ -41,14 +41,23 @@ module LibUI
41
41
  if arg.is_a?(Proc)
42
42
  # The types of the function arguments are recorded beforehand.
43
43
  # See the monkey patch in ffi.rb.
44
- Fiddle::Closure::BlockCaller.new(*func.inner_functions[idx][1..2], &arg)
44
+ callback = Fiddle::Closure::BlockCaller.new(
45
+ *func.callback_argument_types[idx][1..2], &arg
46
+ )
47
+ # Protect from GC
48
+ # See https://github.com/kojix2/LibUI/issues/8
49
+ receiver = args[0]
50
+ callbacks = receiver.instance_variable_get(:@callbacks) || []
51
+ callbacks << callback
52
+ receiver.instance_variable_set(:@callbacks, callback)
53
+ callback
45
54
  else
46
55
  arg
47
56
  end
48
57
  end
49
58
 
50
59
  # Make it possible to omit the last nil. This may be an over-optimization.
51
- siz = func.argtype.size - 1
60
+ siz = func.argument_types.size - 1
52
61
  args[siz] = nil if args.size == siz
53
62
 
54
63
  FFI.public_send(original_method_name, *args)
@@ -4,9 +4,11 @@ require 'fiddle/import'
4
4
 
5
5
  module Fiddle
6
6
  # Change the Function to hold a little more information.
7
- # FIXME: Give inner_function a better name.
8
7
  class Function
9
- attr_accessor :inner_functions, :argtype
8
+ # Note:
9
+ # Ruby 2.7 Fiddle::Function dose not have @argument_types
10
+ # Ruby 3.0 Fiddle::Function has @argument_types
11
+ attr_accessor :callback_argument_types, :argument_types
10
12
  end
11
13
 
12
14
  module Importer
@@ -21,32 +23,34 @@ module Fiddle
21
23
  raise("can't parserake the function prototype: #{signature}")
22
24
  end
23
25
  symname = func
24
- inner_funcs = [] # Added
25
- argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
26
+ callback_argument_types = {} # Added
27
+ argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
26
28
  # Check if it is a function pointer or not
27
- if arg =~ /\(\*.*\)\(.*\)/ # Added
29
+ if arg =~ /\(\*.*\)\(.*\)/ # Added
28
30
  # From the arguments, create a notation that looks like a function declaration
29
31
  # int(*f)(int *, void *) -> int f(int *, void *)
30
- func_arg = arg.sub('(*', ' ').sub(')', '') # Added
32
+ func_arg = arg.sub('(*', ' ').sub(')', '') # Added
31
33
  # Use Fiddle's parse_signature method again.
32
- inner_funcs[idx] = parse_signature(func_arg) # Added
33
- end # Added
34
+ callback_argument_types[idx] = parse_signature(func_arg) # Added
35
+ end
34
36
  parse_ctype(arg, tymap)
35
37
  end
36
- # Added inner_funcs. Original method return only 3 values.
37
- [symname, ctype, argtype, inner_funcs]
38
+ # Added callback_argument_types. Original method return only 3 values.
39
+ [symname, ctype, argtype, callback_argument_types]
38
40
  end
39
41
 
40
42
  def extern(signature, *opts)
41
- symname, ctype, argtype, inner_funcs = parse_signature(signature, type_alias)
43
+ symname, ctype, argtype, callback_argument_types = parse_signature(signature, type_alias)
42
44
  opt = parse_bind_options(opts)
43
- f = import_function(symname, ctype, argtype, opt[:call_type])
45
+ func = import_function(symname, ctype, argtype, opt[:call_type])
44
46
 
45
- f.inner_functions = inner_funcs # Added
46
- f.argtype = argtype # Added
47
+ func.callback_argument_types = callback_argument_types # Added
48
+ # Ruby 2.7 Fiddle::Function dose not have @argument_types
49
+ # Ruby 3.0 Fiddle::Function has @argument_types
50
+ func.argument_types = argtype
47
51
 
48
52
  name = symname.gsub(/@.+/, '')
49
- @func_map[name] = f
53
+ @func_map[name] = func
50
54
  # define_method(name){|*args,&block| f.call(*args,&block)}
51
55
  begin
52
56
  /^(.+?):(\d+)/ =~ caller.first
@@ -61,7 +65,7 @@ module Fiddle
61
65
  end
62
66
  EOS
63
67
  module_function(name)
64
- f
68
+ func
65
69
  end
66
70
  end
67
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LibUI
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-26 00:00:00.000000000 Z
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.2.3
120
+ rubygems_version: 3.1.4
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Ruby bindings to libui