Rev 11404: Merge some pidl fixes: in file:///home/jelmer/bzr.samba/SAMBA_4_0/

Jelmer Vernooij jelmer at samba.org
Thu Feb 8 23:48:23 GMT 2007


At file:///home/jelmer/bzr.samba/SAMBA_4_0/

------------------------------------------------------------
revno: 11404
revision-id: jelmer at samba.org-20070208234639-i0h5mfefbn1a1lkl
parent: svn-v2:21252 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
parent: jelmer at samba.org-20070208160510-qt1c7a40efk16ew0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Fri 2007-02-09 00:46:39 +0100
message:
  Merge some pidl fixes:
  
   * Add tests for wireshark dissector generator
   * Add tests for the header code
   * Some cleanups
   * Fix handling of elements without [in] or [out]
added:
  source/pidl/tests/header.pl    header.pl-20070208094205-onb80lvoyh5ciw5r-1
  source/pidl/tests/wireshark-conf.pl wiresharkconf.pl-20070208154028-socda2mp78zkog3t-1
modified:
  source/pidl/TODO               svn-v2:9459 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2fTODO
  source/pidl/lib/Parse/Pidl/Samba4/Header.pm svn-v2:12463 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fSamba4%2fHeader.pm
  source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm svn-v2:12463 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fSamba4%2fNDR%2fParser.pm
  source/pidl/lib/Parse/Pidl/Util.pm svn-v2:9460 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fUtil.pm
  source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm svn-v2:16824 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fWireshark%2fConformance.pm
  source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm svn-v2:16824 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fWireshark%2fNDR.pm
  source/pidl/tests/samba-ndr.pl svn-v2:20637 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fsamba%2dndr.pl
    ------------------------------------------------------------
    revno: 11390.1.7
    merged: jelmer at samba.org-20070208160510-qt1c7a40efk16ew0
    parent: jelmer at samba.org-20070208154547-1iu4v5vre77r631u
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: pidl-fixes
    timestamp: Thu 2007-02-08 17:05:10 +0100
    message:
      3 more tests.
    ------------------------------------------------------------
    revno: 11390.1.6
    merged: jelmer at samba.org-20070208154547-1iu4v5vre77r631u
    parent: jelmer at samba.org-20070208154341-qydagn1k84pb6yd1
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: pidl-fixes
    timestamp: Thu 2007-02-08 16:45:47 +0100
    message:
      Allow cmd to be undefined.
    ------------------------------------------------------------
    revno: 11390.1.5
    merged: jelmer at samba.org-20070208154341-qydagn1k84pb6yd1
    parent: jelmer at samba.org-20070208154257-zqh0w412ym1w22u9
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: pidl-fixes
    timestamp: Thu 2007-02-08 16:43:41 +0100
    message:
      Remove some debug statements.
    ------------------------------------------------------------
    revno: 11390.1.4
    merged: jelmer at samba.org-20070208154257-zqh0w412ym1w22u9
    parent: jelmer at samba.org-20070208141706-afd7md02c83t939w
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: pidl-fixes
    timestamp: Thu 2007-02-08 16:42:57 +0100
    message:
      Add some tests for the wireshark conformance file reader.
    ------------------------------------------------------------
    revno: 11390.1.3
    merged: jelmer at samba.org-20070208141706-afd7md02c83t939w
    parent: jelmer at samba.org-20070208112519-x9ru04sml0g8wq4x
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: pidl-fixes
    timestamp: Thu 2007-02-08 15:17:06 +0100
    message:
      Add some more tests, reduce number of locations where "absolute" variable 
      names are used.
    ------------------------------------------------------------
    revno: 11390.1.2
    merged: jelmer at samba.org-20070208112519-x9ru04sml0g8wq4x
    parent: jelmer at samba.org-20070208104200-7iq7uyqo7h7fohgk
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: pidl-fixes
    timestamp: Thu 2007-02-08 12:25:19 +0100
    message:
      Fix handling of elements without [in,out]
    ------------------------------------------------------------
    revno: 11390.1.1
    merged: jelmer at samba.org-20070208104200-7iq7uyqo7h7fohgk
    parent: svn-v2:21222 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: pidl-fixes
    timestamp: Thu 2007-02-08 11:42:00 +0100
    message:
      Add some tests for the header code.
=== added file 'source/pidl/tests/header.pl'
--- a/source/pidl/tests/header.pl	1970-01-01 00:00:00 +0000
+++ b/source/pidl/tests/header.pl	2007-02-08 11:25:19 +0000
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+# (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+# Published under the GNU General Public License
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+use FindBin qw($RealBin);
+use lib "$RealBin";
+use Util;
+use Parse::Pidl::Util qw(MyDumper);
+use Parse::Pidl::Samba4::Header;
+use Parse::Pidl::IDL qw(parse_string);
+
+sub parse_idl($)
+{
+	my $text = shift;
+	my $idl = Parse::Pidl::IDL::parse_string($text, "nofile");
+	return Parse::Pidl::Samba4::Header::Parse($idl);
+}
+
+is("/* header auto-generated by pidl */\n\n#include <core.h>\n\n", parse_idl(""), "includes work");
+is("/* header auto-generated by pidl */\n\n#include <core.h>\n\n", parse_idl("interface x {}"), "simple empty interface doesn't cause overhead");
+like(parse_idl("interface p { typedef struct { int y; } x; };"),
+     qr/.*#ifndef _HEADER_p\n#define _HEADER_p\n.+\n#endif \/\* _HEADER_p \*\/.*/ms, "ifdefs are created");
+like(parse_idl("interface p { typedef struct { int y; } x; };"),
+     qr/struct x.*{.*int32_t y;.*}.*;/sm, "interface member generated properly");
+like(parse_idl("interface x { void foo (void); };"),
+     qr/struct foo.*{\s+int _dummy_element;\s+};/sm, "void fn contains dummy element");
+like(parse_idl("interface x { void foo ([in] uint32 x); };"),
+     qr/struct foo.*{\s+struct\s+{\s+uint32_t x;\s+} in;\s+};/sm, "fn in arg works");
+like(parse_idl("interface x { void foo ([out] uint32 x); };"),
+     qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn out arg works");
+like(parse_idl("interface x { void foo ([in,out] uint32 x); };"),
+     qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn in,out arg works");
+like(parse_idl("interface x { void foo (uint32 x); };"), qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn with no props implies in,out");

=== added file 'source/pidl/tests/wireshark-conf.pl'
--- a/source/pidl/tests/wireshark-conf.pl	1970-01-01 00:00:00 +0000
+++ b/source/pidl/tests/wireshark-conf.pl	2007-02-08 16:05:10 +0000
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+# (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+# Published under the GNU General Public License
+# test parsing wireshark conformance files
+use strict;
+use warnings;
+
+use Test::More tests => 20;
+use FindBin qw($RealBin);
+use lib "$RealBin";
+use Util;
+use Parse::Pidl::Util qw(MyDumper);
+use Parse::Pidl::Wireshark::Conformance qw(ReadConformanceFH);
+
+sub parse_conf($)
+{
+	my $str = shift;
+    open(TMP, "+>", undef) or die("unable to open temp file");
+	print TMP $str;
+	seek(TMP, 0, 0);
+	my $data = {};
+	ReadConformanceFH(*TMP, $data, "nofile") or return undef;
+	close(TMP);
+	return $data;
+}
+
+ok(parse_conf("\n"), undef);
+ok(parse_conf(" \n"), undef);
+ok(parse_conf("CODE START\nCODE END\n"));
+test_warnings("nofile:1: Expecting CODE END\n", sub { is(parse_conf("CODE START\n"), undef); });
+ok(parse_conf("#foobar\n"), undef);
+test_warnings("nofile:1: Unknown command `foobar'\n",
+	sub { ok(parse_conf("foobar\n"), undef); });
+
+test_warnings("nofile:1: incomplete HF_RENAME command\n",
+	sub { parse_conf("HF_RENAME\n"); });
+
+
+is_deeply(parse_conf("HF_RENAME foo bar\n")->{hf_renames}->{foo}, 
+	{ OLDNAME => "foo", NEWNAME => "bar", POS => {FILE => "nofile", LINE => 1}, USED => 0});
+
+is_deeply(parse_conf("NOEMIT\n"), { "noemit_dissector" => 1 });
+is_deeply(parse_conf("NOEMIT foo\n"), { "noemit" => { "foo" => 1 } });
+
+test_warnings("nofile:1: incomplete MANUAL command\n",
+	sub { parse_conf("MANUAL\n"); } );
+
+is_deeply(parse_conf("MANUAL foo\n"), { manual => {foo => 1}});
+
+test_warnings("nofile:1: incomplete FIELD_DESCRIPTION command\n",
+	sub { parse_conf("FIELD_DESCRIPTION foo\n"); });
+
+is_deeply(parse_conf("FIELD_DESCRIPTION foo \"my description\"\n"),
+	{ fielddescription => { foo => { DESCRIPTION => "\"my description\"", POS => { FILE => "nofile", LINE => 1}, USED => 0 }}});
+
+is_deeply(parse_conf("FIELD_DESCRIPTION foo my description\n"),
+	{ fielddescription => { foo => { DESCRIPTION => "my", POS => { FILE => "nofile", LINE => 1}, USED => 0 }}});
+
+is_deeply(parse_conf("CODE START\ndata\nCODE END\n"), { override => "data\n" });
+is_deeply(parse_conf("CODE START\ndata\nmore data\nCODE END\n"), { override => "data\nmore data\n" });
+test_warnings("nofile:1: Unknown command `CODE'\n",
+	sub { parse_conf("CODE END\n"); } );

=== modified file 'source/pidl/TODO'
--- a/source/pidl/TODO	2007-02-07 19:03:19 +0000
+++ b/source/pidl/TODO	2007-02-08 14:17:06 +0000
@@ -21,3 +21,10 @@
 - mem_ctx in the interface rather than as struct ndr member.
 
 - real typelibs
+
+- fix [in,out] handling and allocation for samba3:
+ - add inout
+ - make NULL to mean "allocate me"
+ - remove NDR_AUTO_REF_ALLOC flag
+
+- automatic test generator based on IDL pointer types

=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/Header.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/Header.pm	2007-01-22 00:04:59 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/Header.pm	2007-02-08 11:25:19 +0000
@@ -9,7 +9,6 @@
 use strict;
 use Parse::Pidl::Typelist qw(mapType);
 use Parse::Pidl::Util qw(has_property is_constant);
-use Parse::Pidl::NDR qw(GetNextLevel GetPrevLevel);
 use Parse::Pidl::Samba4 qw(is_intree);
 
 use vars qw($VERSION);
@@ -236,15 +235,25 @@
     }
 }
 
+sub ElementDirection($)
+{
+	my ($e) = @_;
+
+	return "inout" if (has_property($e, "in") and has_property($e, "out"));
+	return "in" if (has_property($e, "in"));
+	return "out" if (has_property($e, "out"));
+	return "inout";
+}
+
 #####################################################################
 # parse a function
 sub HeaderFunctionInOut($$)
 {
     my($fn,$prop) = @_;
 
-    foreach (@{$fn->{ELEMENTS}}) {
-		HeaderElement($_) if (has_property($_, $prop));
-    }
+	foreach (@{$fn->{ELEMENTS}}) {
+		HeaderElement($_) if (ElementDirection($_) eq $prop);
+	}
 }
 
 #####################################################################
@@ -255,8 +264,8 @@
 
     return 1 if ($prop eq "out" && $fn->{RETURN_TYPE} ne "void");
 
-    foreach (@{$fn->{ELEMENTS}}) {
-	    return 1 if (has_property($_, $prop));
+	foreach (@{$fn->{ELEMENTS}}) {
+		return 1 if (ElementDirection($_) eq $prop);
     }
 
     return undef;
@@ -278,19 +287,23 @@
     $tab_depth++;
     my $needed = 0;
 
-    if (HeaderFunctionInOut_needed($fn, "in")) {
+    if (HeaderFunctionInOut_needed($fn, "in") or
+	    HeaderFunctionInOut_needed($fn, "inout")) {
 	    pidl tabs()."struct {\n";
 	    $tab_depth++;
 	    HeaderFunctionInOut($fn, "in");
+	    HeaderFunctionInOut($fn, "inout");
 	    $tab_depth--;
 	    pidl tabs()."} in;\n\n";
 	    $needed++;
     }
 
-    if (HeaderFunctionInOut_needed($fn, "out")) {
+    if (HeaderFunctionInOut_needed($fn, "out") or
+	    HeaderFunctionInOut_needed($fn, "inout")) {
 	    pidl tabs()."struct {\n";
 	    $tab_depth++;
 	    HeaderFunctionInOut($fn, "out");
+	    HeaderFunctionInOut($fn, "inout");
 	    if ($fn->{RETURN_TYPE} ne "void") {
 		    pidl tabs().mapType($fn->{RETURN_TYPE}) . " result;\n";
 	    }
@@ -299,7 +312,7 @@
 	    $needed++;
     }
 
-    if (! $needed) {
+    if (!$needed) {
 	    # sigh - some compilers don't like empty structures
 	    pidl tabs()."int _dummy_element;\n";
     }

=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm	2007-02-07 19:03:19 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm	2007-02-08 14:17:06 +0000
@@ -10,7 +10,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 @EXPORT = qw(is_charset_array);
- at EXPORT_OK = qw(check_null_pointer);
+ at EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv);
 
 use strict;
 use Parse::Pidl::Typelist qw(hasType getType mapType);
@@ -451,7 +451,9 @@
 	if ($l->{IS_VARYING} and not $l->{IS_ZERO_TERMINATED}) {
 		defer "if ($var_name) {";
 		defer_indent;
-		my $length = ParseExprExt($l->{LENGTH_IS}, $env, $e->{ORIGINAL}, check_null_pointer($e, $env, \&defer, "return NT_STATUS_INVALID_PARAMETER_MIX;"), check_fully_dereferenced($e, $env));
+		my $length = ParseExprExt($l->{LENGTH_IS}, $env, $e->{ORIGINAL}, 
+			check_null_pointer($e, $env, \&defer, "return NT_STATUS_INVALID_PARAMETER_MIX;"), 
+			check_fully_dereferenced($e, $env));
 		defer "NDR_CHECK(ndr_check_array_length(ndr, (void*)" . get_pointer_to($var_name) . ", $length));";
 		defer_deindent;
 		defer "}"
@@ -689,12 +691,12 @@
 
 #####################################################################
 # parse scalars in a structure element
-sub ParseElementPush($$$$$$)
+sub ParseElementPush($$$$$)
 {
-	my ($e,$ndr,$var_prefix,$env,$primitives,$deferred) = @_;
+	my ($e,$ndr,$env,$primitives,$deferred) = @_;
 	my $subndr = undef;
 
-	my $var_name = $var_prefix.$e->{NAME};
+	my $var_name = $env->{$e->{NAME}};
 
 	return unless $primitives or ($deferred and ContainsDeferred($e, $e->{LEVELS}[0]));
 
@@ -1096,11 +1098,11 @@
 
 #####################################################################
 # parse scalars in a structure element - pull size
-sub ParseElementPull($$$$$$)
+sub ParseElementPull($$$$$)
 {
-	my($e,$ndr,$var_prefix,$env,$primitives,$deferred) = @_;
+	my($e,$ndr,$env,$primitives,$deferred) = @_;
 
-	my $var_name = $var_prefix.$e->{NAME};
+	my $var_name = $env->{$e->{NAME}};
 	my $represent_name;
 	my $transmit_name;
 
@@ -1247,7 +1249,7 @@
 	}
 
 	foreach my $e (@{$struct->{ELEMENTS}}) {
-		ParseElementPush($e, "ndr", "r->", $env, 1, 0);
+		ParseElementPush($e, "ndr", $env, 1, 0);
 	}	
 
 	deindent;
@@ -1261,7 +1263,7 @@
 		pidl "NDR_CHECK(ndr_push_setup_relative_base_offset2(ndr, r));";
 	}
 	foreach my $e (@{$struct->{ELEMENTS}}) {
-		ParseElementPush($e, "ndr", "r->", $env, 0, 1);
+		ParseElementPush($e, "ndr", $env, 0, 1);
 	}
 
 	deindent;
@@ -1547,7 +1549,7 @@
 	}
 
 	foreach my $e (@{$struct->{ELEMENTS}}) {
-		ParseElementPull($e, "ndr", "r->", $env, 1, 0);
+		ParseElementPull($e, "ndr", $env, 1, 0);
 	}	
 
 	add_deferred();
@@ -1562,7 +1564,7 @@
 		pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset2(ndr, r));";
 	}
 	foreach my $e (@{$struct->{ELEMENTS}}) {
-		ParseElementPull($e, "ndr", "r->", $env, 0, 1);
+		ParseElementPull($e, "ndr", $env, 0, 1);
 	}
 
 	add_deferred();
@@ -1662,7 +1664,7 @@
 				pidl "NDR_CHECK(ndr_push_setup_relative_base_offset1(ndr, r, ndr->offset));";
 			}
 			DeclareArrayVariables($el);
-			ParseElementPush($el, "ndr", "r->", {}, 1, 0);
+			ParseElementPush($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 1, 0);
 			deindent;
 		}
 		pidl "break;";
@@ -1689,7 +1691,7 @@
 		pidl "$el->{CASE}:";
 		if ($el->{TYPE} ne "EMPTY") {
 			indent;
-			ParseElementPush($el, "ndr", "r->", {}, 0, 1);
+			ParseElementPush($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 0, 1);
 			deindent;
 		}
 		pidl "break;";
@@ -1810,7 +1812,7 @@
 				# and store it based on the toplevel struct/union
 				pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset1(ndr, r, ndr->offset));";
 			}
-			ParseElementPull($el, "ndr", "r->", {}, 1, 0);
+			ParseElementPull($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 1, 0);
 			deindent;
 		}
 		pidl "break; }";
@@ -1837,7 +1839,7 @@
 		pidl "$el->{CASE}:";
 		if ($el->{TYPE} ne "EMPTY") {
 			indent;
-			ParseElementPull($el, "ndr", "r->", {}, 0, 1);
+			ParseElementPull($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 0, 1);
 			deindent;
 		}
 		pidl "break;";
@@ -1993,7 +1995,7 @@
 
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/in/,@{$e->{DIRECTION}})) {
-			ParseElementPrint($e, "r->in.$e->{NAME}", $env);
+			ParseElementPrint($e, $env->{$e->{NAME}}, $env);
 		}
 	}
 	pidl "ndr->depth--;";
@@ -2008,7 +2010,7 @@
 	$env = GenerateFunctionOutEnv($fn);
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/out/,@{$e->{DIRECTION}})) {
-			ParseElementPrint($e, "r->out.$e->{NAME}", $env);
+			ParseElementPrint($e, $env->{$e->{NAME}}, $env);
 		}
 	}
 	if ($fn->{RETURN_TYPE}) {
@@ -2050,7 +2052,7 @@
 
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/in/,@{$e->{DIRECTION}})) {
-			ParseElementPush($e, "ndr", "r->in.", $env, 1, 1);
+			ParseElementPush($e, "ndr", $env, 1, 1);
 		}
 	}
 
@@ -2063,7 +2065,7 @@
 	$env = GenerateFunctionOutEnv($fn);
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/out/,@{$e->{DIRECTION}})) {
-			ParseElementPush($e, "ndr", "r->out.", $env, 1, 1);
+			ParseElementPush($e, "ndr", $env, 1, 1);
 		}
 	}
 
@@ -2147,7 +2149,7 @@
 
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		next unless (grep(/in/, @{$e->{DIRECTION}}));
-		ParseElementPull($e, "ndr", "r->in.", $env, 1, 1);
+		ParseElementPull($e, "ndr", $env, 1, 1);
 	}
 
 	# allocate the "simple" out ref variables. FIXME: Shouldn't this have it's
@@ -2194,7 +2196,7 @@
 	$env = GenerateFunctionOutEnv($fn);
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		next unless grep(/out/, @{$e->{DIRECTION}});
-		ParseElementPull($e, "ndr", "r->out.", $env, 1, 1);
+		ParseElementPull($e, "ndr", $env, 1, 1);
 	}
 
 	if ($fn->{RETURN_TYPE}) {

=== modified file 'source/pidl/lib/Parse/Pidl/Util.pm'
--- a/source/pidl/lib/Parse/Pidl/Util.pm	2007-02-07 19:03:19 +0000
+++ b/source/pidl/lib/Parse/Pidl/Util.pm	2007-02-08 15:43:41 +0000
@@ -15,9 +15,31 @@
 use Parse::Pidl::Expr;
 use Parse::Pidl qw(error);
 
-#####################################################################
-# a dumper wrapper to prevent dependence on the Data::Dumper module
-# unless we actually need it
+=head1 NAME
+
+Parse::Pidl::Util - Generic utility functions for pidl
+
+=head1 SYNOPSIS
+
+use Parse::Pidl::Util;
+
+=head1 DESCRIPTION
+
+Simple module that contains a couple of trivial helper functions 
+used throughout the various pidl modules.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=cut
+
+=item B<MyDumper>
+a dumper wrapper to prevent dependence on the Data::Dumper module
+unless we actually need it
+
+=cut
+
 sub MyDumper($)
 {
 	require Data::Dumper;
@@ -25,8 +47,10 @@
 	return Data::Dumper::Dumper($s);
 }
 
-#####################################################################
-# see if a pidl property list contains a given property
+=item B<has_property>
+see if a pidl property list contains a given property
+
+=cut
 sub has_property($$)
 {
 	my($e, $p) = @_;
@@ -36,8 +60,10 @@
 	return $e->{PROPERTIES}->{$p};
 }
 
-#####################################################################
-# see if a pidl property matches a value
+=item B<property_matches>
+see if a pidl property matches a value
+
+=cut
 sub property_matches($$$)
 {
 	my($e,$p,$v) = @_;
@@ -53,16 +79,22 @@
 	return undef;
 }
 
-# return 1 if the string is a C constant
+=item B<is_constant>
+return 1 if the string is a C constant
+
+=cut
 sub is_constant($)
 {
 	my $s = shift;
-	return 1 if (defined $s && $s =~ /^\d+$/);
-	return 1 if (defined $s && $s =~ /^0x[0-9A-Fa-f]+$/);
+	return 1 if ($s =~ /^\d+$/);
+	return 1 if ($s =~ /^0x[0-9A-Fa-f]+$/);
 	return 0;
 }
 
-# return a "" quoted string, unless already quoted
+=item B<make_str>
+return a "" quoted string, unless already quoted
+
+=cut
 sub make_str($)
 {
 	my $str = shift;
@@ -72,6 +104,10 @@
 	return "\"$str\"";
 }
 
+=item B<print_uuid>
+Print C representation of a UUID.
+
+=cut
 sub print_uuid($)
 {
 	my ($uuid) = @_;
@@ -87,12 +123,14 @@
 		"{".join(',', map {"0x$_"} @node)."}}";
 }
 
+=item B<ParseExpr>
+Interpret an IDL expression, substituting particular variables.
+
+=cut
 sub ParseExpr($$$)
 {
 	my($expr, $varlist, $e) = @_;
 
-	die("Undefined value in ParseExpr") if not defined($expr);
-
 	my $x = new Parse::Pidl::Expr();
 	
 	return $x->Run($expr, sub { my $x = shift; error($e, $x); },
@@ -104,12 +142,15 @@
 		undef, undef);
 }
 
+=item B<ParseExprExt>
+Interpret an IDL expression, substituting particular variables. Can call 
+callbacks when pointers are being dereferenced or variables are being used.
+
+=cut
 sub ParseExprExt($$$$$)
 {
 	my($expr, $varlist, $e, $deref, $use) = @_;
 
-	die("Undefined value in ParseExpr") if not defined($expr);
-
 	my $x = new Parse::Pidl::Expr();
 	
 	return $x->Run($expr, sub { my $x = shift; error($e, $x); },
@@ -121,4 +162,8 @@
 		$deref, $use);
 }
 
+=back
+
+=cut
+
 1;

=== modified file 'source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm'
--- a/source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm	2007-01-03 15:34:01 +0000
+++ b/source/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm	2007-02-08 15:45:47 +0000
@@ -96,7 +96,7 @@
 $VERSION = '0.01';
 
 @ISA = qw(Exporter);
- at EXPORT_OK = qw(ReadConformance);
+ at EXPORT_OK = qw(ReadConformance ReadConformanceFH);
 
 use strict;
 
@@ -157,7 +157,7 @@
 	my ($pos,$data,$old,$new) = @_;
 
 	unless(defined($new)) {
-		error($pos, "incomplete HF_RENAME command");
+		warning($pos, "incomplete HF_RENAME command");
 		return;
 	}
 
@@ -253,6 +253,11 @@
 {
 	my ($pos,$data,$fn) = @_;
 
+	unless(defined($fn)) {
+		warning($pos, "incomplete MANUAL command");
+		return;
+	}
+
     $data->{manual}->{$fn} = 1;
 }
 
@@ -271,6 +276,11 @@
 {
 	my ($pos,$data,$field,$desc) = @_;
 
+	unless(defined($desc)) {
+		warning($pos, "incomplete FIELD_DESCRIPTION command");
+		return;
+	}
+
 	$data->{fielddescription}->{$field} = {
 		DESCRIPTION => $desc,
 		POS => $pos,
@@ -314,16 +324,26 @@
 sub ReadConformance($$)
 {
 	my ($f,$data) = @_;
-
-	$data->{override} = "";
+	my $ret;
+
+	open(IN,"<$f") or return undef;
+
+	$ret = ReadConformanceFH(*IN, $data, $f);
+
+	close(IN);
+
+	return $ret;
+}
+
+sub ReadConformanceFH($$$)
+{
+	my ($fh,$data,$f) = @_;
 
 	my $incodeblock = 0;
 
-	open(IN,"<$f") or return undef;
-
 	my $ln = 0;
 
-	foreach (<IN>) {
+	foreach (<$fh>) {
 		$ln++;
 		next if (/^#.*$/);
 		next if (/^$/);
@@ -337,7 +357,11 @@
 			$incodeblock = 0;
 			next;
 		} elsif ($incodeblock) {
-			$data->{override}.="$_\n";
+			if (exists $data->{override}) {
+				$data->{override}.="$_\n";
+			} else {
+				$data->{override} = "$_\n";
+			}
 			next;
 		}
 
@@ -349,6 +373,8 @@
 
 		my $pos = { FILE => $f, LINE => $ln };
 
+		next unless(defined($cmd));
+
 		if (not defined($field_handlers{$cmd})) {
 			warning($pos, "Unknown command `$cmd'");
 			next;
@@ -357,7 +383,13 @@
 		$field_handlers{$cmd}($pos, $data, @fields);
 	}
 
-	close(IN);
+	if ($incodeblock) {
+		warning({ FILE => $f, LINE => $ln }, 
+			"Expecting CODE END");
+		return undef;
+	}
+
+	return 1;
 }
 
 1;

=== modified file 'source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm'
--- a/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm	2007-01-05 20:52:12 +0000
+++ b/source/pidl/lib/Parse/Pidl/Wireshark/NDR.pm	2007-02-08 15:42:57 +0000
@@ -2,7 +2,7 @@
 # Samba4 NDR parser generator for IDL structures
 # Copyright tridge at samba.org 2000-2003
 # Copyright tpot at samba.org 2001,2005
-# Copyright jelmer at samba.org 2004-2005
+# Copyright jelmer at samba.org 2004-2007
 # Portions based on idl2eth.c by Ronnie Sahlberg
 # released under the GNU GPL
 
@@ -918,7 +918,9 @@
 	$parser.=$res{ett};
 	$parser.=$res{hf};
 	$parser.=$res{def};
-	$parser.=$conformance->{override};
+	if (exists ($conformance->{override})) {
+		$parser.=$conformance->{override};
+	}
 	$parser.=$res{code};
 
 	my $header = "/* autogenerated by pidl */\n\n";

=== modified file 'source/pidl/tests/samba-ndr.pl'
--- a/source/pidl/tests/samba-ndr.pl	2007-01-10 00:37:30 +0000
+++ b/source/pidl/tests/samba-ndr.pl	2007-02-08 14:17:06 +0000
@@ -4,12 +4,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 16;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
 use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer);
+use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv);
 
 my $output;
 sub print_fn($) { my $x = shift; $output.=$x; }
@@ -133,3 +133,22 @@
 	          sub { $fn->("r->in.bla"); });
 
 is($output, "if (r->in.bla == NULL) return;");
+
+# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
+$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
+is_deeply({ }, GenerateFunctionInEnv($fn));



More information about the samba-cvs mailing list