Unwrap director classes only when returning a pointer or reference to an object
This involves properly counting the number of references and pointers in the return type of a function and only generate unwrapping code if this number is 1. For template instances some post-processing code is added to fix the 'decl' and 'type' attributes of functions if changed in an unfavorable way during template expansion. This commit fixes swig#1811.
This commit is contained in:
parent
b7bcb338cf
commit
01277d700c
9 changed files with 369 additions and 6 deletions
82
Examples/test-suite/director_unwrap_result.i
Normal file
82
Examples/test-suite/director_unwrap_result.i
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
%module(directors="1") director_unwrap_result
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Storage;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) StorageTmpl;
|
||||
|
||||
%feature("director") Element;
|
||||
%feature("director") Storage;
|
||||
%feature("director") StorageTmpl;
|
||||
|
||||
%inline %{
|
||||
|
||||
class Element {
|
||||
Element* self;
|
||||
Element** selfptr;
|
||||
public:
|
||||
Element() {
|
||||
self = this;
|
||||
selfptr = &self;
|
||||
}
|
||||
virtual ~Element() {}
|
||||
Element **getPtrPtr() {
|
||||
return &self;
|
||||
}
|
||||
Element ***getPtrPtrPtr() {
|
||||
return &selfptr;
|
||||
}
|
||||
};
|
||||
|
||||
class Storage {
|
||||
public:
|
||||
virtual ~Storage() {}
|
||||
virtual Element **getIt() = 0;
|
||||
Element getElement() {
|
||||
return **getIt();
|
||||
}
|
||||
Element* const getElementPtr() {
|
||||
return *getIt();
|
||||
}
|
||||
Element& getElementRef() {
|
||||
return **getIt();
|
||||
}
|
||||
Element* const *getElementPtrPtr() {
|
||||
return getIt();
|
||||
}
|
||||
Element *&getElementPtrRef() {
|
||||
return *getIt();
|
||||
}
|
||||
};
|
||||
|
||||
template<class T> class StorageTmpl {
|
||||
public:
|
||||
virtual ~StorageTmpl() {}
|
||||
virtual T &getIt() = 0;
|
||||
T getVal() {
|
||||
return getIt();
|
||||
}
|
||||
T *getPtr() {
|
||||
return &getIt();
|
||||
}
|
||||
T &getRef() {
|
||||
return getIt();
|
||||
}
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%template(ElementStorage) StorageTmpl<Element>;
|
||||
%template(ElementPtrStorage) StorageTmpl<Element *>;
|
||||
%template(ElementPtrPtrStorage) StorageTmpl<Element *const *>;
|
||||
|
||||
%inline %{
|
||||
|
||||
template<class T> T getParam(T t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%template(getIntParam) getParam<int>;
|
||||
%template(getIntPtrParam) getParam<int*>;
|
||||
%template(getElementPtrParam) getParam<Element *>;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue