rbind 0.0.23 → 0.0.24

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
  SHA1:
3
- metadata.gz: a49ac912bcaf33b590650a1a9764e4055e1324f6
4
- data.tar.gz: 2711d7f9cfbbf28b32aa7765914971f9f07f1da6
3
+ metadata.gz: eba08b9155b23d4f0bbd4feffe778fc3ada80722
4
+ data.tar.gz: 42bc3877dd9b3d0573afbda392229c548a683c02
5
5
  SHA512:
6
- metadata.gz: 2b5964e2a7e3b260879ded95cd659af9c918c16d78e7cd729ad34c720571d68a1eccdc620883ab8d246ef84dce2cea10ccb86eced4d7ee918bc42385967cb3f2
7
- data.tar.gz: 8e855c1b6e0599cc5b9a966a794fe2badbdc4d7ba4ba1069d1b13560869c3c67319449ba5264a553014145ca46ec56fdd1b890c4b5ba6557e43aca00ff556086
6
+ metadata.gz: 8b4be23c15b9e23ea938117d4f5f96d17381efa49431cf9c51ec1431c47331883d39df3cc2300cc3310f903958fc1138b0800b35afeb94e7995c6a01d6cc4c04
7
+ data.tar.gz: a43976da4bd469baf51adc8c6c9e51a8b5fedb38f89ea7c36e77d5ed1327465df08f51e25cbb234bc3f057f2bc25a5700271860a916eb510a3fe74db508dfd61
data/lib/rbind/core.rb CHANGED
@@ -11,9 +11,7 @@ require 'rbind/core/rsetter.rb'
11
11
  require 'rbind/core/rnamespace.rb'
12
12
  require 'rbind/core/rclass.rb'
13
13
  require 'rbind/core/rtemplate_class.rb'
14
- require 'rbind/core/rreference.rb'
15
- require 'rbind/core/rpointer.rb'
16
- require 'rbind/core/rtype_qualifier.rb'
14
+ require 'rbind/core/rtype_annotation.rb'
17
15
 
18
16
  require 'rbind/types/std_vector.rb'
19
17
  require 'rbind/types/std_string.rb'
@@ -13,6 +13,9 @@ module Rbind
13
13
  add_parent(p)
14
14
  end
15
15
  super(name)
16
+ # we have to disable the type check for classes
17
+ # otherwise derived types cannot be parsed
18
+ @check_type = false
16
19
  end
17
20
 
18
21
  def basic_type?
@@ -195,9 +198,6 @@ module Rbind
195
198
  if klass.full_name == full_name || klass == self
196
199
  raise ArgumentError,"class #{klass.full_name} cannot be parent of its self"
197
200
  end
198
- # we have to disable the type check for the parent class
199
- # otherwise derived types cannot be parsed
200
- klass.check_type = false
201
201
  @parent_classes[klass.name] = ParentClass.new(klass,accessor)
202
202
  self
203
203
  end
@@ -1,7 +1,6 @@
1
1
 
2
2
  module Rbind
3
3
  class RDataType < RBase
4
- attr_accessor :ptr,:ref
5
4
  attr_accessor :typedef
6
5
  attr_accessor :invalid_value
7
6
  attr_accessor :cdelete_method
@@ -65,27 +64,50 @@ module Rbind
65
64
  end
66
65
 
67
66
  def to_single_ptr
68
- t = to_raw
69
- t = t.to_const if const?
70
- t.to_ptr
67
+ self.to_ptr
71
68
  end
72
69
 
73
70
  def to_ptr
74
- RPointer.new(self)
71
+ RTypeAnnotation.new(self,:ptr => 1)
75
72
  end
76
73
 
77
74
  def to_ref
78
- RReference.new(self)
75
+ RTypeAnnotation.new(self,:ref => true)
79
76
  end
80
77
 
81
78
  def to_const
82
- RTypeQualifier.new(self,:const => true)
79
+ RTypeAnnotation.new(self,:const => true)
80
+ end
81
+
82
+ def to_ownership(val)
83
+ raise "Cannot set memory owner for none pointer types!"
83
84
  end
84
85
 
85
86
  def remove_const
86
87
  self
87
88
  end
88
89
 
90
+ def remove_ownership
91
+ self
92
+ end
93
+
94
+ def remove_ref
95
+ self
96
+ end
97
+
98
+ def remove_ptr
99
+ self
100
+ end
101
+
102
+ # returns true if the type is owner of its memory
103
+ def ownership?
104
+ if ref?
105
+ false
106
+ else
107
+ true
108
+ end
109
+ end
110
+
89
111
  def raw?
90
112
  true
91
113
  end
@@ -0,0 +1,135 @@
1
+ require 'delegate'
2
+
3
+ module Rbind
4
+ class RTypeAnnotation < SimpleDelegator
5
+ attr_accessor :const
6
+
7
+ def initialize(type,options=Hash.new)
8
+ super(type)
9
+ @options = options
10
+ end
11
+
12
+ def to_annotation(key,val)
13
+ if @options.has_key?(key) && @options[key] == val
14
+ self
15
+ else
16
+ opt = @options.clone
17
+ opt[key] = val
18
+ RTypeAnnotation.new(__getobj__,opt)
19
+ end
20
+ end
21
+
22
+ def remove_annotation(key)
23
+ opt = @options.clone
24
+ opt.delete(key)
25
+ if opt.empty?
26
+ __getobj__
27
+ else
28
+ RTypeAnnotation.new(__getobj__,opt)
29
+ end
30
+ end
31
+
32
+ def const?
33
+ if @options.has_key? :const
34
+ !!@options[:const]
35
+ else
36
+ super
37
+ end
38
+ end
39
+
40
+ def to_const
41
+ to_annotation(:const,true)
42
+ end
43
+
44
+ def remove_const
45
+ remove_annotation(:const)
46
+ end
47
+
48
+ def ownership?
49
+ if @options.has_key? :ownership
50
+ !!@options[:ownership]
51
+ else
52
+ super
53
+ end
54
+ end
55
+
56
+ def to_ownership(val=true)
57
+ if ptr?
58
+ to_annotation(:ownership,val)
59
+ else
60
+ super
61
+ end
62
+ end
63
+
64
+ def remove_ownership
65
+ remove_annotation(:ownership)
66
+ end
67
+
68
+ def to_ptr
69
+ val = if ptr?
70
+ @options[:ptr]+1
71
+ else
72
+ 1
73
+ end
74
+ to_annotation(:ptr,val)
75
+ end
76
+
77
+ def ptr?
78
+ if @options.has_key? :ptr
79
+ @options[:ptr] != 0
80
+ else
81
+ super
82
+ end
83
+ end
84
+
85
+ def remove_ptr
86
+ return self if !ptr?
87
+ val = @options[:ptr]-1
88
+ if val == 0
89
+ remove_annotation(:ptr)
90
+ else
91
+ to_annotation(:ptr,val)
92
+ end
93
+ end
94
+
95
+ def to_ref
96
+ to_annotation? :ref,true
97
+ end
98
+
99
+ def ref?
100
+ if @options.has_key? :ref
101
+ !!@options[:ref]
102
+ else
103
+ super
104
+ end
105
+ end
106
+
107
+ def remove_ref
108
+ remove_annotation :ref
109
+ end
110
+
111
+ def raw?
112
+ false
113
+ end
114
+
115
+ def signature(sig=nil)
116
+ generate_signatures[0]
117
+ end
118
+
119
+ def csignature(sig=nil)
120
+ generate_signatures[1]
121
+ end
122
+
123
+ def generate_signatures
124
+ str_pre = ""
125
+ str_post = ""
126
+
127
+ str_pre = "const " if const?
128
+ str_post += "&" if ref?
129
+ str_post += "*" * @options[:ptr] if ptr?
130
+ __getobj__.generate_signatures.map do |s|
131
+ str_pre + s + str_post
132
+ end
133
+ end
134
+ end
135
+ end
@@ -191,12 +191,12 @@ module Rbind
191
191
  end
192
192
  else
193
193
  fct = if !constructor? && (return_type.name != "void" || return_type.ptr?)
194
+ # operator+, operator++ etc
194
195
  if operator? && parameters.size == 1
195
196
  if return_type.basic_type?
196
197
  "return *rbind_obj_ #{operator} #{paras};"
197
198
  elsif return_type.ref?
198
- # the returned value is not the owner of the
199
- # object
199
+ # the returned value is not the owner of the object
200
200
  "return toC(&(*rbind_obj_ #{operator} #{paras}),false);"
201
201
  else
202
202
  "return toC(new #{return_type.full_name}(*rbind_obj_ #{operator} #{paras}));"
@@ -204,10 +204,9 @@ module Rbind
204
204
  elsif return_type.basic_type?
205
205
  "return #{full_name}(#{paras});"
206
206
  elsif return_type.ptr?
207
- "return toC(#{full_name}(#{paras}));"
207
+ "return toC(#{full_name}(#{paras}),#{return_type.ownership?});"
208
208
  elsif return_type.ref?
209
- # the returned value is not the owner of the
210
- # object
209
+ # the returned value is never owner of the memory
211
210
  "return toC(&#{full_name}(#{paras}),false);"
212
211
  else
213
212
  "return toC(new #{return_type.full_name}(#{full_name}(#{paras})));"
@@ -286,7 +285,7 @@ module Rbind
286
285
 
287
286
  def libs
288
287
  str = @root.map do |pkg|
289
- "${#{pkg.upcase}_LIBS} ${#{pkg.upcase}_LDFLAGS}"
288
+ "${#{pkg.upcase}_LIBS} ${#{pkg.upcase}_LDFLAGS_OTHER}"
290
289
  end.join(" ")
291
290
  str += " " + @libs.join(" ")
292
291
  end
@@ -65,6 +65,14 @@ module Rbind
65
65
  parameter.default_value.gsub("f","")
66
66
  elsif parameter.type.name == "double"
67
67
  parameter.default_value.gsub(/\.$/,".0").gsub(/^\./,"0.")
68
+ elsif parameter.type.ptr? &&(parameter.default_value == "0" || parameter.default_value = "NULL")
69
+ # NULL pointer
70
+ t = parameter.type.to_raw
71
+ if t.extern_package_name
72
+ "::#{t.extern_package_name}::#{normalize_type_name(t.full_name)}::null"
73
+ else
74
+ "#{normalize_type_name(t.full_name)}::null"
75
+ end
68
76
  else
69
77
  normalize_type_name(parameter.default_value)
70
78
  end
@@ -97,7 +105,7 @@ module Rbind
97
105
  "#{normalize_method_name(ops.first.name)}(#{(value)})"
98
106
  end
99
107
  elsif t
100
- t = t.to_ptr if parameter.type.ptr?
108
+ t = t.to_raw
101
109
  if t.extern_package_name
102
110
  "::#{t.extern_package_name}::#{normalize_type_name(t.full_name)}.new(#{(value)})"
103
111
  else
@@ -19,6 +19,10 @@ const <%= cname %>* toC(const <%= full_name %>* ptr, bool owner)
19
19
  // converts const <%= cname %> to const <%= full_name %>
20
20
  const <%= full_name %>* fromC(const <%= cname %>* ptr)
21
21
  {
22
+ if(ptr == NULL)
23
+ throw std::runtime_error("<%= full_name %>: Null Pointer!");
24
+ if(!ptr->obj_ptr)
25
+ return NULL;
22
26
  <%- if check_type? -%>
23
27
  // check typeid if available
24
28
  if(ptr->type_id && typeid(<%= full_name %>) != *static_cast<const std::type_info*>(ptr->type_id))
@@ -34,14 +38,14 @@ const <%= full_name %>* fromC(const <%= cname %>* ptr)
34
38
  // check size
35
39
  if(ptr->size && sizeof(<%= full_name %>) > ptr->size)
36
40
  throw std::runtime_error("wrong object size for <%= full_name %>.");
37
- if(!ptr->obj_ptr)
38
- throw std::runtime_error("object for <%= full_name %> was deleted!");
39
41
  return static_cast<const <%= full_name %>*>(ptr->obj_ptr);
40
42
  }
41
43
 
42
44
  // converts <%= cname %>* to <%= full_name %>*
43
45
  <%= full_name %>* fromC(<%= cname %>* ptr)
44
46
  {
47
+ if(ptr == NULL)
48
+ return NULL;
45
49
  return const_cast<<%= full_name %>*>(fromC(static_cast<const <%= cname %>*>(ptr)));
46
50
  }
47
51
 
@@ -2,6 +2,7 @@
2
2
  # @note method wrapper for <%= signature %>
3
3
  def <%=name%>(<%= wrap_parameters_signature %>)
4
4
  <%= add_specialize_ruby -%>
5
+ __validate_pointer__
5
6
  <%- if return_type.basic_type? || operator? -%>
6
7
  Rbind::<%= cname %>( <%= wrap_parameters_call %>)
7
8
  <%- else -%>
@@ -1,6 +1,7 @@
1
1
  <%= add_doc -%>
2
2
  # @note wrapper for overloaded method <%= name %>
3
3
  def <%=name%>(*args)
4
+ __validate_pointer__
4
5
  <%= add_methods %>
5
6
  raise ArgumentError, "No overloaded signature fits to: #{args.map(&:class)}"
6
7
  end
@@ -29,6 +29,11 @@ class <%= name %>
29
29
  <%= name %>Struct
30
30
  end
31
31
 
32
+ # returns a null pointer to the object
33
+ def self.null
34
+ new(<%= name %>Struct.new)
35
+ end
36
+
32
37
  <%= add_constructor_doc -%>
33
38
  def self.new(*args)
34
39
  if args.first.is_a?(FFI::Pointer) || args.first.is_a?(<%= name %>Struct)
@@ -95,6 +100,13 @@ class <%= name %>
95
100
  @__obj_ptr__[:bowner]
96
101
  end
97
102
 
103
+ # @private
104
+ # raises if the underlying pointer is a null pointer
105
+ # the real object
106
+ def __validate_pointer__
107
+ raise "NullPointer" if @__obj_ptr__.null? || @__obj_ptr__[:obj_ptr].address == 0
108
+ end
109
+
98
110
  # converts <%= name %> into a string by crawling through all its attributes
99
111
  def to_s
100
112
  <%= add_to_s %>
data/rbind.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rbind'
3
- s.version = '0.0.23'
4
- s.date = '2013-10-29'
3
+ s.version = '0.0.24'
4
+ s.date = '2014-02-16'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Alexander Duda']
7
7
  s.email = ['Alexander.Duda@dfki.de']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Duda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-29 00:00:00.000000000 Z
11
+ date: 2014-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hooks
@@ -64,11 +64,9 @@ files:
64
64
  - lib/rbind/core/rnamespace.rb
65
65
  - lib/rbind/core/roperation.rb
66
66
  - lib/rbind/core/rparameter.rb
67
- - lib/rbind/core/rpointer.rb
68
- - lib/rbind/core/rreference.rb
69
67
  - lib/rbind/core/rsetter.rb
70
68
  - lib/rbind/core/rtemplate_class.rb
71
- - lib/rbind/core/rtype_qualifier.rb
69
+ - lib/rbind/core/rtype_annotation.rb
72
70
  - lib/rbind/default_parser.rb
73
71
  - lib/rbind/generator_c.rb
74
72
  - lib/rbind/generator_extern.rb
@@ -1,70 +0,0 @@
1
- require 'delegate'
2
-
3
- module Rbind
4
- class RPointer < SimpleDelegator
5
- attr_accessor :const
6
-
7
- def initialize(type)
8
- super(type)
9
- end
10
-
11
- def name
12
- super.to_s + "*"
13
- end
14
-
15
- def full_name
16
- super.to_s + "*"
17
- end
18
-
19
- def signature(sig=nil)
20
- super.to_s + "*"
21
- end
22
-
23
- def csignature(sig=nil)
24
- super.to_s + "*"
25
- end
26
-
27
- def ptr?
28
- true
29
- end
30
-
31
- def ref?
32
- false
33
- end
34
-
35
- def raw?
36
- false
37
- end
38
-
39
- def remove_const
40
- RPointer.new __getobj__.remove_const
41
- end
42
-
43
- def to_ptr
44
- RPointer.new(self)
45
- end
46
-
47
- def to_ref
48
- RReference.new(self)
49
- end
50
-
51
- def to_const
52
- return self if const?
53
- RTypeQualifier.new(self,:const => true)
54
- end
55
-
56
- def signature(sig=nil)
57
- generate_signatures[0]
58
- end
59
-
60
- def csignature(sig=nil)
61
- generate_signatures[1]
62
- end
63
-
64
- def generate_signatures
65
- __getobj__.generate_signatures.map do |s|
66
- s + "*"
67
- end
68
- end
69
- end
70
- end
@@ -1,54 +0,0 @@
1
- require 'delegate'
2
-
3
- module Rbind
4
- class RReference < SimpleDelegator
5
- attr_accessor :const
6
-
7
- def initialize(type)
8
- super(type)
9
- end
10
-
11
- def ref?
12
- true
13
- end
14
-
15
- def ptr?
16
- false
17
- end
18
-
19
- def raw?
20
- false
21
- end
22
-
23
- def to_ptr
24
- RPointer.new(self)
25
- end
26
-
27
- def to_ref
28
- RReference.new(self)
29
- end
30
-
31
- def to_const
32
- return self if const?
33
- RTypeQualifier.new(self,:const => true)
34
- end
35
-
36
- def remove_const
37
- RReference.new __getobj__.remove_const
38
- end
39
-
40
- def signature(sig=nil)
41
- generate_signatures[0]
42
- end
43
-
44
- def csignature(sig=nil)
45
- generate_signatures[1]
46
- end
47
-
48
- def generate_signatures
49
- __getobj__.generate_signatures.map do |s|
50
- s + "&"
51
- end
52
- end
53
- end
54
- end
@@ -1,69 +0,0 @@
1
- require 'delegate'
2
-
3
- module Rbind
4
- class RTypeQualifier < SimpleDelegator
5
- attr_accessor :const
6
-
7
- def initialize(type,options=Hash.new)
8
- super(type)
9
- @const = options[:const]
10
- end
11
-
12
- def const?
13
- !!@const
14
- end
15
-
16
- def to_single_ptr
17
- t = to_raw
18
- t = t.to_const if const?
19
- t.to_ptr
20
- end
21
-
22
- def to_ptr
23
- RPointer.new(self)
24
- end
25
-
26
- def to_ref
27
- RReference.new(self)
28
- end
29
-
30
- def to_const
31
- return self if const?
32
- RTypeQualifier.new(self,:const => true)
33
- end
34
-
35
- def remove_const
36
- __getobj__
37
- end
38
-
39
- def raw?
40
- false
41
- end
42
-
43
- def signature(sig=nil)
44
- generate_signatures[0]
45
- end
46
-
47
- def csignature(sig=nil)
48
- generate_signatures[1]
49
- end
50
-
51
- def generate_signatures
52
- str = if const?
53
- "const "
54
- end
55
- __getobj__.generate_signatures.map do |s|
56
- str + s
57
- end
58
- end
59
-
60
- # Resolve the current delegate to the underlying object
61
- def get_base_delegate
62
- obj = __getobj__
63
- while obj.respond_to?(:__getobj__)
64
- obj = obj.__getobj__
65
- end
66
- obj
67
- end
68
- end
69
- end