add support for accessing 'self.thisown'
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7956 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c6c4de52d3
commit
2a172ffc8a
3 changed files with 58 additions and 12 deletions
|
|
@ -490,7 +490,7 @@ Version 1.3.28 (unreleased).
|
||||||
- Finally, no more ClassPtr shadow classes. You will see
|
- Finally, no more ClassPtr shadow classes. You will see
|
||||||
only a clean Class shadow class in the .py file.
|
only a clean Class shadow class in the .py file.
|
||||||
|
|
||||||
- No more thisown attribute either, the PySwigObject now
|
- No more 'real' thisown attribute either, the PySwigObject now
|
||||||
carries the ownership info.
|
carries the ownership info.
|
||||||
|
|
||||||
You can also do something like
|
You can also do something like
|
||||||
|
|
@ -499,12 +499,31 @@ Version 1.3.28 (unreleased).
|
||||||
>>> True
|
>>> True
|
||||||
|
|
||||||
self.this.disown()
|
self.this.disown()
|
||||||
|
self.this.own(0)
|
||||||
print self.this.own()
|
print self.this.own()
|
||||||
>>> False
|
>>> False
|
||||||
|
|
||||||
self.this.acquire()
|
self.this.acquire()
|
||||||
|
self.this.own(1)
|
||||||
print self.this.own()
|
print self.this.own()
|
||||||
>>> True
|
>>> True
|
||||||
|
|
||||||
|
Still the old way,
|
||||||
|
|
||||||
|
print self.thisown
|
||||||
|
>>> True
|
||||||
|
|
||||||
|
self.thisown = 0
|
||||||
|
print self.thisown
|
||||||
|
>>> False
|
||||||
|
|
||||||
|
self.thisown = 1
|
||||||
|
print self.thisown
|
||||||
|
>>> True
|
||||||
|
|
||||||
|
is supported, and python dispatch the proper method
|
||||||
|
calls as needed.
|
||||||
|
|
||||||
|
|
||||||
- Support for iterators in STL/STD containers, for example, if you have
|
- Support for iterators in STL/STD containers, for example, if you have
|
||||||
|
|
||||||
|
|
@ -605,20 +624,25 @@ Version 1.3.28 (unreleased).
|
||||||
|
|
||||||
*** POTENTIAL INCOMPATIBILITY ***
|
*** POTENTIAL INCOMPATIBILITY ***
|
||||||
|
|
||||||
There is no more 'thisown' attribute. If you use it, you
|
There is no more 'thisown' attribute. If you use it, python
|
||||||
need to change as follows:
|
will translate the following code as follows:
|
||||||
|
|
||||||
if (self.thisown): ==> if (self.this.own()):
|
if (self.thisown): ==> if (self.this.own()):
|
||||||
self.thisown = 1 ==> self.this.acquire()
|
self.thisown = 1 ==> self.this.own(1)
|
||||||
self.thisown = 0 ==> self.this.disown()
|
self.thisown = 0 ==> self.this.own(0)
|
||||||
|
|
||||||
if you really really like the old 'thisown' attribute, you
|
Still, maybe in some strange case the translation is not
|
||||||
can submit a patch to treat it as a property, and dispatch
|
100% secure,so if you have a problem, please report it
|
||||||
the new method calls. Of course, before you try, it needs
|
and/or use the new 'self.this.own()' accessor.
|
||||||
to work with old and new python versions, and with classic
|
|
||||||
and modern python classes.
|
|
||||||
|
|
||||||
|
|
||||||
|
*** POTENTIAL INCOMPATIBILITY ***
|
||||||
|
|
||||||
|
There is no more ClassPtr classes, so, if in the past you
|
||||||
|
needed to resort in some kind of trick to use, or overcome
|
||||||
|
their presence, it is no longer needed, but the extra code
|
||||||
|
you added could break.
|
||||||
|
|
||||||
|
|
||||||
10/30/2005: mkoeppe
|
10/30/2005: mkoeppe
|
||||||
[Guile] Make declared and defined linkage of SWIG_init consistent.
|
[Guile] Make declared and defined linkage of SWIG_init consistent.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,25 @@
|
||||||
from disown import *
|
from disown import *
|
||||||
|
|
||||||
a = A()
|
a = A()
|
||||||
|
|
||||||
|
tmp = a.thisown
|
||||||
|
|
||||||
|
a.thisown = 0
|
||||||
|
if a.thisown:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
a.thisown = 1
|
||||||
|
if (not a.thisown):
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
a.thisown = tmp
|
||||||
|
if (a.thisown != tmp):
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
b = B()
|
b = B()
|
||||||
|
|
||||||
b.acquire(a)
|
b.acquire(a)
|
||||||
|
|
||||||
if a.this.own():
|
if a.thisown:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,7 @@ public:
|
||||||
} else if (strcmp(argv[i],"-classic") == 0) {
|
} else if (strcmp(argv[i],"-classic") == 0) {
|
||||||
classic = 1;
|
classic = 1;
|
||||||
apply = 1;
|
apply = 1;
|
||||||
|
modern = 0;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-cppcast") == 0) {
|
} else if (strcmp(argv[i],"-cppcast") == 0) {
|
||||||
cppcast = 1;
|
cppcast = 1;
|
||||||
|
|
@ -439,6 +440,7 @@ public:
|
||||||
// Python-2.2 object hack
|
// Python-2.2 object hack
|
||||||
Printv(f_shadow,
|
Printv(f_shadow,
|
||||||
"def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n",
|
"def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n",
|
||||||
|
tab4, "if (name == \"thisown\"): return self.this.own(value)\n",
|
||||||
tab4, "if (name == \"this\"):\n",
|
tab4, "if (name == \"this\"):\n",
|
||||||
tab4, tab4, "if type(value).__name__ == 'PySwigObject':\n",
|
tab4, tab4, "if type(value).__name__ == 'PySwigObject':\n",
|
||||||
tab4, tab8, "self.__dict__[name] = value\n",
|
tab4, tab8, "self.__dict__[name] = value\n",
|
||||||
|
|
@ -463,6 +465,7 @@ public:
|
||||||
|
|
||||||
Printv(f_shadow,
|
Printv(f_shadow,
|
||||||
"def _swig_getattr(self,class_type,name):\n",
|
"def _swig_getattr(self,class_type,name):\n",
|
||||||
|
tab4, "if (name == \"thisown\"): return self.this.own()\n",
|
||||||
tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
|
tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
|
||||||
tab4, "if method: return method(self)\n",
|
tab4, "if method: return method(self)\n",
|
||||||
tab4, "raise AttributeError,name\n\n",
|
tab4, "raise AttributeError,name\n\n",
|
||||||
|
|
@ -489,6 +492,7 @@ public:
|
||||||
#ifdef USE_THISOWN
|
#ifdef USE_THISOWN
|
||||||
tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
|
tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
|
||||||
#else
|
#else
|
||||||
|
tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n",
|
||||||
tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
|
tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
|
||||||
#endif
|
#endif
|
||||||
tab4, tab4, tab4, "set(self,name,value)\n",
|
tab4, tab4, tab4, "set(self,name,value)\n",
|
||||||
|
|
@ -2229,6 +2233,8 @@ public:
|
||||||
tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n",
|
tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n",
|
||||||
NIL);
|
NIL);
|
||||||
} else {
|
} else {
|
||||||
|
Printv(f_shadow, tab4, "if _newclass: thisown = property(lambda x: x.this.own(), ",
|
||||||
|
"lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
|
||||||
/* Add static attribute */
|
/* Add static attribute */
|
||||||
if (GetFlag(n,"feature:python:nondynamic")) {
|
if (GetFlag(n,"feature:python:nondynamic")) {
|
||||||
Printv(f_shadow_file,
|
Printv(f_shadow_file,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue