svn commit: samba r7195 - in branches/SAMBA_4_0/source: build/pidl rpc_server/echo torture/rpc

jelmer at samba.org jelmer at samba.org
Thu Jun 2 13:21:11 GMT 2005


Author: jelmer
Date: 2005-06-02 13:21:11 +0000 (Thu, 02 Jun 2005)
New Revision: 7195

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7195

Log:
- Fix echo pipe
- Don't allocate strings
- Give higher preference to the [out] part of variables when they 
  are being used by another [out] variable. Also make sure that
  [in] variables never use [out] variables (i.e. switch_is() on an 
  [in] variable can no longer use an [out] variable).

Modified:
   branches/SAMBA_4_0/source/build/pidl/ndr_parser.pm
   branches/SAMBA_4_0/source/rpc_server/echo/rpc_echo.c
   branches/SAMBA_4_0/source/torture/rpc/echo.c


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/ndr_parser.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/ndr_parser.pm	2005-06-02 06:27:40 UTC (rev 7194)
+++ branches/SAMBA_4_0/source/build/pidl/ndr_parser.pm	2005-06-02 13:21:11 UTC (rev 7195)
@@ -208,16 +208,29 @@
 	return \%env;
 }
 
-sub GenerateFunctionEnv($)
+sub GenerateFunctionInEnv($)
 {
 	my $fn = shift;
 	my %env;
 
 	foreach my $e (@{$fn->{ELEMENTS}}) {
+		if (grep (/in/, @{$e->{DIRECTION}})) {
+			$env{$e->{NAME}} = "r->in.$e->{NAME}";
+		}
+	}
+
+	return \%env;
+}
+
+sub GenerateFunctionOutEnv($)
+{
+	my $fn = shift;
+	my %env;
+
+	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep (/out/, @{$e->{DIRECTION}})) {
 			$env{$e->{NAME}} = "r->out.$e->{NAME}";
-		}
-		if (grep (/in/, @{$e->{DIRECTION}})) {
+		} elsif (grep (/in/, @{$e->{DIRECTION}})) {
 			$env{$e->{NAME}} = "r->in.$e->{NAME}";
 		}
 	}
@@ -1031,13 +1044,15 @@
 
 	my $nl = Ndr::GetNextLevel($e, $l);
 	my $next_is_array = ($nl->{TYPE} eq "ARRAY");
+	my $next_is_string = (($nl->{TYPE} eq "DATA") and 
+						 ($nl->{DATA_TYPE} eq "string"));
 
 	if ($l->{POINTER_TYPE} eq "ref") {
 		unless ($l->{LEVEL} eq "TOP") {
 			pidl "NDR_CHECK(ndr_pull_ref_ptr($ndr, &_ptr_$e->{NAME}));";
 		}
 
-		unless ($next_is_array) {
+		unless ($next_is_array or $next_is_string) {
 			pidl "if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {";
 			pidl "\tNDR_ALLOC($ndr, $var_name);"; 
 			pidl "}";
@@ -1052,7 +1067,7 @@
 
 	# Don't do this for arrays, they're allocated at the actual level 
 	# of the array
-	unless ($next_is_array) { 
+	unless ($next_is_array or $next_is_string) { 
 		pidl "NDR_ALLOC($ndr, $var_name);"; 
 	} else {
 		pidl "NDR_ALLOC_SIZE($ndr, $var_name, 1);"; # FIXME: Yes, this is nasty. We allocate an array twice - once just to indicate that  it's there, then the real allocation...
@@ -1861,8 +1876,6 @@
 
 	return if util::has_property($fn, "noprint");
 
-	my $env = GenerateFunctionEnv($fn);
-
 	pidl "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, struct $fn->{NAME} *r)";
 	pidl "{";
 	indent;
@@ -1883,6 +1896,8 @@
 	pidl "ndr_print_struct(ndr, \"in\", \"$fn->{NAME}\");";
 	pidl "ndr->depth++;";
 
+	my $env = GenerateFunctionInEnv($fn);
+
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/in/,@{$e->{DIRECTION}})) {
 			ParseElementPrint($e, "r->in.$e->{NAME}", $env);
@@ -1896,6 +1911,8 @@
 	indent;
 	pidl "ndr_print_struct(ndr, \"out\", \"$fn->{NAME}\");";
 	pidl "ndr->depth++;";
+
+	$env = GenerateFunctionOutEnv($fn);
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/out/,@{$e->{DIRECTION}})) {
 			ParseElementPrint($e, "r->out.$e->{NAME}", $env);
@@ -1922,8 +1939,6 @@
 
 	return if util::has_property($fn, "nopush");
 
-	my $env = GenerateFunctionEnv($fn);
-
 	pidl fn_prefix($fn) . "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, struct $fn->{NAME} *r)";
 	pidl "{";
 	indent;
@@ -1935,6 +1950,8 @@
 	pidl "if (flags & NDR_IN) {";
 	indent;
 
+	my $env = GenerateFunctionInEnv($fn);
+
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/in/,@{$e->{DIRECTION}})) {
 			ParseElementPush($e, "ndr", "r->in.", $env, 1, 1);
@@ -1947,6 +1964,7 @@
 	pidl "if (flags & NDR_OUT) {";
 	indent;
 
+	$env = GenerateFunctionOutEnv($fn);
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		if (grep(/out/,@{$e->{DIRECTION}})) {
 			ParseElementPush($e, "ndr", "r->out.", $env, 1, 1);
@@ -2001,8 +2019,6 @@
 
 	return if util::has_property($fn, "nopull");
 
-	my $env = GenerateFunctionEnv($fn);
-
 	# pull function args
 	pidl fn_prefix($fn) . "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, int flags, struct $fn->{NAME} *r)";
 	pidl "{";
@@ -2028,6 +2044,8 @@
 		last;
 	}
 
+	my $env = GenerateFunctionInEnv($fn);
+
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		next unless (grep(/in/, @{$e->{DIRECTION}}));
 		ParseElementPull($e, "ndr", "r->in.", $env, 1, 1);
@@ -2040,8 +2058,9 @@
 		next unless (grep(/out/, @{$e->{DIRECTION}}));
 		next unless ($e->{LEVELS}[0]->{TYPE} eq "POINTER" and 
 		             $e->{LEVELS}[0]->{POINTER_TYPE} eq "ref");
+		next if (($e->{LEVELS}[1]->{TYPE} eq "DATA") and 
+				 ($e->{LEVELS}[1]->{DATA_TYPE} eq "string"));
 
-
 		if ($e->{LEVELS}[1]->{TYPE} eq "ARRAY") {
 			my $size = ParseExpr($e->{LEVELS}[1]->{SIZE_IS}, $env);
 			check_null_pointer($size);
@@ -2070,6 +2089,7 @@
 	pidl "if (flags & NDR_OUT) {";
 	indent;
 
+	$env = GenerateFunctionOutEnv($fn);
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		next unless grep(/out/, @{$e->{DIRECTION}});
 		ParseElementPull($e, "ndr", "r->out.", $env, 1, 1);

Modified: branches/SAMBA_4_0/source/rpc_server/echo/rpc_echo.c
===================================================================
--- branches/SAMBA_4_0/source/rpc_server/echo/rpc_echo.c	2005-06-02 06:27:40 UTC (rev 7194)
+++ branches/SAMBA_4_0/source/rpc_server/echo/rpc_echo.c	2005-06-02 13:21:11 UTC (rev 7195)
@@ -56,6 +56,9 @@
 static NTSTATUS echo_SourceData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SourceData *r)
 {
 	int i;
+
+	r->out.data = talloc_array(mem_ctx, uint8_t, r->in.len);
+	
 	for (i=0;i<r->in.len;i++) {
 		r->out.data[i] = i;
 	}

Modified: branches/SAMBA_4_0/source/torture/rpc/echo.c
===================================================================
--- branches/SAMBA_4_0/source/torture/rpc/echo.c	2005-06-02 06:27:40 UTC (rev 7194)
+++ branches/SAMBA_4_0/source/torture/rpc/echo.c	2005-06-02 13:21:11 UTC (rev 7195)
@@ -107,15 +107,11 @@
 	int i;
 	NTSTATUS status;
 	int len = 200000 + (random() % 5000);
-	uint8_t *data_out;
 	struct echo_SourceData r;
 
 	printf("\nTesting SourceData\n");
 
-	data_out = talloc_size(mem_ctx, len);
-
 	r.in.len = len;
-	r.out.data = data_out;
 
 	status = dcerpc_echo_SourceData(p, mem_ctx, &r);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -124,9 +120,9 @@
 	}
 
 	for (i=0;i<len;i++) {
-		uint8_t *v = (uint8_t *)data_out;
+		uint8_t *v = (uint8_t *)r.out.data;
 		if (v[i] != (i & 0xFF)) {
-			printf("bad data 0x%x at %d\n", (uint8_t)data_out[i], i);
+			printf("bad data 0x%x at %d\n", (uint8_t)r.out.data[i], i);
 			return False;
 		}
 	}
@@ -199,6 +195,7 @@
 
 	for (i=1;i<=7;i++) {
 		r.in.level = i;
+		r.out.info = talloc(mem_ctx, union echo_Info);
 
 		printf("\nTesting TestCall2 level %d\n", i);
 		status = dcerpc_echo_TestCall2(p, mem_ctx, &r);



More information about the samba-cvs mailing list