Commits

raineszm committed 8e4455a

Make the rubify method more consistent and check that it handles refcounts properly.

Comments (0)

Files changed (3)

lib/rubypython/conversion.rb

     elsif pObj == RubyPython::Macros.Py_None
       nil
     else
-      RubyPython::Python.Py_IncRef pObj
       pObj
     end
   end

lib/rubypython/pyobject.rb

         deleted = @current_pointers.delete(obj_id)
         if pointer.null?
           puts "Warning: Trying to DecRef NULL pointer" if RubyPython::Python.Py_IsInitialized != 0
+          return
         end
         if deleted and (RubyPython::Python.Py_IsInitialized != 0)
           RubyPython::Python.Py_DecRef pointer

lib/rubypython/rubypyproxy.rb

     # RubyPython will attempt to translate the wrapped object into a native
     # Ruby object. This will only succeed for simple built-in type.
     def rubify
-      @pObject.rubify
+      converted = @pObject.rubify
+      if converted.kind_of? ::FFI::Pointer
+        converted = self.class.new converted
+      end
+      converted
     end
 
     # Returns the String representation of the wrapped object via a call to