Rev 11606: More work towards supporting tagged types. in file:///home/jelmer/bzr.samba/SAMBA_4_0/

Jelmer Vernooij jelmer at samba.org
Tue Feb 27 23:44:40 GMT 2007


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

------------------------------------------------------------
revno: 11606
revision-id: jelmer at samba.org-20070227234431-sph4np74aq8dywrh
parent: svn-v2:21570 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Wed 2007-02-28 00:44:31 +0100
message:
  More work towards supporting tagged types.
modified:
  source/pidl/lib/Parse/Pidl/NDR.pm svn-v2:9460 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fNDR.pm
  source/pidl/lib/Parse/Pidl/Typelist.pm svn-v2:9460 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fTypelist.pm
  source/pidl/tests/ndr.pl       svn-v2:20631 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fndr.pl
  source/pidl/tests/ndr_tagtype.pl svn-v2:14727 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fndr_tagtype.pl
  source/pidl/tests/typelist.pl  svn-v2:21437 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2ftypelist.pl
=== modified file 'source/pidl/lib/Parse/Pidl/NDR.pm'
--- a/source/pidl/lib/Parse/Pidl/NDR.pm	2007-02-21 10:31:14 +0000
+++ b/source/pidl/lib/Parse/Pidl/NDR.pm	2007-02-27 23:44:31 +0000
@@ -35,7 +35,7 @@
 $VERSION = '0.01';
 @ISA = qw(Exporter);
 @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString);
- at EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement);
+ at EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type);
 
 use strict;
 use Parse::Pidl qw(warning fatal);
@@ -335,7 +335,11 @@
 sub align_type($)
 {
 	sub align_type($);
-	my $e = shift;
+	my ($e) = @_;
+
+	if (ref($e) eq "HASH" and $e->{TYPE} eq "SCALAR") {
+		return $scalar_alignment->{$e->{NAME}};
+	}
 
 	unless (hasType($e)) {
 	    # it must be an external type - all we can do is guess 
@@ -343,16 +347,16 @@
 	    return 4;
 	}
 
-	my $dt = getType($e)->{DATA};
+	my $dt = getType($e);
 
-	if ($dt->{TYPE} eq "ENUM") {
+	if ($dt->{TYPE} eq "TYPEDEF") {
+		return align_type($dt->{DATA});
+	} elsif ($dt->{TYPE} eq "ENUM") {
 		return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
 	} elsif ($dt->{TYPE} eq "BITMAP") {
 		return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
 	} elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
 		return find_largest_alignment($dt);
-	} elsif ($dt->{TYPE} eq "SCALAR") {
-		return $scalar_alignment->{$dt->{NAME}};
 	}
 
 	die("Unknown data type type $dt->{TYPE}");

=== modified file 'source/pidl/lib/Parse/Pidl/Typelist.pm'
--- a/source/pidl/lib/Parse/Pidl/Typelist.pm	2007-02-18 23:48:16 +0000
+++ b/source/pidl/lib/Parse/Pidl/Typelist.pm	2007-02-27 23:44:31 +0000
@@ -98,7 +98,9 @@
 sub getType($)
 {
 	my $t = shift;
+	return ($t) if (ref($t) eq "HASH" and not defined($t->{NAME}));
 	return undef if not hasType($t);
+	return $types{$t->{NAME}} if (ref($t) eq "HASH");
 	return $types{$t};
 }
 
@@ -113,6 +115,11 @@
 sub hasType($)
 {
 	my $t = shift;
+	if (ref($t) eq "HASH") {
+		return 1 if (defined($types{$t->{NAME}}) and 
+			$types{$t->{NAME}}->{TYPE} eq $t->{TYPE});
+		return 0;
+	}
 	return 1 if defined($types{$t});
 	return 0;
 }

=== modified file 'source/pidl/tests/ndr.pl'
--- a/source/pidl/tests/ndr.pl	2007-02-19 22:10:23 +0000
+++ b/source/pidl/tests/ndr.pl	2007-02-27 23:44:31 +0000
@@ -4,12 +4,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 12;
+use Test::More tests => 17;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
 use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement);
+use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type);
 
 # Case 1
 
@@ -203,3 +203,11 @@
 
 $ne = ParseElement($e, undef);
 is($ne->{REPRESENTATION_TYPE}, "uint8");
+
+is(align_type("uint32"), 4);
+is(align_type("uint16"), 2);
+is(align_type("uint8"), 1);
+is(align_type({ TYPE => "STRUCT", "NAME" => "bla", 
+			    ELEMENTS => [ { TYPE => "uint16" } ] }), 4);
+is(align_type({ TYPE => "STRUCT", "NAME" => "bla", 
+			    ELEMENTS => [ { TYPE => "uint8" } ] }), 4);

=== modified file 'source/pidl/tests/ndr_tagtype.pl'
--- a/source/pidl/tests/ndr_tagtype.pl	2007-02-18 16:21:28 +0000
+++ b/source/pidl/tests/ndr_tagtype.pl	2007-02-27 23:44:31 +0000
@@ -3,7 +3,7 @@
 # (C) 2005 Jelmer Vernooij. Published under the GNU GPL
 use strict;
 
-use Test::More tests => 1 * 8;
+use Test::More tests => 3 * 8;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util qw(test_samba4_ndr);
@@ -25,3 +25,42 @@
 	if (!data_blob_equal(&result_blob, &expected_blob)) 
 		return 2;
 ');
+
+test_samba4_ndr('struct-notypedef-used', '[public] struct bla { uint8 x; };
+	[public] void myfn([in] struct bla r); ',
+'
+	struct ndr_push *ndr = ndr_push_init_ctx(NULL);
+	struct bla r;
+	uint8_t expected[] = { 0x0D };
+	DATA_BLOB expected_blob = { expected, 1 };
+	DATA_BLOB result_blob;
+	r.x = 13;
+
+	if (NT_STATUS_IS_ERR(ndr_push_myfn(ndr, NDR_IN, &r)))
+		return 1;
+
+	result_blob = ndr_push_blob(ndr);
+	
+	if (!data_blob_equal(&result_blob, &expected_blob)) 
+		return 2;
+');
+
+
+test_samba4_ndr('struct-notypedef-embedded', 'struct bla { uint8 x; };
+	[public] struct myfn { struct bla r; }; ',
+'
+	struct ndr_push *ndr = ndr_push_init_ctx(NULL);
+	struct bla r;
+	uint8_t expected[] = { 0x0D };
+	DATA_BLOB expected_blob = { expected, 1 };
+	DATA_BLOB result_blob;
+	r.x = 13;
+
+	if (NT_STATUS_IS_ERR(ndr_push_myfn(ndr, NDR_IN, &r)))
+		return 1;
+
+	result_blob = ndr_push_blob(ndr);
+	
+	if (!data_blob_equal(&result_blob, &expected_blob)) 
+		return 2;
+');

=== modified file 'source/pidl/tests/typelist.pl'
--- a/source/pidl/tests/typelist.pl	2007-02-18 23:48:16 +0000
+++ b/source/pidl/tests/typelist.pl	2007-02-27 23:44:31 +0000
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 33;
+use Test::More tests => 38;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
@@ -22,15 +22,23 @@
 is("void", mapScalarType("void"));
 is("uint64_t", mapScalarType("hyper"));
 
-my $x = { TYPE => "ENUM", NAME => "foo" };
+my $x = { TYPE => "ENUM", NAME => "foo", EXTRADATA => 1 };
 addType($x);
-is($x, getType("foo"));
+is_deeply($x, getType("foo"));
 is(undef, getType("bloebla"));
+is_deeply(getType({ TYPE => "STRUCT" }), { TYPE => "STRUCT" });
+is_deeply(getType({ TYPE => "ENUM", NAME => "foo" }), $x);
+is_deeply(getType("uint16"), {
+		NAME => "uint16",
+		TYPE => "TYPEDEF",
+		DATA => { NAME => "uint16", TYPE => "SCALAR" }});
 
 is(0, typeIs("someUnknownType", "ENUM"));
 
 is(1, hasType("foo"));
 is(0, hasType("nonexistant"));
+is(0, hasType({TYPE => "ENUM", NAME => "someUnknownType"}));
+is(1, hasType({TYPE => "ENUM", NAME => "foo"}));
 
 is(1, is_scalar("uint32"));
 is(0, is_scalar("nonexistant"));



More information about the samba-cvs mailing list