diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/build/pidl/idl.gram | 10 | ||||
-rw-r--r-- | source4/build/pidl/parser.pm | 68 |
2 files changed, 62 insertions, 16 deletions
diff --git a/source4/build/pidl/idl.gram b/source4/build/pidl/idl.gram index 1a44f6e908..69a6e2458b 100644 --- a/source4/build/pidl/idl.gram +++ b/source4/build/pidl/idl.gram @@ -66,6 +66,12 @@ union_element: '[' 'case' '(' constant ')' ']' base_element ';' "CASE" => $item{constant}, "DATA" => $item{base_element} }} + | 'default' base_element ';' + {{ + "TYPE" => "UNION_ELEMENT", + "CASE" => "default", + "DATA" => $item{base_element} + }} base_element: property_list(s?) type pointer(s?) identifier array_len(?) {{ @@ -82,8 +88,8 @@ array_len: { "*" } | '[' '*' ']' { "*" } - | '[' <commit> text ']' - { "$item{text}" } + | '[' <commit> anytext ']' + { "$item{anytext}" } | <error?> element_list1: base_element(s? /;/) ';' diff --git a/source4/build/pidl/parser.pm b/source4/build/pidl/parser.pm index 1d3e772298..5a39903b8f 100644 --- a/source4/build/pidl/parser.pm +++ b/source4/build/pidl/parser.pm @@ -40,6 +40,10 @@ sub find_size_var($$) if (util::is_constant($size)) { return $size; } + + if ($size =~ /ndr->/) { + return $size; + } if ($fn->{TYPE} ne "FUNCTION") { return "r->$size"; @@ -582,6 +586,7 @@ sub ParseStructPull($) sub ParseUnionPush($) { my $e = shift; + my $have_default = 0; $res .= "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n"; $res .= "\tNDR_CHECK(ndr_push_struct_start(ndr));\n"; @@ -591,24 +596,37 @@ sub ParseUnionPush($) } $res .= "\tswitch (level) {\n"; foreach my $el (@{$e->{DATA}}) { - $res .= "\tcase $el->{CASE}:\n"; + if ($el->{CASE} eq "default") { + $res .= "\tdefault:\n"; + $have_default = 1; + } else { + $res .= "\tcase $el->{CASE}:\n"; + } ParseElementPushScalar($el->{DATA}, "r->", "NDR_SCALARS"); $res .= "\tbreak;\n\n"; } - $res .= "\tdefault:\n"; - $res .= "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n"; + if (! $have_default) { + $res .= "\tdefault:\n"; + $res .= "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n"; + } $res .= "\t}\n"; $res .= "\tndr_push_struct_end(ndr);\n"; $res .= "buffers:\n"; $res .= "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n"; $res .= "\tswitch (level) {\n"; foreach my $el (@{$e->{DATA}}) { - $res .= "\tcase $el->{CASE}:\n"; + if ($el->{CASE} eq "default") { + $res .= "\tdefault:\n"; + } else { + $res .= "\tcase $el->{CASE}:\n"; + } ParseElementPushBuffer($el->{DATA}, "r->", "ndr_flags"); $res .= "\tbreak;\n\n"; } - $res .= "\tdefault:\n"; - $res .= "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n"; + if (! $have_default) { + $res .= "\tdefault:\n"; + $res .= "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n"; + } $res .= "\t}\n"; $res .= "done:\n"; } @@ -618,14 +636,22 @@ sub ParseUnionPush($) sub ParseUnionPrint($) { my $e = shift; + my $have_default = 0; $res .= "\tswitch (level) {\n"; foreach my $el (@{$e->{DATA}}) { - $res .= "\tcase $el->{CASE}:\n"; + if ($el->{CASE} eq "default") { + $have_default = 1; + $res .= "\tdefault:\n"; + } else { + $res .= "\tcase $el->{CASE}:\n"; + } ParseElementPrintScalar($el->{DATA}, "r->"); $res .= "\tbreak;\n\n"; } - $res .= "\tdefault:\n\t\tndr_print_bad_level(ndr, name, level);\n"; + if (! $have_default) { + $res .= "\tdefault:\n\t\tndr_print_bad_level(ndr, name, level);\n"; + } $res .= "\t}\n"; } @@ -634,6 +660,7 @@ sub ParseUnionPrint($) sub ParseUnionPull($) { my $e = shift; + my $have_default = 0; $res .= "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n"; @@ -644,7 +671,12 @@ sub ParseUnionPull($) } $res .= "\tswitch (*level) {\n"; foreach my $el (@{$e->{DATA}}) { - $res .= "\tcase $el->{CASE}: {\n"; + if ($el->{CASE} eq "default") { + $res .= "\tdefault: {\n"; + $have_default = 1; + } else { + $res .= "\tcase $el->{CASE}: {\n"; + } my $e2 = $el->{DATA}; if ($e2->{POINTERS}) { $res .= "\t\tuint32 _ptr_$e2->{NAME};\n"; @@ -652,20 +684,28 @@ sub ParseUnionPull($) ParseElementPullScalar($el->{DATA}, "r->", "NDR_SCALARS"); $res .= "\tbreak; }\n\n"; } - $res .= "\tdefault:\n"; - $res .= "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", *level);\n"; + if (! $have_default) { + $res .= "\tdefault:\n"; + $res .= "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", *level);\n"; + } $res .= "\t}\n"; $res .= "\tndr_pull_struct_end(ndr);\n"; $res .= "buffers:\n"; $res .= "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n"; $res .= "\tswitch (*level) {\n"; foreach my $el (@{$e->{DATA}}) { - $res .= "\tcase $el->{CASE}:\n"; + if ($el->{CASE} eq "default") { + $res .= "\tdefault:\n"; + } else { + $res .= "\tcase $el->{CASE}:\n"; + } ParseElementPullBuffer($el->{DATA}, "r->", "NDR_BUFFERS"); $res .= "\tbreak;\n\n"; } - $res .= "\tdefault:\n"; - $res .= "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", *level);\n"; + if (! $have_default) { + $res .= "\tdefault:\n"; + $res .= "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", *level);\n"; + } $res .= "\t}\n"; $res .= "done:\n"; } |