[glibmm] gmmproc: Pass NULL to C function calls for optional empty strings.



commit 81c1151bc36610c607e6a91808954d8f7851ded1
Author: José Alburquerque <jaalburquerque gmail com>
Date:   Wed Sep 4 15:46:10 2013 -0400

    gmmproc: Pass NULL to C function calls for optional empty strings.
    
        * tools/pm/Output.pm (convert_args_cpp_to_c): When generating
        conversions for the C++ arguments, if the argument is optional
        and it is a std::string or a Glib::ustring, prepend a check for
        the empty string to the standard conversion, passing NULL to the
        C function if the string is empty.
    
        Bug #686909.

 tools/pm/Output.pm |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/tools/pm/Output.pm b/tools/pm/Output.pm
index 1f0421b..975ba75 100644
--- a/tools/pm/Output.pm
+++ b/tools/pm/Output.pm
@@ -1163,13 +1163,21 @@ sub convert_args_cpp_to_c($$$$$)
 
     if ($cppParamType ne $cParamType) #If a type conversion is needed.
     {
-
-
-      push(@conversions, sprintf("_CONVERT(%s,%s,%s,%s)",
-                  $cppParamType,
-                  $cParamType,
-                  $cppParamName,
-                  $wrap_line_number) );
+      my $std_conversion = sprintf("_CONVERT(%s,%s,%s,%s)",
+            $cppParamType,
+            $cParamType,
+            $cppParamName,
+            $wrap_line_number);
+
+      if (($$cpp_param_flags[$cpp_param_index] & FLAG_PARAM_OPTIONAL) &&
+       $cppParamType =~ /^(const\s+)?(std::string|Glib::ustring)&?/)
+      {
+        push(@conversions, "$cppParamName.empty() ? 0 : " . $std_conversion);
+      }
+      else
+      {
+        push(@conversions, $std_conversion);
+      }
     }
     else
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]