From 9dd373d86e71ac69301e4cbfaaeb4bee0eb5be6a Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sat, 5 Jun 2010 19:26:06 +0200 Subject: [PATCH] Bug 620604 - Description of "histogram" procedure is slightly inaccurate Fix totally broken value ranges of integer PDB parameters. Magically, the bug was affecting only exactly the two cases mentioned in above bug report. * tools/pdbgen/pdb.pl (arg_parse): return <, <=, > and >= literally instead of applying a mapping that was originally meant for generated C code that would e.g. transform "0 <= int32 < 10" into "if (value < 0 || value >= 10) fail". This inversion of all operators is now wrong because PDB parameters have been turned into GParamSpecs which always need inclusive ranges as min and max values. * tools/pdbgen/pdbgen.pl (arrayexpand): generated array length type specs must be "0 <= int32", not "0 < int32". * tools/pdbgen/app.pl: when generating integer param specs, check if the value range is specified in terms of < instead of <=, and add/subtract 1, resuting in the inclusive range needed for integer GParamSpecs. * app/pdb/color-cmds.c: regenerated, fixing the two broken ranges mentioned in the bug report. --- app/pdb/color-cmds.c | 4 ++-- tools/pdbgen/app.pl | 42 ++++++++++++++++++++++++++++++++++++------ tools/pdbgen/pdb.pl | 16 +--------------- tools/pdbgen/pdbgen.pl | 4 ++-- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/app/pdb/color-cmds.c b/app/pdb/color-cmds.c index b3e8ce088e..bfa24a4822 100644 --- a/app/pdb/color-cmds.c +++ b/app/pdb/color-cmds.c @@ -1116,13 +1116,13 @@ register_color_procs (GimpPDB *pdb) gimp_param_spec_int32 ("start-range", "start range", "Start of the intensity measurement range", - 0, 256, 0, + 0, 255, 0, GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, gimp_param_spec_int32 ("end-range", "end range", "End of the intensity measurement range", - 0, 256, 0, + 0, 255, 0, GIMP_PARAM_READWRITE)); gimp_procedure_add_return_value (procedure, g_param_spec_double ("mean", diff --git a/tools/pdbgen/app.pl b/tools/pdbgen/app.pl index f867449c94..2a143f1641 100644 --- a/tools/pdbgen/app.pl +++ b/tools/pdbgen/app.pl @@ -324,8 +324,18 @@ g_param_spec_double ("$name", CODE } elsif ($pdbtype eq 'int32') { - $min = defined $typeinfo[0] ? $typeinfo[0] : G_MININT32; - $max = defined $typeinfo[2] ? $typeinfo[2] : G_MAXINT32; + if (defined $typeinfo[0]) { + $min = ($typeinfo[1] eq '<') ? ($typeinfo[0] + 1) : $typeinfo[0]; + } + else { + $min = G_MININT32; + } + if (defined $typeinfo[2]) { + $max = ($typeinfo[3] eq '<') ? ($typeinfo[2] - 1) : $typeinfo[2]; + } + else { + $max = G_MAXINT32; + } $default = exists $arg->{default} ? $arg->{default} : defined $typeinfo[0] ? $typeinfo[0] : 0; $pspec = <{default} ? $arg->{default} : defined $typeinfo[0] ? $typeinfo[0] : 0; $pspec = <{default} ? $arg->{default} : defined $typeinfo[0] ? $typeinfo[0] : 0; $pspec = < '<=', - '>' => '>=', - '<=' => '<', - '>=' => '>' - ); - - my %postmap = ( - '<' => '>=', - '>' => '<=', - '<=' => '>', - '>=' => '<' - ); - my $arg = shift; if ($arg =~ /^enum (\w+)(.*)/) { @@ -264,7 +250,7 @@ sub arg_parse { \s* (\w+) \s* (?:(<=|<) \s* ([+-.\dA-Z_][^\s]*))? /x) { - return ($3, $1, $2 ? $premap{$2} : $2, $5, $4 ? $postmap{$4} : $4); + return ($3, $1, $2, $5, $4); } } diff --git a/tools/pdbgen/pdbgen.pl b/tools/pdbgen/pdbgen.pl index 57444a0bab..57cd1e7df1 100755 --- a/tools/pdbgen/pdbgen.pl +++ b/tools/pdbgen/pdbgen.pl @@ -164,10 +164,10 @@ sub arrayexpand { # We can't have negative lengths, but let them set a min number unless (exists $arg->{type}) { - $arg->{type} = '0 < int32'; + $arg->{type} = '0 <= int32'; } elsif ($arg->{type} !~ /^\s*\d+\s*{type} = '0 < ' . $arg->{type}; + $arg->{type} = '0 <= ' . $arg->{type}; } $arg->{void_ret} = 1 if exists $_->{void_ret};