=cut
# Global Constants
-$XSUBPP_version = "1.937";
+$XSUBPP_version = "1.938";
require 5.002;
use vars '$cplusplus';
$BLOCK_re= '\s*(' . join('|', qw(
REQUIRE BOOT CASE PREINIT INPUT INIT CODE PPCODE OUTPUT
CLEANUP ALIAS PROTOTYPES PROTOTYPE VERSIONCHECK INCLUDE
+ SCOPE
)) . "|$END)\\s*:";
# Input: ($_, @line) == unparsed input.
}
+sub SCOPE_handler ()
+{
+ death("Error: Only 1 SCOPE declaration allowed per xsub")
+ if $scope_in_this_xsub ++ ;
+
+ for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
+ next unless /\S/;
+ TrimWhitespace($_) ;
+ if ($_ =~ /^DISABLE/i) {
+ $ScopeThisXSUB = 0
+ }
+ elsif ($_ =~ /^ENABLE/i) {
+ $ScopeThisXSUB = 1
+ }
+ }
+
+}
+
sub PROTOTYPES_handler ()
{
# the rest of the current line should contain either ENABLE or
undef(%arg_list) ;
undef(@proto_arg) ;
undef($proto_in_this_xsub) ;
+ undef($scope_in_this_xsub) ;
$ProtoThisXSUB = $WantPrototypes ;
+ $ScopeThisXSUB = 0;
$_ = shift(@line);
while ($kwd = check_keyword("REQUIRE|PROTOTYPES|VERSIONCHECK|INCLUDE")) {
$gotRETVAL = 0;
INPUT_handler() ;
- process_keyword("INPUT|PREINIT|ALIAS|PROTOTYPE") ;
+ process_keyword("INPUT|PREINIT|ALIAS|PROTOTYPE|SCOPE") ;
+ print Q<<"EOF" if $ScopeThisXSUB;
+# ENTER;
+# [[
+EOF
+
if (!$thisdone && defined($class)) {
if (defined($static) or $func_name =~ /^new/) {
print "\tchar *";
$args_match{"RETVAL"} = 0;
$var_types{"RETVAL"} = $ret_type;
}
+
print $deferred;
- process_keyword("INIT|ALIAS|PROTOTYPE") ;
+
+ process_keyword("INIT|ALIAS|PROTOTYPE") ;
if (check_keyword("PPCODE")) {
print_section();
death ("PPCODE must be last thing") if @line;
+ print "\tLEAVE;\n" if $ScopeThisXSUB;
print "\tPUTBACK;\n\treturn;\n";
} elsif (check_keyword("CODE")) {
print_section() ;
# do cleanup
process_keyword("CLEANUP|ALIAS|PROTOTYPE") ;
+ print Q<<"EOF" if $ScopeThisXSUB;
+# ]]
+EOF
+ print Q<<"EOF" if $ScopeThisXSUB and not $PPCODE;
+# LEAVE;
+EOF
+
# print function trailer
print Q<<EOF;
# ]]
$subexpr =~ s/\$var/${var}[ix_$var - $argoff]/;
$expr =~ s/DO_ARRAY_ELEM/$subexpr/;
}
+ if ($expr =~ m#/\*.*scope.*\*/#i) { # "scope" in C comments
+ $ScopeThisXSUB = 1;
+ }
if (defined($defaults{$var})) {
$expr =~ s/(\t+)/$1 /g;
$expr =~ s/ /\t/g;
eval qq/print "\\t$var;\\n"/;
$deferred .= eval qq/"\\n\\tif (items < $num)\\n\\t $var = $defaults{$var};\\n\\telse {\\n$expr;\\n\\t}\\n"/;
- } elsif ($expr !~ /^\t\$var =/) {
+ } elsif ($ScopeThisXSUB or $expr !~ /^\t\$var =/) {
eval qq/print "\\t$var;\\n"/;
$deferred .= eval qq/"\\n$expr;\\n"/;
} else {