Add Python support for std::unique_ptr inputs
Equivalent to Java/C# implementation.
This commit is contained in:
parent
c737bd5713
commit
c3c061cac8
8 changed files with 103 additions and 9 deletions
|
|
@ -1357,12 +1357,19 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
}
|
||||
}
|
||||
if (sobj) {
|
||||
if (own)
|
||||
*own = *own | sobj->own;
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
sobj->own = 0;
|
||||
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !sobj->own) {
|
||||
res = SWIG_ERROR_RELEASE_NOT_OWNED;
|
||||
} else {
|
||||
if (own)
|
||||
*own = *own | sobj->own;
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
sobj->own = 0;
|
||||
}
|
||||
if (flags & SWIG_POINTER_CLEAR) {
|
||||
sobj->ptr = 0;
|
||||
}
|
||||
res = SWIG_OK;
|
||||
}
|
||||
res = SWIG_OK;
|
||||
} else {
|
||||
if (implicit_conv) {
|
||||
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,22 @@
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%define %unique_ptr(TYPE)
|
||||
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
|
||||
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
|
||||
%releasenotowned_fail(res, "TYPE *", $symname, $argnum);
|
||||
} else {
|
||||
%argument_fail(res, "TYPE *", $symname, $argnum);
|
||||
}
|
||||
}
|
||||
$1.reset((TYPE *)argp);
|
||||
}
|
||||
|
||||
%typemap (out) std::unique_ptr< TYPE > %{
|
||||
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
|
||||
%}
|
||||
|
||||
%template() std::unique_ptr< TYPE >;
|
||||
%enddef
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue