]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
more swig trickery: automaticall free the pool, add a disown method
authorMichael Schroeder <mls@suse.de>
Fri, 4 Apr 2014 12:09:10 +0000 (14:09 +0200)
committerMichael Schroeder <mls@suse.de>
Fri, 4 Apr 2014 12:09:10 +0000 (14:09 +0200)
bindings/solv.i
doc/libsolv-bindings.3
doc/libsolv-bindings.txt

index eab24308fd44241b841e0094a9f2e851f8105ca0..41cb49a42c11428684fdd737e7d0c555227107af 100644 (file)
@@ -421,7 +421,18 @@ SWIG_AsValDepId(void *obj, int *val) {
 
 }
 
-
+%typemap(out) disown_helper {
+#ifdef SWIGRUBY
+  SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Pool, SWIG_POINTER_DISOWN |  0 );
+#endif
+#ifdef SWIGPYTHON
+  SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Pool, SWIG_POINTER_DISOWN |  0 );
+#endif
+#ifdef SWIGPERL
+  SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Pool, SWIG_POINTER_DISOWN |  0 );
+#endif
+  $result = SWIG_From_int((int)(0));
+}
 
 %include "typemaps.i"
 
@@ -599,6 +610,8 @@ typedef struct {
 
 typedef Dataiterator Datamatch;
 
+typedef int disown_helper;
+
 %}
 
 #ifdef SWIGRUBY
@@ -1102,8 +1115,6 @@ typedef struct {
     Pool *pool = pool_create();
     return pool;
   }
-  ~Pool() {
-  }
   void set_debuglevel(int level) {
     pool_setdebuglevel($self, level);
   }
@@ -1203,10 +1214,18 @@ typedef struct {
   }
 #endif
 
-  void free() {
+  ~Pool() {
     Pool_set_loadcallback($self, 0);
     pool_free($self);
   }
+  disown_helper free() {
+    Pool_set_loadcallback($self, 0);
+    pool_free($self);
+    return 0;
+  }
+  disown_helper disown() {
+    return 0;
+  }
   Id str2id(const char *str, bool create=1) {
     return pool_str2id($self, str, create);
   }
index 7a9cf542f503fdb76039148c59547a837480887c..87e949a2f3e6929c9280dba0ff22b3eecd8f97e3 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: Libsolv-Bindings
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/>
-.\"      Date: 04/03/2014
+.\"      Date: 04/04/2014
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV\-BINDINGS" "3" "04/03/2014" "libsolv" "LIBSOLV"
+.TH "LIBSOLV\-BINDINGS" "3" "04/04/2014" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -390,7 +390,7 @@ my \fI$pool\fR \fB= solv::Pool\->new()\fR;
 .RE
 .\}
 .sp
-Create a new pool instance\&. In most cases you just need one pool\&.
+Create a new pool instance\&. In most cases you just need one pool\&. Note that the returned object "owns" the pool, i\&.e\&. if the object is freed, the pool is also freed\&. You can use the disown method to break this ownership relation\&.
 .SS "ATTRIBUTES"
 .sp
 .if n \{\
@@ -533,7 +533,22 @@ Make the addfileprovides method only add files from the standard locations (i\&.
 .RE
 .\}
 .sp
-Free a pool\&. This is currently done with a method instead of relying on reference counting or garbage collection because it\(cqs hard to track every reference to a pool\&.
+Force a free of the pool\&. After this call, you must not access any object that still references the pool\&.
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBvoid disown()\fR
+\fI$pool\fR\fB\->disown()\fR;
+\fIpool\fR\fB\&.disown()\fR
+\fIpool\fR\fB\&.disown()\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Break the ownership relation betwen the binding object and the pool\&. After this call, the pool will not get freed even if the object goes out of scope\&. This also means that you must manually call the free method to free the pool data\&.
 .sp
 .if n \{\
 .RS 4
index e8c4eb9594d7b357f5faf7cc9f8b38799ae7caf3..5a6523583d29a34aa557c8faa611914edb9dfa39 100644 (file)
@@ -201,8 +201,10 @@ Repositories, Dependencies, each indexed by Ids.
        pool = solv.Pool()
        pool = Solv::Pool.new()
 
-Create a new pool instance. In most cases you just need
-one pool.
+Create a new pool instance. In most cases you just need one pool.
+Note that the returned object "owns" the pool, i.e. if the object is 
+freed, the pool is also freed. You can use the disown method to
+break this ownership relation.
 
 === ATTRIBUTES ===
 
@@ -311,9 +313,18 @@ generates.
        pool.free()
        pool.free()
 
-Free a pool. This is currently done with a method instead of relying on
-reference counting or garbage collection because it's hard to track every
-reference to a pool.
+Force a free of the pool. After this call, you must not access any object
+that still references the pool.
+
+       void disown()
+       $pool->disown();
+       pool.disown()
+       pool.disown()
+
+Break the ownership relation betwen the binding object and the pool. After
+this call, the pool will not get freed even if the object goes out of
+scope. This also means that you must manually call the free method to free
+the pool data.
 
        void setdebuglevel(int level)
        $pool->setdebuglevel($level);