gir_ffi 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,23 @@ module GirFFI
2
2
  # Implements the creation of a Ruby function definition out of a GIR
3
3
  # IFunctionInfo.
4
4
  class FunctionDefinitionBuilder
5
+ ArgData = Struct.new(:arginfo, :inarg, :callarg, :retval, :pre, :post, :postpost,
6
+ :name, :retname)
7
+ class ArgData
8
+ def initialize arginfo=nil
9
+ super
10
+ self.arginfo = arginfo
11
+ self.inarg = nil
12
+ self.callarg = nil
13
+ self.retval = nil
14
+ self.retname = nil
15
+ self.name = nil
16
+ self.pre = []
17
+ self.post = []
18
+ self.postpost = []
19
+ end
20
+ end
21
+
5
22
  KEYWORDS = [
6
23
  "alias", "and", "begin", "break", "case", "class", "def", "do",
7
24
  "else", "elsif", "end", "ensure", "false", "for", "if", "in",
@@ -17,8 +34,10 @@ module GirFFI
17
34
 
18
35
  def generate
19
36
  setup_accumulators
37
+ @data = @info.args.map {|a| ArgData.new a}
38
+ @data.each {|data| prepare_arg data }
39
+ @data.each {|data| process_arg data }
20
40
  process_return_value
21
- @info.args.each {|a| process_arg a}
22
41
  adjust_accumulators
23
42
  return filled_out_template
24
43
  end
@@ -33,126 +52,236 @@ module GirFFI
33
52
  @pre = []
34
53
  @post = []
35
54
 
55
+ @data = []
56
+
36
57
  @capture = ""
37
58
 
38
59
  @varno = 0
39
60
  end
40
61
 
41
- def process_arg arg
62
+ def prepare_arg data
63
+ arg = data.arginfo
64
+ data.name = safe arg.name
65
+ data.callarg = new_var
66
+
67
+ case arg.direction
68
+ when :inout
69
+ data.inarg = data.name
70
+ data.retname = data.retval = new_var
71
+ when :in
72
+ data.inarg = data.name
73
+ when :out
74
+ data.retname = data.retval = new_var
75
+ else
76
+ raise ArgumentError
77
+ end
78
+ end
79
+
80
+ def process_arg data
81
+ arg = data.arginfo
42
82
  case arg.direction
43
83
  when :inout
44
- process_inout_arg arg
84
+ process_inout_arg data
45
85
  when :in
46
- process_in_arg arg
86
+ process_in_arg data
47
87
  when :out
48
- process_out_arg arg
88
+ process_out_arg data
49
89
  else
50
90
  raise ArgumentError
51
91
  end
52
92
  end
53
93
 
54
- def process_inout_arg arg
94
+ def process_inout_arg data
95
+ arg = data.arginfo
96
+
55
97
  raise NotImplementedError unless arg.ownership_transfer == :everything
56
98
 
57
- name = safe arg.name
58
- prevar = new_var
59
- postvar = new_var
99
+ tag = arg.type.tag
60
100
 
61
- @inargs << name
62
- case arg.type.tag
63
- when :int, :int32
64
- @pre << "#{prevar} = GirFFI::ArgHelper.int_to_inoutptr #{name}"
65
- @post << "#{postvar} = GirFFI::ArgHelper.outptr_to_int #{prevar}"
101
+ case tag
102
+ when :interface
103
+ raise NotImplementedError
66
104
  when :array
67
- case arg.type.param_type(0).tag
68
- when :utf8
69
- @pre << "#{prevar} = GirFFI::ArgHelper.string_array_to_inoutptr #{name}"
70
- @post << "#{postvar} = GirFFI::ArgHelper.outptr_to_string_array #{prevar}, #{name}.nil? ? 0 : #{name}.size"
105
+ tag = arg.type.param_type(0).tag
106
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_array_to_inoutptr #{data.inarg}"
107
+ if arg.type.array_length > -1
108
+ idx = arg.type.array_length
109
+ lendata = @data[idx]
110
+ rv = lendata.retval
111
+ lendata.retval = nil
112
+ lname = lendata.inarg
113
+ lendata.inarg = nil
114
+ lendata.pre.unshift "#{lname} = #{data.inarg}.length"
115
+ data.post << "#{data.retval} = GirFFI::ArgHelper.outptr_to_#{tag}_array #{data.callarg}, #{rv}"
116
+ if tag == :utf8
117
+ data.post << "GirFFI::ArgHelper.cleanup_ptr_array_ptr #{data.callarg}, #{rv}"
118
+ else
119
+ data.post << "GirFFI::ArgHelper.cleanup_ptr_ptr #{data.callarg}"
120
+ end
71
121
  else
72
122
  raise NotImplementedError
73
123
  end
74
124
  else
75
- raise NotImplementedError
125
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_to_inoutptr #{data.inarg}"
126
+ data.post << "#{data.retval} = GirFFI::ArgHelper.outptr_to_#{tag} #{data.callarg}"
127
+ data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
76
128
  end
77
- @callargs << prevar
78
- @retvals << postvar
129
+
130
+ data
79
131
  end
80
132
 
81
- def process_out_arg arg
82
- prevar = new_var
83
- postvar = new_var
84
-
85
- case arg.type.tag
86
- when :int, :int32
87
- @pre << "#{prevar} = GirFFI::ArgHelper.int_to_inoutptr 0"
88
- @post << "#{postvar} = GirFFI::ArgHelper.outptr_to_int #{prevar}"
89
- when :double
90
- @pre << "#{prevar} = GirFFI::ArgHelper.double_to_inoutptr 0"
91
- @post << "#{postvar} = GirFFI::ArgHelper.outptr_to_double #{prevar}"
133
+ def process_out_arg data
134
+ arg = data.arginfo
135
+ type = arg.type
136
+ tag = type.tag
137
+
138
+ case tag
92
139
  when :interface
93
140
  iface = arg.type.interface
94
- if iface.type == :struct
95
- @pre << "#{prevar} = #{iface.namespace}::#{iface.name}.new"
96
- @post << "#{postvar} = #{prevar}"
141
+ if arg.caller_allocates?
142
+ data.pre << "#{data.callarg} = #{iface.namespace}::#{iface.name}.allocate"
143
+ data.post << "#{data.retval} = #{data.callarg}"
97
144
  else
98
- raise NotImplementedError,
99
- "Don't know what to do with interface type #{iface.type}"
145
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.pointer_outptr"
146
+ tmpvar = new_var
147
+ data.post << "#{tmpvar} = GirFFI::ArgHelper.outptr_to_pointer #{data.callarg}"
148
+ data.post << "#{data.retval} = #{iface.namespace}::#{iface.name}.wrap #{tmpvar}"
149
+ end
150
+ when :array
151
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.pointer_outptr"
152
+
153
+ tag = arg.type.param_type(0).tag
154
+ size = type.array_fixed_size
155
+ idx = type.array_length
156
+
157
+ if size <= 0
158
+ if idx > -1
159
+ size = @data[idx].retval
160
+ @data[idx].retval = nil
161
+ else
162
+ raise NotImplementedError
163
+ end
164
+ end
165
+ data.postpost << "#{data.retval} = GirFFI::ArgHelper.outptr_to_#{tag}_array #{data.callarg}, #{size}"
166
+ if arg.ownership_transfer == :everything
167
+ if tag == :utf8
168
+ data.postpost << "GirFFI::ArgHelper.cleanup_ptr_array_ptr #{data.callarg}, #{rv}"
169
+ else
170
+ data.postpost << "GirFFI::ArgHelper.cleanup_ptr_ptr #{data.callarg}"
171
+ end
100
172
  end
101
173
  else
102
- raise NotImplementedError,
103
- "Don't know what to do with argument type #{arg.type.tag}"
174
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_outptr"
175
+ data.post << "#{data.retname} = GirFFI::ArgHelper.outptr_to_#{tag} #{data.callarg}"
176
+ if arg.ownership_transfer == :everything
177
+ data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
178
+ end
104
179
  end
105
- @callargs << prevar
106
- @retvals << postvar
180
+
181
+ data
107
182
  end
108
183
 
109
- def process_in_arg arg
110
- name = safe arg.name
184
+ def process_in_arg data
185
+ arg = data.arginfo
186
+
111
187
  type = arg.type
112
188
  tag = type.tag
113
189
 
114
- @inargs << name
115
-
116
- if tag == :interface and type.interface.type == :callback
117
- # TODO: Use arg.scope to decide if this is needed.
118
- procvar = new_var
119
- @pre << "#{procvar} = GirFFI::ArgHelper.mapped_callback_args #{name}"
120
- @pre << "::#{@libmodule}::CALLBACKS << #{procvar}"
121
- @callargs << procvar
122
- elsif tag == :void
190
+ case tag
191
+ when :interface
192
+ if type.interface.type == :callback
193
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.mapped_callback_args #{data.inarg}"
194
+ data.pre << "::#{@libmodule}::CALLBACKS << #{data.callarg}"
195
+ else
196
+ data.pre << "#{data.callarg} = #{data.inarg}"
197
+ end
198
+ when :void
123
199
  raise NotImplementedError unless arg.type.pointer?
124
- prevar = new_var
125
- @pre << "#{prevar} = GirFFI::ArgHelper.object_to_inptr #{name}"
126
- @callargs << prevar
200
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.object_to_inptr #{data.inarg}"
201
+ when :array
202
+ if type.array_fixed_size > 0
203
+ data.pre << "GirFFI::ArgHelper.check_fixed_array_size #{type.array_fixed_size}, #{data.inarg}, \"#{data.inarg}\""
204
+ elsif type.array_length > -1
205
+ idx = type.array_length
206
+ lenvar = @data[idx].inarg
207
+ @data[idx].inarg = nil
208
+ @data[idx].pre.unshift "#{lenvar} = #{data.inarg}.nil? ? 0 : #{data.inarg}.length"
209
+ end
210
+
211
+ tag = arg.type.param_type(0).tag
212
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.#{tag}_array_to_inptr #{data.inarg}"
213
+ unless arg.ownership_transfer == :everything
214
+ if tag == :utf8
215
+ data.post << "GirFFI::ArgHelper.cleanup_ptr_ptr #{data.callarg}"
216
+ else
217
+ data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
218
+ end
219
+ end
220
+ when :utf8
221
+ data.pre << "#{data.callarg} = GirFFI::ArgHelper.utf8_to_inptr #{data.name}"
222
+ # TODO:
223
+ #data.post << "GirFFI::ArgHelper.cleanup_ptr #{data.callarg}"
127
224
  else
128
- @callargs << name
225
+ data.pre << "#{data.callarg} = #{data.name}"
129
226
  end
227
+
228
+ data
130
229
  end
131
230
 
132
231
  def process_return_value
232
+ @rvdata = ArgData.new
133
233
  type = @info.return_type
134
234
  tag = type.tag
135
235
  return if tag == :void
136
236
  cvar = new_var
137
237
  @capture = "#{cvar} = "
138
238
 
139
- if tag == :interface
239
+ case tag
240
+ when :interface
140
241
  interface = type.interface
141
242
  namespace = interface.namespace
142
243
  name = interface.name
143
244
  GirFFI::Builder.build_class namespace, name
144
245
  retval = new_var
145
- @post << "#{retval} = ::#{namespace}::#{name}._real_new(#{cvar})"
246
+ @rvdata.post << "#{retval} = ::#{namespace}::#{name}.wrap(#{cvar})"
146
247
  if interface.type == :object
147
- @post << "GirFFI::ArgHelper.sink_if_floating(#{retval})"
248
+ @rvdata.post << "GirFFI::ArgHelper.sink_if_floating(#{retval})"
148
249
  end
149
- @retvals << retval
250
+ @rvdata.retval = retval
251
+ when :array
252
+ tag = type.param_type(0).tag
253
+ size = type.array_fixed_size
254
+ idx = type.array_length
255
+
256
+ retval = new_var
257
+ if size > 0
258
+ @rvdata.post << "#{retval} = GirFFI::ArgHelper.ptr_to_#{tag}_array #{cvar}, #{size}"
259
+ elsif idx > -1
260
+ lendata = @data[idx]
261
+ rv = lendata.retval
262
+ lendata.retval = nil
263
+ @rvdata.post << "#{retval} = GirFFI::ArgHelper.ptr_to_#{tag}_array #{cvar}, #{rv}"
264
+ end
265
+ @rvdata.retval = retval
150
266
  else
151
- @retvals << cvar
267
+ @rvdata.retval = cvar
152
268
  end
153
269
  end
154
270
 
155
271
  def adjust_accumulators
272
+ @retvals << @rvdata.retval
273
+ @data.each do |data|
274
+ @inargs << data.inarg
275
+ @callargs << data.callarg
276
+ @retvals << data.retval
277
+ @pre += data.pre
278
+ @post += data.post
279
+ end
280
+ @data.each do |data|
281
+ @post += data.postpost
282
+ end
283
+ @post += @rvdata.post
284
+
156
285
  if @info.throws?
157
286
  errvar = new_var
158
287
  @pre << "#{errvar} = FFI::MemoryPointer.new(:pointer).write_pointer nil"
@@ -160,7 +289,8 @@ module GirFFI
160
289
  @callargs << errvar
161
290
  end
162
291
 
163
- @post << "return #{@retvals.join(', ')}" unless @retvals.empty?
292
+ @retvals = @retvals.compact
293
+ @post << "return #{@retvals.compact.join(', ')}" unless @retvals.empty?
164
294
 
165
295
  if @info.method?
166
296
  @callargs.unshift "self"
@@ -169,9 +299,9 @@ module GirFFI
169
299
 
170
300
  def filled_out_template
171
301
  return <<-CODE
172
- def #{@info.name} #{@inargs.join(', ')}
302
+ def #{@info.name} #{@inargs.compact.join(', ')}
173
303
  #{@pre.join("\n")}
174
- #{@capture}::#{@libmodule}.#{@info.symbol} #{@callargs.join(', ')}
304
+ #{@capture}::#{@libmodule}.#{@info.symbol} #{@callargs.compact.join(', ')}
175
305
  #{@post.join("\n")}
176
306
  end
177
307
  CODE
@@ -12,6 +12,9 @@ module GirFFI
12
12
  def optional?
13
13
  Lib.g_arg_info_is_optional @gobj
14
14
  end
15
+ def caller_allocates?
16
+ Lib.g_arg_info_is_caller_allocates @gobj
17
+ end
15
18
  def may_be_null?
16
19
  Lib.g_arg_info_may_be_null @gobj
17
20
  end
@@ -1,5 +1,5 @@
1
1
  module GirFFI
2
- # Wraps a GICallbackInfo struct. Has no methods in addition to the onese
2
+ # Wraps a GICallbackInfo struct. Has no methods in addition to the ones
3
3
  # inherited from ICallableInfo.
4
4
  class ICallbackInfo < ICallableInfo
5
5
  end
@@ -1,7 +1,72 @@
1
1
  module GirFFI
2
- # Wraps a GIInterfaceInfo struct.
2
+ # Wraps a IInterfaceInfo struct.
3
3
  # Represents an interface.
4
- # Not implemented yet.
5
4
  class IInterfaceInfo < IRegisteredTypeInfo
5
+ def n_prerequisites
6
+ Lib.g_interface_info_get_n_prerequisites @gobj
7
+ end
8
+ def prerequisite index
9
+ IBaseInfo.wrap(Lib.g_interface_info_get_prerequisite @gobj, index)
10
+ end
11
+ ##
12
+ build_array_method :prerequisites
13
+
14
+ def n_properties
15
+ Lib.g_interface_info_get_n_properties @gobj
16
+ end
17
+ def property index
18
+ IPropertyInfo.wrap(Lib.g_interface_info_get_property @gobj, index)
19
+ end
20
+ ##
21
+ build_array_method :properties, :property
22
+
23
+ def n_methods
24
+ Lib.g_interface_info_get_n_methods @gobj
25
+ end
26
+ def method index
27
+ IFunctionInfo.wrap(Lib.g_interface_info_get_method @gobj, index)
28
+ end
29
+ ##
30
+ build_array_method :methods
31
+
32
+ def find_method name
33
+ IFunctionInfo.wrap(Lib.g_interface_info_find_method @gobj, name)
34
+ end
35
+
36
+ def n_signals
37
+ Lib.g_interface_info_get_n_signals @gobj
38
+ end
39
+ def signal index
40
+ ISignalInfo.wrap(Lib.g_interface_info_get_signal @gobj, index)
41
+ end
42
+ ##
43
+ build_array_method :signals
44
+
45
+ def n_vfuncs
46
+ Lib.g_interface_info_get_n_vfuncs @gobj
47
+ end
48
+ def vfunc index
49
+ IVFuncInfo.wrap(Lib.g_interface_info_get_vfunc @gobj, index)
50
+ end
51
+ ##
52
+ build_array_method :vfuncs
53
+
54
+ def find_vfunc name
55
+ IVFuncInfo.wrap(Lib.g_interface_info_find_vfunc @gobj, name)
56
+ end
57
+
58
+ def n_constants
59
+ Lib.g_interface_info_get_n_constants @gobj
60
+ end
61
+ def constant index
62
+ IConstantInfo.wrap(Lib.g_interface_info_get_constant @gobj, index)
63
+ end
64
+ ##
65
+ build_array_method :constants
66
+
67
+ def iface_struct
68
+ IStructInfo.wrap(Lib.g_interface_info_get_iface_struct @gobj)
69
+ end
70
+
6
71
  end
7
72
  end
@@ -96,6 +96,11 @@ module GirFFI
96
96
  return wrap ptr
97
97
  end
98
98
 
99
+ def find_by_gtype gtype
100
+ ptr = Lib.g_irepository_find_by_gtype @gobj, gtype
101
+ return wrap ptr
102
+ end
103
+
99
104
  def shared_library namespace
100
105
  Lib.g_irepository_get_shared_library @gobj, namespace
101
106
  end
data/lib/gir_ffi/lib.rb CHANGED
@@ -17,6 +17,8 @@ module GirFFI
17
17
  [:pointer, :string, :int], :pointer
18
18
  attach_function :g_irepository_find_by_name,
19
19
  [:pointer, :string, :string], :pointer
20
+ attach_function :g_irepository_find_by_gtype, [:pointer, :size_t], :pointer
21
+
20
22
  attach_function :g_irepository_get_shared_library,
21
23
  [:pointer, :string], :string
22
24
 
@@ -85,6 +87,7 @@ module GirFFI
85
87
  attach_function :g_arg_info_get_direction, [:pointer], :IDirection
86
88
  attach_function :g_arg_info_is_return_value, [:pointer], :bool
87
89
  attach_function :g_arg_info_is_optional, [:pointer], :bool
90
+ attach_function :g_arg_info_is_caller_allocates, [:pointer], :bool
88
91
  attach_function :g_arg_info_may_be_null, [:pointer], :bool
89
92
  attach_function :g_arg_info_get_ownership_transfer, [:pointer], :ITransfer
90
93
  attach_function :g_arg_info_get_scope, [:pointer], :IScopeType
@@ -150,7 +153,7 @@ module GirFFI
150
153
  # IRegisteredTypeInfo
151
154
  attach_function :g_registered_type_info_get_type_name, [:pointer], :string
152
155
  attach_function :g_registered_type_info_get_type_init, [:pointer], :string
153
- attach_function :g_registered_type_info_get_g_type, [:pointer], :int
156
+ attach_function :g_registered_type_info_get_g_type, [:pointer], :size_t
154
157
 
155
158
  # IEnumInfo
156
159
  attach_function :g_enum_info_get_storage_type, [:pointer], :ITypeTag
@@ -192,5 +195,23 @@ module GirFFI
192
195
  attach_function :g_vfunc_info_get_offset, [:pointer], :int
193
196
  attach_function :g_vfunc_info_get_signal, [:pointer], :pointer
194
197
  attach_function :g_vfunc_info_get_invoker, [:pointer], :pointer
198
+
199
+ # IInterfaceInfo
200
+ attach_function :g_interface_info_get_n_prerequisites, [:pointer], :int
201
+ attach_function :g_interface_info_get_prerequisite, [:pointer, :int], :pointer
202
+ attach_function :g_interface_info_get_n_properties, [:pointer], :int
203
+ attach_function :g_interface_info_get_property, [:pointer, :int], :pointer
204
+ attach_function :g_interface_info_get_n_methods, [:pointer], :int
205
+ attach_function :g_interface_info_get_method, [:pointer, :int], :pointer
206
+ attach_function :g_interface_info_find_method, [:pointer, :string], :pointer
207
+ attach_function :g_interface_info_get_n_signals, [:pointer], :int
208
+ attach_function :g_interface_info_get_signal, [:pointer, :int], :pointer
209
+ attach_function :g_interface_info_get_n_vfuncs, [:pointer], :int
210
+ attach_function :g_interface_info_get_vfunc, [:pointer, :int], :pointer
211
+ attach_function :g_interface_info_find_vfunc, [:pointer, :string], :pointer
212
+ attach_function :g_interface_info_get_n_constants, [:pointer], :int
213
+ attach_function :g_interface_info_get_constant, [:pointer, :int], :pointer
214
+ attach_function :g_interface_info_get_iface_struct, [:pointer], :pointer
215
+
195
216
  end
196
217
  end
@@ -70,6 +70,7 @@ module GirFFI
70
70
  unless (class << @lib; self.include? FFI::Library; end)
71
71
  @lib.extend FFI::Library
72
72
  libs = gir.shared_library(@namespace).split(/,/)
73
+ @lib.ffi_lib_flags :global, :lazy
73
74
  @lib.ffi_lib(*libs)
74
75
  end
75
76
 
@@ -7,9 +7,10 @@ module GirFFI
7
7
  end
8
8
 
9
9
  module ClassMethods
10
+ # FIXME: These four helper methods belong elsewhere.
10
11
  def type_from_instance_pointer inst_ptr
11
- base = ::GObject::TypeInstance.new inst_ptr
12
- kls = ::GObject::TypeClass.new(base[:g_class])
12
+ base = ::GObject::TypeInstance.wrap inst_ptr
13
+ kls = ::GObject::TypeClass.wrap(base[:g_class])
13
14
  kls[:g_type]
14
15
  end
15
16
 
@@ -38,14 +39,6 @@ module GirFFI
38
39
  end
39
40
  end
40
41
 
41
- # FIXME: This is a private helper function. Move elsewhere?
42
- def signal_callback_args sig, klass, &block
43
- return Proc.new do |*args|
44
- mapped = Helper.cast_back_signal_arguments sig, klass, *args
45
- block.call(*mapped)
46
- end
47
- end
48
-
49
42
  def signal_emit object, signal, *args
50
43
  type = type_from_instance object
51
44
 
@@ -80,19 +73,29 @@ module GirFFI
80
73
  if sig.nil?
81
74
  raise "Signal #{signal} is invalid for #{object}"
82
75
  end
76
+ if block.nil?
77
+ raise ArgumentError, "Block needed"
78
+ end
83
79
 
84
80
  rettype = GirFFI::Builder.itypeinfo_to_ffitype sig.return_type
85
81
 
86
82
  argtypes = [:pointer] + sig.args.map {|a| :pointer} + [:pointer]
87
83
 
88
84
  callback = FFI::Function.new rettype, argtypes,
89
- &(signal_callback_args(sig, object.class, &block))
85
+ &(Helper.signal_callback_args(sig, object.class, &block))
90
86
 
91
87
  signal_connect_data object, signal, callback, data, nil, 0
92
88
  end
93
89
  end
94
90
 
95
91
  module Helper
92
+ def self.signal_callback_args sig, klass, &block
93
+ return Proc.new do |*args|
94
+ mapped = cast_back_signal_arguments sig, klass, *args
95
+ block.call(*mapped)
96
+ end
97
+ end
98
+
96
99
  def self.signal_arguments_to_gvalue_array signal, instance, *rest
97
100
  sig = instance.class.gir_ffi_builder.find_signal signal
98
101
 
@@ -137,7 +140,7 @@ module GirFFI
137
140
 
138
141
  # Instance
139
142
  instptr = args.shift
140
- instance = klass.send :_real_new, instptr
143
+ instance = klass.wrap instptr
141
144
  result << instance
142
145
 
143
146
  # Extra arguments
@@ -146,7 +149,7 @@ module GirFFI
146
149
  if info.type.tag == :interface
147
150
  iface = info.type.interface
148
151
  kls = GirFFI::Builder.build_class(iface.namespace, iface.name)
149
- result << kls.send(:_real_new, arg)
152
+ result << kls.wrap(arg)
150
153
  else
151
154
  result << arg
152
155
  end
@@ -18,7 +18,7 @@ module GirFFI
18
18
  module ClassMethods
19
19
 
20
20
  def init_with_auto_argv
21
- (my_len, my_args) = init_without_auto_argv ARGV.length + 1, [$0, *ARGV]
21
+ my_args = init_without_auto_argv [$0, *ARGV]
22
22
  my_args.shift
23
23
  ARGV.replace my_args
24
24
  end