Complete the Python support for shared_ptr mainly for derived classes. This includes the smartptr feature for overriding the class registration function and shared_ptr typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10236 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a85143fe7d
commit
f39242fa92
6 changed files with 124 additions and 12 deletions
|
|
@ -448,7 +448,7 @@ PySwigObject_dealloc(PyObject *v)
|
|||
{
|
||||
PySwigObject *sobj = (PySwigObject *) v;
|
||||
PyObject *next = sobj->next;
|
||||
if (sobj->own) {
|
||||
if (sobj->own == SWIG_POINTER_OWN) {
|
||||
swig_type_info *ty = sobj->ty;
|
||||
PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0;
|
||||
PyObject *destroy = data ? data->destroy : 0;
|
||||
|
|
@ -977,7 +977,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj)
|
|||
|
||||
SWIGRUNTIME int
|
||||
SWIG_Python_AcquirePtr(PyObject *obj, int own) {
|
||||
if (own) {
|
||||
if (own == SWIG_POINTER_OWN) {
|
||||
PySwigObject *sobj = SWIG_Python_GetSwigThis(obj);
|
||||
if (sobj) {
|
||||
int oldown = sobj->own;
|
||||
|
|
@ -997,6 +997,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
if (ptr) *ptr = 0;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (own)
|
||||
*own = 0;
|
||||
PySwigObject *sobj = SWIG_Python_GetSwigThis(obj);
|
||||
while (sobj) {
|
||||
void *vptr = sobj->ptr;
|
||||
|
|
@ -1011,7 +1013,15 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
if (!tc) {
|
||||
sobj = (PySwigObject *)sobj->next;
|
||||
} else {
|
||||
if (ptr) *ptr = SWIG_TypeCast(tc,vptr);
|
||||
if (ptr) {
|
||||
int newmemory = 0;
|
||||
*ptr = SWIG_TypeCast(tc,vptr,&newmemory);
|
||||
if (newmemory == SWIG_CAST_NEW_MEMORY) {
|
||||
assert(own);
|
||||
if (own)
|
||||
*own = *own | SWIG_CAST_NEW_MEMORY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1021,7 +1031,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
}
|
||||
}
|
||||
if (sobj) {
|
||||
if (own) *own = sobj->own;
|
||||
if (own)
|
||||
*own = *own | sobj->own;
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
sobj->own = 0;
|
||||
}
|
||||
|
|
@ -1087,7 +1098,7 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
|
|||
if (ty) {
|
||||
swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
|
||||
if (!tc) return SWIG_ERROR;
|
||||
*ptr = SWIG_TypeCast(tc,vptr);
|
||||
*ptr = SWIG_TypeCast(tc,vptr,0);
|
||||
} else {
|
||||
*ptr = vptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,8 +44,12 @@ SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
|
|||
%define SWIG_SHARED_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
|
||||
SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
|
||||
SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
|
||||
%types(SWIG_SHARED_PTR_NAMESPACE::shared_ptr< TYPE > = SWIG_SHARED_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE >) %{
|
||||
*newmemory = SWIG_CAST_NEW_MEMORY;
|
||||
return (void *) new SWIG_SHARED_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_SHARED_PTR_NAMESPACE::shared_ptr< TYPE > *)$from);
|
||||
%}
|
||||
%extend TYPE {
|
||||
static SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) {
|
||||
static SWIG_SHARED_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_SHARED_PTR_NAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) {
|
||||
return swigSharedPtrUpcast;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
|
||||
/* Flags for pointer conversions */
|
||||
#define SWIG_POINTER_DISOWN 0x1
|
||||
#define SWIG_CAST_NEW_MEMORY 0x2
|
||||
|
||||
/* Flags for new pointer objects */
|
||||
#define SWIG_POINTER_OWN 0x1
|
||||
|
|
@ -182,7 +183,7 @@ SWIGINTERNINLINE int SWIG_CheckState(int r) {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void *(*swig_converter_func)(void *);
|
||||
typedef void *(*swig_converter_func)(void *, int *);
|
||||
typedef struct swig_type_info *(*swig_dycast_func)(void **);
|
||||
|
||||
/* Structure to store information on one type */
|
||||
|
|
@ -312,8 +313,8 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) {
|
|||
Cast a pointer up an inheritance hierarchy
|
||||
*/
|
||||
SWIGRUNTIMEINLINE void *
|
||||
SWIG_TypeCast(swig_cast_info *ty, void *ptr) {
|
||||
return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
|
||||
SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
|
||||
return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue