From 97733543e2c267c1f54560a50ff61ffab4f15419 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 15 Apr 2021 12:50:32 +1200 Subject: [PATCH] Fix directorout typemap for const TYPE & Previous we were returning a pointer or reference to a local variable. --- Lib/php/utils.i | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Lib/php/utils.i b/Lib/php/utils.i index ed6e08ff4..09507fc8b 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -79,12 +79,21 @@ CONVERT_IN($result, $1_ltype, *$input); } %} -%typemap(directorout) const TYPE & ($*1_ltype temp) +%typemap(directorout) const TYPE & %{ + $*1_ltype swig_val; if (!EG(exception)) { - CONVERT_IN(temp, $*1_ltype, *$input); + CONVERT_IN(swig_val, $*1_ltype, *$input); + $1_ltype temp = new $*1_ltype(($*1_ltype)swig_val); + swig_acquire_ownership(temp); + $result = temp; + } +%} +%typemap(directorfree) const TYPE & +%{ + if (director) { + director->swig_release_ownership(%as_voidptr($input)); } - $result = &temp; %} %enddef