Permalink
Browse files

Use better array retrieval

  • Loading branch information...
1 parent 4916cfb commit 28aff126492bb6f40bad9aaabc81e7dec7300dc7 @manveru committed Mar 10, 2010
Showing with 14 additions and 11 deletions.
  1. +14 −11 lib/ffi-tk/ffi/tcl/eval_result.rb
@@ -9,19 +9,22 @@ def self.reset_types(interp)
list = Tcl.new_list_obj(0, nil)
Tcl.append_all_obj_types(interp, list)
- result_pointer = MemoryPointer.new(:pointer)
- count_pointer = MemoryPointer.new(:int)
- length_pointer = MemoryPointer.new(:int)
+ objc_ptr = MemoryPointer.new(:int)
+ objv_ptr = MemoryPointer.new(:pointer)
- Tcl.list_obj_length(interp, list, count_pointer)
- count = count_pointer.get_int(0)
+ string_length_ptr = MemoryPointer.new(:int)
- (0...count).each do |idx|
- Tcl.list_obj_index(interp, list, idx, result_pointer)
- element_pointer = result_pointer.get_pointer(0)
- name = Tcl.get_string_from_obj(element_pointer, length_pointer)
- type = Tcl.get_obj_type(name)
- TYPES[type.to_i] = name.to_sym
+ if Tcl.list_obj_get_elements(interp, list, objc_ptr, objv_ptr) == 0
+ array_ptr = objv_ptr.get_pointer(0)
+ array_length = objc_ptr.get_int(0)
+ array = array_ptr.read_array_of_pointer(array_length)
+ array.each do |type_ptr|
+ name = Tcl.get_string_from_obj(type_ptr, string_length_ptr)
+ type = Tcl.get_obj_type(name)
+ TYPES[type.to_i] = name.to_sym
+ end
+ else
+ panic 'Tcl_ListObjGetElements'
end
end

0 comments on commit 28aff12

Please sign in to comment.