From 717b7866d4e438e1ae3483f796eb07f96e246fe6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Dec 2017 07:49:56 +0000 Subject: [PATCH] Perl - Add support for missing directorfree typemaps Related to issue #1167, to free up memory when returning reference types. SWIG_Perl_AcquirePtr still needs implementing. --- CHANGES.current | 3 +++ Lib/perl5/perlrun.swg | 9 +++++++++ Source/Modules/perl5.cxx | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 331806b8f..1c361fbec 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2017-12-13: wsfulton + [Perl] add missing support for directorfree typemaps. + 2017-12-13: wsfulton Issue #1167 Fix directorout typemaps which were causing undefined behaviour when returning pointers by reference. diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index cc4ba446a..02714c451 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -20,6 +20,7 @@ #define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags) #define SWIG_ConvertPtrAndOwn(obj, pp, type, flags,own) SWIG_Perl_ConvertPtrAndOwn(SWIG_PERL_OBJECT_CALL obj, pp, type, flags, own) #define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags) +#define SWIG_AcquirePtr(ptr, src) SWIG_Perl_AcquirePtr(ptr, src) #define swig_owntype int /* for raw packed data */ @@ -229,6 +230,14 @@ SWIG_TypeProxyCheck(const char *c, swig_type_info *ty) { return 0; } +/* Acquire a pointer value */ + +SWIGRUNTIME int +SWIG_Perl_AcquirePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, int own) { + /* TODO */ + return 0; +} + /* Function for getting a pointer value */ SWIGRUNTIME int diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index d49da695f..3212a501b 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -900,6 +900,15 @@ public: Printf(f->code, "%s\n", tm); } + if (director_method) { + if ((tm = Swig_typemap_lookup("directorfree", n, Swig_cresult_name(), 0))) { + Replaceall(tm, "$input", Swig_cresult_name()); + Replaceall(tm, "$result", "ST(argvi)"); + Printf(f->code, "%s\n", tm); + Delete(tm); + } + } + Printv(f->code, "XSRETURN(argvi);\n", "fail:\n", cleanup, "SWIG_croak_null();\n" "}\n" "}\n", NIL); /* Add the dXSARGS last */