Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a fix to RedoDims that allows actually setting the $SIZE macro.
This hasn't worked in, well, ever due to a scope bug in the macro
definition.  (never nest closures if you can help it...)
  • Loading branch information
Craig DeForest authored and mohawk2 committed May 2, 2015
1 parent 0dabdf2 commit 84b7335
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Basic/Gen/PP.pm
Expand Up @@ -3477,11 +3477,17 @@ $PDL::PP::deftbl =

# The RedoDimsSub rule is a bit weird since it takes in the RedoDims target
# twice (directly and via RedoDims-PostComp). Can this be cleaned up?
#
# [I don't know who put this in, or when -- but I don't understand it. CED 13-April-2015]
PDL::PP::Rule->new("RedoDims-PreComp", "RedoDims",
sub { return $_[0] . ' $PRIV(__ddone) = 1;'; }),
PDL::PP::Rule::MakeComp->new("RedoDims-PostComp",
["RedoDims-PreComp", "PrivNames", "PrivObjs"], "PRIV"),

# RedoDimsSub is supposed to allow you to use $SIZE as an lvalue, to resize things. It hasn't
# worked since I can remember (at least since I started messing around with range). The reason
# appears to be that the SIZE macro was using the redodims argument instead of its own zeroth
# argument. Renaming gone wrong? Anyway I've fixed it to use $_[0] instead of $redodims in the
# SIZE closure. -- CED 13-April-2015
PDL::PP::Rule->new("RedoDimsSub",
["RedoDims", "RedoDims-PostComp", "_DimObjs"],
sub {
Expand All @@ -3490,9 +3496,10 @@ $PDL::PP::deftbl =
my $dimobjs = $_[2];

$result->[1]{"SIZE"} = sub {
croak "can't get SIZE of undefined dimension (RedoDims=$redodims)."
unless defined $dimobjs->{$redodims};
return $dimobjs->{$redodims}->get_size();
eval 'use PDL::IO::Dumper';

This comment has been minimized.

Copy link
@mohawk2

mohawk2 May 2, 2015

Member

@drzowie This should be in an "if" block, something like:

if (!defined $dimobjs->{$_[0]}) {
  my $msg = "FOO can't get SIZE of undefined dimension (RedoDims=$redodims).\nredodims is $redodims\n";
  eval { require PDL::IO::Dumper };
  $msg .= "dimobjs is ". PDL::IO::Dumper::sdump($dimobjs) ."\n" unless $@;
  croak $msg;
}
croak "FOO can't get SIZE of undefined dimension (RedoDims=$redodims).\nredodims is $redodims\ndimobjs is ".sdump($dimobjs)."\n"
unless defined $dimobjs->{$_[0]}; # This is the closure's $_[0], not the rule definition's $_[0]
return $dimobjs->{$_[0]}->get_size();
};
return $result;
}),
Expand Down

0 comments on commit 84b7335

Please sign in to comment.