Add simple PySwigObject to handle the C/C++ instance pointers,
instead of using PyCObject or plain strings.
The new PySwigObject is even safer than PyCObject, and
more friendly than plain strings:
now you can do
print a.this
<Swig Object at _00691608_p_A>
print str(a.this)
_00691608_p_A
print long(a.this)
135686400
print "%s 0x%x" % (a.this, a.this)
_00691608_p_A 0x8166900
the last one is very useful when debugging the C/C++ side, since
is the pointer value you will usually get from the debugger.
Also, if you have some old code that uses the string representation
"_00691608_p_A", you can use it now again by calling str(ptr), or
maybe nothing special by just calling PyString_AsString(..).
This change is mainly for nostalgic swig users that miss the
string representation, but also allows to say again
if a.this == b.this:
return "a is b"
and well, since the change were really simple, maybe in the future
we will be able to do
next = a.this + 1
or add native python iteration over native C/C++ arrays, ie, no
need to create/copy new tuples when returning and array or vector.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6759 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e83dbc195b
commit
121d73d58c
6 changed files with 384 additions and 44 deletions
20
SWIG/Examples/test-suite/python/swigobject.i
Normal file
20
SWIG/Examples/test-suite/python/swigobject.i
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
%module swigobject
|
||||
|
||||
|
||||
|
||||
%inline
|
||||
{
|
||||
struct A {
|
||||
char name[4];
|
||||
};
|
||||
|
||||
const char* pointer_str(A *a){
|
||||
static char result[1024];
|
||||
sprintf(result,"%x",a);
|
||||
return result;
|
||||
}
|
||||
|
||||
A *a_ptr(A *a){
|
||||
return a;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue