From: Michael Schroeder Date: Fri, 4 Apr 2014 12:09:10 +0000 (+0200) Subject: more swig trickery: automaticall free the pool, add a disown method X-Git-Tag: upstream/0.6.4~41 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fdff34f4855b84438b5bff3f79cba33d6bf35865;p=platform%2Fupstream%2Flibsolv.git more swig trickery: automaticall free the pool, add a disown method --- diff --git a/bindings/solv.i b/bindings/solv.i index eab2430..41cb49a 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -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); } diff --git a/doc/libsolv-bindings.3 b/doc/libsolv-bindings.3 index 7a9cf54..87e949a 100644 --- a/doc/libsolv-bindings.3 +++ b/doc/libsolv-bindings.3 @@ -2,12 +2,12 @@ .\" Title: Libsolv-Bindings .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.78.0 -.\" 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 diff --git a/doc/libsolv-bindings.txt b/doc/libsolv-bindings.txt index e8c4eb9..5a65235 100644 --- a/doc/libsolv-bindings.txt +++ b/doc/libsolv-bindings.txt @@ -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);