Don't define _GNU_SOURCE if it's already defined on the command-line.
[ira/wip.git] / pidl / lib / Parse / Pidl / Samba4 / NDR / Parser.pm
index 0a4e44ef0ec256301403c4b768a9c32b76e638e0..0e4a7e22894b6b12ef01dd4890e2fed723c45cf2 100644 (file)
@@ -857,8 +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) {");
+                       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("}");
                }
@@ -2165,7 +2173,7 @@ sub ParseFunctionPull($$)
                        if (grep(/in/, @{$e->{DIRECTION}})) {
                                $self->pidl("memcpy(r->out.$e->{NAME}, r->in.$e->{NAME}, ($size) * sizeof(*r->in.$e->{NAME}));");
                        } else {
-                               $self->pidl("memset(CONST_DISCARD(struct $fn->{NAME} *,r->out.$e->{NAME}), 0, ($size) * sizeof(*r->out.$e->{NAME}));");
+                               $self->pidl("memset(r->out.$e->{NAME}, 0, ($size) * sizeof(*r->out.$e->{NAME}));");
                        }
                } else {
                        $self->pidl("NDR_PULL_ALLOC($ndr, r->out.$e->{NAME});");
@@ -2228,7 +2236,7 @@ sub AuthServiceStruct($$$)
 sub FunctionCallEntry($$)
 {
        my ($self, $d) = @_;
-       return if not defined($d->{OPNUM});
+       return if not defined($d->{OPNUM});
        $self->pidl("\t{");
        $self->pidl("\t\t\"$d->{NAME}\",");
        $self->pidl("\t\tsizeof(struct $d->{NAME}),");
@@ -2237,6 +2245,7 @@ sub FunctionCallEntry($$)
        $self->pidl("\t\t(ndr_print_function_t) ndr_print_$d->{NAME},");
        $self->pidl("\t\t".($d->{ASYNC}?"true":"false").",");
        $self->pidl("\t},");
+       return 1;
 }
 
 #####################################################################
@@ -2253,8 +2262,7 @@ sub FunctionTable($$)
        $self->pidl("static const struct ndr_interface_call $interface->{NAME}\_calls[] = {");
 
        foreach my $d (@{$interface->{INHERITED_FUNCTIONS}},@{$interface->{FUNCTIONS}}) {
-               $self->FunctionCallEntry($d);
-               $count++;
+               $count += $self->FunctionCallEntry($d);
        }
        $self->pidl("\t{ NULL, 0, NULL, NULL, NULL, false }");
        $self->pidl("};");
@@ -2540,7 +2548,9 @@ sub GenerateIncludes($)
        if (is_intree()) {
                $self->pidl("#include \"includes.h\"");
        } else {
+               $self->pidl("#ifndef _GNU_SOURCE");
                $self->pidl("#define _GNU_SOURCE");
+               $self->pidl("#endif");
                $self->pidl("#include <stdint.h>");
                $self->pidl("#include <stdlib.h>");
                $self->pidl("#include <stdio.h>");