]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
wireshark-pidl: Do not calculate functions replaced by manual code
authorJohn Thacker <johnthacker@gmail.com>
Sun, 12 Oct 2025 19:14:47 +0000 (15:14 -0400)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 5 Nov 2025 10:08:28 +0000 (10:08 +0000)
From the Wireshark development branch:

    commit d2232d7e51640e0e736d7b8df1b21598a21a1c85
    Author: John Thacker <johnthacker@gmail.com>
    Date:   Fri Oct 10 23:02:58 2025 -0400

        pidl: Do not produce a function that is replaced by MANUAL code

        If a MANUAL directive in a conformance file causes a function not to be
        emitted, do not bother calculating the function that will not be used.
        This is similar to the NOEMIT directive, but has different logic because
        MANUAL only prevents emitting the function for one level of an element
        instead of all the functions and variables. This does not change the
        dissectors produced at all, only skips some unnecessary compilation.

        In particular, the messages when compiling the pidl-dissectors target:

        dnsserver.idl:159: error: Inline arrays not supported
        eventlog.idl:54: error: Inline arrays not supported

        are no longer inaccurately produced. The inline arrays in those two IDL
        files have long been supported through the MANUAL code blocks.

        Expand on the error message to suggest the use of MANUAL directives
        for implementation.

Signed-off-by: John Thacker <johnthacker@gmail.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
pidl/lib/Parse/Pidl/Wireshark/NDR.pm

index ce0010acc98a41fc21b65a7ed37f8045dd0854fa..b7785d389eebdb6659e383f3e4c94069a012340a 100644 (file)
@@ -322,7 +322,7 @@ sub ElementLevel($$$$$$$$)
                $self->pidl_code("offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, di, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes})) . " ($e->{TYPE})\",$hf);");
        } elsif ($l->{TYPE} eq "ARRAY") {
                if ($l->{IS_INLINE}) {
-                       error($e->{ORIGINAL}, "Inline arrays not supported");
+                       error($e->{ORIGINAL}, "Inline arrays not supported automatically. Use conformance file MANUAL directives for `$myname' and `$l->{SIZE_IS}' to implement them.");
                } elsif ($l->{IS_FIXED}) {
                        $self->pidl_code("int i;");
                        $self->pidl_code("for (i = 0; i < $l->{SIZE_IS}; i++)");
@@ -564,22 +564,24 @@ sub Element($$$$$$)
                next if ($_->{TYPE} eq "SWITCH");
                next if (defined($self->{conformance}->{noemit}->{"$dissectorname$add"}));
                $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_$moreparam);");
-               $self->pidl_fn_start("$dissectorname$add");
-               $self->pidl_code("static int");
-               $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_$moreparam)");
-               $self->pidl_code("{");
-               $self->indent;
+               if (not defined($self->{conformance}->{manual}->{"$dissectorname$add"})) {
+                       $self->pidl_fn_start("$dissectorname$add");
+                       $self->pidl_code("static int");
+                       $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_$moreparam)");
+                       $self->pidl_code("{");
+                       $self->indent;
+
+                       $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname,$param);
+                       if (defined $oldparam) {
+                               $param = $oldparam;
+                       }
 
-               $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname,$param);
-               if (defined $oldparam) {
-                       $param = $oldparam;
+                       $self->pidl_code("");
+                       $self->pidl_code("return offset;");
+                       $self->deindent;
+                       $self->pidl_code("}\n");
+                       $self->pidl_fn_end("$dissectorname$add");
                }
-
-               $self->pidl_code("");
-               $self->pidl_code("return offset;");
-               $self->deindent;
-               $self->pidl_code("}\n");
-               $self->pidl_fn_end("$dissectorname$add");
                $add.="_";
                last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED});
        }