Explicitly pass $hiertype to map_type()
authorJames E. Keenan <jkeenan@cpan.org>
Sat, 20 Mar 2010 18:20:29 +0000 (14:20 -0400)
committerSteffen Mueller <smueller@cpan.org>
Tue, 12 Jul 2011 18:53:51 +0000 (20:53 +0200)
Also adjust all (3) calls to map_type() to suit. We can do this
because $hiertype is read, but not written to, within map_type().
map_type() is now fully encapsulated and can be extracted from the
main package and placed in EU::PXS::Utilities.

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm

index 8a46ef9..39d5a3e 100644 (file)
@@ -18,6 +18,7 @@ use ExtUtils::ParseXS::Utilities qw(
   valid_proto_string
   process_typemaps
   make_targetable
+  map_type
 );
 
 our (@ISA, @EXPORT_OK, $VERSION);
@@ -690,7 +691,7 @@ EOF
       }
       else {
         if ($ret_type ne "void") {
-          print "\t" . &map_type($ret_type, 'RETVAL') . ";\n"
+          print "\t" . &map_type($ret_type, 'RETVAL', $hiertype) . ";\n"
             if !$retvaldone;
           $args_match{"RETVAL"} = 0;
           $var_types{"RETVAL"} = $ret_type;
@@ -1133,11 +1134,11 @@ sub INPUT_handler {
     # one can use 2-args map_type() unconditionally.
     if ($var_type =~ / \( \s* \* \s* \) /x) {
       # Function pointers are not yet supported with &output_init!
-      print "\t" . &map_type($var_type, $var_name);
+      print "\t" . &map_type($var_type, $var_name, $hiertype);
       $printed_name = 1;
     }
     else {
-      print "\t" . &map_type($var_type);
+      print "\t" . &map_type($var_type, undef, $hiertype);
       $printed_name = 0;
     }
     $var_num = $args_match{$var_name};
@@ -1882,21 +1883,4 @@ sub generate_output {
   }
 }
 
-sub map_type {
-  my($type, $varname) = @_;
-
-  # C++ has :: in types too so skip this
-  $type =~ tr/:/_/ unless $hiertype;
-  $type =~ s/^array\(([^,]*),(.*)\).*/$1 */s;
-  if ($varname) {
-    if ($varname && $type =~ / \( \s* \* (?= \s* \) ) /xg) {
-      (substr $type, pos $type, 0) = " $varname ";
-    }
-    else {
-      $type .= "\t$varname";
-    }
-  }
-  $type;
-}
-
 1;
index 94d7790..94f28bd 100644 (file)
@@ -15,6 +15,7 @@ our (@ISA, @EXPORT_OK);
   valid_proto_string
   process_typemaps
   make_targetable
+  map_type
 );
 
 =head1 NAME
@@ -393,4 +394,21 @@ sub make_targetable {
   return %targetable;
 }
 
+sub map_type {
+  my ($type, $varname, $hiertype) = @_;
+
+  # C++ has :: in types too so skip this
+  $type =~ tr/:/_/ unless $hiertype;
+  $type =~ s/^array\(([^,]*),(.*)\).*/$1 */s;
+  if ($varname) {
+    if ($type =~ / \( \s* \* (?= \s* \) ) /xg) {
+      (substr $type, pos $type, 0) = " $varname ";
+    }
+    else {
+      $type .= "\t$varname";
+    }
+  }
+  return $type;
+}
+
 1;