pidl: Remove "max" and make "range" smarter about unsigned types
authorTim Prouty <tprouty@samba.org>
Sat, 17 Jan 2009 22:40:12 +0000 (14:40 -0800)
committerTim Prouty <tprouty@samba.org>
Sun, 18 Jan 2009 03:37:52 +0000 (19:37 -0800)
This eliminates a warning in pidl generated code, while preserving
cross-platform idl compatibility.

pidl/lib/Parse/Pidl/Compat.pm
pidl/lib/Parse/Pidl/NDR.pm
pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
pidl/lib/Parse/Pidl/Typelist.pm

index 58ba136591b915c1e41ac80cafc924ea0bee62e0..1b49c439c43bd3fdc4b679c0838d4bd832000949 100644 (file)
@@ -67,7 +67,6 @@ my %supported_properties = (
 
        # array
        "range"                 => ["ELEMENT"],
-       "max"                   => ["ELEMENT"],
        "size_is"               => ["ELEMENT"],
        "string"                => ["ELEMENT"],
        "noheader"              => ["ELEMENT"],
index 89632437c10f74e1cd18d9cddb3c132cddde8be7..5ee26d16b68c76f611c4fedc832aab5671f513e1 100644 (file)
@@ -921,7 +921,6 @@ my %property_list = (
 
        # array
        "range"                 => ["ELEMENT"],
-       "max"                   => ["ELEMENT"],
        "size_is"               => ["ELEMENT"],
        "string"                => ["ELEMENT"],
        "noheader"              => ["ELEMENT"],
index e2b14c10b1e1c63f642678017ce2c08ff50f18cc..44d21f0b4a6460087ffc9c961943ef9060515580 100644 (file)
@@ -857,14 +857,16 @@ sub ParseDataPull($$$$$$$)
 
                if (my $range = has_property($e, "range")) {
                        $var_name = get_value_of($var_name);
+                       my $signed = Parse::Pidl::Typelist::is_signed($l->{DATA_TYPE});
                        my ($low, $high) = split(/,/, $range, 2);
-                       $self->pidl("if ($var_name < $low || $var_name > $high) {");
-                       $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");");
-                       $self->pidl("}");
-               }
-               if (my $max = has_property($e, "max")) {
-                       $var_name = get_value_of($var_name);
-                       $self->pidl("if ($var_name > $max) {");
+                       if ($low < 0 and not $signed) {
+                               warning(0, "$low is invalid for the range of an unsigned type");
+                       }
+                       if ($low == 0 and not $signed) {
+                               $self->pidl("if ($var_name > $high) {");
+                       } else {
+                               $self->pidl("if ($var_name < $low || $var_name > $high) {");
+                       }
                        $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");");
                        $self->pidl("}");
                }
index 0e3fd8de444c3988c04e365f6bc2d1f4e49439a2..4f9d982c215fdade246b69a4ff2aefdbfa8e9341 100644 (file)
@@ -8,7 +8,7 @@ package Parse::Pidl::Typelist;
 require Exporter;
 @ISA = qw(Exporter);
 @EXPORT_OK = qw(hasType getType resolveType mapTypeName scalar_is_reference expandAlias
-                           mapScalarType addType typeIs is_scalar enum_type_fn
+                           mapScalarType addType typeIs is_signed is_scalar enum_type_fn
                                bitmap_type_fn mapType typeHasBody
 );
 use vars qw($VERSION);
@@ -145,6 +145,19 @@ sub hasType($)
        return 0;
 }
 
+sub is_signed($)
+{
+    my $t = shift;
+
+    return ($t eq "int8"
+           or $t eq "int16"
+           or $t eq "int32"
+           or $t eq "dlong"
+           or $t eq "int"
+           or $t eq "long"
+           or $t eq "short");
+}
+
 sub is_scalar($)
 {
        sub is_scalar($);