Rev 11611: Use utility function for naming pull/push/print
functions. in file:///home/jelmer/bzr.samba/SAMBA_4_0/
Jelmer Vernooij
jelmer at samba.org
Wed Feb 28 01:48:06 GMT 2007
At file:///home/jelmer/bzr.samba/SAMBA_4_0/
------------------------------------------------------------
revno: 11611
revision-id: jelmer at samba.org-20070228014756-k9hoae1822hg8fke
parent: svn-v2:21575 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 02:47:56 +0100
message:
Use utility function for naming pull/push/print functions.
modified:
source/pidl/README svn-v2:9459 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2fREADME
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/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/samba-ndr.pl svn-v2:20637 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fsamba%2dndr.pl
=== modified file 'source/pidl/README'
--- a/source/pidl/README 2006-07-05 20:49:50 +0000
+++ b/source/pidl/README 2007-02-28 01:47:56 +0000
@@ -4,7 +4,7 @@
compiler for Samba 4.
The main sources for pidl are available by Subversion on
-svn+ssh://svnanon.samba.org/samba/branches/SAMBA_4_0/source/pidl
+svn://svn.samba.org/samba/branches/SAMBA_4_0/source/pidl
Pidl works by building a parse tree from a .pidl file (a simple
dump of it's internal parse tree) or a .idl file
=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm 2007-02-26 01:03:19 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm 2007-02-28 01:47:56 +0000
@@ -12,7 +12,7 @@
@EXPORT = qw(is_charset_array);
@EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv
GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction
- NeededElement NeededType $res NeededInterface);
+ NeededElement NeededType $res NeededInterface TypeFunctionName);
use strict;
use Parse::Pidl::Typelist qw(hasType getType mapTypeName);
@@ -898,20 +898,14 @@
defined($l->{DATA_TYPE}->{NAME})) {
my $ndr_flags = CalcNdrFlags($l, $primitives, $deferred);
- my $t;
- if (ref($l->{DATA_TYPE}) eq "HASH") {
- $t = "$l->{DATA_TYPE}->{TYPE}_$l->{DATA_TYPE}->{NAME}";
- } else {
- $t = $l->{DATA_TYPE};
- }
- if (Parse::Pidl::Typelist::scalar_is_reference($t)) {
+ if (Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
$var_name = get_pointer_to($var_name);
}
$var_name = get_pointer_to($var_name);
- pidl "NDR_CHECK(ndr_pull_$t($ndr, $ndr_flags, $var_name));";
+ pidl "NDR_CHECK(".TypeFunctionName("ndr_pull", $l->{DATA_TYPE})."($ndr, $ndr_flags, $var_name));";
if (my $range = has_property($e, "range")) {
$var_name = get_value_of($var_name);
@@ -2457,7 +2451,7 @@
my ($e, $varname) = @_;
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "push", $e->{NAME}, $varname);
- fn_declare("push", $e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)") or return;
+ fn_declare("push", $e, "NTSTATUS ".TypeFunctionName("ndr_push", $e)."(struct ndr_push *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
@@ -2485,7 +2479,7 @@
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "pull", $e->{NAME}, $varname);
- fn_declare("pull", $e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)") or return;
+ fn_declare("pull", $e, "NTSTATUS ".TypeFunctionName("ndr_pull", $e)."(struct ndr_pull *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
@@ -2508,11 +2502,11 @@
my ($e, $varname) = @_;
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "print", $e->{NAME}, $varname);
- pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);";
+ pidl_hdr "void ".TypeFunctionName("ndr_print", $e)."(struct ndr_print *ndr, const char *name, $args);";
return if (has_property($e, "noprint"));
- pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)";
+ pidl "_PUBLIC_ void ".TypeFunctionName("ndr_print", $e)."(struct ndr_print *ndr, const char *name, $args)";
pidl "{";
indent;
ParseTypePrint($e, $varname);
@@ -2558,26 +2552,27 @@
# Typedefs
foreach my $d (@{$interface->{TYPES}}) {
- ($needed->{"push_$d->{NAME}"}) && ParseTypePushFunction($d, "r");
- ($needed->{"pull_$d->{NAME}"}) && ParseTypePullFunction($d, "r");
- ($needed->{"print_$d->{NAME}"}) && ParseTypePrintFunction($d, "r");
+ ($needed->{TypeFunctionName("ndr_push", $d)}) && ParseTypePushFunction($d, "r");
+ ($needed->{TypeFunctionName("ndr_pull", $d)}) && ParseTypePullFunction($d, "r");
+ ($needed->{TypeFunctionName("ndr_print", $d)}) && ParseTypePrintFunction($d, "r");
# Make sure we don't generate a function twice...
- $needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} =
- $needed->{"print_$d->{NAME}"} = 0;
+ $needed->{TypeFunctionName("ndr_push", $d)} =
+ $needed->{TypeFunctionName("ndr_pull", $d)} =
+ $needed->{TypeFunctionName("ndr_print", $d)} = 0;
($needed->{"ndr_size_$d->{NAME}"}) && ParseTypeNdrSize($d);
}
# Functions
foreach my $d (@{$interface->{FUNCTIONS}}) {
- ($needed->{"push_$d->{NAME}"}) && ParseFunctionPush($d);
- ($needed->{"pull_$d->{NAME}"}) && ParseFunctionPull($d);
- ($needed->{"print_$d->{NAME}"}) && ParseFunctionPrint($d);
+ ($needed->{"ndr_push_$d->{NAME}"}) && ParseFunctionPush($d);
+ ($needed->{"ndr_pull_$d->{NAME}"}) && ParseFunctionPull($d);
+ ($needed->{"ndr_print_$d->{NAME}"}) && ParseFunctionPrint($d);
# Make sure we don't generate a function twice...
- $needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} =
- $needed->{"print_$d->{NAME}"} = 0;
+ $needed->{"ndr_push_$d->{NAME}"} = $needed->{"ndr_pull_$d->{NAME}"} =
+ $needed->{"ndr_print_$d->{NAME}"} = 0;
}
FunctionTable($interface);
@@ -2670,13 +2665,13 @@
my @fn = ();
if ($dir eq "print") {
- push(@fn, "print_$rt");
+ push(@fn, TypeFunctionName("ndr_print", $e->{REPRESENTATION_TYPE}));
} elsif ($dir eq "pull") {
- push (@fn, "pull_$t");
+ push (@fn, TypeFunctionName("ndr_pull", $e->{TYPE}));
push (@fn, "ndr_$t\_to_$rt")
if ($rt ne $t);
} elsif ($dir eq "push") {
- push (@fn, "push_$t");
+ push (@fn, TypeFunctionName("ndr_push", $e->{TYPE}));
push (@fn, "ndr_$rt\_to_$t")
if ($rt ne $t);
} else {
@@ -2693,9 +2688,9 @@
sub NeededFunction($$)
{
my ($fn,$needed) = @_;
- $needed->{"pull_$fn->{NAME}"} = 1;
- $needed->{"push_$fn->{NAME}"} = 1;
- $needed->{"print_$fn->{NAME}"} = 1;
+ $needed->{"ndr_pull_$fn->{NAME}"} = 1;
+ $needed->{"ndr_push_$fn->{NAME}"} = 1;
+ $needed->{"ndr_print_$fn->{NAME}"} = 1;
foreach my $e (@{$fn->{ELEMENTS}}) {
$e->{PARENT} = $fn;
NeededElement($e, $_, $needed) foreach ("pull", "push", "print");
@@ -2729,17 +2724,27 @@
NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}});
foreach (reverse @{$interface->{TYPES}}) {
if (has_property($_, "public")) {
- $needed->{"pull\_$_->{NAME}"} = $needed->{"push\_$_->{NAME}"} =
- $needed->{"print\_$_->{NAME}"} = 1;
+ $needed->{TypeFunctionName("ndr_pull", $_)} = $needed->{TypeFunctionName("ndr_push", $_)} =
+ $needed->{TypeFunctionName("ndr_print", $_)} = 1;
}
- NeededType($_, $needed, "pull") if ($needed->{"pull_$_->{NAME}"});
- NeededType($_, $needed, "push") if ($needed->{"push_$_->{NAME}"});
- NeededType($_, $needed, "print") if ($needed->{"print_$_->{NAME}"});
+ NeededType($_, $needed, "pull") if ($needed->{TypeFunctionName("ndr_pull", $_)});
+ NeededType($_, $needed, "push") if ($needed->{TypeFunctionName("ndr_push", $_)});
+ NeededType($_, $needed, "print") if ($needed->{TypeFunctionName("ndr_print", $_)});
if (has_property($_, "gensize")) {
$needed->{"ndr_size_$_->{NAME}"} = 1;
}
}
}
+sub TypeFunctionName($$)
+{
+ my ($prefix, $t) = @_;
+
+ return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and
+ ($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE"));
+ return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH");
+ return "$prefix\_$t";
+}
+
1;
=== modified file 'source/pidl/tests/ndr_tagtype.pl'
--- a/source/pidl/tests/ndr_tagtype.pl 2007-02-27 23:47:07 +0000
+++ b/source/pidl/tests/ndr_tagtype.pl 2007-02-28 01:47:56 +0000
@@ -17,7 +17,7 @@
DATA_BLOB result_blob;
r.x = 13;
- if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
+ if (NT_STATUS_IS_ERR(ndr_push_STRUCT_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
return 1;
result_blob = ndr_push_blob(ndr);
@@ -56,7 +56,7 @@
DATA_BLOB result_blob;
r.x = 13;
- if (NT_STATUS_IS_ERR(ndr_push_myfn(ndr, NDR_IN, &r)))
+ if (NT_STATUS_IS_ERR(ndr_push_STRUCT_myfn(ndr, NDR_IN, &r)))
return 1;
result_blob = ndr_push_blob(ndr);
=== modified file 'source/pidl/tests/samba-ndr.pl'
--- a/source/pidl/tests/samba-ndr.pl 2007-02-21 10:31:14 +0000
+++ b/source/pidl/tests/samba-ndr.pl 2007-02-28 01:47:56 +0000
@@ -4,7 +4,7 @@
use strict;
use warnings;
-use Test::More tests => 34;
+use Test::More tests => 38;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
@@ -12,7 +12,7 @@
use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer
GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
EnvSubstituteValue NeededFunction NeededElement NeededType $res
- NeededInterface);
+ NeededInterface TypeFunctionName);
my $output;
sub print_fn($) { my $x = shift; $output.=$x; }
@@ -185,28 +185,28 @@
my $needed = {};
NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "pull", $needed);
-is_deeply($needed, { pull_foo => 1 });
+is_deeply($needed, { ndr_pull_foo => 1 });
# old settings should be kept
-$needed = { pull_foo => 0 };
+$needed = { ndr_pull_foo => 0 };
NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "pull", $needed);
-is_deeply($needed, { pull_foo => 0 });
+is_deeply($needed, { ndr_pull_foo => 0 });
# print/pull/push are independent of each other
-$needed = { pull_foo => 0 };
+$needed = { ndr_pull_foo => 0 };
NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "print", $needed);
-is_deeply($needed, { pull_foo => 0, print_foo => 1 });
+is_deeply($needed, { ndr_pull_foo => 0, ndr_print_foo => 1 });
$needed = { };
NeededFunction({ NAME => "foo", ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] }, $needed);
-is_deeply($needed, { pull_foo => 1, print_foo => 1, push_foo => 1,
- pull_bar => 1, print_bar => 1, push_bar => 1});
+is_deeply($needed, { ndr_pull_foo => 1, ndr_print_foo => 1, ndr_push_foo => 1,
+ ndr_pull_bar => 1, ndr_print_bar => 1, ndr_push_bar => 1});
# push/pull/print are always set for functions
-$needed = { pull_foo => 0 };
+$needed = { ndr_pull_foo => 0 };
NeededFunction({ NAME => "foo", ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] }, $needed);
-is_deeply($needed, { pull_foo => 1, print_foo => 1, push_foo => 1,
- pull_bar => 1, push_bar => 1, print_bar => 1});
+is_deeply($needed, { ndr_pull_foo => 1, ndr_print_foo => 1, ndr_push_foo => 1,
+ ndr_pull_bar => 1, ndr_push_bar => 1, ndr_print_bar => 1});
# public structs are always needed
$needed = {};
@@ -220,7 +220,7 @@
TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT", ELEMENTS => [] } } ] },
$needed);
-is_deeply($needed, { pull_bla => 1, push_bla => 1, print_bla => 1 });
+is_deeply($needed, { ndr_pull_bla => 1, ndr_push_bla => 1, ndr_print_bla => 1 });
# make sure types for elements are set too
$needed = {};
@@ -229,8 +229,8 @@
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] } } ] },
$needed);
-is_deeply($needed, { pull_bla => 1, pull_bar => 1, push_bla => 1, push_bar => 1,
- print_bla => 1, print_bar => 1});
+is_deeply($needed, { ndr_pull_bla => 1, ndr_pull_bar => 1, ndr_push_bla => 1, ndr_push_bar => 1,
+ ndr_print_bla => 1, ndr_print_bar => 1});
$needed = {};
NeededInterface({ TYPES => [ { PROPERTIES => { gensize => 1}, NAME => "bla",
@@ -241,13 +241,13 @@
is_deeply($needed, { ndr_size_bla => 1 });
# make sure types for elements are set too
-$needed = { pull_bla => 1 };
+$needed = { ndr_pull_bla => 1 };
NeededType({ NAME => "bla",
TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] } },
$needed, "pull");
-is_deeply($needed, { pull_bla => 1, pull_bar => 1 });
+is_deeply($needed, { ndr_pull_bla => 1, ndr_pull_bar => 1 });
$needed = {};
NeededInterface({ TYPES => [ { PROPERTIES => { public => 1},
@@ -255,8 +255,9 @@
TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "rep" } ] } } ] }, $needed);
-is_deeply($needed, { pull_bla => 1, push_bla => 1, print_bla => 1, print_rep => 1,
- pull_bar => 1, push_bar => 1,
+is_deeply($needed, { ndr_pull_bla => 1, ndr_push_bla => 1, ndr_print_bla => 1,
+ ndr_print_rep => 1,
+ ndr_pull_bar => 1, ndr_push_bar => 1,
ndr_bar_to_rep => 1, ndr_rep_to_bar => 1});
$res = "";
@@ -297,3 +298,8 @@
if (ndr_flags & NDR_BUFFERS) {
}
");
+
+is(TypeFunctionName("ndr_pull", "uint32"), "ndr_pull_uint32");
+is(TypeFunctionName("ndr_pull", {TYPE => "ENUM", NAME => "bar"}), "ndr_pull_ENUM_bar");
+is(TypeFunctionName("ndr_pull", {TYPE => "TYPEDEF", NAME => "bar", DATA => undef}), "ndr_pull_bar");
+is(TypeFunctionName("ndr_push", {TYPE => "STRUCT", NAME => "bar"}), "ndr_push_STRUCT_bar");
More information about the samba-cvs
mailing list