<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -29,6 +29,10 @@
 
 
 
+require 'ffi'
+need{ 'autorelease' }
+
+
 # OpaqueStruct represents a Struct with an unknown layout.
 # This is meant to be used when the C library designer has
 # intentionally hidden the layout (e.g. to prevent user access).
@@ -44,23 +48,12 @@
 # {:autorelease =&gt; false} as an option to #new
 #
 class NiceFFI::OpaqueStruct
-
-  class &lt;&lt; self
-
-    # Returns a NiceFFI::TypedPointer instance for this class.
-    def typed_pointer
-      @typed_pointer or
-        (@typed_pointer = NiceFFI::TypedPointer.new(self))
-    end
+  include NiceFFI::AutoRelease
 
 
-    # Calls the class's release method if it exists. Used for autorelease.
-    def _release( pointer )       # :nodoc:
-      if( respond_to?(:release) )
-        release( pointer )
-      end
-    end
-
+  # Returns a NiceFFI::TypedPointer instance for this class.
+  def self.typed_pointer
+    @typed_pointer or (@typed_pointer = NiceFFI::TypedPointer.new(self))
   end
 
 
@@ -69,10 +62,10 @@ class NiceFFI::OpaqueStruct
   # create a new instance wrapping the same pointer.
   # 
   # If val is an instance of FFI::Pointer and you have defined
-  # MyClass.release, the pointer will be passed to MyClass.release 
-  # when the instance is garbage collected. Use MyClass.release to
-  # free the memory for the struct, as appropriate for your class.
-  # To disable autorelease for this instance, set {:autorelease =&gt; false}
+  # MyClass.release, the pointer will be passed to MyClass.release
+  # when the memory is no longer being used. Use MyClass.release to
+  # free the memory for the struct, as appropriate for your class. To
+  # disable autorelease for this instance, set {:autorelease =&gt; false}
   # in +options+.
   # 
   # (Note: FFI::MemoryPointer and FFI::Buffer have built-in memory
@@ -94,17 +87,12 @@ class NiceFFI::OpaqueStruct
 
     when FFI::Pointer
       if( val.instance_of? FFI::Pointer ) # not MemoryPointer or Buffer
-        if( self.class.respond_to?(:release) and options[:autorelease] )
-          # Wrap in an AutoPointer to call self.class._release when it's GC'd.
-          @pointer = FFI::AutoPointer.new( val, self.class.method(:_release) )
-        else
-          @pointer = val
-        end
+        @pointer = _make_autopointer( val, options[:autorelease] )
+
       else
         raise TypeError, &quot;unsupported pointer type #{val.class.name}&quot;
       end
 
-
     else
       raise TypeError, &quot;cannot create new #{self.class} from #{val.inspect}&quot;
 </diff>
      <filename>lib/nice-ffi/opaquestruct.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c4d447468be6777dc2cc3261c13b47460367ada9</id>
    </parent>
  </parents>
  <author>
    <name>John Croisant</name>
    <email>jacius@gmail.com</email>
  </author>
  <url>http://github.com/jacius/nice-ffi/commit/b1e31e1126c4c21082bb8e951591bfdc4fc0a81d</url>
  <id>b1e31e1126c4c21082bb8e951591bfdc4fc0a81d</id>
  <committed-date>2009-07-27T19:03:03-07:00</committed-date>
  <authored-date>2009-07-27T18:55:34-07:00</authored-date>
  <message>Updated OpaqueStruct to use AutoRelease.</message>
  <tree>a7bf432faf79db777bba9612c3a2fc1d180f93cf</tree>
  <committer>
    <name>John Croisant</name>
    <email>jacius@gmail.com</email>
  </committer>
</commit>
