Hi,
I found this old bug[0] when I search in bugzilla for something else and
it will be enough interesting for me, that I investigate how perl and
its bindings works and how it works for submodules.
In the end I came with fix, that I test myself.
Problem was that perl pass variable as string type and not as reference
to string. So I addapt bindings to handle both situation.

Martin - please review my patch.

Thanks
Josef

[0] https://bugzilla.novell.com/show_bug.cgi?id=535200

-- 
Josef Reidinger
Software Engineer Appliance Department

SUSE LINUX, s. r. o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic

[email protected]
SUSE
Index: pluglib-bindings/swig/stl/string.i
===================================================================
--- pluglib-bindings/swig/stl/string.i	(revision 67536)
+++ pluglib-bindings/swig/stl/string.i	(working copy)
@@ -31,8 +31,15 @@
     const std::string* (std::string temp), const std::string& (std::string temp)
 {
     SV *sv;
-    if (!SvROK($input) || !(sv = (SV*)SvRV($input)) || !SvPOK(sv) )
-	SWIG_croak("Type error in argument $argnum of $symname. Expected a REFERENCE to STRING.\n");
+    /*support string by value and also by reference */
+    if (SvPOK($input))
+    { /* we get string value */
+        sv = $input;
+    }
+    else if (!SvROK($input) || !(sv = (SV*)SvRV($input)) || !SvPOK(sv) )
+    {
+        SWIG_croak("Type error in argument $argnum of $symname. Expected a REFERENCE to STRING or STRING.\n");
+    }
 
     STRLEN len;
     const char *ptr = SvPV(sv, len);
@@ -52,7 +59,9 @@
 
 %typemap(argout) std::string*, std::string&
 {
-    SV *sv = (SV *)SvRV($input);
+    SV *sv = $input;
+    if (SvROK($input)) /* input can be reference of bare string */
+      sv = (SV *)SvRV($input);
     sv_setpv(sv, $1->c_str());
 }
 

Reply via email to