From 70ca53749862a9cf0c511ca3f89ac132d53ab1ac Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 10 Jan 2008 20:38:14 +0100 Subject: pidl: Fix samba3-cli test after Günthers formatting fixes. (This used to be commit bd4ce069b4b6d3fdc182b16060c20e6fe8e8a87d) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source4/pidl/tests/samba3-cli.pl | 69 +++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/tests/samba3-cli.pl b/source4/pidl/tests/samba3-cli.pl index 5086300e46..1b2a3c9785 100755 --- a/source4/pidl/tests/samba3-cli.pl +++ b/source4/pidl/tests/samba3-cli.pl @@ -29,31 +29,40 @@ my $x = new Parse::Pidl::Samba3::ClientNDR(); $fn = { NAME => "bar", ELEMENTS => [ ] }; $x->ParseFunction("foo", $fn); -is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx) +is($x->{res}, +"NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx) { \tstruct bar r; \tNTSTATUS status; -\t + \t/* In parameters */ -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_IN_DEBUG(bar, &r); -\t -\tstatus = cli_do_rpc_ndr(cli, mem_ctx, PI_FOO, &ndr_table_foo, NDR_BAR, &r); -\t +\t} + + status = cli_do_rpc_ndr(cli, + mem_ctx, + PI_FOO, + &ndr_table_foo, + NDR_BAR, + &r); + \tif (!NT_STATUS_IS_OK(status)) { \t\treturn status; \t} -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_OUT_DEBUG(bar, &r); -\t +\t} + \tif (NT_STATUS_IS_ERR(status)) { \t\treturn status; \t} -\t + \t/* Return variables */ -\t + \t/* Return result */ \treturn NT_STATUS_OK; } @@ -64,36 +73,46 @@ $x = new Parse::Pidl::Samba3::ClientNDR(); $fn = { NAME => "bar", ELEMENTS => [ ], RETURN_TYPE => "WERROR" }; $x->ParseFunction("foo", $fn); -is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, WERROR *werror) +is($x->{res}, +"NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + WERROR *werror) { \tstruct bar r; \tNTSTATUS status; -\t + \t/* In parameters */ -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_IN_DEBUG(bar, &r); -\t -\tstatus = cli_do_rpc_ndr(cli, mem_ctx, PI_FOO, &ndr_table_foo, NDR_BAR, &r); -\t +\t} + + status = cli_do_rpc_ndr(cli, + mem_ctx, + PI_FOO, + &ndr_table_foo, + NDR_BAR, + &r); + \tif (!NT_STATUS_IS_OK(status)) { \t\treturn status; \t} -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_OUT_DEBUG(bar, &r); -\t +\t} + \tif (NT_STATUS_IS_ERR(status)) { \t\treturn status; \t} -\t + \t/* Return variables */ -\t + \t/* Return result */ \tif (werror) { \t\t*werror = r.out.result; \t} -\t + \treturn werror_to_ntstatus(r.out.result); } -- cgit From 47fff7a1b91c3ae89b8c1c1713366d74ac3497bb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 20:19:47 +0100 Subject: pidl: Remove multiple copies of get_pointer_of and get_value_of. (This used to be commit 79344c9c5e0e38155facb0c7b16e84a0dca3d2eb) --- source4/pidl/lib/Parse/Pidl/CUtil.pm | 39 ++++++++++++++++++++++++ source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm | 27 ++-------------- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 24 +-------------- 3 files changed, 42 insertions(+), 48 deletions(-) create mode 100644 source4/pidl/lib/Parse/Pidl/CUtil.pm (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/CUtil.pm b/source4/pidl/lib/Parse/Pidl/CUtil.pm new file mode 100644 index 0000000000..bd7b16812c --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/CUtil.pm @@ -0,0 +1,39 @@ +################################################### +# C utility functions for pidl +# Copyright jelmer@samba.org 2005-2007 +# released under the GNU GPL +package Parse::Pidl::CUtil; + +require Exporter; +@ISA = qw(Exporter); +@EXPORT = qw(get_pointer_to get_value_of); +use vars qw($VERSION); +$VERSION = '0.01'; + +use strict; + +sub get_pointer_to($) +{ + my $var_name = shift; + + if ($var_name =~ /^\*(.*)$/) { + return $1; + } elsif ($var_name =~ /^\&(.*)$/) { + return "&($var_name)"; + } else { + return "&$var_name"; + } +} + +sub get_value_of($) +{ + my $var_name = shift; + + if ($var_name =~ /^\&(.*)$/) { + return $1; + } else { + return "*$var_name"; + } +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index 2e9bc0953c..36cc469ff6 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -8,10 +8,11 @@ package Parse::Pidl::Samba4::EJS; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(get_pointer_to get_value_of check_null_pointer fn_declare TypeFunctionName); +@EXPORT_OK = qw(check_null_pointer fn_declare TypeFunctionName); use strict; use Parse::Pidl::Typelist; +use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel); use Parse::Pidl::Samba4::NDR::Parser qw(GenerateStructEnv GenerateFunctionInEnv @@ -54,30 +55,6 @@ sub deindent($) $self->{tabs} = substr($self->{tabs}, 0, -1); } -sub get_pointer_to($) -{ - my $var_name = shift; - - if ($var_name =~ /^\*(.*)$/) { - return $1; - } elsif ($var_name =~ /^\&(.*)$/) { - return "&($var_name)"; - } else { - return "&$var_name"; - } -} - -sub get_value_of($) -{ - my $var_name = shift; - - if ($var_name =~ /^\&(.*)$/) { - return $1; - } else { - return "*$var_name"; - } -} - ##################################################################### # check that a variable we get from ParseExpr isn't a null pointer sub check_null_pointer($$) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index c9b48b017c..a261910c17 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -14,6 +14,7 @@ require Exporter; use strict; use Parse::Pidl::Typelist qw(hasType getType mapTypeName); use Parse::Pidl::Util qw(has_property ParseExpr ParseExprExt print_uuid); +use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(is_intree choose_header); use Parse::Pidl qw(warning); @@ -89,29 +90,6 @@ sub is_charset_array($$) return has_property($e, "charset"); } -sub get_pointer_to($) -{ - my $var_name = shift; - - if ($var_name =~ /^\*(.*)$/) { - return $1; - } elsif ($var_name =~ /^\&(.*)$/) { - return "&($var_name)"; - } else { - return "&$var_name"; - } -} - -sub get_value_of($) -{ - my $var_name = shift; - - if ($var_name =~ /^\&(.*)$/) { - return $1; - } else { - return "*$var_name"; - } -} #################################### # pidl() is our basic output routine -- cgit From 92950a9f2f300292c237a78b308d9e95fba2bed2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 01:10:59 +0100 Subject: pidl: Remove support for the "declare" keyword in the parser. (This used to be commit ea3371389226a756ba641a7fc02cfbee78663411) --- source4/pidl/idl.yp | 38 +- source4/pidl/lib/Parse/Pidl/IDL.pm | 2226 +++++++++++++++++------------------- 2 files changed, 1060 insertions(+), 1204 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/idl.yp b/source4/pidl/idl.yp index c372569a75..d2543c580c 100644 --- a/source4/pidl/idl.yp +++ b/source4/pidl/idl.yp @@ -93,7 +93,7 @@ definitions: ; -definition: function | const | typedef | declare | typedecl +definition: function | const | typedef | typedecl ; const: 'const' identifier pointers identifier '=' anytext ';' @@ -132,40 +132,6 @@ function: property_list type identifier '(' element_list2 ')' ';' }} ; -declare: 'declare' decl_type identifier';' - {{ - "TYPE" => "DECLARE", - "NAME" => $_[3], - "DATA" => $_[2], - "FILE" => $_[0]->YYData->{FILE}, - "LINE" => $_[0]->YYData->{LINE}, - }} -; - -decl_type: decl_enum | decl_bitmap | decl_union -; - -decl_enum: property_list 'enum' - {{ - "TYPE" => "ENUM", - "PROPERTIES" => $_[1] - }} -; - -decl_bitmap: property_list 'bitmap' - {{ - "TYPE" => "BITMAP", - "PROPERTIES" => $_[1] - }} -; - -decl_union: property_list 'union' - {{ - "TYPE" => "UNION", - "PROPERTIES" => $_[1] - }} -; - typedef: property_list 'typedef' type identifier array_len ';' {{ "TYPE" => "TYPEDEF", @@ -476,7 +442,7 @@ again: if (s/^([\w_]+)//) { $parser->YYData->{LAST_TOKEN} = $1; if ($1 =~ - /^(coclass|interface|const|typedef|declare|union|cpp_quote + /^(coclass|interface|const|typedef|union|cpp_quote |struct|enum|bitmap|void|unsigned|signed|import|include |importlib)$/x) { return $1; diff --git a/source4/pidl/lib/Parse/Pidl/IDL.pm b/source4/pidl/lib/Parse/Pidl/IDL.pm index e9155e4e00..5956c43e43 100644 --- a/source4/pidl/lib/Parse/Pidl/IDL.pm +++ b/source4/pidl/lib/Parse/Pidl/IDL.pm @@ -38,7 +38,7 @@ sub new { "import" => 7, "include" => 13 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { 'cpp_quote' => 11, 'importlib' => 10, @@ -124,7 +124,7 @@ sub new { } }, {#State 16 - DEFAULT => -124 + DEFAULT => -116 }, {#State 17 DEFAULT => -11 @@ -184,7 +184,7 @@ sub new { } }, {#State 26 - DEFAULT => -120 + DEFAULT => -112 }, {#State 27 ACTIONS => { @@ -206,10 +206,10 @@ sub new { ACTIONS => { "(" => 40 }, - DEFAULT => -95 + DEFAULT => -87 }, {#State 31 - DEFAULT => -93 + DEFAULT => -85 }, {#State 32 DEFAULT => -8 @@ -231,10 +231,9 @@ sub new { }, {#State 37 ACTIONS => { - "declare" => 49, - "const" => 53 + "const" => 51 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { 'typedecl' => 42, 'function' => 43, @@ -243,12 +242,11 @@ sub new { 'definition' => 48, 'property_list' => 47, 'usertype' => 46, - 'const' => 52, - 'declare' => 51, - 'struct' => 50, - 'typedef' => 55, - 'enum' => 54, - 'union' => 56 + 'const' => 50, + 'struct' => 49, + 'typedef' => 53, + 'enum' => 52, + 'union' => 54 } }, {#State 38 @@ -257,1539 +255,1482 @@ sub new { }, GOTOS => { 'identifier' => 30, - 'property' => 57 + 'property' => 55 } }, {#State 39 - DEFAULT => -92 + DEFAULT => -84 }, {#State 40 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'text' => 63, - 'listtext' => 59, - 'anytext' => 58, - 'constant' => 60 + 'identifier' => 60, + 'text' => 61, + 'listtext' => 57, + 'anytext' => 56, + 'constant' => 58 } }, {#State 41 ACTIONS => { - "}" => 64, - "interface" => 65 + "}" => 62, + "interface" => 63 } }, {#State 42 - DEFAULT => -24 + DEFAULT => -23 }, {#State 43 DEFAULT => -20 }, {#State 44 - DEFAULT => -39 + DEFAULT => -31 }, {#State 45 ACTIONS => { - "}" => 66, - "declare" => 49, - "const" => 53 + "}" => 64, + "const" => 51 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { 'typedecl' => 42, 'function' => 43, 'bitmap' => 44, - 'definition' => 67, + 'definition' => 65, 'property_list' => 47, 'usertype' => 46, - 'const' => 52, - 'struct' => 50, - 'declare' => 51, - 'typedef' => 55, - 'enum' => 54, - 'union' => 56 + 'struct' => 49, + 'const' => 50, + 'typedef' => 53, + 'enum' => 52, + 'union' => 54 } }, {#State 46 ACTIONS => { - ";" => 68 + ";" => 66 } }, {#State 47 ACTIONS => { - "typedef" => 69, + "typedef" => 67, 'IDENTIFIER' => 26, - "signed" => 77, - "union" => 70, - "enum" => 79, - "bitmap" => 80, - 'void' => 71, - "unsigned" => 81, + "signed" => 75, + "union" => 68, + "enum" => 77, + "bitmap" => 78, + 'void' => 69, + "unsigned" => 79, "[" => 20, - "struct" => 76 + "struct" => 74 }, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 82, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 80, + 'union' => 54, + 'sign' => 73 } }, {#State 48 DEFAULT => -18 }, {#State 49 - DEFAULT => -91, - GOTOS => { - 'decl_enum' => 84, - 'decl_bitmap' => 85, - 'decl_type' => 87, - 'decl_union' => 86, - 'property_list' => 83 - } + DEFAULT => -28 }, {#State 50 - DEFAULT => -36 - }, - {#State 51 - DEFAULT => -23 - }, - {#State 52 DEFAULT => -21 }, - {#State 53 + {#State 51 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 88 + 'identifier' => 81 } }, + {#State 52 + DEFAULT => -30 + }, + {#State 53 + DEFAULT => -22 + }, {#State 54 - DEFAULT => -38 + DEFAULT => -29 }, {#State 55 - DEFAULT => -22 + DEFAULT => -86 }, {#State 56 - DEFAULT => -37 + ACTIONS => { + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -89 }, {#State 57 - DEFAULT => -94 + ACTIONS => { + "," => 97, + ")" => 98 + } }, {#State 58 - ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -97 + DEFAULT => -95 }, {#State 59 - ACTIONS => { - "," => 104, - ")" => 105 - } + DEFAULT => -115 }, {#State 60 - DEFAULT => -103 + DEFAULT => -94 }, {#State 61 - DEFAULT => -123 + DEFAULT => -96 }, {#State 62 - DEFAULT => -102 - }, - {#State 63 - DEFAULT => -104 - }, - {#State 64 ACTIONS => { - ";" => 106 + ";" => 99 }, - DEFAULT => -125, + DEFAULT => -117, GOTOS => { - 'optional_semicolon' => 107 + 'optional_semicolon' => 100 } }, - {#State 65 + {#State 63 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 108 + 'identifier' => 101 } }, - {#State 66 + {#State 64 ACTIONS => { - ";" => 106 + ";" => 99 }, - DEFAULT => -125, + DEFAULT => -117, GOTOS => { - 'optional_semicolon' => 109 + 'optional_semicolon' => 102 } }, - {#State 67 + {#State 65 DEFAULT => -19 }, - {#State 68 - DEFAULT => -40 + {#State 66 + DEFAULT => -32 }, - {#State 69 + {#State 67 ACTIONS => { 'IDENTIFIER' => 26, - "signed" => 77, - 'void' => 71, - "unsigned" => 81 + "signed" => 75, + 'void' => 69, + "unsigned" => 79 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 110, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 103, + 'union' => 54, + 'sign' => 73 } }, - {#State 70 + {#State 68 ACTIONS => { - 'IDENTIFIER' => 111 + 'IDENTIFIER' => 104 }, - DEFAULT => -122, + DEFAULT => -114, GOTOS => { - 'optional_identifier' => 112 + 'optional_identifier' => 105 } }, - {#State 71 - DEFAULT => -47 + {#State 69 + DEFAULT => -39 }, - {#State 72 + {#State 70 ACTIONS => { - "union" => 70, - "enum" => 79, - "bitmap" => 80, + "union" => 68, + "enum" => 77, + "bitmap" => 78, "[" => 20, - "struct" => 76 + "struct" => 74 } }, - {#State 73 - DEFAULT => -45 + {#State 71 + DEFAULT => -37 }, - {#State 74 - DEFAULT => -44 + {#State 72 + DEFAULT => -36 }, - {#State 75 + {#State 73 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 113 + 'identifier' => 106 } }, - {#State 76 + {#State 74 ACTIONS => { - 'IDENTIFIER' => 111 + 'IDENTIFIER' => 104 }, - DEFAULT => -122, + DEFAULT => -114, GOTOS => { - 'optional_identifier' => 114 + 'optional_identifier' => 107 } }, - {#State 77 - DEFAULT => -41 - }, - {#State 78 - DEFAULT => -46 + {#State 75 + DEFAULT => -33 }, - {#State 79 - ACTIONS => { - 'IDENTIFIER' => 111 - }, - DEFAULT => -122, - GOTOS => { - 'optional_identifier' => 115 - } + {#State 76 + DEFAULT => -38 }, - {#State 80 + {#State 77 ACTIONS => { - 'IDENTIFIER' => 111 + 'IDENTIFIER' => 104 }, - DEFAULT => -122, + DEFAULT => -114, GOTOS => { - 'optional_identifier' => 116 + 'optional_identifier' => 108 } }, - {#State 81 - DEFAULT => -42 - }, - {#State 82 + {#State 78 ACTIONS => { - 'IDENTIFIER' => 26 + 'IDENTIFIER' => 104 }, + DEFAULT => -114, GOTOS => { - 'identifier' => 117 - } - }, - {#State 83 - ACTIONS => { - "union" => 118, - "enum" => 119, - "bitmap" => 120, - "[" => 20 + 'optional_identifier' => 109 } }, - {#State 84 - DEFAULT => -29 - }, - {#State 85 - DEFAULT => -30 - }, - {#State 86 - DEFAULT => -31 + {#State 79 + DEFAULT => -34 }, - {#State 87 + {#State 80 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 121 + 'identifier' => 110 } }, - {#State 88 - DEFAULT => -80, + {#State 81 + DEFAULT => -72, GOTOS => { - 'pointers' => 122 + 'pointers' => 111 } }, - {#State 89 + {#State 82 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 123, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 112, + 'text' => 61, + 'constant' => 58 } }, - {#State 90 + {#State 83 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 124, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 113, + 'text' => 61, + 'constant' => 58 } }, - {#State 91 + {#State 84 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 125, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 114, + 'text' => 61, + 'constant' => 58 } }, - {#State 92 + {#State 85 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 126, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 115, + 'text' => 61, + 'constant' => 58 } }, - {#State 93 + {#State 86 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 127, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 116, + 'text' => 61, + 'constant' => 58 } }, - {#State 94 + {#State 87 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 128, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 117, + 'text' => 61, + 'constant' => 58 } }, - {#State 95 + {#State 88 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 129, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 118, + 'text' => 61, + 'constant' => 58 } }, - {#State 96 + {#State 89 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 130, - 'text' => 63, - 'constant' => 60, - 'commalisttext' => 131 + 'identifier' => 60, + 'anytext' => 119, + 'text' => 61, + 'constant' => 58, + 'commalisttext' => 120 } }, - {#State 97 + {#State 90 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 132, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 121, + 'text' => 61, + 'constant' => 58 } }, - {#State 98 + {#State 91 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 133, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 122, + 'text' => 61, + 'constant' => 58 } }, - {#State 99 + {#State 92 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 134, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 123, + 'text' => 61, + 'constant' => 58 } }, - {#State 100 + {#State 93 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 130, - 'text' => 63, - 'constant' => 60, - 'commalisttext' => 135 + 'identifier' => 60, + 'anytext' => 119, + 'text' => 61, + 'constant' => 58, + 'commalisttext' => 124 } }, - {#State 101 + {#State 94 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 136, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 125, + 'text' => 61, + 'constant' => 58 } }, - {#State 102 + {#State 95 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 137, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 126, + 'text' => 61, + 'constant' => 58 } }, - {#State 103 + {#State 96 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 138, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 127, + 'text' => 61, + 'constant' => 58 } }, - {#State 104 + {#State 97 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 139, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 128, + 'text' => 61, + 'constant' => 58 } }, - {#State 105 - DEFAULT => -96 + {#State 98 + DEFAULT => -88 }, - {#State 106 - DEFAULT => -126 + {#State 99 + DEFAULT => -118 }, - {#State 107 + {#State 100 DEFAULT => -13 }, - {#State 108 + {#State 101 ACTIONS => { - ";" => 140 + ";" => 129 } }, - {#State 109 + {#State 102 DEFAULT => -16 }, - {#State 110 + {#State 103 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 141 + 'identifier' => 130 } }, - {#State 111 - DEFAULT => -121 + {#State 104 + DEFAULT => -113 }, - {#State 112 + {#State 105 ACTIONS => { - "{" => 143 + "{" => 132 }, - DEFAULT => -76, + DEFAULT => -68, GOTOS => { - 'union_body' => 144, - 'opt_union_body' => 142 + 'union_body' => 133, + 'opt_union_body' => 131 } }, - {#State 113 - DEFAULT => -43 + {#State 106 + DEFAULT => -35 }, - {#State 114 + {#State 107 ACTIONS => { - "{" => 146 + "{" => 135 }, - DEFAULT => -66, + DEFAULT => -58, GOTOS => { - 'struct_body' => 145, - 'opt_struct_body' => 147 + 'struct_body' => 134, + 'opt_struct_body' => 136 } }, - {#State 115 + {#State 108 ACTIONS => { - "{" => 148 + "{" => 137 }, - DEFAULT => -49, + DEFAULT => -41, GOTOS => { - 'opt_enum_body' => 150, - 'enum_body' => 149 + 'opt_enum_body' => 139, + 'enum_body' => 138 } }, - {#State 116 + {#State 109 ACTIONS => { - "{" => 152 + "{" => 141 }, - DEFAULT => -57, + DEFAULT => -49, GOTOS => { - 'bitmap_body' => 153, - 'opt_bitmap_body' => 151 + 'bitmap_body' => 142, + 'opt_bitmap_body' => 140 } }, - {#State 117 - ACTIONS => { - "(" => 154 - } - }, - {#State 118 - DEFAULT => -34 - }, - {#State 119 - DEFAULT => -32 - }, - {#State 120 - DEFAULT => -33 - }, - {#State 121 + {#State 110 ACTIONS => { - ";" => 155 + "(" => 143 } }, - {#State 122 + {#State 111 ACTIONS => { 'IDENTIFIER' => 26, - "*" => 157 + "*" => 145 }, GOTOS => { - 'identifier' => 156 + 'identifier' => 144 } }, - {#State 123 - ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -114 - }, - {#State 124 + {#State 112 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -105 + DEFAULT => -106 }, - {#State 125 + {#State 113 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -109 + DEFAULT => -97 }, - {#State 126 + {#State 114 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -117 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -101 }, - {#State 127 + {#State 115 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -116 + DEFAULT => -109 }, - {#State 128 + {#State 116 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -107 + DEFAULT => -108 }, - {#State 129 + {#State 117 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -113 + DEFAULT => -99 }, - {#State 130 + {#State 118 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -99 + DEFAULT => -105 }, - {#State 131 + {#State 119 + ACTIONS => { + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -91 + }, + {#State 120 ACTIONS => { - "}" => 158, - "," => 159 + "}" => 146, + "," => 147 } }, - {#State 132 + {#State 121 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -111 + DEFAULT => -103 }, - {#State 133 + {#State 122 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -112 + DEFAULT => -104 }, - {#State 134 + {#State 123 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -115 + DEFAULT => -107 }, - {#State 135 + {#State 124 ACTIONS => { - "," => 159, - ")" => 160 + "," => 147, + ")" => 148 } }, - {#State 136 + {#State 125 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -110 + DEFAULT => -102 }, - {#State 137 + {#State 126 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -106 + DEFAULT => -98 }, - {#State 138 + {#State 127 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -108 + DEFAULT => -100 }, - {#State 139 + {#State 128 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -98 + DEFAULT => -90 }, - {#State 140 + {#State 129 DEFAULT => -15 }, - {#State 141 + {#State 130 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 162 + 'array_len' => 150 } }, - {#State 142 - DEFAULT => -78 + {#State 131 + DEFAULT => -70 }, - {#State 143 - DEFAULT => -73, + {#State 132 + DEFAULT => -65, GOTOS => { - 'union_elements' => 163 + 'union_elements' => 151 } }, - {#State 144 - DEFAULT => -77 + {#State 133 + DEFAULT => -69 }, - {#State 145 - DEFAULT => -67 + {#State 134 + DEFAULT => -59 }, - {#State 146 - DEFAULT => -82, + {#State 135 + DEFAULT => -74, GOTOS => { - 'element_list1' => 164 + 'element_list1' => 152 } }, - {#State 147 - DEFAULT => -68 + {#State 136 + DEFAULT => -60 }, - {#State 148 + {#State 137 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 165, - 'enum_element' => 166, - 'enum_elements' => 167 + 'identifier' => 153, + 'enum_element' => 154, + 'enum_elements' => 155 } }, - {#State 149 - DEFAULT => -50 + {#State 138 + DEFAULT => -42 }, - {#State 150 - DEFAULT => -51 + {#State 139 + DEFAULT => -43 }, - {#State 151 - DEFAULT => -59 + {#State 140 + DEFAULT => -51 }, - {#State 152 + {#State 141 ACTIONS => { 'IDENTIFIER' => 26 }, - DEFAULT => -62, + DEFAULT => -54, GOTOS => { - 'identifier' => 170, - 'bitmap_element' => 169, - 'bitmap_elements' => 168, - 'opt_bitmap_elements' => 171 + 'identifier' => 158, + 'bitmap_element' => 157, + 'bitmap_elements' => 156, + 'opt_bitmap_elements' => 159 } }, - {#State 153 - DEFAULT => -58 + {#State 142 + DEFAULT => -50 }, - {#State 154 + {#State 143 ACTIONS => { - "," => -84, - "void" => 175, - ")" => -84 + "," => -76, + "void" => 163, + ")" => -76 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'base_element' => 172, - 'element_list2' => 174, - 'property_list' => 173 + 'base_element' => 160, + 'element_list2' => 162, + 'property_list' => 161 } }, - {#State 155 - DEFAULT => -28 - }, - {#State 156 + {#State 144 ACTIONS => { - "[" => 161, - "=" => 177 + "[" => 149, + "=" => 165 }, GOTOS => { - 'array_len' => 176 + 'array_len' => 164 } }, - {#State 157 - DEFAULT => -81 + {#State 145 + DEFAULT => -73 }, - {#State 158 + {#State 146 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 178, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 166, + 'text' => 61, + 'constant' => 58 } }, - {#State 159 + {#State 147 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 179, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 167, + 'text' => 61, + 'constant' => 58 } }, - {#State 160 + {#State 148 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 180, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 168, + 'text' => 61, + 'constant' => 58 } }, - {#State 161 + {#State 149 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, - "]" => 181, + "]" => 169, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 182, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 170, + 'text' => 61, + 'constant' => 58 } }, - {#State 162 + {#State 150 ACTIONS => { - ";" => 183 + ";" => 171 } }, - {#State 163 + {#State 151 ACTIONS => { - "}" => 184 + "}" => 172 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'optional_base_element' => 186, - 'property_list' => 185 + 'optional_base_element' => 174, + 'property_list' => 173 } }, - {#State 164 + {#State 152 ACTIONS => { - "}" => 187 + "}" => 175 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'base_element' => 188, - 'property_list' => 173 + 'base_element' => 176, + 'property_list' => 161 } }, - {#State 165 + {#State 153 ACTIONS => { - "=" => 189 + "=" => 177 }, - DEFAULT => -54 + DEFAULT => -46 }, - {#State 166 - DEFAULT => -52 + {#State 154 + DEFAULT => -44 }, - {#State 167 + {#State 155 ACTIONS => { - "}" => 190, - "," => 191 + "}" => 178, + "," => 179 } }, - {#State 168 + {#State 156 ACTIONS => { - "," => 192 + "," => 180 }, - DEFAULT => -63 + DEFAULT => -55 }, - {#State 169 - DEFAULT => -60 + {#State 157 + DEFAULT => -52 }, - {#State 170 + {#State 158 ACTIONS => { - "=" => 193 + "=" => 181 } }, - {#State 171 + {#State 159 ACTIONS => { - "}" => 194 + "}" => 182 } }, - {#State 172 - DEFAULT => -86 + {#State 160 + DEFAULT => -78 }, - {#State 173 + {#State 161 ACTIONS => { 'IDENTIFIER' => 26, - "signed" => 77, - 'void' => 71, - "unsigned" => 81, + "signed" => 75, + 'void' => 69, + "unsigned" => 79, "[" => 20 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 195, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 183, + 'union' => 54, + 'sign' => 73 } }, - {#State 174 + {#State 162 ACTIONS => { - "," => 196, - ")" => 197 + "," => 184, + ")" => 185 } }, - {#State 175 - DEFAULT => -85 + {#State 163 + DEFAULT => -77 }, - {#State 176 + {#State 164 ACTIONS => { - "=" => 198 + "=" => 186 } }, - {#State 177 + {#State 165 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 199, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 187, + 'text' => 61, + 'constant' => 58 } }, - {#State 178 + {#State 166 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -119 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -111 }, - {#State 179 + {#State 167 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -100 + DEFAULT => -92 }, - {#State 180 + {#State 168 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -118 + DEFAULT => -110 }, - {#State 181 + {#State 169 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 200 + 'array_len' => 188 } }, - {#State 182 + {#State 170 ACTIONS => { - "-" => 90, - ":" => 89, - "?" => 95, - "<" => 91, - "+" => 93, - "~" => 92, - "&" => 97, - "{" => 96, - "/" => 98, - "=" => 99, - "|" => 101, - "(" => 100, - "*" => 94, - "." => 102, - "]" => 201, - ">" => 103 + "-" => 83, + ":" => 82, + "?" => 88, + "<" => 84, + "+" => 86, + "~" => 85, + "&" => 90, + "{" => 89, + "/" => 91, + "=" => 92, + "|" => 94, + "(" => 93, + "*" => 87, + "." => 95, + "]" => 189, + ">" => 96 } }, - {#State 183 - DEFAULT => -35 + {#State 171 + DEFAULT => -27 }, - {#State 184 - DEFAULT => -75 + {#State 172 + DEFAULT => -67 }, - {#State 185 + {#State 173 ACTIONS => { "[" => 20 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'base_or_empty' => 202, - 'base_element' => 203, - 'empty_element' => 204, - 'property_list' => 205 + 'base_or_empty' => 190, + 'base_element' => 191, + 'empty_element' => 192, + 'property_list' => 193 } }, - {#State 186 - DEFAULT => -74 + {#State 174 + DEFAULT => -66 }, - {#State 187 - DEFAULT => -65 + {#State 175 + DEFAULT => -57 }, - {#State 188 + {#State 176 ACTIONS => { - ";" => 206 + ";" => 194 } }, - {#State 189 + {#State 177 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 207, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 195, + 'text' => 61, + 'constant' => 58 } }, - {#State 190 - DEFAULT => -48 + {#State 178 + DEFAULT => -40 }, - {#State 191 + {#State 179 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 165, - 'enum_element' => 208 + 'identifier' => 153, + 'enum_element' => 196 } }, - {#State 192 + {#State 180 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 170, - 'bitmap_element' => 209 + 'identifier' => 158, + 'bitmap_element' => 197 } }, - {#State 193 + {#State 181 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 210, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 198, + 'text' => 61, + 'constant' => 58 } }, - {#State 194 - DEFAULT => -56 + {#State 182 + DEFAULT => -48 }, - {#State 195 - DEFAULT => -80, + {#State 183 + DEFAULT => -72, GOTOS => { - 'pointers' => 211 + 'pointers' => 199 } }, - {#State 196 - DEFAULT => -91, + {#State 184 + DEFAULT => -83, GOTOS => { - 'base_element' => 212, - 'property_list' => 173 + 'base_element' => 200, + 'property_list' => 161 } }, - {#State 197 + {#State 185 ACTIONS => { - ";" => 213 + ";" => 201 } }, - {#State 198 + {#State 186 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 214, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 202, + 'text' => 61, + 'constant' => 58 } }, - {#State 199 + {#State 187 ACTIONS => { - "-" => 90, - ":" => 89, - "?" => 95, - "<" => 91, - ";" => 215, - "+" => 93, - "~" => 92, - "&" => 97, - "{" => 96, - "/" => 98, - "=" => 99, - "|" => 101, - "(" => 100, - "*" => 94, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "?" => 88, + "<" => 84, + ";" => 203, + "+" => 86, + "~" => 85, + "&" => 90, + "{" => 89, + "/" => 91, + "=" => 92, + "|" => 94, + "(" => 93, + "*" => 87, + "." => 95, + ">" => 96 } }, - {#State 200 - DEFAULT => -89 + {#State 188 + DEFAULT => -81 }, - {#State 201 + {#State 189 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 216 + 'array_len' => 204 } }, - {#State 202 - DEFAULT => -72 + {#State 190 + DEFAULT => -64 }, - {#State 203 + {#State 191 ACTIONS => { - ";" => 217 + ";" => 205 } }, - {#State 204 - DEFAULT => -71 + {#State 192 + DEFAULT => -63 }, - {#State 205 + {#State 193 ACTIONS => { 'IDENTIFIER' => 26, - "signed" => 77, - ";" => 218, - 'void' => 71, - "unsigned" => 81, + "signed" => 75, + ";" => 206, + 'void' => 69, + "unsigned" => 79, "[" => 20 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 195, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 183, + 'union' => 54, + 'sign' => 73 } }, - {#State 206 - DEFAULT => -83 + {#State 194 + DEFAULT => -75 }, - {#State 207 + {#State 195 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -55 + DEFAULT => -47 }, - {#State 208 - DEFAULT => -53 + {#State 196 + DEFAULT => -45 }, - {#State 209 - DEFAULT => -61 + {#State 197 + DEFAULT => -53 }, - {#State 210 - ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + {#State 198 + ACTIONS => { + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -64 + DEFAULT => -56 }, - {#State 211 + {#State 199 ACTIONS => { 'IDENTIFIER' => 26, - "*" => 157 + "*" => 145 }, GOTOS => { - 'identifier' => 219 + 'identifier' => 207 } }, - {#State 212 - DEFAULT => -87 + {#State 200 + DEFAULT => -79 }, - {#State 213 - DEFAULT => -27 + {#State 201 + DEFAULT => -26 }, - {#State 214 - ACTIONS => { - "-" => 90, - ":" => 89, - "?" => 95, - "<" => 91, - ";" => 220, - "+" => 93, - "~" => 92, - "&" => 97, - "{" => 96, - "/" => 98, - "=" => 99, - "|" => 101, - "(" => 100, - "*" => 94, - "." => 102, - ">" => 103 - } - }, - {#State 215 - DEFAULT => -25 + {#State 202 + ACTIONS => { + "-" => 83, + ":" => 82, + "?" => 88, + "<" => 84, + ";" => 208, + "+" => 86, + "~" => 85, + "&" => 90, + "{" => 89, + "/" => 91, + "=" => 92, + "|" => 94, + "(" => 93, + "*" => 87, + "." => 95, + ">" => 96 + } }, - {#State 216 - DEFAULT => -90 + {#State 203 + DEFAULT => -24 }, - {#State 217 - DEFAULT => -70 + {#State 204 + DEFAULT => -82 }, - {#State 218 - DEFAULT => -69 + {#State 205 + DEFAULT => -62 + }, + {#State 206 + DEFAULT => -61 }, - {#State 219 + {#State 207 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 221 + 'array_len' => 209 } }, - {#State 220 - DEFAULT => -26 + {#State 208 + DEFAULT => -25 }, - {#State 221 - DEFAULT => -79 + {#State 209 + DEFAULT => -71 } ], yyrules => @@ -1803,43 +1744,43 @@ sub new { [#Rule 2 'idl', 2, sub -#line 19 "idl.yp" +#line 19 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 3 'idl', 2, sub -#line 20 "idl.yp" +#line 20 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 4 'idl', 2, sub -#line 21 "idl.yp" +#line 21 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 5 'idl', 2, sub -#line 22 "idl.yp" +#line 22 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 6 'idl', 2, sub -#line 23 "idl.yp" +#line 23 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 7 'idl', 2, sub -#line 24 "idl.yp" +#line 24 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 8 'import', 3, sub -#line 27 "idl.yp" +#line 27 "pidl/idl.yp" {{ "TYPE" => "IMPORT", "PATHS" => $_[2], @@ -1850,7 +1791,7 @@ sub [#Rule 9 'include', 3, sub -#line 34 "idl.yp" +#line 34 "pidl/idl.yp" {{ "TYPE" => "INCLUDE", "PATHS" => $_[2], @@ -1861,7 +1802,7 @@ sub [#Rule 10 'importlib', 3, sub -#line 41 "idl.yp" +#line 41 "pidl/idl.yp" {{ "TYPE" => "IMPORTLIB", "PATHS" => $_[2], @@ -1872,19 +1813,19 @@ sub [#Rule 11 'commalist', 1, sub -#line 50 "idl.yp" +#line 50 "pidl/idl.yp" { [ $_[1] ] } ], [#Rule 12 'commalist', 3, sub -#line 51 "idl.yp" +#line 51 "pidl/idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], [#Rule 13 'coclass', 7, sub -#line 55 "idl.yp" +#line 55 "pidl/idl.yp" {{ "TYPE" => "COCLASS", "PROPERTIES" => $_[1], @@ -1900,13 +1841,13 @@ sub [#Rule 15 'interface_names', 4, sub -#line 67 "idl.yp" +#line 67 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 16 'interface', 7, sub -#line 71 "idl.yp" +#line 71 "pidl/idl.yp" {{ "TYPE" => "INTERFACE", "PROPERTIES" => $_[1], @@ -1919,7 +1860,7 @@ sub [#Rule 17 'cpp_quote', 4, sub -#line 82 "idl.yp" +#line 82 "pidl/idl.yp" {{ "TYPE" => "CPP_QUOTE", "FILE" => $_[0]->YYData->{FILE}, @@ -1930,13 +1871,13 @@ sub [#Rule 18 'definitions', 1, sub -#line 91 "idl.yp" +#line 91 "pidl/idl.yp" { [ $_[1] ] } ], [#Rule 19 'definitions', 2, sub -#line 92 "idl.yp" +#line 92 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 20 @@ -1952,12 +1893,9 @@ sub 'definition', 1, undef ], [#Rule 24 - 'definition', 1, undef - ], - [#Rule 25 'const', 7, sub -#line 100 "idl.yp" +#line 100 "pidl/idl.yp" {{ "TYPE" => "CONST", "DTYPE" => $_[2], @@ -1968,10 +1906,10 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 26 + [#Rule 25 'const', 8, sub -#line 110 "idl.yp" +#line 110 "pidl/idl.yp" {{ "TYPE" => "CONST", "DTYPE" => $_[2], @@ -1983,10 +1921,10 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 27 + [#Rule 26 'function', 7, sub -#line 124 "idl.yp" +#line 124 "pidl/idl.yp" {{ "TYPE" => "FUNCTION", "NAME" => $_[3], @@ -1997,58 +1935,10 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 28 - 'declare', 4, -sub -#line 136 "idl.yp" -{{ - "TYPE" => "DECLARE", - "NAME" => $_[3], - "DATA" => $_[2], - "FILE" => $_[0]->YYData->{FILE}, - "LINE" => $_[0]->YYData->{LINE}, - }} - ], - [#Rule 29 - 'decl_type', 1, undef - ], - [#Rule 30 - 'decl_type', 1, undef - ], - [#Rule 31 - 'decl_type', 1, undef - ], - [#Rule 32 - 'decl_enum', 2, -sub -#line 149 "idl.yp" -{{ - "TYPE" => "ENUM", - "PROPERTIES" => $_[1] - }} - ], - [#Rule 33 - 'decl_bitmap', 2, -sub -#line 156 "idl.yp" -{{ - "TYPE" => "BITMAP", - "PROPERTIES" => $_[1] - }} - ], - [#Rule 34 - 'decl_union', 2, -sub -#line 163 "idl.yp" -{{ - "TYPE" => "UNION", - "PROPERTIES" => $_[1] - }} - ], - [#Rule 35 + [#Rule 27 'typedef', 6, sub -#line 170 "idl.yp" +#line 136 "pidl/idl.yp" {{ "TYPE" => "TYPEDEF", "PROPERTIES" => $_[1], @@ -2059,67 +1949,67 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 36 + [#Rule 28 'usertype', 1, undef ], - [#Rule 37 + [#Rule 29 'usertype', 1, undef ], - [#Rule 38 + [#Rule 30 'usertype', 1, undef ], - [#Rule 39 + [#Rule 31 'usertype', 1, undef ], - [#Rule 40 + [#Rule 32 'typedecl', 2, sub -#line 183 "idl.yp" +#line 149 "pidl/idl.yp" { $_[1] } ], - [#Rule 41 + [#Rule 33 'sign', 1, undef ], - [#Rule 42 + [#Rule 34 'sign', 1, undef ], - [#Rule 43 + [#Rule 35 'existingtype', 2, sub -#line 188 "idl.yp" +#line 154 "pidl/idl.yp" { ($_[1]?$_[1]:"signed") ." $_[2]" } ], - [#Rule 44 + [#Rule 36 'existingtype', 1, undef ], - [#Rule 45 + [#Rule 37 'type', 1, undef ], - [#Rule 46 + [#Rule 38 'type', 1, undef ], - [#Rule 47 + [#Rule 39 'type', 1, sub -#line 192 "idl.yp" +#line 158 "pidl/idl.yp" { "void" } ], - [#Rule 48 + [#Rule 40 'enum_body', 3, sub -#line 194 "idl.yp" +#line 160 "pidl/idl.yp" { $_[2] } ], - [#Rule 49 + [#Rule 41 'opt_enum_body', 0, undef ], - [#Rule 50 + [#Rule 42 'opt_enum_body', 1, undef ], - [#Rule 51 + [#Rule 43 'enum', 4, sub -#line 197 "idl.yp" +#line 163 "pidl/idl.yp" {{ "TYPE" => "ENUM", "PROPERTIES" => $_[1], @@ -2127,43 +2017,43 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 52 + [#Rule 44 'enum_elements', 1, sub -#line 206 "idl.yp" +#line 172 "pidl/idl.yp" { [ $_[1] ] } ], - [#Rule 53 + [#Rule 45 'enum_elements', 3, sub -#line 207 "idl.yp" +#line 173 "pidl/idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], - [#Rule 54 + [#Rule 46 'enum_element', 1, undef ], - [#Rule 55 + [#Rule 47 'enum_element', 3, sub -#line 211 "idl.yp" +#line 177 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 56 + [#Rule 48 'bitmap_body', 3, sub -#line 214 "idl.yp" +#line 180 "pidl/idl.yp" { $_[2] } ], - [#Rule 57 + [#Rule 49 'opt_bitmap_body', 0, undef ], - [#Rule 58 + [#Rule 50 'opt_bitmap_body', 1, undef ], - [#Rule 59 + [#Rule 51 'bitmap', 4, sub -#line 217 "idl.yp" +#line 183 "pidl/idl.yp" {{ "TYPE" => "BITMAP", "PROPERTIES" => $_[1], @@ -2171,46 +2061,46 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 60 + [#Rule 52 'bitmap_elements', 1, sub -#line 226 "idl.yp" +#line 192 "pidl/idl.yp" { [ $_[1] ] } ], - [#Rule 61 + [#Rule 53 'bitmap_elements', 3, sub -#line 227 "idl.yp" +#line 193 "pidl/idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], - [#Rule 62 + [#Rule 54 'opt_bitmap_elements', 0, undef ], - [#Rule 63 + [#Rule 55 'opt_bitmap_elements', 1, undef ], - [#Rule 64 + [#Rule 56 'bitmap_element', 3, sub -#line 232 "idl.yp" +#line 198 "pidl/idl.yp" { "$_[1] ( $_[3] )" } ], - [#Rule 65 + [#Rule 57 'struct_body', 3, sub -#line 235 "idl.yp" +#line 201 "pidl/idl.yp" { $_[2] } ], - [#Rule 66 + [#Rule 58 'opt_struct_body', 0, undef ], - [#Rule 67 + [#Rule 59 'opt_struct_body', 1, undef ], - [#Rule 68 + [#Rule 60 'struct', 4, sub -#line 239 "idl.yp" +#line 205 "pidl/idl.yp" {{ "TYPE" => "STRUCT", "PROPERTIES" => $_[1], @@ -2218,10 +2108,10 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 69 + [#Rule 61 'empty_element', 2, sub -#line 248 "idl.yp" +#line 214 "pidl/idl.yp" {{ "NAME" => "", "TYPE" => "EMPTY", @@ -2232,43 +2122,43 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 70 + [#Rule 62 'base_or_empty', 2, undef ], - [#Rule 71 + [#Rule 63 'base_or_empty', 1, undef ], - [#Rule 72 + [#Rule 64 'optional_base_element', 2, sub -#line 262 "idl.yp" +#line 228 "pidl/idl.yp" { $_[2]->{PROPERTIES} = FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] } ], - [#Rule 73 + [#Rule 65 'union_elements', 0, undef ], - [#Rule 74 + [#Rule 66 'union_elements', 2, sub -#line 267 "idl.yp" +#line 233 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], - [#Rule 75 + [#Rule 67 'union_body', 3, sub -#line 270 "idl.yp" +#line 236 "pidl/idl.yp" { $_[2] } ], - [#Rule 76 + [#Rule 68 'opt_union_body', 0, undef ], - [#Rule 77 + [#Rule 69 'opt_union_body', 1, undef ], - [#Rule 78 + [#Rule 70 'union', 4, sub -#line 274 "idl.yp" +#line 240 "pidl/idl.yp" {{ "TYPE" => "UNION", "PROPERTIES" => $_[1], @@ -2276,10 +2166,10 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 79 + [#Rule 71 'base_element', 5, sub -#line 283 "idl.yp" +#line 249 "pidl/idl.yp" {{ "NAME" => $_[4], "TYPE" => $_[2], @@ -2290,241 +2180,241 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 80 + [#Rule 72 'pointers', 0, sub -#line 297 "idl.yp" +#line 263 "pidl/idl.yp" { 0 } ], - [#Rule 81 + [#Rule 73 'pointers', 2, sub -#line 298 "idl.yp" +#line 264 "pidl/idl.yp" { $_[1]+1 } ], - [#Rule 82 + [#Rule 74 'element_list1', 0, sub -#line 302 "idl.yp" +#line 268 "pidl/idl.yp" { [] } ], - [#Rule 83 + [#Rule 75 'element_list1', 3, sub -#line 303 "idl.yp" +#line 269 "pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], - [#Rule 84 + [#Rule 76 'element_list2', 0, undef ], - [#Rule 85 + [#Rule 77 'element_list2', 1, undef ], - [#Rule 86 + [#Rule 78 'element_list2', 1, sub -#line 309 "idl.yp" +#line 275 "pidl/idl.yp" { [ $_[1] ] } ], - [#Rule 87 + [#Rule 79 'element_list2', 3, sub -#line 310 "idl.yp" +#line 276 "pidl/idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], - [#Rule 88 + [#Rule 80 'array_len', 0, undef ], - [#Rule 89 + [#Rule 81 'array_len', 3, sub -#line 315 "idl.yp" +#line 281 "pidl/idl.yp" { push(@{$_[3]}, "*"); $_[3] } ], - [#Rule 90 + [#Rule 82 'array_len', 4, sub -#line 316 "idl.yp" +#line 282 "pidl/idl.yp" { push(@{$_[4]}, "$_[2]"); $_[4] } ], - [#Rule 91 + [#Rule 83 'property_list', 0, undef ], - [#Rule 92 + [#Rule 84 'property_list', 4, sub -#line 322 "idl.yp" +#line 288 "pidl/idl.yp" { FlattenHash([$_[1],$_[3]]); } ], - [#Rule 93 + [#Rule 85 'properties', 1, sub -#line 325 "idl.yp" +#line 291 "pidl/idl.yp" { $_[1] } ], - [#Rule 94 + [#Rule 86 'properties', 3, sub -#line 326 "idl.yp" +#line 292 "pidl/idl.yp" { FlattenHash([$_[1], $_[3]]); } ], - [#Rule 95 + [#Rule 87 'property', 1, sub -#line 329 "idl.yp" +#line 295 "pidl/idl.yp" {{ "$_[1]" => "1" }} ], - [#Rule 96 + [#Rule 88 'property', 4, sub -#line 330 "idl.yp" +#line 296 "pidl/idl.yp" {{ "$_[1]" => "$_[3]" }} ], - [#Rule 97 + [#Rule 89 'listtext', 1, undef ], - [#Rule 98 + [#Rule 90 'listtext', 3, sub -#line 335 "idl.yp" +#line 301 "pidl/idl.yp" { "$_[1] $_[3]" } ], - [#Rule 99 + [#Rule 91 'commalisttext', 1, undef ], - [#Rule 100 + [#Rule 92 'commalisttext', 3, sub -#line 340 "idl.yp" +#line 306 "pidl/idl.yp" { "$_[1],$_[3]" } ], - [#Rule 101 + [#Rule 93 'anytext', 0, sub -#line 344 "idl.yp" +#line 310 "pidl/idl.yp" { "" } ], - [#Rule 102 + [#Rule 94 'anytext', 1, undef ], - [#Rule 103 + [#Rule 95 'anytext', 1, undef ], - [#Rule 104 + [#Rule 96 'anytext', 1, undef ], - [#Rule 105 + [#Rule 97 'anytext', 3, sub -#line 346 "idl.yp" +#line 312 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 106 + [#Rule 98 'anytext', 3, sub -#line 347 "idl.yp" +#line 313 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 107 + [#Rule 99 'anytext', 3, sub -#line 348 "idl.yp" +#line 314 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 108 + [#Rule 100 'anytext', 3, sub -#line 349 "idl.yp" +#line 315 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 109 + [#Rule 101 'anytext', 3, sub -#line 350 "idl.yp" +#line 316 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 110 + [#Rule 102 'anytext', 3, sub -#line 351 "idl.yp" +#line 317 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 111 + [#Rule 103 'anytext', 3, sub -#line 352 "idl.yp" +#line 318 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 112 + [#Rule 104 'anytext', 3, sub -#line 353 "idl.yp" +#line 319 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 113 + [#Rule 105 'anytext', 3, sub -#line 354 "idl.yp" +#line 320 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 114 + [#Rule 106 'anytext', 3, sub -#line 355 "idl.yp" +#line 321 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 115 + [#Rule 107 'anytext', 3, sub -#line 356 "idl.yp" +#line 322 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 116 + [#Rule 108 'anytext', 3, sub -#line 357 "idl.yp" +#line 323 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 117 + [#Rule 109 'anytext', 3, sub -#line 358 "idl.yp" +#line 324 "pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 118 + [#Rule 110 'anytext', 5, sub -#line 359 "idl.yp" +#line 325 "pidl/idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], - [#Rule 119 + [#Rule 111 'anytext', 5, sub -#line 360 "idl.yp" +#line 326 "pidl/idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], - [#Rule 120 + [#Rule 112 'identifier', 1, undef ], - [#Rule 121 + [#Rule 113 'optional_identifier', 1, undef ], - [#Rule 122 + [#Rule 114 'optional_identifier', 0, undef ], - [#Rule 123 + [#Rule 115 'constant', 1, undef ], - [#Rule 124 + [#Rule 116 'text', 1, sub -#line 374 "idl.yp" +#line 340 "pidl/idl.yp" { "\"$_[1]\"" } ], - [#Rule 125 + [#Rule 117 'optional_semicolon', 0, undef ], - [#Rule 126 + [#Rule 118 'optional_semicolon', 1, undef ] ], @@ -2532,7 +2422,7 @@ sub bless($self,$class); } -#line 385 "idl.yp" +#line 351 "pidl/idl.yp" use Parse::Pidl qw(error); @@ -2627,7 +2517,7 @@ again: if (s/^([\w_]+)//) { $parser->YYData->{LAST_TOKEN} = $1; if ($1 =~ - /^(coclass|interface|const|typedef|declare|union|cpp_quote + /^(coclass|interface|const|typedef|union|cpp_quote |struct|enum|bitmap|void|unsigned|signed|import|include |importlib)$/x) { return $1; -- cgit From 87fc0a43915fcdce3ac8deea50f3fafffaa42c37 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 01:22:23 +0100 Subject: pidl: Remove support for the declare keyword in other parts of the pidl code. (This used to be commit 2fe013f715bdee6c01a833bc6c883e830bdc5dfd) --- source4/pidl/lib/Parse/Pidl/Compat.pm | 7 ------- source4/pidl/lib/Parse/Pidl/NDR.pm | 10 ++-------- source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 2 +- source4/pidl/lib/Parse/Pidl/Typelist.pm | 5 +---- 5 files changed, 5 insertions(+), 21 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Compat.pm b/source4/pidl/lib/Parse/Pidl/Compat.pm index f1241ef341..7939bb2df2 100644 --- a/source4/pidl/lib/Parse/Pidl/Compat.pm +++ b/source4/pidl/lib/Parse/Pidl/Compat.pm @@ -152,13 +152,6 @@ sub CheckInterface($) $if->{PROPERTIES}->{pointer_default_top} ne "ref") { warning($if, "pointer_default_top() is pidl-specific"); } - - foreach my $x (@{$if->{DATA}}) { - if ($x->{TYPE} eq "DECLARE") { - warning($if, "the declare keyword is pidl-specific"); - next; - } - } } sub Check($) diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index f624d2bdc0..8e7cf40d90 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -287,8 +287,6 @@ sub can_contain_deferred($) return 0 if (Parse::Pidl::Typelist::is_scalar($type)); - return 1 if ($type->{TYPE} eq "DECLARE"); # assume the worst - return can_contain_deferred($type->{DATA}) if ($type->{TYPE} eq "TYPEDEF"); return 0 unless defined($type->{ELEMENTS}); @@ -362,7 +360,7 @@ sub align_type($) my $dt = getType($e); - if ($dt->{TYPE} eq "TYPEDEF" or $dt->{TYPE} eq "DECLARE") { + 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)); @@ -650,7 +648,6 @@ sub ParseInterface($) my @consts = (); my @functions = (); my @endpoints; - my @declares = (); my $opnum = 0; my $version; @@ -667,9 +664,7 @@ sub ParseInterface($) } foreach my $d (@{$idl->{DATA}}) { - if ($d->{TYPE} eq "DECLARE") { - push (@declares, $d); - } elsif ($d->{TYPE} eq "FUNCTION") { + if ($d->{TYPE} eq "FUNCTION") { push (@functions, ParseFunction($idl, $d, \$opnum)); } elsif ($d->{TYPE} eq "CONST") { push (@consts, ParseConst($idl, $d)); @@ -701,7 +696,6 @@ sub ParseInterface($) FUNCTIONS => \@functions, CONSTS => \@consts, TYPES => \@types, - DECLARES => \@declares, ENDPOINTS => \@endpoints }; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index 36cc469ff6..fa0c97961c 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -860,7 +860,7 @@ sub TypeFunctionName($$) my ($prefix, $t) = @_; return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and - ($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE")); + $t->{TYPE} eq "TYPEDEF"); return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH"); return "$prefix\_$t"; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index a261910c17..abbfe2259b 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -2723,7 +2723,7 @@ sub TypeFunctionName($$) my ($prefix, $t) = @_; return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and - ($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE")); + $t->{TYPE} eq "TYPEDEF"); return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH"); return "$prefix\_$t"; } diff --git a/source4/pidl/lib/Parse/Pidl/Typelist.pm b/source4/pidl/lib/Parse/Pidl/Typelist.pm index b2069c784b..8fb7448070 100644 --- a/source4/pidl/lib/Parse/Pidl/Typelist.pm +++ b/source4/pidl/lib/Parse/Pidl/Typelist.pm @@ -138,8 +138,7 @@ sub is_scalar($) return 1 if (ref($type) eq "HASH" and $type->{TYPE} eq "SCALAR"); if (my $dt = getType($type)) { - return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF" or - $dt->{TYPE} eq "DECLARE"); + return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF"); return 1 if ($dt->{TYPE} eq "SCALAR" or $dt->{TYPE} eq "ENUM" or $dt->{TYPE} eq "BITMAP"); } @@ -214,7 +213,6 @@ sub mapType($$) my ($t, $n) = @_; return mapType($t->{DATA}, $n) if ($t->{TYPE} eq "TYPEDEF"); - return mapType($t->{DATA}, $n) if ($t->{TYPE} eq "DECLARE"); return mapScalarType($n) if ($t->{TYPE} eq "SCALAR"); return "enum $n" if ($t->{TYPE} eq "ENUM"); return "struct $n" if ($t->{TYPE} eq "STRUCT"); @@ -248,7 +246,6 @@ sub LoadIdl($) foreach my $y (@{$x->{DATA}}) { addType($y) if ( $y->{TYPE} eq "TYPEDEF" - or $y->{TYPE} eq "DECLARE" or $y->{TYPE} eq "UNION" or $y->{TYPE} eq "STRUCT" or $y->{TYPE} eq "ENUM" -- cgit From 6963e9b90bc1bfa1e370701e792f34fb0c3e6944 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 21:14:44 +0100 Subject: pidl: Move tests for the CUtil module to a separate file. (This used to be commit ce40890ef0166ad11dd835249f52e2ab5876efba) --- source4/pidl/tests/cutil.pl | 21 +++++++++++++++++++++ source4/pidl/tests/samba-ejs.pl | 13 ++----------- 2 files changed, 23 insertions(+), 11 deletions(-) create mode 100755 source4/pidl/tests/cutil.pl (limited to 'source4/pidl') diff --git a/source4/pidl/tests/cutil.pl b/source4/pidl/tests/cutil.pl new file mode 100755 index 0000000000..78c8bce45e --- /dev/null +++ b/source4/pidl/tests/cutil.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +# (C) 2007 Jelmer Vernooij +# Published under the GNU General Public License +use strict; +use warnings; + +use Test::More tests => 7; +use FindBin qw($RealBin); +use lib "$RealBin"; +use Util; +use Parse::Pidl::Util qw(MyDumper); +use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); + +is("&foo", get_pointer_to("foo")); +is("&(&foo)", get_pointer_to(get_pointer_to("foo"))); +is("*foo", get_pointer_to("**foo")); +is("foo", get_pointer_to("*foo")); + +is("foo", get_value_of("&foo")); +is("*foo", get_value_of("foo")); +is("**foo", get_value_of("*foo")); diff --git a/source4/pidl/tests/samba-ejs.pl b/source4/pidl/tests/samba-ejs.pl index adc00e224f..094d37a103 100755 --- a/source4/pidl/tests/samba-ejs.pl +++ b/source4/pidl/tests/samba-ejs.pl @@ -4,23 +4,14 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 10; use FindBin qw($RealBin); use lib "$RealBin"; use Util; use Parse::Pidl::Util qw(MyDumper); -use Parse::Pidl::Samba4::EJS qw(get_pointer_to get_value_of check_null_pointer +use Parse::Pidl::Samba4::EJS qw(check_null_pointer fn_declare TypeFunctionName); -is("&foo", get_pointer_to("foo")); -is("&(&foo)", get_pointer_to(get_pointer_to("foo"))); -is("*foo", get_pointer_to("**foo")); -is("foo", get_pointer_to("*foo")); - -is("foo", get_value_of("&foo")); -is("*foo", get_value_of("foo")); -is("**foo", get_value_of("*foo")); - my $ejs = new Parse::Pidl::Samba4::EJS(); $ejs->check_null_pointer("bla"); -- cgit From 1b906190091718eb16ea3754c671ebccb78a0b33 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 21:21:14 +0100 Subject: pidl: Remove declare tests, add more tests for typedef. (This used to be commit 254bf85c2eb69fc2ee22d3a92a6b027a25594250) --- source4/pidl/lib/Parse/Pidl/IDL.pm | 150 ++++++++++++++++++------------------- source4/pidl/lib/Parse/Pidl/NDR.pm | 6 +- source4/pidl/tests/ndr.pl | 11 ++- source4/pidl/tests/typelist.pl | 3 +- 4 files changed, 90 insertions(+), 80 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/IDL.pm b/source4/pidl/lib/Parse/Pidl/IDL.pm index 5956c43e43..35e1d7bcd7 100644 --- a/source4/pidl/lib/Parse/Pidl/IDL.pm +++ b/source4/pidl/lib/Parse/Pidl/IDL.pm @@ -1744,43 +1744,43 @@ sub new { [#Rule 2 'idl', 2, sub -#line 19 "pidl/idl.yp" +#line 19 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 3 'idl', 2, sub -#line 20 "pidl/idl.yp" +#line 20 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 4 'idl', 2, sub -#line 21 "pidl/idl.yp" +#line 21 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 5 'idl', 2, sub -#line 22 "pidl/idl.yp" +#line 22 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 6 'idl', 2, sub -#line 23 "pidl/idl.yp" +#line 23 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 7 'idl', 2, sub -#line 24 "pidl/idl.yp" +#line 24 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 8 'import', 3, sub -#line 27 "pidl/idl.yp" +#line 27 "idl.yp" {{ "TYPE" => "IMPORT", "PATHS" => $_[2], @@ -1791,7 +1791,7 @@ sub [#Rule 9 'include', 3, sub -#line 34 "pidl/idl.yp" +#line 34 "idl.yp" {{ "TYPE" => "INCLUDE", "PATHS" => $_[2], @@ -1802,7 +1802,7 @@ sub [#Rule 10 'importlib', 3, sub -#line 41 "pidl/idl.yp" +#line 41 "idl.yp" {{ "TYPE" => "IMPORTLIB", "PATHS" => $_[2], @@ -1813,19 +1813,19 @@ sub [#Rule 11 'commalist', 1, sub -#line 50 "pidl/idl.yp" +#line 50 "idl.yp" { [ $_[1] ] } ], [#Rule 12 'commalist', 3, sub -#line 51 "pidl/idl.yp" +#line 51 "idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], [#Rule 13 'coclass', 7, sub -#line 55 "pidl/idl.yp" +#line 55 "idl.yp" {{ "TYPE" => "COCLASS", "PROPERTIES" => $_[1], @@ -1841,13 +1841,13 @@ sub [#Rule 15 'interface_names', 4, sub -#line 67 "pidl/idl.yp" +#line 67 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 16 'interface', 7, sub -#line 71 "pidl/idl.yp" +#line 71 "idl.yp" {{ "TYPE" => "INTERFACE", "PROPERTIES" => $_[1], @@ -1860,7 +1860,7 @@ sub [#Rule 17 'cpp_quote', 4, sub -#line 82 "pidl/idl.yp" +#line 82 "idl.yp" {{ "TYPE" => "CPP_QUOTE", "FILE" => $_[0]->YYData->{FILE}, @@ -1871,13 +1871,13 @@ sub [#Rule 18 'definitions', 1, sub -#line 91 "pidl/idl.yp" +#line 91 "idl.yp" { [ $_[1] ] } ], [#Rule 19 'definitions', 2, sub -#line 92 "pidl/idl.yp" +#line 92 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 20 @@ -1895,7 +1895,7 @@ sub [#Rule 24 'const', 7, sub -#line 100 "pidl/idl.yp" +#line 100 "idl.yp" {{ "TYPE" => "CONST", "DTYPE" => $_[2], @@ -1909,7 +1909,7 @@ sub [#Rule 25 'const', 8, sub -#line 110 "pidl/idl.yp" +#line 110 "idl.yp" {{ "TYPE" => "CONST", "DTYPE" => $_[2], @@ -1924,7 +1924,7 @@ sub [#Rule 26 'function', 7, sub -#line 124 "pidl/idl.yp" +#line 124 "idl.yp" {{ "TYPE" => "FUNCTION", "NAME" => $_[3], @@ -1938,7 +1938,7 @@ sub [#Rule 27 'typedef', 6, sub -#line 136 "pidl/idl.yp" +#line 136 "idl.yp" {{ "TYPE" => "TYPEDEF", "PROPERTIES" => $_[1], @@ -1964,7 +1964,7 @@ sub [#Rule 32 'typedecl', 2, sub -#line 149 "pidl/idl.yp" +#line 149 "idl.yp" { $_[1] } ], [#Rule 33 @@ -1976,7 +1976,7 @@ sub [#Rule 35 'existingtype', 2, sub -#line 154 "pidl/idl.yp" +#line 154 "idl.yp" { ($_[1]?$_[1]:"signed") ." $_[2]" } ], [#Rule 36 @@ -1991,13 +1991,13 @@ sub [#Rule 39 'type', 1, sub -#line 158 "pidl/idl.yp" +#line 158 "idl.yp" { "void" } ], [#Rule 40 'enum_body', 3, sub -#line 160 "pidl/idl.yp" +#line 160 "idl.yp" { $_[2] } ], [#Rule 41 @@ -2009,7 +2009,7 @@ sub [#Rule 43 'enum', 4, sub -#line 163 "pidl/idl.yp" +#line 163 "idl.yp" {{ "TYPE" => "ENUM", "PROPERTIES" => $_[1], @@ -2020,13 +2020,13 @@ sub [#Rule 44 'enum_elements', 1, sub -#line 172 "pidl/idl.yp" +#line 172 "idl.yp" { [ $_[1] ] } ], [#Rule 45 'enum_elements', 3, sub -#line 173 "pidl/idl.yp" +#line 173 "idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], [#Rule 46 @@ -2035,13 +2035,13 @@ sub [#Rule 47 'enum_element', 3, sub -#line 177 "pidl/idl.yp" +#line 177 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 48 'bitmap_body', 3, sub -#line 180 "pidl/idl.yp" +#line 180 "idl.yp" { $_[2] } ], [#Rule 49 @@ -2053,7 +2053,7 @@ sub [#Rule 51 'bitmap', 4, sub -#line 183 "pidl/idl.yp" +#line 183 "idl.yp" {{ "TYPE" => "BITMAP", "PROPERTIES" => $_[1], @@ -2064,13 +2064,13 @@ sub [#Rule 52 'bitmap_elements', 1, sub -#line 192 "pidl/idl.yp" +#line 192 "idl.yp" { [ $_[1] ] } ], [#Rule 53 'bitmap_elements', 3, sub -#line 193 "pidl/idl.yp" +#line 193 "idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], [#Rule 54 @@ -2082,13 +2082,13 @@ sub [#Rule 56 'bitmap_element', 3, sub -#line 198 "pidl/idl.yp" +#line 198 "idl.yp" { "$_[1] ( $_[3] )" } ], [#Rule 57 'struct_body', 3, sub -#line 201 "pidl/idl.yp" +#line 201 "idl.yp" { $_[2] } ], [#Rule 58 @@ -2100,7 +2100,7 @@ sub [#Rule 60 'struct', 4, sub -#line 205 "pidl/idl.yp" +#line 205 "idl.yp" {{ "TYPE" => "STRUCT", "PROPERTIES" => $_[1], @@ -2111,7 +2111,7 @@ sub [#Rule 61 'empty_element', 2, sub -#line 214 "pidl/idl.yp" +#line 214 "idl.yp" {{ "NAME" => "", "TYPE" => "EMPTY", @@ -2131,7 +2131,7 @@ sub [#Rule 64 'optional_base_element', 2, sub -#line 228 "pidl/idl.yp" +#line 228 "idl.yp" { $_[2]->{PROPERTIES} = FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] } ], [#Rule 65 @@ -2140,13 +2140,13 @@ sub [#Rule 66 'union_elements', 2, sub -#line 233 "pidl/idl.yp" +#line 233 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 67 'union_body', 3, sub -#line 236 "pidl/idl.yp" +#line 236 "idl.yp" { $_[2] } ], [#Rule 68 @@ -2158,7 +2158,7 @@ sub [#Rule 70 'union', 4, sub -#line 240 "pidl/idl.yp" +#line 240 "idl.yp" {{ "TYPE" => "UNION", "PROPERTIES" => $_[1], @@ -2169,7 +2169,7 @@ sub [#Rule 71 'base_element', 5, sub -#line 249 "pidl/idl.yp" +#line 249 "idl.yp" {{ "NAME" => $_[4], "TYPE" => $_[2], @@ -2183,25 +2183,25 @@ sub [#Rule 72 'pointers', 0, sub -#line 263 "pidl/idl.yp" +#line 263 "idl.yp" { 0 } ], [#Rule 73 'pointers', 2, sub -#line 264 "pidl/idl.yp" +#line 264 "idl.yp" { $_[1]+1 } ], [#Rule 74 'element_list1', 0, sub -#line 268 "pidl/idl.yp" +#line 268 "idl.yp" { [] } ], [#Rule 75 'element_list1', 3, sub -#line 269 "pidl/idl.yp" +#line 269 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 76 @@ -2213,13 +2213,13 @@ sub [#Rule 78 'element_list2', 1, sub -#line 275 "pidl/idl.yp" +#line 275 "idl.yp" { [ $_[1] ] } ], [#Rule 79 'element_list2', 3, sub -#line 276 "pidl/idl.yp" +#line 276 "idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], [#Rule 80 @@ -2228,13 +2228,13 @@ sub [#Rule 81 'array_len', 3, sub -#line 281 "pidl/idl.yp" +#line 281 "idl.yp" { push(@{$_[3]}, "*"); $_[3] } ], [#Rule 82 'array_len', 4, sub -#line 282 "pidl/idl.yp" +#line 282 "idl.yp" { push(@{$_[4]}, "$_[2]"); $_[4] } ], [#Rule 83 @@ -2243,31 +2243,31 @@ sub [#Rule 84 'property_list', 4, sub -#line 288 "pidl/idl.yp" +#line 288 "idl.yp" { FlattenHash([$_[1],$_[3]]); } ], [#Rule 85 'properties', 1, sub -#line 291 "pidl/idl.yp" +#line 291 "idl.yp" { $_[1] } ], [#Rule 86 'properties', 3, sub -#line 292 "pidl/idl.yp" +#line 292 "idl.yp" { FlattenHash([$_[1], $_[3]]); } ], [#Rule 87 'property', 1, sub -#line 295 "pidl/idl.yp" +#line 295 "idl.yp" {{ "$_[1]" => "1" }} ], [#Rule 88 'property', 4, sub -#line 296 "pidl/idl.yp" +#line 296 "idl.yp" {{ "$_[1]" => "$_[3]" }} ], [#Rule 89 @@ -2276,7 +2276,7 @@ sub [#Rule 90 'listtext', 3, sub -#line 301 "pidl/idl.yp" +#line 301 "idl.yp" { "$_[1] $_[3]" } ], [#Rule 91 @@ -2285,13 +2285,13 @@ sub [#Rule 92 'commalisttext', 3, sub -#line 306 "pidl/idl.yp" +#line 306 "idl.yp" { "$_[1],$_[3]" } ], [#Rule 93 'anytext', 0, sub -#line 310 "pidl/idl.yp" +#line 310 "idl.yp" { "" } ], [#Rule 94 @@ -2306,91 +2306,91 @@ sub [#Rule 97 'anytext', 3, sub -#line 312 "pidl/idl.yp" +#line 312 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 98 'anytext', 3, sub -#line 313 "pidl/idl.yp" +#line 313 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 99 'anytext', 3, sub -#line 314 "pidl/idl.yp" +#line 314 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 100 'anytext', 3, sub -#line 315 "pidl/idl.yp" +#line 315 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 101 'anytext', 3, sub -#line 316 "pidl/idl.yp" +#line 316 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 102 'anytext', 3, sub -#line 317 "pidl/idl.yp" +#line 317 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 103 'anytext', 3, sub -#line 318 "pidl/idl.yp" +#line 318 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 104 'anytext', 3, sub -#line 319 "pidl/idl.yp" +#line 319 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 105 'anytext', 3, sub -#line 320 "pidl/idl.yp" +#line 320 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 106 'anytext', 3, sub -#line 321 "pidl/idl.yp" +#line 321 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 107 'anytext', 3, sub -#line 322 "pidl/idl.yp" +#line 322 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 108 'anytext', 3, sub -#line 323 "pidl/idl.yp" +#line 323 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 109 'anytext', 3, sub -#line 324 "pidl/idl.yp" +#line 324 "idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 110 'anytext', 5, sub -#line 325 "pidl/idl.yp" +#line 325 "idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], [#Rule 111 'anytext', 5, sub -#line 326 "pidl/idl.yp" +#line 326 "idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], [#Rule 112 @@ -2408,7 +2408,7 @@ sub [#Rule 116 'text', 1, sub -#line 340 "pidl/idl.yp" +#line 340 "idl.yp" { "\"$_[1]\"" } ], [#Rule 117 @@ -2422,7 +2422,7 @@ sub bless($self,$class); } -#line 351 "pidl/idl.yp" +#line 351 "idl.yp" use Parse::Pidl qw(error); diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index 8e7cf40d90..80ecec938a 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -352,9 +352,11 @@ sub align_type($) return $scalar_alignment->{$e->{NAME}}; } + return 0 if ($e eq "EMPTY"); + unless (hasType($e)) { # it must be an external type - all we can do is guess - # print "Warning: assuming alignment of unknown type '$e' is 4\n"; + # warning($e, "assuming alignment of unknown type '$e' is 4"); return 4; } @@ -367,6 +369,8 @@ sub align_type($) } 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")) { + # Struct/union without body: assume 4 + return 4 unless (defined($dt->{ELEMENTS})); return find_largest_alignment($dt); } diff --git a/source4/pidl/tests/ndr.pl b/source4/pidl/tests/ndr.pl index 1512f19d52..09f1d4969b 100755 --- a/source4/pidl/tests/ndr.pl +++ b/source4/pidl/tests/ndr.pl @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 34; +use Test::More tests => 37; use FindBin qw($RealBin); use lib "$RealBin"; use Util; @@ -212,9 +212,16 @@ is(align_type({ TYPE => "STRUCT", "NAME" => "bla", ELEMENTS => [ { TYPE => "uint16" } ] }), 4); is(align_type({ TYPE => "STRUCT", ELEMENTS => [ { TYPE => "hyper" } ] }), 8); -is(align_type({ TYPE => "DECLARE", DATA => { +is(align_type({ TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT", ELEMENTS => [ { TYPE => "hyper" } ] }}), 8); +# typedef of struct without body +is(align_type({ TYPE => "TYPEDEF", DATA => { + TYPE => "STRUCT", ELEMENTS => undef }}), 4); +# struct without body +is(align_type({ TYPE => "STRUCT", ELEMENTS => undef }), 4); +# empty struct +is(align_type({ TYPE => "STRUCT", ELEMENTS => [] }), 1); is(align_type({ TYPE => "STRUCT", "NAME" => "bla", ELEMENTS => [ { TYPE => "uint8" } ] }), 4); diff --git a/source4/pidl/tests/typelist.pl b/source4/pidl/tests/typelist.pl index c5c409a525..90cb853a52 100755 --- a/source4/pidl/tests/typelist.pl +++ b/source4/pidl/tests/typelist.pl @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 53; +use Test::More tests => 52; use FindBin qw($RealBin); use lib "$RealBin"; use Util; @@ -56,7 +56,6 @@ is(1, is_scalar({TYPE => "ENUM"})); is(0, is_scalar({TYPE => "STRUCT"})); is(1, is_scalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM" }})); is(1, is_scalar("mytypedef")); -is(1, is_scalar({TYPE => "DECLARE", DATA => {TYPE => "ENUM" }})); is(1, scalar_is_reference("string")); is(0, scalar_is_reference("uint32")); -- cgit From 79c4bd95b8ff249ad2e738c852a2fe4b6271fe12 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 21:33:18 +0100 Subject: pidl: Update documentation. (This used to be commit a13f51dae591684dbc9620f385d2fbccf31ec137) --- source4/pidl/README | 1 + source4/pidl/TODO | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl') diff --git a/source4/pidl/README b/source4/pidl/README index 5bf7752da9..d678387282 100644 --- a/source4/pidl/README +++ b/source4/pidl/README @@ -40,6 +40,7 @@ Parse::Pidl::Samba4::NDR::Server - Generates server side implementation in C Parse::Pidl::Samba4::TDR - Parser generator for the "Trivial Data Representation" Parse::Pidl::Samba4::Template - Generates stubs in C for server implementation Parse::Pidl::Samba4::EJS - Generates bindings for Embedded JavaScript (EJS) +Parse::Pidl::Samba4::Python - Generates bindings for Python -- Samba COM / DCOM -- Parse::Pidl::Samba4::COM::Proxy - Generates proxy object for DCOM (client-side) diff --git a/source4/pidl/TODO b/source4/pidl/TODO index 487d51d11e..f1cca0ab23 100644 --- a/source4/pidl/TODO +++ b/source4/pidl/TODO @@ -6,7 +6,6 @@ - compatibility mode for generating MIDL-readable data: - strip out pidl-specific properties -- remove declare in favor of typedef - make bitmap an optional attribute on enum - support nested elements - support typedefs properly (e.g. allow "typedef void **bla;") -- cgit From 0e4be859f2b681492d6f9556769afe256e9d0167 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 21:37:46 +0100 Subject: pidl: Add more parsing tests. (This used to be commit e44ee3e60ac4eb56cca02b58fdecb171269daca4) --- source4/pidl/tests/parse_idl.pl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'source4/pidl') diff --git a/source4/pidl/tests/parse_idl.pl b/source4/pidl/tests/parse_idl.pl index 96c7b2adc8..d14c374740 100755 --- a/source4/pidl/tests/parse_idl.pl +++ b/source4/pidl/tests/parse_idl.pl @@ -4,7 +4,7 @@ # Published under the GNU General Public License use strict; -use Test::More tests => 65 * 2 + 3; +use Test::More tests => 65 * 2 + 5; use FindBin qw($RealBin); use lib "$RealBin"; use Util qw(test_errors); @@ -129,4 +129,20 @@ is_deeply($x, [ { 'FILE' => '', 'DATA' => '"foobar"', 'TYPE' => 'CPP_QUOTE', 'LINE' => 0 } ]); +# A typedef of a struct without body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct x y; }", ""); +is_deeply($x, + [ { 'FILE' => '', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { + TYPE => 'STRUCT', NAME => 'x' } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); + +# A typedef of a struct with empty body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct {} y; }", ""); + +is_deeply($x, + [ { 'FILE' => '', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { + TYPE => 'STRUCT', ELEMENTS => [] } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); -- cgit From 7a43cba72325a0e190dd7b6ce0ceab3893e1205a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 22:00:14 +0100 Subject: pidl: Add CPAN metadata. (This used to be commit 7569fd5fce55fdc5c2639ec5c0a8e39e37a21fe8) --- source4/pidl/MANIFEST | 2 +- source4/pidl/META.yml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 source4/pidl/META.yml (limited to 'source4/pidl') diff --git a/source4/pidl/MANIFEST b/source4/pidl/MANIFEST index 7f30c3ab54..051c5d2b19 100644 --- a/source4/pidl/MANIFEST +++ b/source4/pidl/MANIFEST @@ -40,4 +40,4 @@ idl.yp TODO README pidl -META.yml Module meta-data (added by MakeMaker) +META.yml diff --git a/source4/pidl/META.yml b/source4/pidl/META.yml new file mode 100644 index 0000000000..4822b50f09 --- /dev/null +++ b/source4/pidl/META.yml @@ -0,0 +1,18 @@ +name: Parse-Pidl +abstract: Generate parsers / DCE/RPC-clients from IDL +author: + - Andrew Tridgell + - Jelmer Vernooij + - Stefan Metzmacher + - Tim Potter +license: gplv3 +installdirs: site +homepage: http://www.samba.org/ +bugtracker: http://bugzilla.samba.org/ +requires: + Parse::Yapp: 0 +recommends: + Data::Dumper: 0 +meta-spec: + version: 1.3 + url: http://module-build.sourceforge.net/META-spec-v1.3.html -- cgit From c9e39b1d908e88fb6c6f3ff245827050a60ba851 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 22:03:05 +0100 Subject: pidl: Remove obsolete smb_interfaces code. (This used to be commit 169e91b07c29a69113f40214543be2653d7fecf5) --- source4/pidl/smb_interfaces.pm | 1272 ---------------------------------------- source4/pidl/smb_interfaces.yp | 233 -------- 2 files changed, 1505 deletions(-) delete mode 100644 source4/pidl/smb_interfaces.pm delete mode 100644 source4/pidl/smb_interfaces.yp (limited to 'source4/pidl') diff --git a/source4/pidl/smb_interfaces.pm b/source4/pidl/smb_interfaces.pm deleted file mode 100644 index c9cc4495b1..0000000000 --- a/source4/pidl/smb_interfaces.pm +++ /dev/null @@ -1,1272 +0,0 @@ -#################################################################### -# -# This file was generated using Parse::Yapp version 1.05. -# -# Don't edit this file, use source file instead. -# -# ANY CHANGE MADE HERE WILL BE LOST ! -# -#################################################################### -package smb_interfaces; -use vars qw ( @ISA ); -use strict; - -@ISA= qw ( Parse::Yapp::Driver ); -#Included Parse/Yapp/Driver.pm file---------------------------------------- -{ -# -# Module Parse::Yapp::Driver -# -# This module is part of the Parse::Yapp package available on your -# nearest CPAN -# -# Any use of this module in a standalone parser make the included -# text under the same copyright as the Parse::Yapp module itself. -# -# This notice should remain unchanged. -# -# (c) Copyright 1998-2001 Francois Desarmenien, all rights reserved. -# (see the pod text in Parse::Yapp module for use and distribution rights) -# - -package Parse::Yapp::Driver; - -require 5.004; - -use strict; - -use vars qw ( $VERSION $COMPATIBLE $FILENAME ); - -$VERSION = '1.05'; -$COMPATIBLE = '0.07'; -$FILENAME=__FILE__; - -use Carp; - -#Known parameters, all starting with YY (leading YY will be discarded) -my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '', - YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => ''); -#Mandatory parameters -my(@params)=('LEX','RULES','STATES'); - -sub new { - my($class)=shift; - my($errst,$nberr,$token,$value,$check,$dotpos); - my($self)={ ERROR => \&_Error, - ERRST => \$errst, - NBERR => \$nberr, - TOKEN => \$token, - VALUE => \$value, - DOTPOS => \$dotpos, - STACK => [], - DEBUG => 0, - CHECK => \$check }; - - _CheckParams( [], \%params, \@_, $self ); - - exists($$self{VERSION}) - and $$self{VERSION} < $COMPATIBLE - and croak "Yapp driver version $VERSION ". - "incompatible with version $$self{VERSION}:\n". - "Please recompile parser module."; - - ref($class) - and $class=ref($class); - - bless($self,$class); -} - -sub YYParse { - my($self)=shift; - my($retval); - - _CheckParams( \@params, \%params, \@_, $self ); - - if($$self{DEBUG}) { - _DBLoad(); - $retval = eval '$self->_DBParse()';#Do not create stab entry on compile - $@ and die $@; - } - else { - $retval = $self->_Parse(); - } - $retval -} - -sub YYData { - my($self)=shift; - - exists($$self{USER}) - or $$self{USER}={}; - - $$self{USER}; - -} - -sub YYErrok { - my($self)=shift; - - ${$$self{ERRST}}=0; - undef; -} - -sub YYNberr { - my($self)=shift; - - ${$$self{NBERR}}; -} - -sub YYRecovering { - my($self)=shift; - - ${$$self{ERRST}} != 0; -} - -sub YYAbort { - my($self)=shift; - - ${$$self{CHECK}}='ABORT'; - undef; -} - -sub YYAccept { - my($self)=shift; - - ${$$self{CHECK}}='ACCEPT'; - undef; -} - -sub YYError { - my($self)=shift; - - ${$$self{CHECK}}='ERROR'; - undef; -} - -sub YYSemval { - my($self)=shift; - my($index)= $_[0] - ${$$self{DOTPOS}} - 1; - - $index < 0 - and -$index <= @{$$self{STACK}} - and return $$self{STACK}[$index][1]; - - undef; #Invalid index -} - -sub YYCurtok { - my($self)=shift; - - @_ - and ${$$self{TOKEN}}=$_[0]; - ${$$self{TOKEN}}; -} - -sub YYCurval { - my($self)=shift; - - @_ - and ${$$self{VALUE}}=$_[0]; - ${$$self{VALUE}}; -} - -sub YYExpect { - my($self)=shift; - - keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}} -} - -sub YYLexer { - my($self)=shift; - - $$self{LEX}; -} - - -################# -# Private stuff # -################# - - -sub _CheckParams { - my($mandatory,$checklist,$inarray,$outhash)=@_; - my($prm,$value); - my($prmlst)={}; - - while(($prm,$value)=splice(@$inarray,0,2)) { - $prm=uc($prm); - exists($$checklist{$prm}) - or croak("Unknow parameter '$prm'"); - ref($value) eq $$checklist{$prm} - or croak("Invalid value for parameter '$prm'"); - $prm=unpack('@2A*',$prm); - $$outhash{$prm}=$value; - } - for (@$mandatory) { - exists($$outhash{$_}) - or croak("Missing mandatory parameter '".lc($_)."'"); - } -} - -sub _Error { - print "Parse error.\n"; -} - -sub _DBLoad { - { - no strict 'refs'; - - exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ? - and return; - } - my($fname)=__FILE__; - my(@drv); - open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname"; - while() { - /^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/ - and do { - s/^#DBG>//; - push(@drv,$_); - } - } - close(DRV); - - $drv[0]=~s/_P/_DBP/; - eval join('',@drv); -} - -#Note that for loading debugging version of the driver, -#this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive. -#So, DO NOT remove comment at end of sub !!! -sub _Parse { - my($self)=shift; - - my($rules,$states,$lex,$error) - = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' }; - my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos) - = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' }; - -#DBG> my($debug)=$$self{DEBUG}; -#DBG> my($dbgerror)=0; - -#DBG> my($ShowCurToken) = sub { -#DBG> my($tok)='>'; -#DBG> for (split('',$$token)) { -#DBG> $tok.= (ord($_) < 32 or ord($_) > 126) -#DBG> ? sprintf('<%02X>',ord($_)) -#DBG> : $_; -#DBG> } -#DBG> $tok.='<'; -#DBG> }; - - $$errstatus=0; - $$nberror=0; - ($$token,$$value)=(undef,undef); - @$stack=( [ 0, undef ] ); - $$check=''; - - while(1) { - my($actions,$act,$stateno); - - $stateno=$$stack[-1][0]; - $actions=$$states[$stateno]; - -#DBG> print STDERR ('-' x 40),"\n"; -#DBG> $debug & 0x2 -#DBG> and print STDERR "In state $stateno:\n"; -#DBG> $debug & 0x08 -#DBG> and print STDERR "Stack:[". -#DBG> join(',',map { $$_[0] } @$stack). -#DBG> "]\n"; - - - if (exists($$actions{ACTIONS})) { - - defined($$token) - or do { - ($$token,$$value)=&$lex($self); -#DBG> $debug & 0x01 -#DBG> and print STDERR "Need token. Got ".&$ShowCurToken."\n"; - }; - - $act= exists($$actions{ACTIONS}{$$token}) - ? $$actions{ACTIONS}{$$token} - : exists($$actions{DEFAULT}) - ? $$actions{DEFAULT} - : undef; - } - else { - $act=$$actions{DEFAULT}; -#DBG> $debug & 0x01 -#DBG> and print STDERR "Don't need token.\n"; - } - - defined($act) - and do { - - $act > 0 - and do { #shift - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Shift and go to state $act.\n"; - - $$errstatus - and do { - --$$errstatus; - -#DBG> $debug & 0x10 -#DBG> and $dbgerror -#DBG> and $$errstatus == 0 -#DBG> and do { -#DBG> print STDERR "**End of Error recovery.\n"; -#DBG> $dbgerror=0; -#DBG> }; - }; - - - push(@$stack,[ $act, $$value ]); - - $$token ne '' #Don't eat the eof - and $$token=$$value=undef; - next; - }; - - #reduce - my($lhs,$len,$code,@sempar,$semval); - ($lhs,$len,$code)=@{$$rules[-$act]}; - -#DBG> $debug & 0x04 -#DBG> and $act -#DBG> and print STDERR "Reduce using rule ".-$act." ($lhs,$len): "; - - $act - or $self->YYAccept(); - - $$dotpos=$len; - - unpack('A1',$lhs) eq '@' #In line rule - and do { - $lhs =~ /^\@[0-9]+\-([0-9]+)$/ - or die "In line rule name '$lhs' ill formed: ". - "report it as a BUG.\n"; - $$dotpos = $1; - }; - - @sempar = $$dotpos - ? map { $$_[1] } @$stack[ -$$dotpos .. -1 ] - : (); - - $semval = $code ? &$code( $self, @sempar ) - : @sempar ? $sempar[0] : undef; - - splice(@$stack,-$len,$len); - - $$check eq 'ACCEPT' - and do { - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Accept.\n"; - - return($semval); - }; - - $$check eq 'ABORT' - and do { - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Abort.\n"; - - return(undef); - - }; - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Back to state $$stack[-1][0], then "; - - $$check eq 'ERROR' - or do { -#DBG> $debug & 0x04 -#DBG> and print STDERR -#DBG> "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n"; - -#DBG> $debug & 0x10 -#DBG> and $dbgerror -#DBG> and $$errstatus == 0 -#DBG> and do { -#DBG> print STDERR "**End of Error recovery.\n"; -#DBG> $dbgerror=0; -#DBG> }; - - push(@$stack, - [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]); - $$check=''; - next; - }; - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Forced Error recovery.\n"; - - $$check=''; - - }; - - #Error - $$errstatus - or do { - - $$errstatus = 1; - &$error($self); - $$errstatus # if 0, then YYErrok has been called - or next; # so continue parsing - -#DBG> $debug & 0x10 -#DBG> and do { -#DBG> print STDERR "**Entering Error recovery.\n"; -#DBG> ++$dbgerror; -#DBG> }; - - ++$$nberror; - - }; - - $$errstatus == 3 #The next token is not valid: discard it - and do { - $$token eq '' # End of input: no hope - and do { -#DBG> $debug & 0x10 -#DBG> and print STDERR "**At eof: aborting.\n"; - return(undef); - }; - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n"; - - $$token=$$value=undef; - }; - - $$errstatus=3; - - while( @$stack - and ( not exists($$states[$$stack[-1][0]]{ACTIONS}) - or not exists($$states[$$stack[-1][0]]{ACTIONS}{error}) - or $$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) { - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**Pop state $$stack[-1][0].\n"; - - pop(@$stack); - } - - @$stack - or do { - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**No state left on stack: aborting.\n"; - - return(undef); - }; - - #shift the error token - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**Shift \$error token and go to state ". -#DBG> $$states[$$stack[-1][0]]{ACTIONS}{error}. -#DBG> ".\n"; - - push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]); - - } - - #never reached - croak("Error in driver logic. Please, report it as a BUG"); - -}#_Parse -#DO NOT remove comment - -1; - -} -#End of include-------------------------------------------------- - - - - -sub new { - my($class)=shift; - ref($class) - and $class=ref($class); - - my($self)=$class->SUPER::new( yyversion => '1.05', - yystates => -[ - {#State 0 - ACTIONS => { - 'UNION' => 5, - 'ENUM' => 1, - 'TYPEDEF' => 7, - 'STRUCT' => 2 - }, - GOTOS => { - 'struct' => 6, - 'enum' => 9, - 'typedef' => 8, - 'union' => 10, - 'definitions' => 3, - 'definition' => 4 - } - }, - {#State 1 - ACTIONS => { - 'IDENTIFIER' => 11 - } - }, - {#State 2 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 13 - } - }, - {#State 3 - ACTIONS => { - '' => 14, - 'UNION' => 5, - 'ENUM' => 1, - 'TYPEDEF' => 7, - 'STRUCT' => 2 - }, - GOTOS => { - 'struct' => 6, - 'typedef' => 8, - 'enum' => 9, - 'union' => 10, - 'definition' => 15 - } - }, - {#State 4 - DEFAULT => -1 - }, - {#State 5 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 16 - } - }, - {#State 6 - DEFAULT => -3 - }, - {#State 7 - ACTIONS => { - 'STRUCT' => 17 - } - }, - {#State 8 - DEFAULT => -5 - }, - {#State 9 - DEFAULT => -6 - }, - {#State 10 - DEFAULT => -4 - }, - {#State 11 - ACTIONS => { - "{" => 18 - } - }, - {#State 12 - DEFAULT => -32 - }, - {#State 13 - ACTIONS => { - "{" => 19 - } - }, - {#State 14 - DEFAULT => 0 - }, - {#State 15 - DEFAULT => -2 - }, - {#State 16 - ACTIONS => { - "{" => 20 - } - }, - {#State 17 - ACTIONS => { - "{" => 21 - } - }, - {#State 18 - ACTIONS => { - 'IDENTIFIER' => 22 - }, - GOTOS => { - 'enum_identifiers' => 23, - 'enum_identifier' => 24 - } - }, - {#State 19 - DEFAULT => -15, - GOTOS => { - 'elements' => 25 - } - }, - {#State 20 - DEFAULT => -15, - GOTOS => { - 'elements' => 26 - } - }, - {#State 21 - DEFAULT => -15, - GOTOS => { - 'elements' => 27 - } - }, - {#State 22 - ACTIONS => { - "=" => 28 - }, - DEFAULT => -13 - }, - {#State 23 - ACTIONS => { - "}" => 29, - "," => 30 - } - }, - {#State 24 - DEFAULT => -11 - }, - {#State 25 - ACTIONS => { - "}" => 31, - 'UNION' => 37, - 'IDENTIFIER' => 33, - 'ENUM' => 32, - 'STRUCT' => 35, - 'CONST' => 34 - }, - GOTOS => { - 'struct' => 38, - 'type' => 39, - 'union' => 40, - 'element' => 36 - } - }, - {#State 26 - ACTIONS => { - "}" => 41, - 'UNION' => 37, - 'IDENTIFIER' => 33, - 'ENUM' => 32, - 'STRUCT' => 35, - 'CONST' => 34 - }, - GOTOS => { - 'struct' => 38, - 'type' => 39, - 'union' => 40, - 'element' => 36 - } - }, - {#State 27 - ACTIONS => { - "}" => 42, - 'UNION' => 37, - 'IDENTIFIER' => 33, - 'ENUM' => 32, - 'STRUCT' => 35, - 'CONST' => 34 - }, - GOTOS => { - 'struct' => 38, - 'type' => 39, - 'union' => 40, - 'element' => 36 - } - }, - {#State 28 - ACTIONS => { - 'IDENTIFIER' => 43 - } - }, - {#State 29 - ACTIONS => { - ";" => 44 - } - }, - {#State 30 - ACTIONS => { - 'IDENTIFIER' => 22 - }, - GOTOS => { - 'enum_identifier' => 45 - } - }, - {#State 31 - DEFAULT => -28, - GOTOS => { - 'pointers' => 46 - } - }, - {#State 32 - ACTIONS => { - 'IDENTIFIER' => 47 - } - }, - {#State 33 - DEFAULT => -26 - }, - {#State 34 - ACTIONS => { - 'IDENTIFIER' => 33, - 'ENUM' => 32 - }, - GOTOS => { - 'type' => 48 - } - }, - {#State 35 - ACTIONS => { - 'IDENTIFIER' => 49 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 13 - } - }, - {#State 36 - DEFAULT => -16 - }, - {#State 37 - ACTIONS => { - 'IDENTIFIER' => 50 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 16 - } - }, - {#State 38 - DEFAULT => -18 - }, - {#State 39 - DEFAULT => -28, - GOTOS => { - 'pointers' => 51 - } - }, - {#State 40 - DEFAULT => -19 - }, - {#State 41 - DEFAULT => -28, - GOTOS => { - 'pointers' => 52 - } - }, - {#State 42 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 53 - } - }, - {#State 43 - DEFAULT => -14 - }, - {#State 44 - DEFAULT => -10 - }, - {#State 45 - DEFAULT => -12 - }, - {#State 46 - ACTIONS => { - 'IDENTIFIER' => 12, - "*" => 55 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 54, - 'optional_identifiers' => 56 - } - }, - {#State 47 - DEFAULT => -27 - }, - {#State 48 - DEFAULT => -28, - GOTOS => { - 'pointers' => 57 - } - }, - {#State 49 - ACTIONS => { - "{" => -32 - }, - DEFAULT => -28, - GOTOS => { - 'pointers' => 58 - } - }, - {#State 50 - ACTIONS => { - "{" => -32 - }, - DEFAULT => -28, - GOTOS => { - 'pointers' => 59 - } - }, - {#State 51 - ACTIONS => { - 'IDENTIFIER' => 60, - "*" => 55 - } - }, - {#State 52 - ACTIONS => { - 'IDENTIFIER' => 12, - "*" => 55 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 61 - } - }, - {#State 53 - ACTIONS => { - ";" => 62 - } - }, - {#State 54 - DEFAULT => -30 - }, - {#State 55 - DEFAULT => -29 - }, - {#State 56 - ACTIONS => { - ";" => 63, - "," => 64 - } - }, - {#State 57 - ACTIONS => { - 'IDENTIFIER' => 65, - "*" => 55 - } - }, - {#State 58 - ACTIONS => { - 'IDENTIFIER' => 66, - "*" => 55 - } - }, - {#State 59 - ACTIONS => { - 'IDENTIFIER' => 67, - "*" => 55 - } - }, - {#State 60 - ACTIONS => { - "[" => 69 - }, - DEFAULT => -24, - GOTOS => { - 'array' => 68 - } - }, - {#State 61 - ACTIONS => { - ";" => 70 - } - }, - {#State 62 - DEFAULT => -9 - }, - {#State 63 - DEFAULT => -7 - }, - {#State 64 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 71 - } - }, - {#State 65 - ACTIONS => { - "[" => 69 - }, - DEFAULT => -24, - GOTOS => { - 'array' => 72 - } - }, - {#State 66 - ACTIONS => { - ";" => 73 - } - }, - {#State 67 - ACTIONS => { - ";" => 74 - } - }, - {#State 68 - ACTIONS => { - ";" => 75 - } - }, - {#State 69 - ACTIONS => { - 'CONSTANT' => 76 - } - }, - {#State 70 - DEFAULT => -8 - }, - {#State 71 - DEFAULT => -31 - }, - {#State 72 - ACTIONS => { - ";" => 77 - } - }, - {#State 73 - DEFAULT => -20 - }, - {#State 74 - DEFAULT => -21 - }, - {#State 75 - DEFAULT => -23 - }, - {#State 76 - ACTIONS => { - "]" => 78 - } - }, - {#State 77 - DEFAULT => -22 - }, - {#State 78 - DEFAULT => -25 - } -], - yyrules => -[ - [#Rule 0 - '$start', 2, undef - ], - [#Rule 1 - 'definitions', 1, -sub -#line 14 "build/pidl/smb_interfaces.yp" -{ [$_[1]] } - ], - [#Rule 2 - 'definitions', 2, -sub -#line 15 "build/pidl/smb_interfaces.yp" -{ push(@{$_[1]}, $_[2]); $_[1] } - ], - [#Rule 3 - 'definition', 1, undef - ], - [#Rule 4 - 'definition', 1, undef - ], - [#Rule 5 - 'definition', 1, undef - ], - [#Rule 6 - 'definition', 1, undef - ], - [#Rule 7 - 'struct', 8, -sub -#line 26 "build/pidl/smb_interfaces.yp" -{ - { - "NAME" => $_[7], - "STRUCT_NAME" => $_[2], - "TYPE" => "struct", - "DATA" => $_[4], - } - } - ], - [#Rule 8 - 'union', 8, -sub -#line 38 "build/pidl/smb_interfaces.yp" -{ - { - "NAME" => $_[7], - "UNION_NAME" => $_[2], - "TYPE" => "union", - "DATA" => $_[4], - } - } - ], - [#Rule 9 - 'typedef', 7, undef - ], - [#Rule 10 - 'enum', 6, undef - ], - [#Rule 11 - 'enum_identifiers', 1, undef - ], - [#Rule 12 - 'enum_identifiers', 3, undef - ], - [#Rule 13 - 'enum_identifier', 1, undef - ], - [#Rule 14 - 'enum_identifier', 3, undef - ], - [#Rule 15 - 'elements', 0, undef - ], - [#Rule 16 - 'elements', 2, -sub -#line 65 "build/pidl/smb_interfaces.yp" -{ push(@{$_[1]}, $_[2]); $_[1] } - ], - [#Rule 17 - 'element', 0, undef - ], - [#Rule 18 - 'element', 1, undef - ], - [#Rule 19 - 'element', 1, undef - ], - [#Rule 20 - 'element', 5, -sub -#line 72 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => [$_[2]], - "POINTERS" => $_[3], - "TYPE" => "struct $_[2]", - }} - ], - [#Rule 21 - 'element', 5, -sub -#line 78 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => $_[2], - "POINTERS" => $_[3], - "TYPE" => "union $_[2]", - }} - ], - [#Rule 22 - 'element', 6, -sub -#line 84 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => [$_[4]], - "TYPE" => $_[2], - "POINTERS" => $_[3], - }} - ], - [#Rule 23 - 'element', 5, -sub -#line 90 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => [$_[3]], - "TYPE" => $_[1], - "POINTERS" => $_[2], - "ARRAY_LENGTH" => $_[4] - }} - ], - [#Rule 24 - 'array', 0, undef - ], - [#Rule 25 - 'array', 3, -sub -#line 99 "build/pidl/smb_interfaces.yp" -{ int($_[2]) } - ], - [#Rule 26 - 'type', 1, undef - ], - [#Rule 27 - 'type', 2, -sub -#line 104 "build/pidl/smb_interfaces.yp" -{ "enum $_[2]" } - ], - [#Rule 28 - 'pointers', 0, undef - ], - [#Rule 29 - 'pointers', 2, -sub -#line 109 "build/pidl/smb_interfaces.yp" -{ $_[1]+1 } - ], - [#Rule 30 - 'optional_identifiers', 1, -sub -#line 112 "build/pidl/smb_interfaces.yp" -{ [$_[1]] } - ], - [#Rule 31 - 'optional_identifiers', 3, -sub -#line 113 "build/pidl/smb_interfaces.yp" -{ push(@{$_[1]}, $_[3]); $_[1] } - ], - [#Rule 32 - 'optional_identifier', 1, undef - ], - [#Rule 33 - 'optional_identifier', 0, undef - ] -], - @_); - bless($self,$class); -} - -#line 119 "build/pidl/smb_interfaces.yp" - - -##################################################################### -# traverse a perl data structure removing any empty arrays or -# hashes and any hash elements that map to undef -sub CleanData($) -{ - sub CleanData($); - my($v) = shift; - if (ref($v) eq "ARRAY") { - foreach my $i (0 .. $#{$v}) { - CleanData($v->[$i]); - if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) { - $v->[$i] = undef; - next; - } - } - # this removes any undefined elements from the array - @{$v} = grep { defined $_ } @{$v}; - } elsif (ref($v) eq "HASH") { - foreach my $x (keys %{$v}) { - CleanData($v->{$x}); - if (!defined $v->{$x}) { delete($v->{$x}); next; } - if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; } - } - } - return $v; -} - -sub _Error { - if (exists $_[0]->YYData->{ERRMSG}) { - print $_[0]->YYData->{ERRMSG}; - delete $_[0]->YYData->{ERRMSG}; - return; - }; - my $line = $_[0]->YYData->{LINE}; - my $last_token = $_[0]->YYData->{LAST_TOKEN}; - my $file = $_[0]->YYData->{INPUT_FILENAME}; - - print "$file:$line: Syntax error near '$last_token'\n"; -} - -sub _Lexer($) -{ - my($parser)=shift; - - $parser->YYData->{INPUT} or return('',undef); - -again: - $parser->YYData->{INPUT} =~ s/^[ \t]*//; - - for ($parser->YYData->{INPUT}) { - if (/^\#/) { - if (s/^\# (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^(\#.*)$//m) { - goto again; - } - } - if (s/^(\n)//) { - $parser->YYData->{LINE}++; - goto again; - } - if (s/^\"(.*?)\"//) { - $parser->YYData->{LAST_TOKEN} = $1; - return('TEXT',$1); - } - if (s/^(\d+)(\W|$)/$2/) { - $parser->YYData->{LAST_TOKEN} = $1; - return('CONSTANT',$1); - } - if (s/^([\w_]+)//) { - $parser->YYData->{LAST_TOKEN} = $1; - if ($1 =~ - /^(const|typedef|union|struct|enum)$/x) { - return uc($1); - } - return('IDENTIFIER',$1); - } - if (s/^(.)//s) { - $parser->YYData->{LAST_TOKEN} = $1; - return($1,$1); - } - } -} - -sub parse($$) -{ - my ($self,$filename) = @_; - - my $saved_delim = $/; - undef $/; - my $cpp = $ENV{CPP}; - if (! defined $cpp) { - $cpp = "cpp" - } - my $data = `$cpp -D__PIDL__ -xc $filename`; - $/ = $saved_delim; - - $self->YYData->{INPUT} = $data; - $self->YYData->{LINE} = 0; - $self->YYData->{LAST_TOKEN} = "NONE"; - - my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); - - return CleanData($idl); -} - -1; diff --git a/source4/pidl/smb_interfaces.yp b/source4/pidl/smb_interfaces.yp deleted file mode 100644 index f8c34eacdc..0000000000 --- a/source4/pidl/smb_interfaces.yp +++ /dev/null @@ -1,233 +0,0 @@ -######################## -# Parse::Yapp parser for a C header file that contains only structures -# or unions. - -# Copyright (C) 2005, Tim Potter released under the -# GNU GPL version 2 or later - -################ -# grammar - -%% - -definitions: - definition { [$_[1]] } - | definitions definition { push(@{$_[1]}, $_[2]); $_[1] } -; - -definition: - struct - | union - | typedef - | enum -; - -struct: STRUCT optional_identifier '{' elements '}' pointers optional_identifiers ';' - { - { - "NAME" => $_[7], - "STRUCT_NAME" => $_[2], - "TYPE" => "struct", - "DATA" => $_[4], - } - } -; - -union: - UNION optional_identifier '{' elements '}' pointers optional_identifier ';' - { - { - "NAME" => $_[7], - "UNION_NAME" => $_[2], - "TYPE" => "union", - "DATA" => $_[4], - } - } -; - -typedef: - TYPEDEF STRUCT '{' elements '}' optional_identifier ';' -; - -enum: - ENUM IDENTIFIER '{' enum_identifiers '}' ';' -; - -enum_identifiers: enum_identifier - | enum_identifiers ',' enum_identifier -; - -enum_identifier: IDENTIFIER - | IDENTIFIER '=' IDENTIFIER -; - -elements: #empty - | elements element { push(@{$_[1]}, $_[2]); $_[1] } -; - -element: - | struct - | union - | STRUCT IDENTIFIER pointers IDENTIFIER ';' - {{ - "NAME" => [$_[2]], - "POINTERS" => $_[3], - "TYPE" => "struct $_[2]", - }} - | UNION IDENTIFIER pointers IDENTIFIER ';' - {{ - "NAME" => $_[2], - "POINTERS" => $_[3], - "TYPE" => "union $_[2]", - }} - | CONST type pointers IDENTIFIER array ';' - {{ - "NAME" => [$_[4]], - "TYPE" => $_[2], - "POINTERS" => $_[3], - }} - | type pointers IDENTIFIER array ';' - {{ - "NAME" => [$_[3]], - "TYPE" => $_[1], - "POINTERS" => $_[2], - "ARRAY_LENGTH" => $_[4] - }} -; - -array: #empty - | '[' CONSTANT ']' { int($_[2]) } -; - -type: IDENTIFIER - | ENUM IDENTIFIER - { "enum $_[2]" } -; - -pointers: - #empty { 0 } - | pointers '*' { $_[1]+1 } -; - -optional_identifiers: optional_identifier { [$_[1]] } - | optional_identifiers ',' optional_identifier { push(@{$_[1]}, $_[3]); $_[1] } -; - -optional_identifier: IDENTIFIER | #empty { undef } -; - -%% - -##################################################################### -# traverse a perl data structure removing any empty arrays or -# hashes and any hash elements that map to undef -sub CleanData($) -{ - sub CleanData($); - my($v) = shift; - if (ref($v) eq "ARRAY") { - foreach my $i (0 .. $#{$v}) { - CleanData($v->[$i]); - if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) { - $v->[$i] = undef; - next; - } - } - # this removes any undefined elements from the array - @{$v} = grep { defined $_ } @{$v}; - } elsif (ref($v) eq "HASH") { - foreach my $x (keys %{$v}) { - CleanData($v->{$x}); - if (!defined $v->{$x}) { delete($v->{$x}); next; } - if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; } - } - } - return $v; -} - -sub _Error { - if (exists $_[0]->YYData->{ERRMSG}) { - print $_[0]->YYData->{ERRMSG}; - delete $_[0]->YYData->{ERRMSG}; - return; - }; - my $line = $_[0]->YYData->{LINE}; - my $last_token = $_[0]->YYData->{LAST_TOKEN}; - my $file = $_[0]->YYData->{INPUT_FILENAME}; - - print "$file:$line: Syntax error near '$last_token'\n"; -} - -sub _Lexer($) -{ - my($parser)=shift; - - $parser->YYData->{INPUT} or return('',undef); - -again: - $parser->YYData->{INPUT} =~ s/^[ \t]*//; - - for ($parser->YYData->{INPUT}) { - if (/^\#/) { - if (s/^\# (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^(\#.*)$//m) { - goto again; - } - } - if (s/^(\n)//) { - $parser->YYData->{LINE}++; - goto again; - } - if (s/^\"(.*?)\"//) { - $parser->YYData->{LAST_TOKEN} = $1; - return('TEXT',$1); - } - if (s/^(\d+)(\W|$)/$2/) { - $parser->YYData->{LAST_TOKEN} = $1; - return('CONSTANT',$1); - } - if (s/^([\w_]+)//) { - $parser->YYData->{LAST_TOKEN} = $1; - if ($1 =~ - /^(const|typedef|union|struct|enum)$/x) { - return uc($1); - } - return('IDENTIFIER',$1); - } - if (s/^(.)//s) { - $parser->YYData->{LAST_TOKEN} = $1; - return($1,$1); - } - } -} - -sub parse($$) -{ - my ($self,$filename) = @_; - - my $saved_delim = $/; - undef $/; - my $cpp = $ENV{CPP}; - if (! defined $cpp) { - $cpp = "cpp" - } - my $data = `$cpp -D__PIDL__ -xc $filename`; - $/ = $saved_delim; - - $self->YYData->{INPUT} = $data; - $self->YYData->{LINE} = 0; - $self->YYData->{LAST_TOKEN} = "NONE"; - - my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); - - return CleanData($idl); -} -- cgit From 97ad5d5d80d0967c3ca7dbcd424883d3ad613138 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 22:15:12 +0100 Subject: pidl: Add ability to write type metadata to a file. (This used to be commit e8ab241ff47f2c3e6f80f9c62373139e4c9f5a1e) --- source4/pidl/lib/Parse/Pidl/Typelist.pm | 7 ++++++- source4/pidl/pidl | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Typelist.pm b/source4/pidl/lib/Parse/Pidl/Typelist.pm index 8fb7448070..3721800b97 100644 --- a/source4/pidl/lib/Parse/Pidl/Typelist.pm +++ b/source4/pidl/lib/Parse/Pidl/Typelist.pm @@ -238,7 +238,7 @@ sub mapTypeName($) sub LoadIdl($) { - my $idl = shift; + my ($idl) = @_; foreach my $x (@{$idl}) { next if $x->{TYPE} ne "INTERFACE"; @@ -254,6 +254,11 @@ sub LoadIdl($) } } +sub GenerateTypeLib() +{ + return Parse::Pidl::Util::MyDumper(\%types); +} + RegisterScalars(); 1; diff --git a/source4/pidl/pidl b/source4/pidl/pidl index 4395df2020..500b4dcbfc 100755 --- a/source4/pidl/pidl +++ b/source4/pidl/pidl @@ -17,7 +17,7 @@ pidl - An IDL compiler written in Perl pidl --help -pidl [--outputdir[=OUTNAME]] [--includedir DIR...] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--python[=OUTPUT]] [--swig[=OUTPUT]] [--ndr-parser[=OUTPUT]] [--client] [--server] [--warn-compat] [--quiet] [--verbose] [--template] [--ws-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [--samba3-ndr-server[=OUTPUT]] [.idl]... +pidl [--outputdir[=OUTNAME]] [--includedir DIR...] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--python[=OUTPUT]] [--swig[=OUTPUT]] [--ndr-parser[=OUTPUT]] [--client] [--server] [--warn-compat] [--quiet] [--verbose] [--template] [--ws-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [--samba3-ndr-server[=OUTPUT]] [--typelib=[OUTPUT]] [.idl]... =head1 DESCRIPTION @@ -88,6 +88,10 @@ Generate a C file and C header containing TDR parsers. The filename for the parser defaults to tdr_OUTNAME.c. The header filename will be the parser filename with the extension changed from .c to .h. +=item I<--typelib> + +Write type information to the specified file. + =item I<--server> Generate boilerplate for the RPC server that implements @@ -462,6 +466,7 @@ my($opt_samba3_ndr_client); my($opt_samba3_ndr_server); my($opt_template) = 0; my($opt_client); +my($opt_typelib); my($opt_server); my($opt_ndr_parser); my($opt_tdr_parser); @@ -498,6 +503,7 @@ Debugging: --dump-ndr-tree[=FILE] dump internal NDR data tree to file [BASENAME.ndr] --dump-idl regenerate IDL file --diff run diff on original IDL and dumped output + --typelib print type information Samba 4 output: --header[=OUTFILE] create generic header file [BASENAME.h] @@ -534,6 +540,7 @@ my $result = GetOptions ( 'samba3-ndr-server:s' => \$opt_samba3_ndr_server, 'header:s' => \$opt_header, 'server:s' => \$opt_server, + 'typelib:s' => \$opt_typelib, 'tdr-parser:s' => \$opt_tdr_parser, 'template' => \$opt_template, 'ndr-parser:s' => \$opt_ndr_parser, @@ -711,6 +718,12 @@ sub process_file($) FileSave($tdr_header, $hdr); } + if (defined($opt_typelib)) { + my $typelib = ($opt_typelib or "$outputdir/$basename.tlb"); + require Parse::Pidl::Typelist; + FileSave($typelib, Parse::Pidl::Typelist::GenerateTypeLib()); + } + if ($opt_template) { require Parse::Pidl::Samba4::Template; print Parse::Pidl::Samba4::Template::Parse($pidl); -- cgit From 90198fa7ca83b41516ac5bea014ae0396a1d128f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 22:35:28 +0100 Subject: pidl: Prevent empty declarations for enums without body. (This used to be commit c1e0570506d7c77112065a03a876cda4e4db7769) --- source4/pidl/lib/Parse/Pidl/Samba4/Header.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm index 7a6ffa46d6..9e27719d51 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -108,25 +108,28 @@ sub HeaderEnum($$) my $first = 1; pidl "#ifndef USE_UINT_ENUMS\n"; - pidl "enum $name {\n"; - $tab_depth++; + pidl "enum $name"; if (defined($enum->{ELEMENTS})) { + pidl " {\n"; + $tab_depth++; foreach my $e (@{$enum->{ELEMENTS}}) { unless ($first) { pidl ",\n"; } $first = 0; pidl tabs(); pidl $e; } + pidl "\n"; + $tab_depth--; + pidl "}"; } pidl "\n"; - $tab_depth--; - pidl "}\n"; pidl "#else\n"; my $count = 0; - pidl "enum $name { __donnot_use_enum_$name=0x7FFFFFFF}\n"; + pidl "enum $name"; my $with_val = 0; my $without_val = 0; if (defined($enum->{ELEMENTS})) { + pidl " { __donnot_use_enum_$name=0x7FFFFFFF}"; foreach my $e (@{$enum->{ELEMENTS}}) { my $t = "$e"; my $name; @@ -144,9 +147,10 @@ sub HeaderEnum($$) fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") unless ($with_val == 0); } - pidl "#define $name ( $value )\n"; + pidl "\n#define $name ( $value )"; } } + pidl "\n"; pidl "#endif\n"; } @@ -215,7 +219,7 @@ sub HeaderType($$$) sub HeaderTypedef($) { my($typedef) = shift; - HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME}); + HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME}) if defined ($typedef->{DATA}); } ##################################################################### -- cgit From 532154af9bebbdf76b2f62ee2b0810e66bc431c7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 23:06:00 +0100 Subject: pidl: Move more stuff outside ifdef when defining enums and generate pretty code for enums without body. (This used to be commit d91af936ae51e33c8598d88c77575abbeb0e556b) --- source4/pidl/lib/Parse/Pidl/Samba4/Header.pm | 56 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm index 9e27719d51..b96a58783c 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -107,9 +107,9 @@ sub HeaderEnum($$) my($enum,$name) = @_; my $first = 1; - pidl "#ifndef USE_UINT_ENUMS\n"; pidl "enum $name"; if (defined($enum->{ELEMENTS})) { + pidl "\n#ifndef USE_UINT_ENUMS\n"; pidl " {\n"; $tab_depth++; foreach my $e (@{$enum->{ELEMENTS}}) { @@ -121,37 +121,35 @@ sub HeaderEnum($$) pidl "\n"; $tab_depth--; pidl "}"; - } - pidl "\n"; - pidl "#else\n"; - my $count = 0; - pidl "enum $name"; - my $with_val = 0; - my $without_val = 0; - if (defined($enum->{ELEMENTS})) { - pidl " { __donnot_use_enum_$name=0x7FFFFFFF}"; - foreach my $e (@{$enum->{ELEMENTS}}) { - my $t = "$e"; - my $name; - my $value; - if ($t =~ /(.*)=(.*)/) { - $name = $1; - $value = $2; - $with_val = 1; - fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") - unless ($without_val == 0); - } else { - $name = $t; - $value = $count++; - $without_val = 1; - fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") - unless ($with_val == 0); + pidl "\n"; + pidl "#else\n"; + my $count = 0; + my $with_val = 0; + my $without_val = 0; + if (defined($enum->{ELEMENTS})) { + pidl " { __donnot_use_enum_$name=0x7FFFFFFF}\n"; + foreach my $e (@{$enum->{ELEMENTS}}) { + my $t = "$e"; + my $name; + my $value; + if ($t =~ /(.*)=(.*)/) { + $name = $1; + $value = $2; + $with_val = 1; + fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") + unless ($without_val == 0); + } else { + $name = $t; + $value = $count++; + $without_val = 1; + fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") + unless ($with_val == 0); + } + pidl "#define $name ( $value )\n"; } - pidl "\n#define $name ( $value )"; } + pidl "#endif\n"; } - pidl "\n"; - pidl "#endif\n"; } ##################################################################### -- cgit From ad559581406313741276e39cf0d28b4d3acdaab1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 23:10:28 +0100 Subject: pidl: Add function for determining whether a type has a body. (This used to be commit 893f4102c93c1c2cd6b836f12644d06d9e31800c) --- source4/pidl/lib/Parse/Pidl/NDR.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 3 ++- source4/pidl/lib/Parse/Pidl/Typelist.pm | 15 ++++++++++++++- source4/pidl/tests/ndr.pl | 6 +++++- source4/pidl/tests/typelist.pl | 7 +++++-- 5 files changed, 27 insertions(+), 6 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index 80ecec938a..1d059ebdf7 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -633,7 +633,7 @@ sub FindNestedTypes($$) sub FindNestedTypes($$); my ($l, $t) = @_; - return if not defined($t->{ELEMENTS}); + return unless defined($t->{ELEMENTS}); return if ($t->{TYPE} eq "ENUM"); return if ($t->{TYPE} eq "BITMAP"); diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index abbfe2259b..cfd16c7b40 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -12,7 +12,7 @@ require Exporter; @EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction NeededElement NeededType $res NeededInterface TypeFunctionName ParseElementPrint); use strict; -use Parse::Pidl::Typelist qw(hasType getType mapTypeName); +use Parse::Pidl::Typelist qw(hasType getType mapTypeName typeHasBody); use Parse::Pidl::Util qw(has_property ParseExpr ParseExprExt print_uuid); use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); @@ -2543,6 +2543,7 @@ sub ParseInterface($$$) # Typedefs foreach my $d (@{$interface->{TYPES}}) { + next unless typeHasBody($d); ($needed->{TypeFunctionName("ndr_push", $d)}) && $self->ParseTypePushFunction($d, "r"); ($needed->{TypeFunctionName("ndr_pull", $d)}) && $self->ParseTypePullFunction($d, "r"); ($needed->{TypeFunctionName("ndr_print", $d)}) && $self->ParseTypePrintFunction($d, "r"); diff --git a/source4/pidl/lib/Parse/Pidl/Typelist.pm b/source4/pidl/lib/Parse/Pidl/Typelist.pm index 3721800b97..aad0cf426c 100644 --- a/source4/pidl/lib/Parse/Pidl/Typelist.pm +++ b/source4/pidl/lib/Parse/Pidl/Typelist.pm @@ -9,7 +9,7 @@ require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(hasType getType mapTypeName scalar_is_reference expandAlias mapScalarType addType typeIs is_scalar enum_type_fn - bitmap_type_fn mapType + bitmap_type_fn mapType typeHasBody ); use vars qw($VERSION); $VERSION = '0.01'; @@ -207,6 +207,19 @@ sub bitmap_type_fn($) return "uint32"; } +sub typeHasBody($) +{ + sub typeHasBody($); + my ($e) = @_; + + if ($e->{TYPE} eq "TYPEDEF") { + return 0 unless(defined($e->{DATA})); + return typeHasBody($e->{DATA}); + } + + return defined($e->{ELEMENTS}); +} + sub mapType($$) { sub mapType($$); diff --git a/source4/pidl/tests/ndr.pl b/source4/pidl/tests/ndr.pl index 09f1d4969b..ba7fef361b 100755 --- a/source4/pidl/tests/ndr.pl +++ b/source4/pidl/tests/ndr.pl @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 37; +use Test::More tests => 39; use FindBin qw($RealBin); use lib "$RealBin"; use Util; @@ -275,3 +275,7 @@ ok(not can_contain_deferred({ TYPE => "TYPEDEF", ELEMENTS => [ { TYPE => "uint32" } ]}})); ok(can_contain_deferred({ TYPE => "STRUCT", ELEMENTS => [ { TYPE => "someunknowntype" } ]})); +# Make sure the elements for a enum without body aren't filled in +ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref")->{ELEMENTS})); +# Make sure the elements for a bitmap without body aren't filled in +ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref")->{ELEMENTS})); diff --git a/source4/pidl/tests/typelist.pl b/source4/pidl/tests/typelist.pl index 90cb853a52..54f4d34586 100755 --- a/source4/pidl/tests/typelist.pl +++ b/source4/pidl/tests/typelist.pl @@ -4,11 +4,11 @@ use strict; use warnings; -use Test::More tests => 52; +use Test::More tests => 54; use FindBin qw($RealBin); use lib "$RealBin"; use Util; -use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias +use Parse::Pidl::Typelist qw(hasType typeHasBody getType mapTypeName expandAlias mapScalarType addType typeIs is_scalar scalar_is_reference enum_type_fn bitmap_type_fn mapType); @@ -80,3 +80,6 @@ is("uint32_t", mapType({TYPE => "TYPEDEF", DATA => {TYPE => "SCALAR"}}, "uint32" is("void", mapTypeName(undef)); is("uint32_t", mapTypeName("uint32")); is("int32_t", mapTypeName("int")); + +ok(not typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT" }})); +ok(typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT", ELEMENTS => [] }})); -- cgit From 3f9812f951bb110700077503a96b9d7d8cfdb2dc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 23:38:05 +0100 Subject: pidl/ejs: Fix bug that filled in the body for types without body. (This used to be commit 4f4dfa6042178c157a09df61d72a42af7aa5c67b) --- source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm | 10 +++++++--- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 3 ++- source4/pidl/tests/parse_idl.pl | 13 ++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index fa0c97961c..24270340b9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -11,7 +11,7 @@ use Exporter; @EXPORT_OK = qw(check_null_pointer fn_declare TypeFunctionName); use strict; -use Parse::Pidl::Typelist; +use Parse::Pidl::Typelist qw(typeHasBody); use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel); @@ -274,6 +274,7 @@ sub EjsUnionPull($$$) sub EjsEnumConstant($$) { my ($self, $d) = @_; + return unless (defined($d->{ELEMENTS})); my $v = 0; foreach my $e (@{$d->{ELEMENTS}}) { my $el = $e; @@ -572,6 +573,7 @@ sub EjsEnumPush($$$) sub EjsBitmapPush($$$) { my ($self, $d, $varname) = @_; + return unless (defined($d->{ELEMENTS})); my $type_fn = $d->{BASE_TYPE}; # put the bitmap elements in the constants array foreach my $e (@{$d->{ELEMENTS}}) { @@ -710,6 +712,7 @@ sub EjsInterface($$$) $self->pidl_hdr("\n"); foreach my $d (@{$interface->{TYPES}}) { + next unless (typeHasBody($d)); ($needed->{TypeFunctionName("ejs_push", $d)}) && $self->EjsTypePushFunction($d, $d->{NAME}); ($needed->{TypeFunctionName("ejs_pull", $d)}) && $self->EjsTypePullFunction($d, $d->{NAME}); } @@ -823,8 +826,9 @@ sub NeededType($$$) NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF"); - return if (($t->{TYPE} ne "STRUCT") and - ($t->{TYPE} ne "UNION")); + return unless (($t->{TYPE} eq "STRUCT") or ($t->{TYPE} eq "UNION")); + + return unless(typeHasBody($t)); foreach (@{$t->{ELEMENTS}}) { next if (has_property($_, "subcontext")); #FIXME: Support subcontexts diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index cfd16c7b40..451e899ffb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -2543,7 +2543,8 @@ sub ParseInterface($$$) # Typedefs foreach my $d (@{$interface->{TYPES}}) { - next unless typeHasBody($d); + next unless(typeHasBody($d)); + ($needed->{TypeFunctionName("ndr_push", $d)}) && $self->ParseTypePushFunction($d, "r"); ($needed->{TypeFunctionName("ndr_pull", $d)}) && $self->ParseTypePullFunction($d, "r"); ($needed->{TypeFunctionName("ndr_print", $d)}) && $self->ParseTypePrintFunction($d, "r"); diff --git a/source4/pidl/tests/parse_idl.pl b/source4/pidl/tests/parse_idl.pl index d14c374740..93f772ef41 100755 --- a/source4/pidl/tests/parse_idl.pl +++ b/source4/pidl/tests/parse_idl.pl @@ -4,7 +4,7 @@ # Published under the GNU General Public License use strict; -use Test::More tests => 65 * 2 + 5; +use Test::More tests => 65 * 2 + 6; use FindBin qw($RealBin); use lib "$RealBin"; use Util qw(test_errors); @@ -143,6 +143,13 @@ $x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct {} y; }", "< is_deeply($x, [ { 'FILE' => '', 'NAME' => 'foo', 'DATA' => [ - { 'FILE' => '', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { - TYPE => 'STRUCT', ELEMENTS => [] } } ], + { 'FILE' => '', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'STRUCT', ELEMENTS => [] } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); + +# A typedef of a bitmap with no body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef bitmap x y; }", ""); + +is_deeply($x, + [ { 'FILE' => '', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'BITMAP', NAME => 'x' } } ], 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); -- cgit From b36a0aedd2dbe47429bfc2dda6ea802a92efb526 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 00:05:24 +0100 Subject: pidl: Avoid accidently filling in empty body for types without body. (This used to be commit 1fe5c1ad07c574dc094f59f728025dfcafa0cf22) --- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 1 + source4/pidl/lib/Parse/Pidl/Typelist.pm | 6 ++++-- source4/pidl/tests/ndr.pl | 4 +++- source4/pidl/tests/parse_idl.pl | 11 ++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 451e899ffb..8eb2f9ad15 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -2688,6 +2688,7 @@ sub NeededType($$$) NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF"); if ($t->{TYPE} eq "STRUCT" or $t->{TYPE} eq "UNION") { + return unless defined($t->{ELEMENTS}); for my $e (@{$t->{ELEMENTS}}) { $e->{PARENT} = $t; if (has_property($e, "compression")) { diff --git a/source4/pidl/lib/Parse/Pidl/Typelist.pm b/source4/pidl/lib/Parse/Pidl/Typelist.pm index aad0cf426c..e54ef11b88 100644 --- a/source4/pidl/lib/Parse/Pidl/Typelist.pm +++ b/source4/pidl/lib/Parse/Pidl/Typelist.pm @@ -135,7 +135,9 @@ sub is_scalar($) sub is_scalar($); my $type = shift; - return 1 if (ref($type) eq "HASH" and $type->{TYPE} eq "SCALAR"); + return 1 if (ref($type) eq "HASH" and + ($type->{TYPE} eq "SCALAR" or $type->{TYPE} eq "ENUM" or + $type->{TYPE} eq "BITMAP")); if (my $dt = getType($type)) { return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF"); @@ -149,7 +151,7 @@ sub is_scalar($) sub scalar_is_reference($) { my $name = shift; - + return 1 if (grep(/^$name$/, @reference_scalars)); return 0; } diff --git a/source4/pidl/tests/ndr.pl b/source4/pidl/tests/ndr.pl index ba7fef361b..7fcc7ef40e 100755 --- a/source4/pidl/tests/ndr.pl +++ b/source4/pidl/tests/ndr.pl @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 39; +use Test::More tests => 40; use FindBin qw($RealBin); use lib "$RealBin"; use Util; @@ -279,3 +279,5 @@ ok(can_contain_deferred({ TYPE => "STRUCT", ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref")->{ELEMENTS})); # Make sure the elements for a bitmap without body aren't filled in ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref")->{ELEMENTS})); +# Make sure the elements for a union without body aren't filled in +ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, "ref")->{ELEMENTS})); diff --git a/source4/pidl/tests/parse_idl.pl b/source4/pidl/tests/parse_idl.pl index 93f772ef41..9d43ddccc7 100755 --- a/source4/pidl/tests/parse_idl.pl +++ b/source4/pidl/tests/parse_idl.pl @@ -4,7 +4,7 @@ # Published under the GNU General Public License use strict; -use Test::More tests => 65 * 2 + 6; +use Test::More tests => 65 * 2 + 7; use FindBin qw($RealBin); use lib "$RealBin"; use Util qw(test_errors); @@ -153,3 +153,12 @@ is_deeply($x, [ { 'FILE' => '', 'NAME' => 'foo', 'DATA' => [ { 'FILE' => '', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'BITMAP', NAME => 'x' } } ], 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); + + +# A typedef of a union with no body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef union x y; }", ""); + +is_deeply($x, + [ { 'FILE' => '', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'UNION', NAME => 'x' } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); -- cgit From 83c56f2118393e142021e232f7731e4622d2dfb3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 18:11:45 +0100 Subject: python/pidl: More work on wrapping enums, bitmaps and structs. (This used to be commit 732c3453f0784d5052705b00735b750809afce61) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 102 ++++++++++++++++++++------- 1 file changed, 76 insertions(+), 26 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 8effff9d5e..7c379548ed 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -9,7 +9,7 @@ use Exporter; @ISA = qw(Exporter); use strict; -use Parse::Pidl::Typelist; +use Parse::Pidl::Typelist qw(hasType getType mapTypeName); use Parse::Pidl::Util qw(has_property ParseExpr); use vars qw($VERSION); @@ -17,7 +17,8 @@ $VERSION = '0.01'; sub new($) { my ($class) = @_; - my $self = { res => "", res_hdr => "", tabs => "", constants => {}}; + my $self = { res => "", res_hdr => "", tabs => "", constants => {}, + module_methods => []}; bless($self, $class); } @@ -63,7 +64,26 @@ sub Import sub Const($$) { my ($self, $const) = @_; - $self->{constants}->{$const->{NAME}} = [$const->{DATA}->{TYPE}, $const->{VALUE}]; + $self->register_constant($const->{NAME}, $const->{DATA}->{TYPE}, $const->{VALUE}); +} + +sub register_constant($$$$) +{ + my ($self, $name, $type, $value) = @_; + + $self->{constants}->{$name} = [$type, $value]; +} + +sub EnumAndBitmapConsts($$$) +{ + my ($self, $name, $d) = @_; + + foreach my $e (@{$d->{ELEMENTS}}) { + $e =~ /^([A-Za-z0-9_]+)=(.*)$/; + my $cname = $1; + + $self->register_constant($cname, $d, $cname); + } } sub FromTypeToPythonFunction($$) @@ -97,6 +117,8 @@ sub TypeConstructor($$) $self->pidl("static PyObject *py_$type->{NAME}_getattr(PyTypeObject *obj, char *name)"); $self->pidl("{"); $self->indent; + $self->pidl("$type->{NAME}_Object *py_object = ($type->{NAME}_Object *)obj;"); + $self->pidl(mapTypeName($type) . " *object = talloc_get_type(py_object->object, ".mapTypeName($type).");"); $self->pidl("return Py_None;"); $self->deindent; $self->pidl("}"); @@ -115,6 +137,8 @@ sub TypeConstructor($$) $self->pidl("static PyObject *py_$type->{NAME}_setattr(PyTypeObject *obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; + $self->pidl("$type->{NAME}_Object *py_object = ($type->{NAME}_Object *)obj;"); + $self->pidl(mapTypeName($type) . " *object = talloc_get_type(py_object->object, ".mapTypeName($type).");"); $self->pidl("return Py_None;"); $self->deindent; $self->pidl("}"); @@ -133,7 +157,8 @@ sub TypeConstructor($$) $self->pidl(""); - $self->pidl("static PyObject *py_$type->{NAME}(PyObject *self, PyObject *args)"); + my $py_fnname = "py_$type->{NAME}"; + $self->pidl("static PyObject *$py_fnname(PyObject *self, PyObject *args)"); $self->pidl("{"); $self->indent; $self->pidl("$type->{NAME}\_Object *ret;"); @@ -142,6 +167,8 @@ sub TypeConstructor($$) $self->deindent; $self->pidl("}"); $self->pidl(""); + + return $py_fnname; } sub PythonFunction($$$) @@ -175,9 +202,36 @@ sub handle_ntstatus($$$) $self->pidl(""); } -sub Interface($$) +sub PythonType($$$) { - my($self,$interface) = @_; + my ($self, $d, $interface, $basename) = @_; + + if ($d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "TYPEDEF" and + $d->{DATA}->{TYPE} eq "STRUCT") { + $self->FromTypeToPythonFunction($d); + $self->FromPythonToTypeFunction($d); + my $py_fnname = $self->TypeConstructor($d); + + my $fn_name = $d->{NAME}; + + $fn_name =~ s/^$interface->{NAME}_//; + $fn_name =~ s/^$basename\_//; + + $self->register_module_method($fn_name, $py_fnname, "METH_VARARGS|METH_KEYWORDS", "NULL"); + } + + if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP") { + $self->EnumAndBitmapConsts($d->{NAME}, $d); + } + + if ($d->{TYPE} eq "TYPEDEF" and ($d->{DATA}->{TYPE} eq "ENUM" or $d->{DATA}->{TYPE} eq "BITMAP")) { + $self->EnumAndBitmapConsts($d->{NAME}, $d->{DATA}); + } +} + +sub Interface($$$) +{ + my($self,$interface,$basename) = @_; $self->pidl_hdr("#ifndef _HEADER_PYTHON_$interface->{NAME}\n"); $self->pidl_hdr("#define _HEADER_PYTHON_$interface->{NAME}\n\n"); @@ -186,10 +240,10 @@ sub Interface($$) $self->Const($_) foreach (@{$interface->{CONSTS}}); - foreach (@{$interface->{TYPES}}) { - $self->FromTypeToPythonFunction($_); - $self->FromPythonToTypeFunction($_); - $self->TypeConstructor($_); + foreach my $d (@{$interface->{TYPES}}) { + next if has_property($d, "nopython"); + + $self->PythonType($d, $interface, $basename); } $self->pidl("staticforward PyTypeObject $interface->{NAME}_InterfaceType;"); @@ -257,6 +311,7 @@ sub Interface($$) $self->pidl(""); + $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "NULL"); $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args)"); $self->pidl("{"); $self->indent; @@ -285,6 +340,13 @@ sub Interface($$) $self->pidl_hdr("#endif /* _HEADER_NDR_$interface->{NAME} */\n"); } +sub register_module_method($$$$$) +{ + my ($self, $fn_name, $pyfn_name, $flags, $doc) = @_; + + push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) +} + sub Parse($$$$) { my($self,$basename,$ndr,$hdr) = @_; @@ -305,27 +367,15 @@ sub Parse($$$$) "); foreach my $x (@$ndr) { - ($x->{TYPE} eq "INTERFACE") && $self->Interface($x); + ($x->{TYPE} eq "INTERFACE") && $self->Interface($x, $basename); ($x->{TYPE} eq "IMPORT") && $self->Import(@{$x->{PATHS}}); } $self->pidl("static PyMethodDef $basename\_methods[] = {"); $self->indent; - foreach my $x (@$ndr) { - next if ($x->{TYPE} ne "INTERFACE"); - $self->pidl("{ \"$x->{NAME}\", (PyCFunction)interface_$x->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); - - foreach my $d (@{$x->{TYPES}}) { - next if has_property($d, "nopython"); - next if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP"); - - my $fn_name = $d->{NAME}; - - $fn_name =~ s/^$x->{NAME}_//; - $fn_name =~ s/^$basename\_//; - - $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); - } + foreach (@{$self->{module_methods}}) { + my ($fn_name, $pyfn_name, $flags, $doc) = @$_; + $self->pidl("{ \"$fn_name\", (PyCFunction)$pyfn_name, $flags, $doc },"); } $self->pidl("{ NULL, NULL, 0, NULL }"); -- cgit From 7aa0f25d7f0a8a1eac19c886477b13ab00bd76fe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 18:27:47 +0100 Subject: python/pidl: Handle non-string types. (This used to be commit 02dd02c529d578ad7fa4a6b825097685555604fe) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 7c379548ed..5077102fc7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -347,6 +347,24 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } +sub ConvertObjectToPython($$$) +{ + my ($self, $ctype, $cvar) = @_; + + if ($cvar =~ /^".*"$/) { + return "PyString_FromString($cvar)"; + } + + if ($cvar =~ /^[0-9]+$/ or + $ctype->{TYPE} eq "ENUM" or $ctype->{TYPE} eq "BITMAP" or + $ctype->{TYPE} eq "TYPEDEF" and + ($ctype->{TYPE} eq "ENUM" or $ctype->{TYPE} eq "BITMAP")) { + return "PyInt_FromLong($cvar)"; + } + + die("Unknown type for ".mapTypeName($ctype).": $cvar"); +} + sub Parse($$$$) { my($self,$basename,$ndr,$hdr) = @_; @@ -391,7 +409,7 @@ sub Parse($$$$) $self->pidl("m = Py_InitModule(\"$basename\", $basename\_methods);"); foreach (keys %{$self->{constants}}) { # FIXME: Handle non-string constants - $self->pidl("PyModule_AddObject(m, \"$_\", PyString_FromString(" . $self->{constants}->{$_}->[1] . "));"); + $self->pidl("PyModule_AddObject(m, \"$_\", " . $self->ConvertObjectToPython($self->{constants}->{$_}->[0], $self->{constants}->{$_}->[1]) . ");"); } $self->deindent; $self->pidl("}"); -- cgit From f71df735556947f70c6a14bf9588988d0f6adfe3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 20:00:46 +0100 Subject: python/pidl: Start wrapping function arguments. (This used to be commit c2595d3754db4d03bafd53b6f62158516493657e) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 198 ++++++++++++++++++++++----- 1 file changed, 160 insertions(+), 38 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 5077102fc7..6b4b41f74f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -86,83 +86,121 @@ sub EnumAndBitmapConsts($$$) } } -sub FromTypeToPythonFunction($$) +sub FromUnionToPythonFunction($$) { my ($self, $type) = @_; #FIXME + + $self->pidl("return NULL;"); } -sub FromPythonToTypeFunction($$) +sub FromStructToPythonFunction($$) { my ($self, $type) = @_; #FIXME + $self->pidl("return NULL;"); } -sub TypeConstructor($$) +sub FromPythonToUnionFunction($$) { my ($self, $type) = @_; - $self->pidl("staticforward PyTypeObject $type->{NAME}_ObjectType;"); + #FIXME + $self->pidl("return NULL;"); +} + +sub FromPythonToStructFunction($$) +{ + my ($self, $type) = @_; + + #FIXME + $self->pidl("return NULL;"); +} + +sub PythonStruct($$$$) +{ + my ($self, $name, $cname, $d) = @_; + + $self->pidl("staticforward PyTypeObject $name\_ObjectType;"); $self->pidl("typedef struct {"); $self->indent; $self->pidl("PyObject_HEAD"); - $self->pidl("void *object;"); # FIXME: Use real type rather than void + $self->pidl("$cname *object;"); $self->deindent; - $self->pidl("} $type->{NAME}_Object;"); + $self->pidl("} $name\_Object;"); $self->pidl(""); - $self->pidl("static PyObject *py_$type->{NAME}_getattr(PyTypeObject *obj, char *name)"); + $self->pidl("static PyObject *py_$name\_getattr(PyTypeObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $self->pidl("$type->{NAME}_Object *py_object = ($type->{NAME}_Object *)obj;"); - $self->pidl(mapTypeName($type) . " *object = talloc_get_type(py_object->object, ".mapTypeName($type).");"); - $self->pidl("return Py_None;"); + $self->pidl("$name\_Object *py_object = ($name\_Object *)obj;"); + $self->pidl("$cname *object = talloc_get_type(py_object->object, $cname);"); + foreach my $e (@{$d->{ELEMENTS}}) { + $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); + my $varname = "object->$e->{NAME}"; + $self->indent; + $self->pidl("return ".$self->ConvertObjectToPython($e->{TYPE}, $varname) . ";"); + $self->deindent; + $self->pidl("}"); + } + $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); + $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("static void py_$type->{NAME}_dealloc(PyObject* self)"); + $self->pidl("static void py_$name\_dealloc(PyObject* self)"); $self->pidl("{"); $self->indent; - $self->pidl("$type->{NAME}_Object *obj = ($type->{NAME}_Object *)self;"); + $self->pidl("$name\_Object *obj = ($name\_Object *)self;"); $self->pidl("talloc_free(obj->object);"); $self->pidl("PyObject_Del(self);"); $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$type->{NAME}_setattr(PyTypeObject *obj, char *name, PyObject *value)"); + $self->pidl("static PyObject *py_$name\_setattr(PyTypeObject *obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $self->pidl("$type->{NAME}_Object *py_object = ($type->{NAME}_Object *)obj;"); - $self->pidl(mapTypeName($type) . " *object = talloc_get_type(py_object->object, ".mapTypeName($type).");"); - $self->pidl("return Py_None;"); + $self->pidl("$name\_Object *py_object = ($name\_Object *)obj;"); + $self->pidl("$cname *object = talloc_get_type(py_object->object, $cname);"); + foreach my $e (@{$d->{ELEMENTS}}) { + $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); + my $varname = "object->$e->{NAME}"; + $self->indent; + $self->pidl("/* FIXME: talloc_free($varname) if necessary */"); + $self->pidl("$varname = " . $self->ConvertObjectFromPython($e->{TYPE}, "value") . ";"); + $self->deindent; + $self->pidl("}"); + } + $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); + $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyTypeObject $type->{NAME}_ObjectType = {"); + $self->pidl("static PyTypeObject $name\_ObjectType = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); - $self->pidl(".tp_name = \"$type->{NAME}\","); - $self->pidl(".tp_basicsize = sizeof($type->{NAME}_Object),"); - $self->pidl(".tp_dealloc = (destructor)py_$type->{NAME}_dealloc,"); - $self->pidl(".tp_getattr = (getattrfunc)py_$type->{NAME}_getattr,"); - $self->pidl(".tp_setattr = (setattrfunc)py_$type->{NAME}_setattr,"); + $self->pidl(".tp_name = \"$name\","); + $self->pidl(".tp_basicsize = sizeof($name\_Object),"); + $self->pidl(".tp_dealloc = (destructor)py_$name\_dealloc,"); + $self->pidl(".tp_getattr = (getattrfunc)py_$name\_getattr,"); + $self->pidl(".tp_setattr = (setattrfunc)py_$name\_setattr,"); $self->deindent; $self->pidl("};"); $self->pidl(""); - my $py_fnname = "py_$type->{NAME}"; + my $py_fnname = "py_$name"; $self->pidl("static PyObject *$py_fnname(PyObject *self, PyObject *args)"); $self->pidl("{"); $self->indent; - $self->pidl("$type->{NAME}\_Object *ret;"); - $self->pidl("ret = PyObject_New($type->{NAME}_Object, &$type->{NAME}_ObjectType);"); + $self->pidl("$name\_Object *ret;"); + $self->pidl("ret = PyObject_New($name\_Object, &$name\_ObjectType);"); $self->pidl("return (PyObject *) ret;"); $self->deindent; $self->pidl("}"); @@ -180,22 +218,51 @@ sub PythonFunction($$$) $self->indent; $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); + $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); + $self->pidl("struct dcerpc_$fn->{NAME} r;"); + $self->pidl("PyObject *result = Py_None;"); + foreach my $e (@{$fn->{ELEMENTS}}) { + $self->pidl("PyObject *py_$e->{NAME};"); + } + if ($fn->{RETURN_TYPE}) { + $self->pidl("PyObject *py_result;"); + } $self->pidl(""); - # FIXME - $self->handle_ntstatus("status", "NULL"); - $self->pidl("return Py_None;"); + $self->pidl("ZERO_STRUCT(r.out);"); + + foreach my $e (@{$fn->{ELEMENTS}}) { + if (grep(/in/,@{$e->{DIRECTION}})) { + $self->pidl("r.in.$e->{NAME} = " . $self->ConvertObjectFromPython($e->{TYPE}, "py_$e->{NAME}") . ";"); + } + } + $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); + $self->handle_ntstatus("status", "NULL", "mem_ctx"); + + foreach my $e (@{$fn->{ELEMENTS}}) { + if (grep(/out/,@{$e->{DIRECTION}})) { + $self->pidl("py_$e->{NAME} = " . $self->ConvertObjectToPython($e->{TYPE}, "r.out.$e->{NAME}") . ";"); + } + } + + if ($fn->{RETURN_TYPE}) { + $self->pidl("py_result = " . $self->ConvertObjectToPython($fn->{RETURN_TYPE}, "r.out.result") . ";"); + } + + $self->pidl("talloc_free(mem_ctx);"); + $self->pidl("return result;"); $self->deindent; $self->pidl("}"); $self->pidl(""); } -sub handle_ntstatus($$$) +sub handle_ntstatus($$$$) { - my ($self, $var, $retval) = @_; + my ($self, $var, $retval, $mem_ctx) = @_; $self->pidl("if (NT_STATUS_IS_ERR($var)) {"); $self->indent; $self->pidl("PyErr_SetString(PyExc_RuntimeError, nt_errstr($var));"); + $self->pidl("talloc_free($mem_ctx);") if ($mem_ctx); $self->pidl("return $retval;"); $self->deindent; $self->pidl("}"); @@ -206,11 +273,19 @@ sub PythonType($$$) { my ($self, $d, $interface, $basename) = @_; + my $actual_ctype = $d; + if ($actual_ctype->{TYPE} eq "TYPEDEF") { + $actual_ctype = $actual_ctype->{DATA}; + } + if ($d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "TYPEDEF" and $d->{DATA}->{TYPE} eq "STRUCT") { - $self->FromTypeToPythonFunction($d); - $self->FromPythonToTypeFunction($d); - my $py_fnname = $self->TypeConstructor($d); + my $py_fnname; + if ($d->{TYPE} eq "STRUCT") { + $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d); + } else { + $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d->{DATA}); + } my $fn_name = $d->{NAME}; @@ -227,6 +302,26 @@ sub PythonType($$$) if ($d->{TYPE} eq "TYPEDEF" and ($d->{DATA}->{TYPE} eq "ENUM" or $d->{DATA}->{TYPE} eq "BITMAP")) { $self->EnumAndBitmapConsts($d->{NAME}, $d->{DATA}); } + + if ($actual_ctype->{TYPE} eq "UNION" or $actual_ctype->{TYPE} eq "STRUCT") { + $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . "*in)"); + $self->pidl("{"); + $self->indent; + $self->FromStructToPythonFunction($d) if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromUnionToPythonFunction($d) if ($actual_ctype->{TYPE} eq "UNION"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + + $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)"); + $self->pidl("{"); + $self->indent; + $self->FromPythonToStructFunction($d) if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromPythonToUnionFunction($d) if ($actual_ctype->{TYPE} eq "UNION"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + } } sub Interface($$$) @@ -319,6 +414,7 @@ sub Interface($$$) $self->pidl("const char *binding_string;"); $self->pidl("struct cli_credentials *credentials;"); $self->pidl("struct loadparm_context *lp_ctx;"); + $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); @@ -328,7 +424,7 @@ sub Interface($$$) $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); - $self->handle_ntstatus("status", "NULL"); + $self->handle_ntstatus("status", "NULL", "mem_ctx"); $self->pidl("return (PyObject *)ret;"); $self->deindent; @@ -347,6 +443,13 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } +sub ConvertObjectFromPython($$$) +{ + my ($self, $ctype, $cvar) = @_; + + return "FIXME($cvar)"; +} + sub ConvertObjectToPython($$$) { my ($self, $ctype, $cvar) = @_; @@ -355,14 +458,33 @@ sub ConvertObjectToPython($$$) return "PyString_FromString($cvar)"; } + if (ref($ctype) ne "HASH") { + $ctype = getType($ctype); + } + + my $actual_ctype = $ctype; + if ($ctype->{TYPE} eq "TYPEDEF") { + $actual_ctype = $ctype->{DATA}; + } + if ($cvar =~ /^[0-9]+$/ or - $ctype->{TYPE} eq "ENUM" or $ctype->{TYPE} eq "BITMAP" or - $ctype->{TYPE} eq "TYPEDEF" and - ($ctype->{TYPE} eq "ENUM" or $ctype->{TYPE} eq "BITMAP")) { + $actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or + $actual_ctype->{TYPE} eq "SCALAR" and ( + $actual_ctype->{NAME} =~ /^(uint[0-9]+|hyper)$/)) { return "PyInt_FromLong($cvar)"; } - die("Unknown type for ".mapTypeName($ctype).": $cvar"); + if ($ctype->{TYPE} eq "TYPEDEF" and ( + $actual_ctype->{TYPE} eq "STRUCT" or + $actual_ctype->{TYPE} eq "UNION")) { + return "py_import_$ctype->{NAME}($cvar)"; + } + + if ($ctype->{TYPE} eq "STRUCT" or $ctype->{TYPE} eq "UNION") { + return "py_import_$ctype->{TYPE}_$ctype->{NAME}($cvar)"; + } + + die("unknown type ".mapTypeName($ctype) . ": $cvar"); } sub Parse($$$$) -- cgit From 8986f3ee6f46c354fed2cce5e434dda060e6318b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 20:37:08 +0100 Subject: pidl/python: Convert some Python objects back to C, return proper tuples in client calls. (This used to be commit 1ab617296943dc1d270cbf999dedcfb3073d3d20) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 47 +++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 6b4b41f74f..4454eeefd7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -1,6 +1,6 @@ ################################################### # Python function wrapper generator -# Copyright jelmer@samba.org 2007 +# Copyright jelmer@samba.org 2007-2008 # released under the GNU GPL package Parse::Pidl::Samba4::Python; @@ -11,6 +11,7 @@ use Exporter; use strict; use Parse::Pidl::Typelist qw(hasType getType mapTypeName); use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::CUtil qw(get_value_of get_pointer_of); use vars qw($VERSION); $VERSION = '0.01'; @@ -220,12 +221,19 @@ sub PythonFunction($$$) $self->pidl("NTSTATUS status;"); $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); $self->pidl("struct dcerpc_$fn->{NAME} r;"); - $self->pidl("PyObject *result = Py_None;"); + $self->pidl("PyObject *result;"); + my $result_size = 0; + foreach my $e (@{$fn->{ELEMENTS}}) { - $self->pidl("PyObject *py_$e->{NAME};"); + if (grep(/in/,@{$e->{DIRECTION}})) { + $self->pidl("PyObject *py_$e->{NAME};"); + } + if (grep(/out/,@{$e->{DIRECTION}})) { + $result_size++; + } } if ($fn->{RETURN_TYPE}) { - $self->pidl("PyObject *py_result;"); + $result_size++; } $self->pidl(""); $self->pidl("ZERO_STRUCT(r.out);"); @@ -238,14 +246,20 @@ sub PythonFunction($$$) $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); $self->handle_ntstatus("status", "NULL", "mem_ctx"); + $self->pidl("result = PyTuple_New($result_size);"); + + my $i = 0; + foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/out/,@{$e->{DIRECTION}})) { - $self->pidl("py_$e->{NAME} = " . $self->ConvertObjectToPython($e->{TYPE}, "r.out.$e->{NAME}") . ";"); + $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPython($e->{TYPE}, "r.out.$e->{NAME}") . ");"); + + $i++; } } if ($fn->{RETURN_TYPE}) { - $self->pidl("py_result = " . $self->ConvertObjectToPython($fn->{RETURN_TYPE}, "r.out.result") . ";"); + $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPython($fn->{RETURN_TYPE}, "r.out.result") . ");"); } $self->pidl("talloc_free(mem_ctx);"); @@ -304,7 +318,7 @@ sub PythonType($$$) } if ($actual_ctype->{TYPE} eq "UNION" or $actual_ctype->{TYPE} eq "STRUCT") { - $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . "*in)"); + $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; $self->FromStructToPythonFunction($d) if ($actual_ctype->{TYPE} eq "STRUCT"); @@ -447,6 +461,21 @@ sub ConvertObjectFromPython($$$) { my ($self, $ctype, $cvar) = @_; + if (ref($ctype) ne "HASH") { + $ctype = getType($ctype); + } + + my $actual_ctype = $ctype; + if ($ctype->{TYPE} eq "TYPEDEF") { + $actual_ctype = $ctype->{DATA}; + } + + if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or + $actual_ctype->{TYPE} eq "SCALAR" and ( + $actual_ctype->{NAME} =~ /^(uint[0-9]+|hyper)$/)) { + return "PyInt_AsLong($cvar)"; + } + return "FIXME($cvar)"; } @@ -484,6 +513,10 @@ sub ConvertObjectToPython($$$) return "py_import_$ctype->{TYPE}_$ctype->{NAME}($cvar)"; } + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { + return "PyInt_FromLong($cvar->v)"; + } + die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -- cgit From 375624ecf95a0aac6e29ce0c7dca35f239c9dd12 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 12 Jan 2008 01:09:28 +0100 Subject: pidl/python: Some more support for special case types. (This used to be commit 991aa950a377bbc07e0bf05758574f850a6d0ff7) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 48 ++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 4454eeefd7..2bf5f1528a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -11,7 +11,7 @@ use Exporter; use strict; use Parse::Pidl::Typelist qw(hasType getType mapTypeName); use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::CUtil qw(get_value_of get_pointer_of); +use Parse::Pidl::CUtil qw(get_value_of get_pointer_to); use vars qw($VERSION); $VERSION = '0.01'; @@ -288,12 +288,11 @@ sub PythonType($$$) my ($self, $d, $interface, $basename) = @_; my $actual_ctype = $d; - if ($actual_ctype->{TYPE} eq "TYPEDEF") { + if ($actual_ctype->{TYPE} eq "TYPEDEF" or $actual_ctype->{TYPE} eq "DECLARE") { $actual_ctype = $actual_ctype->{DATA}; } - if ($d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "TYPEDEF" and - $d->{DATA}->{TYPE} eq "STRUCT") { + if ($actual_ctype->{TYPE} eq "STRUCT") { my $py_fnname; if ($d->{TYPE} eq "STRUCT") { $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d); @@ -466,13 +465,13 @@ sub ConvertObjectFromPython($$$) } my $actual_ctype = $ctype; - if ($ctype->{TYPE} eq "TYPEDEF") { + if ($ctype->{TYPE} eq "TYPEDEF" or $ctype->{TYPE} eq "DECLARE") { $actual_ctype = $ctype->{DATA}; } if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or $actual_ctype->{TYPE} eq "SCALAR" and ( - $actual_ctype->{NAME} =~ /^(uint[0-9]+|hyper)$/)) { + $actual_ctype->{NAME} =~ /^(uint[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong)$/)) { return "PyInt_AsLong($cvar)"; } @@ -488,18 +487,22 @@ sub ConvertObjectToPython($$$) } if (ref($ctype) ne "HASH") { + if (not hasType($ctype)) { + return "py_import_$ctype($cvar)"; # best bet + } + $ctype = getType($ctype); } my $actual_ctype = $ctype; - if ($ctype->{TYPE} eq "TYPEDEF") { + if ($ctype->{TYPE} eq "TYPEDEF" or $ctype->{TYPE} eq "DECLARE") { $actual_ctype = $ctype->{DATA}; } if ($cvar =~ /^[0-9]+$/ or $actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or - $actual_ctype->{TYPE} eq "SCALAR" and ( - $actual_ctype->{NAME} =~ /^(uint[0-9]+|hyper)$/)) { + ($actual_ctype->{TYPE} eq "SCALAR" and + $actual_ctype->{NAME} =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/)) { return "PyInt_FromLong($cvar)"; } @@ -509,6 +512,11 @@ sub ConvertObjectToPython($$$) return "py_import_$ctype->{NAME}($cvar)"; } + if ($actual_ctype->{TYPE} eq "SCALAR" and + $actual_ctype->{NAME} eq "DATA_BLOB") { + return "PyString_FromStringAndSize($cvar->data, $cvar->length)"; + } + if ($ctype->{TYPE} eq "STRUCT" or $ctype->{TYPE} eq "UNION") { return "py_import_$ctype->{TYPE}_$ctype->{NAME}($cvar)"; } @@ -517,6 +525,28 @@ sub ConvertObjectToPython($$$) return "PyInt_FromLong($cvar->v)"; } + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { + return "PyInt_FromLong($cvar->v)"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and + ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string")) { + return "PyString_FromString($cvar)"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "string_array") { + return "FIXME($cvar)"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { + return "FIXME($cvar)"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "pointer") { + return "PyCObject_FromVoidPtr($cvar, talloc_free)"; + } + + die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -- cgit From f0916ef230b48e3140a4fca68f96ab33350bee93 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 01:35:06 +0100 Subject: pidl/python: Remove references to DECLARE, which has been removed. (This used to be commit 9a907567c8e0836b731e0ef01f8d097a33de21b0) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2bf5f1528a..98e9ee9ec2 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -288,7 +288,7 @@ sub PythonType($$$) my ($self, $d, $interface, $basename) = @_; my $actual_ctype = $d; - if ($actual_ctype->{TYPE} eq "TYPEDEF" or $actual_ctype->{TYPE} eq "DECLARE") { + if ($actual_ctype->{TYPE} eq "TYPEDEF") { $actual_ctype = $actual_ctype->{DATA}; } @@ -465,7 +465,7 @@ sub ConvertObjectFromPython($$$) } my $actual_ctype = $ctype; - if ($ctype->{TYPE} eq "TYPEDEF" or $ctype->{TYPE} eq "DECLARE") { + if ($ctype->{TYPE} eq "TYPEDEF") { $actual_ctype = $ctype->{DATA}; } @@ -495,7 +495,7 @@ sub ConvertObjectToPython($$$) } my $actual_ctype = $ctype; - if ($ctype->{TYPE} eq "TYPEDEF" or $ctype->{TYPE} eq "DECLARE") { + if ($ctype->{TYPE} eq "TYPEDEF") { $actual_ctype = $ctype->{DATA}; } -- cgit From 4ba71079272b1231c457112ac2d90f1f920cf5c8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 01:50:31 +0100 Subject: pidl/python: Fix conversion of last few non-standard types. (This used to be commit b8bdbc38c15598e34c55fb9e3ee1f6894964d2c6) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 98e9ee9ec2..4ae647aa0a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -9,7 +9,7 @@ use Exporter; @ISA = qw(Exporter); use strict; -use Parse::Pidl::Typelist qw(hasType getType mapTypeName); +use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::CUtil qw(get_value_of get_pointer_to); @@ -471,7 +471,7 @@ sub ConvertObjectFromPython($$$) if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or $actual_ctype->{TYPE} eq "SCALAR" and ( - $actual_ctype->{NAME} =~ /^(uint[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong)$/)) { + expandAlias($actual_ctype->{NAME}) =~ /^(uint[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong)$/)) { return "PyInt_AsLong($cvar)"; } @@ -502,7 +502,7 @@ sub ConvertObjectToPython($$$) if ($cvar =~ /^[0-9]+$/ or $actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or ($actual_ctype->{TYPE} eq "SCALAR" and - $actual_ctype->{NAME} =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/)) { + expandAlias($actual_ctype->{NAME}) =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/)) { return "PyInt_FromLong($cvar)"; } @@ -513,7 +513,7 @@ sub ConvertObjectToPython($$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and - $actual_ctype->{NAME} eq "DATA_BLOB") { + expandAlias($actual_ctype->{NAME}) eq "DATA_BLOB") { return "PyString_FromStringAndSize($cvar->data, $cvar->length)"; } @@ -530,7 +530,7 @@ sub ConvertObjectToPython($$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and - ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string")) { + ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) { return "PyString_FromString($cvar)"; } -- cgit From d814f3ce1c58be53886deab31a815e444ca6c5d5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 03:15:55 +0100 Subject: pidl/python: Fix const type wrapping. (This used to be commit 35a4843f9c75a59ab98e785520114809903575cf) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 4ae647aa0a..ae4931571a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -65,7 +65,7 @@ sub Import sub Const($$) { my ($self, $const) = @_; - $self->register_constant($const->{NAME}, $const->{DATA}->{TYPE}, $const->{VALUE}); + $self->register_constant($const->{NAME}, $const->{DTYPE}, $const->{VALUE}); } sub register_constant($$$$) @@ -258,7 +258,7 @@ sub PythonFunction($$$) } } - if ($fn->{RETURN_TYPE}) { + if (defined($fn->{RETURN_TYPE})) { $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPython($fn->{RETURN_TYPE}, "r.out.result") . ");"); } @@ -460,10 +460,16 @@ sub ConvertObjectFromPython($$$) { my ($self, $ctype, $cvar) = @_; + die("undef type for $cvar") unless(defined($ctype)); + if (ref($ctype) ne "HASH") { $ctype = getType($ctype); } + if (ref($ctype) ne "HASH") { + return "FIXME($cvar)"; + } + my $actual_ctype = $ctype; if ($ctype->{TYPE} eq "TYPEDEF") { $actual_ctype = $ctype->{DATA}; @@ -482,13 +488,23 @@ sub ConvertObjectToPython($$$) { my ($self, $ctype, $cvar) = @_; + if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) { + return "PyInt_FromLong($cvar)"; + } + + die("undef type for $cvar") unless(defined($ctype)); + if ($cvar =~ /^".*"$/) { return "PyString_FromString($cvar)"; } if (ref($ctype) ne "HASH") { if (not hasType($ctype)) { - return "py_import_$ctype($cvar)"; # best bet + if (ref($ctype) eq "HASH") { + return "py_import_$ctype->{TYPE}_$ctype->{NAME}($cvar)"; + } else { + return "py_import_$ctype($cvar)"; # best bet + } } $ctype = getType($ctype); @@ -499,8 +515,7 @@ sub ConvertObjectToPython($$$) $actual_ctype = $ctype->{DATA}; } - if ($cvar =~ /^[0-9]+$/ or - $actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or + if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or ($actual_ctype->{TYPE} eq "SCALAR" and expandAlias($actual_ctype->{NAME}) =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/)) { return "PyInt_FromLong($cvar)"; -- cgit From 4a8ceb8c56c66059791e4ef74ef3cbef4259f961 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 15:11:28 +0100 Subject: pidl/python: Fix bug accidently filling in the body of enums/bitmaps without body. (This used to be commit 97971f0d8080f3934ea5940cc0f230004afb94a1) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index ae4931571a..d0a5bbd7e3 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -79,6 +79,8 @@ sub EnumAndBitmapConsts($$$) { my ($self, $name, $d) = @_; + return unless (defined($d->{ELEMENTS})); + foreach my $e (@{$d->{ELEMENTS}}) { $e =~ /^([A-Za-z0-9_]+)=(.*)$/; my $cname = $1; -- cgit From c660845737f454713f60f01d015125b053435b2c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 15:29:56 +0100 Subject: pidl/python: Fix more warnings in the generated code. (This used to be commit 23add37b729aaa85b83cbf6ba98e7042c01f6472) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 51 +++++++++++++++------------- source4/pidl/pidl | 3 +- 2 files changed, 30 insertions(+), 24 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index d0a5bbd7e3..fc5480b661 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -89,37 +89,39 @@ sub EnumAndBitmapConsts($$$) } } -sub FromUnionToPythonFunction($$) +sub FromUnionToPythonFunction($$$) { - my ($self, $type) = @_; + my ($self, $type, $name) = @_; #FIXME $self->pidl("return NULL;"); } -sub FromStructToPythonFunction($$) +sub FromStructToPythonFunction($$$) { - my ($self, $type) = @_; + my ($self, $type, $name) = @_; - #FIXME - $self->pidl("return NULL;"); + $self->pidl("$type->{NAME}\_Object *ret;"); + $self->pidl("ret = PyObject_New($type->{NAME}\_Object, &$type->{NAME}\_ObjectType);"); + $self->pidl("ret->object = talloc_reference(NULL, $name);"); + $self->pidl("return (PyObject *) ret;"); } -sub FromPythonToUnionFunction($$) +sub FromPythonToUnionFunction($$$$) { - my ($self, $type) = @_; + my ($self, $type, $mem_ctx, $name) = @_; #FIXME $self->pidl("return NULL;"); } -sub FromPythonToStructFunction($$) +sub FromPythonToStructFunction($$$$) { - my ($self, $type) = @_; + my ($self, $type, $mem_ctx, $name) = @_; - #FIXME - $self->pidl("return NULL;"); + $self->pidl("$type->{NAME}\_Object *py_object = ($type->{NAME}_Object *)$name;"); + $self->pidl("return talloc_reference($mem_ctx, py_object->object);"); } sub PythonStruct($$$$) @@ -222,7 +224,7 @@ sub PythonFunction($$$) $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); - $self->pidl("struct dcerpc_$fn->{NAME} r;"); + $self->pidl("struct $fn->{NAME} r;"); $self->pidl("PyObject *result;"); my $result_size = 0; @@ -234,11 +236,13 @@ sub PythonFunction($$$) $result_size++; } } + if ($result_size > 0) { + $self->pidl(""); + $self->pidl("ZERO_STRUCT(r.out);"); + } if ($fn->{RETURN_TYPE}) { $result_size++; } - $self->pidl(""); - $self->pidl("ZERO_STRUCT(r.out);"); foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$e->{DIRECTION}})) { @@ -322,8 +326,8 @@ sub PythonType($$$) $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; - $self->FromStructToPythonFunction($d) if ($actual_ctype->{TYPE} eq "STRUCT"); - $self->FromUnionToPythonFunction($d) if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromStructToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromUnionToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -331,8 +335,8 @@ sub PythonType($$$) $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)"); $self->pidl("{"); $self->indent; - $self->FromPythonToStructFunction($d) if ($actual_ctype->{TYPE} eq "STRUCT"); - $self->FromPythonToUnionFunction($d) if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromPythonToStructFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromPythonToUnionFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -414,8 +418,8 @@ sub Interface($$$) $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$interface->{NAME}\","); $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); - $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); - $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); + $self->pidl(".tp_dealloc = (destructor)interface_$interface->{NAME}_dealloc,"); + $self->pidl(".tp_getattr = (getattrfunc)interface_$interface->{NAME}_getattr,"); $self->deindent; $self->pidl("};"); @@ -567,9 +571,9 @@ sub ConvertObjectToPython($$$) die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -sub Parse($$$$) +sub Parse($$$$$) { - my($self,$basename,$ndr,$hdr) = @_; + my($self,$basename,$ndr,$ndr_hdr,$hdr) = @_; my $py_hdr = $hdr; $py_hdr =~ s/ndr_([^\/]+)$/py_$1/g; @@ -582,6 +586,7 @@ sub Parse($$$$) #include #include \"librpc/rpc/dcerpc.h\" #include \"$hdr\" +#include \"$ndr_hdr\" #include \"$py_hdr\" "); diff --git a/source4/pidl/pidl b/source4/pidl/pidl index 500b4dcbfc..4dfd57dc20 100755 --- a/source4/pidl/pidl +++ b/source4/pidl/pidl @@ -671,7 +671,8 @@ sub process_file($) if (defined($opt_python)) { require Parse::Pidl::Samba4::Python; my $generator = new Parse::Pidl::Samba4::Python(); - my ($hdr,$prsr) = $generator->Parse($basename, $ndr, $h_filename); + my ($hdr,$prsr) = $generator->Parse($basename, $ndr, + "$outputdir/ndr_$basename\_c.h", $h_filename); FileSave("$outputdir/py_$basename.c", $prsr); FileSave("$outputdir/py_$basename.h", $hdr); } -- cgit From ce874c0b898eee3dfa8439424350579bf974e98f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 15:51:15 +0100 Subject: pidl/python: Convert unions. (This used to be commit e9037d0f5d222efd4ca04a0f8ce5c39cb3bb6997) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 57 +++++++++++++++++++++------- 1 file changed, 43 insertions(+), 14 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index fc5480b661..8720421088 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -91,36 +91,65 @@ sub EnumAndBitmapConsts($$$) sub FromUnionToPythonFunction($$$) { - my ($self, $type, $name) = @_; + my ($self, $type, $switch, $name) = @_; - #FIXME + $self->pidl("switch ($switch) {"); + $self->indent; + + foreach my $e (@{$type->{ELEMENTS}}) { + my $conv = $self->ConvertObjectToPython($e->{TYPE}, "$name->$e->{NAME}"); + if (defined($e->{CASE})) { + $self->pidl("$e->{CASE}: return $conv;"); + } else { + $self->pidl("default: return $conv;"); + } + } + $self->deindent; + $self->pidl("}"); + + $self->pidl("PyErr_SetString(PyExc_TypeError, \"unknown union level\");"); $self->pidl("return NULL;"); } sub FromStructToPythonFunction($$$) { - my ($self, $type, $name) = @_; + my ($self, $type, $typename, $name) = @_; - $self->pidl("$type->{NAME}\_Object *ret;"); - $self->pidl("ret = PyObject_New($type->{NAME}\_Object, &$type->{NAME}\_ObjectType);"); + $self->pidl("$typename\_Object *ret;"); + $self->pidl("ret = PyObject_New($typename\_Object, &$typename\_ObjectType);"); $self->pidl("ret->object = talloc_reference(NULL, $name);"); $self->pidl("return (PyObject *) ret;"); } sub FromPythonToUnionFunction($$$$) { - my ($self, $type, $mem_ctx, $name) = @_; + my ($self, $type, $switch, $mem_ctx, $name) = @_; - #FIXME + $self->pidl("switch ($switch) {"); + $self->indent; + + foreach my $e (@{$type->{ELEMENTS}}) { + my $conv = $self->ConvertObjectFromPython($e->{TYPE}, "$name"); + if (defined($e->{CASE})) { + $self->pidl("$e->{CASE}: return $conv;"); + } else { + $self->pidl("default: return $conv;"); + } + } + + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("PyErr_SetString(PyExc_TypeError, \"invalid union level value\");"); $self->pidl("return NULL;"); } -sub FromPythonToStructFunction($$$$) +sub FromPythonToStructFunction($$$$$) { - my ($self, $type, $mem_ctx, $name) = @_; + my ($self, $type, $typename, $mem_ctx, $name) = @_; - $self->pidl("$type->{NAME}\_Object *py_object = ($type->{NAME}_Object *)$name;"); + $self->pidl("$typename\_Object *py_object = ($typename\_Object *)$name;"); $self->pidl("return talloc_reference($mem_ctx, py_object->object);"); } @@ -326,8 +355,8 @@ sub PythonType($$$) $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; - $self->FromStructToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "STRUCT"); - $self->FromUnionToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromStructToPythonFunction($actual_ctype, $d->{NAME}, "in") if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromUnionToPythonFunction($actual_ctype, "level", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -335,8 +364,8 @@ sub PythonType($$$) $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)"); $self->pidl("{"); $self->indent; - $self->FromPythonToStructFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "STRUCT"); - $self->FromPythonToUnionFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromPythonToStructFunction($actual_ctype, $d->{NAME}, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromPythonToUnionFunction($actual_ctype, "level", "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); -- cgit From d06c990dbe89cb3b5996b3470a36de1b821bcdfc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 16:59:15 +0100 Subject: pidl/python: Use new talloc utility functions. (This used to be commit 48cfd44dc088717c0282436148888e45b2632946) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 73 +++++++++------------------- 1 file changed, 24 insertions(+), 49 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 8720421088..4b552a9ba9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -112,16 +112,6 @@ sub FromUnionToPythonFunction($$$) $self->pidl("return NULL;"); } -sub FromStructToPythonFunction($$$) -{ - my ($self, $type, $typename, $name) = @_; - - $self->pidl("$typename\_Object *ret;"); - $self->pidl("ret = PyObject_New($typename\_Object, &$typename\_ObjectType);"); - $self->pidl("ret->object = talloc_reference(NULL, $name);"); - $self->pidl("return (PyObject *) ret;"); -} - sub FromPythonToUnionFunction($$$$) { my ($self, $type, $switch, $mem_ctx, $name) = @_; @@ -145,33 +135,19 @@ sub FromPythonToUnionFunction($$$$) $self->pidl("return NULL;"); } -sub FromPythonToStructFunction($$$$$) -{ - my ($self, $type, $typename, $mem_ctx, $name) = @_; - - $self->pidl("$typename\_Object *py_object = ($typename\_Object *)$name;"); - $self->pidl("return talloc_reference($mem_ctx, py_object->object);"); -} - sub PythonStruct($$$$) { my ($self, $name, $cname, $d) = @_; $self->pidl("staticforward PyTypeObject $name\_ObjectType;"); - $self->pidl("typedef struct {"); - $self->indent; - $self->pidl("PyObject_HEAD"); - $self->pidl("$cname *object;"); - $self->deindent; - $self->pidl("} $name\_Object;"); $self->pidl(""); $self->pidl("static PyObject *py_$name\_getattr(PyTypeObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $self->pidl("$name\_Object *py_object = ($name\_Object *)obj;"); - $self->pidl("$cname *object = talloc_get_type(py_object->object, $cname);"); + $self->pidl("py_talloc_Object *py_object = (py_talloc_Object *)obj;"); + $self->pidl("$cname *object = py_talloc_get_type(py_object, $cname);"); foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; @@ -186,21 +162,11 @@ sub PythonStruct($$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static void py_$name\_dealloc(PyObject* self)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$name\_Object *obj = ($name\_Object *)self;"); - $self->pidl("talloc_free(obj->object);"); - $self->pidl("PyObject_Del(self);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("static PyObject *py_$name\_setattr(PyTypeObject *obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $self->pidl("$name\_Object *py_object = ($name\_Object *)obj;"); - $self->pidl("$cname *object = talloc_get_type(py_object->object, $cname);"); + $self->pidl("py_talloc_Object *py_object = (py_talloc_Object *)obj;"); + $self->pidl("$cname *object = py_talloc_get_type(py_object, $cname);"); foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; @@ -220,8 +186,8 @@ sub PythonStruct($$$$) $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$name\","); - $self->pidl(".tp_basicsize = sizeof($name\_Object),"); - $self->pidl(".tp_dealloc = (destructor)py_$name\_dealloc,"); + $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),"); + $self->pidl(".tp_dealloc = (destructor)py_talloc_dealloc,"); $self->pidl(".tp_getattr = (getattrfunc)py_$name\_getattr,"); $self->pidl(".tp_setattr = (setattrfunc)py_$name\_setattr,"); $self->deindent; @@ -233,9 +199,8 @@ sub PythonStruct($$$$) $self->pidl("static PyObject *$py_fnname(PyObject *self, PyObject *args)"); $self->pidl("{"); $self->indent; - $self->pidl("$name\_Object *ret;"); - $self->pidl("ret = PyObject_New($name\_Object, &$name\_ObjectType);"); - $self->pidl("return (PyObject *) ret;"); + $self->pidl("$cname *ret = talloc_zero(NULL, $cname);"); + $self->pidl("return py_talloc_import(&$name\_ObjectType, ret);"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -351,11 +316,10 @@ sub PythonType($$$) $self->EnumAndBitmapConsts($d->{NAME}, $d->{DATA}); } - if ($actual_ctype->{TYPE} eq "UNION" or $actual_ctype->{TYPE} eq "STRUCT") { + if ($actual_ctype->{TYPE} eq "UNION") { $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; - $self->FromStructToPythonFunction($actual_ctype, $d->{NAME}, "in") if ($actual_ctype->{TYPE} eq "STRUCT"); $self->FromUnionToPythonFunction($actual_ctype, "level", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); @@ -364,7 +328,6 @@ sub PythonType($$$) $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)"); $self->pidl("{"); $self->indent; - $self->FromPythonToStructFunction($actual_ctype, $d->{NAME}, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "STRUCT"); $self->FromPythonToUnionFunction($actual_ctype, "level", "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); @@ -516,6 +479,14 @@ sub ConvertObjectFromPython($$$) return "PyInt_AsLong($cvar)"; } + if ($actual_ctype->{TYPE} eq "STRUCT") { + return "py_talloc_get_type($cvar, " . mapTypeName($ctype) . ")"; + } + + if ($actual_ctype->{TYPE} eq "UNION") { + return "py_export_$ctype->{NAME}($cvar)"; + } + return "FIXME($cvar)"; } @@ -556,12 +527,15 @@ sub ConvertObjectToPython($$$) return "PyInt_FromLong($cvar)"; } - if ($ctype->{TYPE} eq "TYPEDEF" and ( - $actual_ctype->{TYPE} eq "STRUCT" or - $actual_ctype->{TYPE} eq "UNION")) { + if ($ctype->{TYPE} eq "TYPEDEF" and $actual_ctype->{TYPE} eq "UNION") { return "py_import_$ctype->{NAME}($cvar)"; } + if ($ctype->{TYPE} eq "TYPEDEF" and $actual_ctype->{TYPE} eq "STRUCT") { + # FIXME: if $cvar is not a pointer, do a talloc_dup() + return "py_talloc_import(&$ctype->{NAME}_ObjectType, $cvar)"; + } + if ($actual_ctype->{TYPE} eq "SCALAR" and expandAlias($actual_ctype->{NAME}) eq "DATA_BLOB") { return "PyString_FromStringAndSize($cvar->data, $cvar->length)"; @@ -614,6 +588,7 @@ sub Parse($$$$$) #include \"includes.h\" #include #include \"librpc/rpc/dcerpc.h\" +#include \"scripting/python/pytalloc.h\" #include \"$hdr\" #include \"$ndr_hdr\" #include \"$py_hdr\" -- cgit From 915f1589252be8cb9fb86eed479e328371e355e1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 17:15:56 +0100 Subject: pidl/python: Support more scalar types when converting from Python. (This used to be commit 1f3bbb65e5a46715c49225eecc760faaf5dbb9d7) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 67 +++++++++++++++++++--------- 1 file changed, 47 insertions(+), 20 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 4b552a9ba9..1c0cafc050 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -120,7 +120,7 @@ sub FromPythonToUnionFunction($$$$) $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - my $conv = $self->ConvertObjectFromPython($e->{TYPE}, "$name"); + my $conv = $self->ConvertObjectFromPython($mem_ctx, $e->{TYPE}, "$name"); if (defined($e->{CASE})) { $self->pidl("$e->{CASE}: return $conv;"); } else { @@ -143,11 +143,10 @@ sub PythonStruct($$$$) $self->pidl(""); - $self->pidl("static PyObject *py_$name\_getattr(PyTypeObject *obj, char *name)"); + $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $self->pidl("py_talloc_Object *py_object = (py_talloc_Object *)obj;"); - $self->pidl("$cname *object = py_talloc_get_type(py_object, $cname);"); + $self->pidl("$cname *object = py_talloc_get_type(obj, $cname);"); foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; @@ -162,17 +161,16 @@ sub PythonStruct($$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$name\_setattr(PyTypeObject *obj, char *name, PyObject *value)"); + $self->pidl("static PyObject *py_$name\_setattr(PyObject *obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $self->pidl("py_talloc_Object *py_object = (py_talloc_Object *)obj;"); $self->pidl("$cname *object = py_talloc_get_type(py_object, $cname);"); foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; $self->indent; $self->pidl("/* FIXME: talloc_free($varname) if necessary */"); - $self->pidl("$varname = " . $self->ConvertObjectFromPython($e->{TYPE}, "value") . ";"); + $self->pidl("$varname = " . $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value") . ";"); $self->deindent; $self->pidl("}"); } @@ -187,9 +185,9 @@ sub PythonStruct($$$$) $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$name\","); $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),"); - $self->pidl(".tp_dealloc = (destructor)py_talloc_dealloc,"); - $self->pidl(".tp_getattr = (getattrfunc)py_$name\_getattr,"); - $self->pidl(".tp_setattr = (setattrfunc)py_$name\_setattr,"); + $self->pidl(".tp_dealloc = py_talloc_dealloc,"); + $self->pidl(".tp_getattr = py_$name\_getattr,"); + $self->pidl(".tp_setattr = py_$name\_setattr,"); $self->deindent; $self->pidl("};"); @@ -240,7 +238,7 @@ sub PythonFunction($$$) foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$e->{DIRECTION}})) { - $self->pidl("r.in.$e->{NAME} = " . $self->ConvertObjectFromPython($e->{TYPE}, "py_$e->{NAME}") . ";"); + $self->pidl("r.in.$e->{NAME} = " . $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "py_$e->{NAME}") . ";"); } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); @@ -396,10 +394,10 @@ sub Interface($$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyTypeObject *obj, char *name)"); + $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, (PyObject *)obj, name);"); + $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, obj, name);"); $self->deindent; $self->pidl("}"); @@ -454,9 +452,9 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } -sub ConvertObjectFromPython($$$) +sub ConvertObjectFromPython($$$$) { - my ($self, $ctype, $cvar) = @_; + my ($self, $mem_ctx, $ctype, $cvar) = @_; die("undef type for $cvar") unless(defined($ctype)); @@ -475,7 +473,7 @@ sub ConvertObjectFromPython($$$) if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or $actual_ctype->{TYPE} eq "SCALAR" and ( - expandAlias($actual_ctype->{NAME}) =~ /^(uint[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong)$/)) { + expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) { return "PyInt_AsLong($cvar)"; } @@ -487,7 +485,37 @@ sub ConvertObjectFromPython($$$) return "py_export_$ctype->{NAME}($cvar)"; } - return "FIXME($cvar)"; + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "DATA_BLOB") { + return "data_blob_talloc($mem_ctx, PyString_AsString($cvar), PyString_Size($cvar))"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and + ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) { + return "talloc_strdup($mem_ctx, PyString_AsString($cvar))"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { + return "FIXME($cvar)"; + } + + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { + return "PyInt_AsLong($cvar)"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { + return "PyInt_AsLong($cvar)"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "string_array") { + return "FIXME($cvar)"; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "pointer") { + return "PyCObject_AsVoidPtr($cvar)"; + } + + die("unknown type ".mapTypeName($ctype) . ": $cvar"); } sub ConvertObjectToPython($$$) @@ -546,11 +574,11 @@ sub ConvertObjectToPython($$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { - return "PyInt_FromLong($cvar->v)"; + return "PyInt_FromLong(NT_STATUS_V($cvar))"; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { - return "PyInt_FromLong($cvar->v)"; + return "PyInt_FromLong(W_ERROR_V($cvar))"; } if ($actual_ctype->{TYPE} eq "SCALAR" and @@ -570,7 +598,6 @@ sub ConvertObjectToPython($$$) return "PyCObject_FromVoidPtr($cvar, talloc_free)"; } - die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -- cgit From be01d080247c70ec260763adc7711976c8ee19fc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 18:05:43 +0100 Subject: pidl/python: Work towards supporting more complex types (arrays, etc). (This used to be commit 49d91a1a92e226c015db86ddc9ef772030415d76) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 191 ++++++++++++++++----------- 1 file changed, 115 insertions(+), 76 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 1c0cafc050..545d233d08 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -97,7 +97,13 @@ sub FromUnionToPythonFunction($$$) $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - my $conv = $self->ConvertObjectToPython($e->{TYPE}, "$name->$e->{NAME}"); + my $conv; + + if ($e->{NAME}) { + $conv = $self->ConvertObjectToPython($e->{TYPE}, "$name->$e->{NAME}"); + } else { + $conv = "Py_None"; + } if (defined($e->{CASE})) { $self->pidl("$e->{CASE}: return $conv;"); } else { @@ -112,27 +118,46 @@ sub FromUnionToPythonFunction($$$) $self->pidl("return NULL;"); } -sub FromPythonToUnionFunction($$$$) +sub FromPythonToUnionFunction($$$$$) { - my ($self, $type, $switch, $mem_ctx, $name) = @_; + my ($self, $type, $typename, $switch, $mem_ctx, $name) = @_; + + my $has_default = 0; + + $self->pidl("$typename *ret = talloc_zero($mem_ctx, $typename);"); $self->pidl("switch ($switch) {"); $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - my $conv = $self->ConvertObjectFromPython($mem_ctx, $e->{TYPE}, "$name"); if (defined($e->{CASE})) { - $self->pidl("$e->{CASE}: return $conv;"); + $self->pidl("$e->{CASE}:"); } else { - $self->pidl("default: return $conv;"); + $has_default = 1; + $self->pidl("default:"); } + $self->indent; + if ($e->{NAME}) { + $self->ConvertObjectFromPython($mem_ctx, $e->{TYPE}, $name, "ret->$e->{NAME}"); + } + $self->pidl("break;"); + $self->deindent; + $self->pidl(""); + } + + if (!$has_default) { + $self->pidl("default:"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"invalid union level value\");"); + $self->pidl("talloc_free(ret);"); + $self->pidl("ret = NULL;"); + $self->deindent; } $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("PyErr_SetString(PyExc_TypeError, \"invalid union level value\");"); - $self->pidl("return NULL;"); + $self->pidl("return ret;"); } sub PythonStruct($$$$) @@ -161,21 +186,22 @@ sub PythonStruct($$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$name\_setattr(PyObject *obj, char *name, PyObject *value)"); + $self->pidl("static int py_$name\_setattr(PyObject *py_obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = py_talloc_get_type(py_object, $cname);"); + $self->pidl("$cname *object = py_talloc_get_type(py_obj, $cname);"); foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; $self->indent; $self->pidl("/* FIXME: talloc_free($varname) if necessary */"); - $self->pidl("$varname = " . $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value") . ";"); + $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value", $varname); + $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); } $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); - $self->pidl("return NULL;"); + $self->pidl("return -1;"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -238,7 +264,7 @@ sub PythonFunction($$$) foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$e->{DIRECTION}})) { - $self->pidl("r.in.$e->{NAME} = " . $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "py_$e->{NAME}") . ";"); + $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "py_$e->{NAME}", "r.in.$e->{NAME}"); } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); @@ -303,7 +329,7 @@ sub PythonType($$$) $fn_name =~ s/^$interface->{NAME}_//; $fn_name =~ s/^$basename\_//; - $self->register_module_method($fn_name, $py_fnname, "METH_VARARGS|METH_KEYWORDS", "NULL"); + $self->register_module_method($fn_name, $py_fnname, "METH_NOARGS", "NULL"); } if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP") { @@ -315,7 +341,7 @@ sub PythonType($$$) } if ($actual_ctype->{TYPE} eq "UNION") { - $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)"); + $self->pidl("PyObject *py_import_$d->{NAME}(int level, " .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; $self->FromUnionToPythonFunction($actual_ctype, "level", "in") if ($actual_ctype->{TYPE} eq "UNION"); @@ -323,10 +349,10 @@ sub PythonType($$$) $self->pidl("}"); $self->pidl(""); - $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)"); + $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, PyObject *in)"); $self->pidl("{"); $self->indent; - $self->FromPythonToUnionFunction($actual_ctype, "level", "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromPythonToUnionFunction($actual_ctype, mapTypeName($d), "level", "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -452,9 +478,9 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } -sub ConvertObjectFromPython($$$$) +sub ConvertObjectFromPython($$$$$) { - my ($self, $mem_ctx, $ctype, $cvar) = @_; + my ($self, $mem_ctx, $ctype, $cvar, $target) = @_; die("undef type for $cvar") unless(defined($ctype)); @@ -463,7 +489,8 @@ sub ConvertObjectFromPython($$$$) } if (ref($ctype) ne "HASH") { - return "FIXME($cvar)"; + $self->pidl("$target = FIXME($cvar);"); + return; } my $actual_ctype = $ctype; @@ -474,64 +501,102 @@ sub ConvertObjectFromPython($$$$) if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or $actual_ctype->{TYPE} eq "SCALAR" and ( expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) { - return "PyInt_AsLong($cvar)"; + $self->pidl("$target = PyInt_AsLong($cvar);"); + return; } if ($actual_ctype->{TYPE} eq "STRUCT") { - return "py_talloc_get_type($cvar, " . mapTypeName($ctype) . ")"; + $self->pidl("$target = py_talloc_get_type($cvar, " . mapTypeName($ctype) . ");"); + return; } if ($actual_ctype->{TYPE} eq "UNION") { - return "py_export_$ctype->{NAME}($cvar)"; + $self->pidl("$target = py_export_$ctype->{NAME}($cvar);"); + return; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "DATA_BLOB") { - return "data_blob_talloc($mem_ctx, PyString_AsString($cvar), PyString_Size($cvar))"; + $self->pidl("$target = data_blob_talloc($mem_ctx, PyString_AsString($cvar), PyString_Size($cvar));"); + return; } if ($actual_ctype->{TYPE} eq "SCALAR" and ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) { - return "talloc_strdup($mem_ctx, PyString_AsString($cvar))"; + $self->pidl("$target = talloc_strdup($mem_ctx, PyString_AsString($cvar));"); + return; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { - return "FIXME($cvar)"; + $self->pidl("$target = FIXME($cvar);"); + return; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { - return "PyInt_AsLong($cvar)"; + $self->pidl("$target = PyInt_AsLong($cvar);"); + return; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { - return "PyInt_AsLong($cvar)"; + $self->pidl("$target = PyInt_AsLong($cvar);"); + return; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "string_array") { - return "FIXME($cvar)"; + $self->pidl("$target = FIXME($cvar);"); + return; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "pointer") { - return "PyCObject_AsVoidPtr($cvar)"; + $self->pidl("$target = PyCObject_AsVoidPtr($cvar);"); + return; } die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -sub ConvertObjectToPython($$$) +sub ConvertScalarToPython($$$) { - my ($self, $ctype, $cvar) = @_; + my ($self, $ctypename, $cvar) = @_; - if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) { + $ctypename = expandAlias($ctypename); + + if ($ctypename =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { return "PyInt_FromLong($cvar)"; } - die("undef type for $cvar") unless(defined($ctype)); + if ($ctypename eq "DATA_BLOB") { + return "PyString_FromStringAndSize($cvar->data, $cvar->length)"; + } + + if ($ctypename eq "NTSTATUS") { + return "PyInt_FromLong(NT_STATUS_V($cvar))"; + } + + if ($ctypename eq "WERROR") { + return "PyInt_FromLong(W_ERROR_V($cvar))"; + } - if ($cvar =~ /^".*"$/) { + if (($ctypename eq "string" or $ctypename eq "nbt_string" or $ctypename eq "nbt_name" or $ctypename eq "wrepl_nbt_name")) { return "PyString_FromString($cvar)"; } + if ($ctypename eq "string_array") { return "FIXME($cvar)"; } + + if ($$ctypename eq "ipv4address") { return "FIXME($cvar)"; } + if ($ctypename eq "pointer") { + return "PyCObject_FromVoidPtr($cvar, talloc_free)"; + } + + die("Unknown scalar type $ctypename"); +} + +sub ConvertObjectToPython($$$) +{ + my ($self, $ctype, $cvar) = @_; + + die("undef type for $cvar") unless(defined($ctype)); + if (ref($ctype) ne "HASH") { if (not hasType($ctype)) { if (ref($ctype) eq "HASH") { @@ -550,54 +615,19 @@ sub ConvertObjectToPython($$$) } if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or - ($actual_ctype->{TYPE} eq "SCALAR" and - expandAlias($actual_ctype->{NAME}) =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/)) { - return "PyInt_FromLong($cvar)"; + ($actual_ctype->{TYPE} eq "SCALAR") { + return $self->ConvertScalarToPython($actual_ctype->{NAME}, $cvar); } - if ($ctype->{TYPE} eq "TYPEDEF" and $actual_ctype->{TYPE} eq "UNION") { + if ($actual_ctype->{TYPE} eq "UNION") { return "py_import_$ctype->{NAME}($cvar)"; } - if ($ctype->{TYPE} eq "TYPEDEF" and $actual_ctype->{TYPE} eq "STRUCT") { + if ($actual_ctype->{TYPE} eq "STRUCT") { # FIXME: if $cvar is not a pointer, do a talloc_dup() return "py_talloc_import(&$ctype->{NAME}_ObjectType, $cvar)"; } - if ($actual_ctype->{TYPE} eq "SCALAR" and - expandAlias($actual_ctype->{NAME}) eq "DATA_BLOB") { - return "PyString_FromStringAndSize($cvar->data, $cvar->length)"; - } - - if ($ctype->{TYPE} eq "STRUCT" or $ctype->{TYPE} eq "UNION") { - return "py_import_$ctype->{TYPE}_$ctype->{NAME}($cvar)"; - } - - if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { - return "PyInt_FromLong(NT_STATUS_V($cvar))"; - } - - if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { - return "PyInt_FromLong(W_ERROR_V($cvar))"; - } - - if ($actual_ctype->{TYPE} eq "SCALAR" and - ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) { - return "PyString_FromString($cvar)"; - } - - if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "string_array") { - return "FIXME($cvar)"; - } - - if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { - return "FIXME($cvar)"; - } - - if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "pointer") { - return "PyCObject_FromVoidPtr($cvar, talloc_free)"; - } - die("unknown type ".mapTypeName($ctype) . ": $cvar"); } @@ -646,8 +676,17 @@ sub Parse($$$$$) $self->pidl("PyObject *m;"); $self->pidl("m = Py_InitModule(\"$basename\", $basename\_methods);"); foreach (keys %{$self->{constants}}) { - # FIXME: Handle non-string constants - $self->pidl("PyModule_AddObject(m, \"$_\", " . $self->ConvertObjectToPython($self->{constants}->{$_}->[0], $self->{constants}->{$_}->[1]) . ");"); + my $py_obj; + my ($ctype, $cvar) = @{$self->{constants}->{$_}}; + if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) { + $py_obj = "PyInt_FromLong($cvar)"; + } elsif ($cvar =~ /^".*"$/) { + $py_obj = "PyString_FromString($cvar)"; + } else { + $py_obj = $self->ConvertScalarToPython($ctype, $cvar); + } + + $self->pidl("PyModule_AddObject(m, \"$_\", $py_obj);"); } $self->deindent; $self->pidl("}"); -- cgit From a99dff8660ca2d168523b7264d9208a8a12ca5cc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 18:15:12 +0100 Subject: pidl: Move Generate*Env functions to Parse::Pidl::Samba4::Header because they only work with the structures generated by that file. (This used to be commit 9aeb7f31b0fc3b9679e5af07e65e79bc8073c4e1) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 4 +- source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba4/Header.pm | 71 +++++++++++++++++++++++- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 65 +--------------------- source4/pidl/tests/header.pl | 54 +++++++++++++++++- source4/pidl/tests/samba-ndr.pl | 51 +---------------- source4/pidl/tests/samba3-cli.pl | 2 +- 7 files changed, 130 insertions(+), 119 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index b7372a802a..86b8951026 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -9,7 +9,7 @@ package Parse::Pidl::Samba3::ClientNDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(GenerateFunctionInEnv ParseFunction $res $res_hdr); +@EXPORT_OK = qw(ParseFunction $res $res_hdr); use strict; use Parse::Pidl qw(fatal warning); @@ -17,7 +17,7 @@ use Parse::Pidl::Typelist qw(hasType getType mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(has_property is_constant ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(DeclLong); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionInEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv); use vars qw($VERSION); $VERSION = '0.01'; diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index 24270340b9..efb3f2858d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -15,7 +15,7 @@ use Parse::Pidl::Typelist qw(typeHasBody); use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateStructEnv GenerateFunctionInEnv +use Parse::Pidl::Samba4::Header qw(GenerateStructEnv GenerateFunctionInEnv GenerateFunctionOutEnv); use vars qw($VERSION); diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm index b96a58783c..06e9ec4b9f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -6,10 +6,15 @@ package Parse::Pidl::Samba4::Header; +require Exporter; + +@ISA = qw(Exporter); +@EXPORT_OK = qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv); + use strict; use Parse::Pidl qw(fatal); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); -use Parse::Pidl::Util qw(has_property is_constant unmake_str); +use Parse::Pidl::Util qw(has_property is_constant unmake_str ParseExpr); use Parse::Pidl::Samba4 qw(is_intree ElementStars ArrayBrackets choose_header); use vars qw($VERSION); @@ -406,4 +411,68 @@ sub Parse($) return $res; } +sub GenerateStructEnv($$) +{ + my ($x, $v) = @_; + my %env; + + foreach my $e (@{$x->{ELEMENTS}}) { + $env{$e->{NAME}} = "$v->$e->{NAME}"; + } + + $env{"this"} = $v; + + return \%env; +} + +sub EnvSubstituteValue($$) +{ + my ($env,$s) = @_; + + # Substitute the value() values in the env + foreach my $e (@{$s->{ELEMENTS}}) { + next unless (defined(my $v = has_property($e, "value"))); + + $env->{$e->{NAME}} = ParseExpr($v, $env, $e); + } + + return $env; +} + +sub GenerateFunctionInEnv($;$) +{ + my ($fn, $base) = @_; + my %env; + + $base = "r->" unless defined($base); + + foreach my $e (@{$fn->{ELEMENTS}}) { + if (grep (/in/, @{$e->{DIRECTION}})) { + $env{$e->{NAME}} = $base."in.$e->{NAME}"; + } + } + + return \%env; +} + +sub GenerateFunctionOutEnv($;$) +{ + my ($fn, $base) = @_; + my %env; + + $base = "r->" unless defined($base); + + foreach my $e (@{$fn->{ELEMENTS}}) { + if (grep (/out/, @{$e->{DIRECTION}})) { + $env{$e->{NAME}} = $base."out.$e->{NAME}"; + } elsif (grep (/in/, @{$e->{DIRECTION}})) { + $env{$e->{NAME}} = $base."in.$e->{NAME}"; + } + } + + return \%env; +} + + + 1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 8eb2f9ad15..0800a19fab 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -9,7 +9,7 @@ package Parse::Pidl::Samba4::NDR::Parser; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction NeededElement NeededType $res NeededInterface TypeFunctionName ParseElementPrint); +@EXPORT_OK = qw(check_null_pointer NeededFunction NeededElement NeededType $res NeededInterface TypeFunctionName ParseElementPrint); use strict; use Parse::Pidl::Typelist qw(hasType getType mapTypeName typeHasBody); @@ -17,6 +17,7 @@ use Parse::Pidl::Util qw(has_property ParseExpr ParseExprExt print_uuid); use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(is_intree choose_header); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv); use Parse::Pidl qw(warning); use vars qw($VERSION); @@ -193,68 +194,6 @@ sub end_flags($$) } } -sub GenerateStructEnv($$) -{ - my ($x, $v) = @_; - my %env; - - foreach my $e (@{$x->{ELEMENTS}}) { - $env{$e->{NAME}} = "$v->$e->{NAME}"; - } - - $env{"this"} = $v; - - return \%env; -} - -sub EnvSubstituteValue($$) -{ - my ($env,$s) = @_; - - # Substitute the value() values in the env - foreach my $e (@{$s->{ELEMENTS}}) { - next unless (defined(my $v = has_property($e, "value"))); - - $env->{$e->{NAME}} = ParseExpr($v, $env, $e); - } - - return $env; -} - -sub GenerateFunctionInEnv($;$) -{ - my ($fn, $base) = @_; - my %env; - - $base = "r->" unless defined($base); - - foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep (/in/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = $base."in.$e->{NAME}"; - } - } - - return \%env; -} - -sub GenerateFunctionOutEnv($;$) -{ - my ($fn, $base) = @_; - my %env; - - $base = "r->" unless defined($base); - - foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep (/out/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = $base."out.$e->{NAME}"; - } elsif (grep (/in/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = $base."in.$e->{NAME}"; - } - } - - return \%env; -} - ##################################################################### # parse the data of an array - push side sub ParseArrayPushHeader($$$$$$) diff --git a/source4/pidl/tests/header.pl b/source4/pidl/tests/header.pl index 8d0dccf507..db59484444 100755 --- a/source4/pidl/tests/header.pl +++ b/source4/pidl/tests/header.pl @@ -4,12 +4,14 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 27; use FindBin qw($RealBin); use lib "$RealBin"; use Util; use Parse::Pidl::Util qw(MyDumper); -use Parse::Pidl::Samba4::Header; +use Parse::Pidl::Samba4::Header qw( + GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv + EnvSubstituteValue); use Parse::Pidl::IDL qw(parse_string); use Parse::Pidl::NDR; @@ -56,3 +58,51 @@ like(parse_idl("interface p { typedef struct x { int p; } x; };"), like(parse_idl("cpp_quote(\"some-foo\")"), qr/some-foo/sm, "cpp quote"); + +# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work +my $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)); + +$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; +is_deeply({ foo => "r->foo", bar => "r->bar", this => "r" }, + GenerateStructEnv($fn, "r")); + +$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; +is_deeply({ foo => "some->complex.variable->foo", + bar => "some->complex.variable->bar", + this => "some->complex.variable" }, + GenerateStructEnv($fn, "some->complex.variable")); + +$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 3 }} ] }; + +my $env = GenerateStructEnv($fn, "r"); +EnvSubstituteValue($env, $fn); +is_deeply($env, { foo => 3, this => "r" }); + +$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; +$env = GenerateStructEnv($fn, "r"); +EnvSubstituteValue($env, $fn); +is_deeply($env, { foo => 'r->foo', bar => 'r->bar', this => "r" }); + +$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 0 }} ] }; + +$env = GenerateStructEnv($fn, "r"); +EnvSubstituteValue($env, $fn); +is_deeply($env, { foo => 0, this => "r" }); + + diff --git a/source4/pidl/tests/samba-ndr.pl b/source4/pidl/tests/samba-ndr.pl index 05c3c1c0df..a14111961f 100755 --- a/source4/pidl/tests/samba-ndr.pl +++ b/source4/pidl/tests/samba-ndr.pl @@ -4,15 +4,14 @@ use strict; use warnings; -use Test::More tests => 41; +use Test::More tests => 30; use FindBin qw($RealBin); use lib "$RealBin"; use Util; use strict; use Parse::Pidl::Util qw(MyDumper); use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer - GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv - EnvSubstituteValue NeededFunction NeededElement NeededType + NeededFunction NeededElement NeededType NeededInterface TypeFunctionName ParseElementPrint); my $output; @@ -138,52 +137,6 @@ test_warnings("nofile:2: unknown dereferenced expression `r->in.bla'\n", 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)); - -$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; -is_deeply({ foo => "r->foo", bar => "r->bar", this => "r" }, - GenerateStructEnv($fn, "r")); - -$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; -is_deeply({ foo => "some->complex.variable->foo", - bar => "some->complex.variable->bar", - this => "some->complex.variable" }, - GenerateStructEnv($fn, "some->complex.variable")); - -$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 3 }} ] }; - -my $env = GenerateStructEnv($fn, "r"); -EnvSubstituteValue($env, $fn); -is_deeply($env, { foo => 3, this => "r" }); - -$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; -$env = GenerateStructEnv($fn, "r"); -EnvSubstituteValue($env, $fn); -is_deeply($env, { foo => 'r->foo', bar => 'r->bar', this => "r" }); - -$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 0 }} ] }; - -$env = GenerateStructEnv($fn, "r"); -EnvSubstituteValue($env, $fn); -is_deeply($env, { foo => 0, this => "r" }); - my $needed = {}; NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "pull", $needed); is_deeply($needed, { ndr_pull_foo => 1 }); diff --git a/source4/pidl/tests/samba3-cli.pl b/source4/pidl/tests/samba3-cli.pl index 1b2a3c9785..f5b51b7d34 100755 --- a/source4/pidl/tests/samba3-cli.pl +++ b/source4/pidl/tests/samba3-cli.pl @@ -10,7 +10,7 @@ use lib "$RealBin"; use Util; use Parse::Pidl::Util qw(MyDumper); use Parse::Pidl::Samba3::ClientNDR qw(ParseFunction); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionInEnv GenerateFunctionOutEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv); # Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] }; -- cgit From f7a0ef04f00cd44845bcee0a171e4cc05a545350 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 18:38:12 +0100 Subject: pidl/python: Support repr() for python types. (This used to be commit cf3664594d3540db20d32bc844f18e20abfa0d96) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 545d233d08..a5f8053834 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -214,6 +214,7 @@ sub PythonStruct($$$$) $self->pidl(".tp_dealloc = py_talloc_dealloc,"); $self->pidl(".tp_getattr = py_$name\_getattr,"); $self->pidl(".tp_setattr = py_$name\_setattr,"); + $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->deindent; $self->pidl("};"); @@ -559,6 +560,8 @@ sub ConvertScalarToPython($$$) { my ($self, $ctypename, $cvar) = @_; + die("expected string for $cvar, not $ctypename") if (ref($ctypename) eq "HASH"); + $ctypename = expandAlias($ctypename); if ($ctypename =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { @@ -583,7 +586,7 @@ sub ConvertScalarToPython($$$) if ($ctypename eq "string_array") { return "FIXME($cvar)"; } - if ($$ctypename eq "ipv4address") { return "FIXME($cvar)"; } + if ($ctypename eq "ipv4address") { return "FIXME($cvar)"; } if ($ctypename eq "pointer") { return "PyCObject_FromVoidPtr($cvar, talloc_free)"; } @@ -614,8 +617,15 @@ sub ConvertObjectToPython($$$) $actual_ctype = $ctype->{DATA}; } - if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or - ($actual_ctype->{TYPE} eq "SCALAR") { + if ($actual_ctype->{TYPE} eq "ENUM") { + return $self->ConvertScalarToPython(Parse::Pidl::Typelist::enum_type_fn($actual_ctype), $cvar); + } + + if ($actual_ctype->{TYPE} eq "BITMAP") { + return $self->ConvertScalarToPython(Parse::Pidl::Typelist::bitmap_type_fn($actual_ctype), $cvar); + } + + if ($actual_ctype->{TYPE} eq "SCALAR") { return $self->ConvertScalarToPython($actual_ctype->{NAME}, $cvar); } @@ -675,18 +685,18 @@ sub Parse($$$$$) $self->indent; $self->pidl("PyObject *m;"); $self->pidl("m = Py_InitModule(\"$basename\", $basename\_methods);"); - foreach (keys %{$self->{constants}}) { + foreach my $name (keys %{$self->{constants}}) { my $py_obj; - my ($ctype, $cvar) = @{$self->{constants}->{$_}}; + my ($ctype, $cvar) = @{$self->{constants}->{$name}}; if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) { $py_obj = "PyInt_FromLong($cvar)"; } elsif ($cvar =~ /^".*"$/) { $py_obj = "PyString_FromString($cvar)"; } else { - $py_obj = $self->ConvertScalarToPython($ctype, $cvar); + $py_obj = $self->ConvertObjectToPython($ctype, $cvar); } - $self->pidl("PyModule_AddObject(m, \"$_\", $py_obj);"); + $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);"); } $self->deindent; $self->pidl("}"); -- cgit From bfab9862fcdd657a1bddafde49cdd182f89fcf8b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 20:41:34 +0100 Subject: python: Allow wrapping pointers within talloc'ed memory that are not talloc contexts. (This used to be commit 9c038a74113fb55ed5eb12a7d0ae4a46bad9050c) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 44 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index a5f8053834..cea3889938 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -138,7 +138,7 @@ sub FromPythonToUnionFunction($$$$$) } $self->indent; if ($e->{NAME}) { - $self->ConvertObjectFromPython($mem_ctx, $e->{TYPE}, $name, "ret->$e->{NAME}"); + $self->ConvertObjectFromPython($mem_ctx, $e->{TYPE}, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); } $self->pidl("break;"); $self->deindent; @@ -164,8 +164,6 @@ sub PythonStruct($$$$) { my ($self, $name, $cname, $d) = @_; - $self->pidl("staticforward PyTypeObject $name\_ObjectType;"); - $self->pidl(""); $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); @@ -190,12 +188,15 @@ sub PythonStruct($$$$) $self->pidl("{"); $self->indent; $self->pidl("$cname *object = py_talloc_get_type(py_obj, $cname);"); + $self->pidl("TALLOC_CTX *mem_ctx = py_talloc_get_mem_ctx(py_obj);"); foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; $self->indent; - $self->pidl("/* FIXME: talloc_free($varname) if necessary */"); - $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value", $varname); + if ($e->{ORIGINAL}->{POINTERS} > 0) { + $self->pidl("talloc_free($varname);"); + } + $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value", $varname, "talloc_free(mem_ctx); return -1;"); $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); @@ -206,7 +207,11 @@ sub PythonStruct($$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyTypeObject $name\_ObjectType = {"); + $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n"); + $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); + $self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n"); + $self->pidl_hdr("\n"); + $self->pidl("PyTypeObject $name\_Type = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$name\","); @@ -225,7 +230,7 @@ sub PythonStruct($$$$) $self->pidl("{"); $self->indent; $self->pidl("$cname *ret = talloc_zero(NULL, $cname);"); - $self->pidl("return py_talloc_import(&$name\_ObjectType, ret);"); + $self->pidl("return py_talloc_import(&$name\_Type, ret);"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -265,7 +270,7 @@ sub PythonFunction($$$) foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$e->{DIRECTION}})) { - $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "py_$e->{NAME}", "r.in.$e->{NAME}"); + $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "py_$e->{NAME}", "r.in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); @@ -377,7 +382,7 @@ sub Interface($$$) $self->PythonType($d, $interface, $basename); } - $self->pidl("staticforward PyTypeObject $interface->{NAME}_InterfaceType;"); + $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $interface->{NAME}_InterfaceType;\n"); $self->pidl("typedef struct {"); $self->indent; $self->pidl("PyObject_HEAD"); @@ -430,13 +435,13 @@ sub Interface($$$) $self->pidl(""); - $self->pidl("static PyTypeObject $interface->{NAME}_InterfaceType = {"); + $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$interface->{NAME}\","); $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); - $self->pidl(".tp_dealloc = (destructor)interface_$interface->{NAME}_dealloc,"); - $self->pidl(".tp_getattr = (getattrfunc)interface_$interface->{NAME}_getattr,"); + $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); + $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); $self->deindent; $self->pidl("};"); @@ -479,9 +484,9 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } -sub ConvertObjectFromPython($$$$$) +sub ConvertObjectFromPython($$$$$$) { - my ($self, $mem_ctx, $ctype, $cvar, $target) = @_; + my ($self, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; die("undef type for $cvar") unless(defined($ctype)); @@ -502,12 +507,14 @@ sub ConvertObjectFromPython($$$$$) if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or $actual_ctype->{TYPE} eq "SCALAR" and ( expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) { + $self->pidl("PY_CHECK_TYPE(PyInt, $cvar, $fail);"); $self->pidl("$target = PyInt_AsLong($cvar);"); return; } if ($actual_ctype->{TYPE} eq "STRUCT") { - $self->pidl("$target = py_talloc_get_type($cvar, " . mapTypeName($ctype) . ");"); + $self->pidl("PY_CHECK_TYPE($ctype->{NAME}, $cvar, $fail);"); + $self->pidl("$target = py_talloc_get_ptr($cvar);"); return; } @@ -635,7 +642,7 @@ sub ConvertObjectToPython($$$) if ($actual_ctype->{TYPE} eq "STRUCT") { # FIXME: if $cvar is not a pointer, do a talloc_dup() - return "py_talloc_import(&$ctype->{NAME}_ObjectType, $cvar)"; + return "py_talloc_import(&$ctype->{NAME}_Type, $cvar)"; } die("unknown type ".mapTypeName($ctype) . ": $cvar"); @@ -660,6 +667,11 @@ sub Parse($$$$$) #include \"$ndr_hdr\" #include \"$py_hdr\" +#define PY_CHECK_TYPE(type, var, fail) \\ + if (!type ## _Check(var)) {\\ + PyErr_Format(PyExc_TypeError, \"Expected type %s\", type ## _Type.tp_name); \\ + fail; \\ + } "); foreach my $x (@$ndr) { -- cgit From 41057618f890b9053dce9cd671d11db7af7d3612 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 21:23:12 +0100 Subject: pidl/python: Remove unnecessary talloc_free(). (This used to be commit a099d30067a4d965a283f52e56ffd1897137bf1a) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index cea3889938..93a6161ce4 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -196,7 +196,7 @@ sub PythonStruct($$$$) if ($e->{ORIGINAL}->{POINTERS} > 0) { $self->pidl("talloc_free($varname);"); } - $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value", $varname, "talloc_free(mem_ctx); return -1;"); + $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value", $varname, "return -1;"); $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); -- cgit From d8b21ae2534d5b51c1dc5a4c50b3de5ddb32af80 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 23:13:30 +0100 Subject: pidl/python: Fix use of pointers. (This used to be commit 13f2b0380f310b101975d709361a29d4032c3689) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 81 ++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 11 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 93a6161ce4..2d6ec50d39 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -11,6 +11,7 @@ use Exporter; use strict; use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias); use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::CUtil qw(get_value_of get_pointer_to); use vars qw($VERSION); @@ -100,7 +101,7 @@ sub FromUnionToPythonFunction($$$) my $conv; if ($e->{NAME}) { - $conv = $self->ConvertObjectToPython($e->{TYPE}, "$name->$e->{NAME}"); + $conv = $self->ConvertObjectToPython($e, "$name->$e->{NAME}"); } else { $conv = "Py_None"; } @@ -138,7 +139,7 @@ sub FromPythonToUnionFunction($$$$$) } $self->indent; if ($e->{NAME}) { - $self->ConvertObjectFromPython($mem_ctx, $e->{TYPE}, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); + $self->ConvertObjectFromPython($mem_ctx, $e, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); } $self->pidl("break;"); $self->deindent; @@ -174,7 +175,7 @@ sub PythonStruct($$$$) $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; $self->indent; - $self->pidl("return ".$self->ConvertObjectToPython($e->{TYPE}, $varname) . ";"); + $self->pidl("return ".$self->ConvertObjectToPython($e, $varname) . ";"); $self->deindent; $self->pidl("}"); } @@ -188,7 +189,7 @@ sub PythonStruct($$$$) $self->pidl("{"); $self->indent; $self->pidl("$cname *object = py_talloc_get_type(py_obj, $cname);"); - $self->pidl("TALLOC_CTX *mem_ctx = py_talloc_get_mem_ctx(py_obj);"); + my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; @@ -196,7 +197,7 @@ sub PythonStruct($$$$) if ($e->{ORIGINAL}->{POINTERS} > 0) { $self->pidl("talloc_free($varname);"); } - $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "value", $varname, "return -1;"); + $self->ConvertObjectFromPython($mem_ctx, $e, "value", $varname, "return -1;"); $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); @@ -270,7 +271,7 @@ sub PythonFunction($$$) foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$e->{DIRECTION}})) { - $self->ConvertObjectFromPython("mem_ctx", $e->{TYPE}, "py_$e->{NAME}", "r.in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); + $self->ConvertObjectFromPython("mem_ctx", $e, "py_$e->{NAME}", "r.in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); @@ -282,14 +283,14 @@ sub PythonFunction($$$) foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/out/,@{$e->{DIRECTION}})) { - $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPython($e->{TYPE}, "r.out.$e->{NAME}") . ");"); + $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPython($e, "r.out.$e->{NAME}") . ");"); $i++; } } if (defined($fn->{RETURN_TYPE})) { - $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPython($fn->{RETURN_TYPE}, "r.out.result") . ");"); + $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPythonData($fn->{RETURN_TYPE}, "r.out.result") . ");"); } $self->pidl("talloc_free(mem_ctx);"); @@ -484,7 +485,7 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } -sub ConvertObjectFromPython($$$$$$) +sub convertObjectFromPythonData($$$$$$) { my ($self, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; @@ -561,6 +562,36 @@ sub ConvertObjectFromPython($$$$$$) } die("unknown type ".mapTypeName($ctype) . ": $cvar"); + +} + +sub ConvertObjectFromPythonLevel($$$$$$$) +{ + my ($self, $mem_ctx, $e, $l, $var_name, $target, $fail) = @_; + + if ($l->{TYPE} eq "POINTER") { + $self->ConvertObjectFromPythonLevel($mem_ctx, $e, GetNextLevel($e, $l), get_value_of($var_name), $target, $fail); + } elsif ($l->{TYPE} eq "ARRAY") { + $self->ConvertObjectFromPythonLevel($mem_ctx, $e, GetNextLevel($e, $l), $var_name."[i]", $target, $fail); + } elsif ($l->{TYPE} eq "DATA") { + if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or + Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { + $var_name = get_pointer_to($var_name); + } + $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name, $target, $fail); + } elsif ($l->{TYPE} eq "SWITCH") { + $self->ConvertObjectFromPythonLevel($mem_ctx, $e, GetNextLevel($e, $l), get_value_of($var_name), $target, $fail); + } else { + die("unknown level type $l->{TYPE}"); + } +} + +sub ConvertObjectFromPython($$$$$$) +{ + my ($self, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; + + $self->ConvertObjectFromPythonLevel($mem_ctx, $ctype, $ctype->{LEVELS}[0], + $cvar, $target, $fail); } sub ConvertScalarToPython($$$) @@ -601,7 +632,7 @@ sub ConvertScalarToPython($$$) die("Unknown scalar type $ctypename"); } -sub ConvertObjectToPython($$$) +sub ConvertObjectToPythonData($$$) { my ($self, $ctype, $cvar) = @_; @@ -648,6 +679,34 @@ sub ConvertObjectToPython($$$) die("unknown type ".mapTypeName($ctype) . ": $cvar"); } +sub ConvertObjectToPythonLevel($$$$) +{ + my ($self, $e, $l, $var_name) = @_; + + if ($l->{TYPE} eq "POINTER") { + $self->ConvertObjectToPythonLevel($e, GetNextLevel($e, $l), get_value_of($var_name)); + } elsif ($l->{TYPE} eq "ARRAY") { + $self->ConvertObjectToPythonLevel($e, GetNextLevel($e, $l), $var_name."[i]"); + } elsif ($l->{TYPE} eq "SWITCH") { + $self->ConvertObjectToPythonLevel($e, GetNextLevel($e, $l), $var_name); + } elsif ($l->{TYPE} eq "DATA") { + if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or + Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { + $var_name = get_pointer_to($var_name); + } + $self->ConvertObjectToPythonData($l->{DATA_TYPE}, $var_name); + } else { + die("Unknown level type $l->{TYPE} $var_name"); + } +} + +sub ConvertObjectToPython($$$) +{ + my ($self, $ctype, $cvar) = @_; + + $self->ConvertObjectToPythonLevel($ctype, $ctype->{LEVELS}[0], $cvar); +} + sub Parse($$$$$) { my($self,$basename,$ndr,$ndr_hdr,$hdr) = @_; @@ -705,7 +764,7 @@ sub Parse($$$$$) } elsif ($cvar =~ /^".*"$/) { $py_obj = "PyString_FromString($cvar)"; } else { - $py_obj = $self->ConvertObjectToPython($ctype, $cvar); + $py_obj = $self->ConvertObjectToPythonData($ctype, $cvar); } $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);"); -- cgit From 5d60cb6ef1c63ce771ab44b6831147568061aa50 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 01:30:44 +0100 Subject: pidl/python: Fix parsing arguments, fix more pointer issues. (This used to be commit b00c1a072457e5083ffc24a8b74b3793d0b44eee) --- source4/pidl/lib/Parse/Pidl/NDR.pm | 17 ++- source4/pidl/lib/Parse/Pidl/Samba4/Header.pm | 2 - source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 15 +-- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 162 ++++++++++++++++++----- 4 files changed, 146 insertions(+), 50 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index 1d059ebdf7..fc6bfe4c96 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -35,7 +35,7 @@ use vars qw($VERSION); $VERSION = '0.01'; @ISA = qw(Exporter); @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString); -@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType can_contain_deferred); +@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType can_contain_deferred is_charset_array); use strict; use Parse::Pidl qw(warning fatal); @@ -1181,4 +1181,19 @@ sub Validate($) } } +sub is_charset_array($$) +{ + my ($e,$l) = @_; + + return 0 if ($l->{TYPE} ne "ARRAY"); + + my $nl = GetNextLevel($e,$l); + + return 0 unless ($nl->{TYPE} eq "DATA"); + + return has_property($e, "charset"); +} + + + 1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm index 06e9ec4b9f..2b3a9df80f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -473,6 +473,4 @@ sub GenerateFunctionOutEnv($;$) return \%env; } - - 1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 0800a19fab..02d3a80992 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -15,7 +15,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType mapTypeName typeHasBody); use Parse::Pidl::Util qw(has_property ParseExpr ParseExprExt print_uuid); use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred is_charset_array); use Parse::Pidl::Samba4 qw(is_intree choose_header); use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv); use Parse::Pidl qw(warning); @@ -78,19 +78,6 @@ sub has_fast_array($$) return ($t->{NAME} eq "uint8") or ($t->{NAME} eq "string"); } -sub is_charset_array($$) -{ - my ($e,$l) = @_; - - return 0 if ($l->{TYPE} ne "ARRAY"); - - my $nl = GetNextLevel($e,$l); - - return 0 unless ($nl->{TYPE} eq "DATA"); - - return has_property($e, "charset"); -} - #################################### # pidl() is our basic output routine diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2d6ec50d39..9a3e82a94b 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -11,8 +11,9 @@ use Exporter; use strict; use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias); use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred is_charset_array); use Parse::Pidl::CUtil qw(get_value_of get_pointer_to); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv); use vars qw($VERSION); $VERSION = '0.01'; @@ -94,22 +95,31 @@ sub FromUnionToPythonFunction($$$) { my ($self, $type, $switch, $name) = @_; + $self->pidl("PyObject *ret;"); + $self->pidl(""); + $self->pidl("switch ($switch) {"); $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - my $conv; - - if ($e->{NAME}) { - $conv = $self->ConvertObjectToPython($e, "$name->$e->{NAME}"); + if (defined($e->{CASE})) { + $self->pidl("$e->{CASE}:"); } else { - $conv = "Py_None"; + $self->pidl("default:"); } - if (defined($e->{CASE})) { - $self->pidl("$e->{CASE}: return $conv;"); + + $self->indent; + + if ($e->{NAME}) { + $self->ConvertObjectToPython({}, $e, "$name->$e->{NAME}", "ret"); } else { - $self->pidl("default: return $conv;"); + $self->pidl("ret = Py_None;"); } + + $self->pidl("return ret;"); + $self->pidl(""); + + $self->deindent; } $self->deindent; @@ -165,6 +175,8 @@ sub PythonStruct($$$$) { my ($self, $name, $cname, $d) = @_; + my $env = GenerateStructEnv($d, "object"); + $self->pidl(""); $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); @@ -175,7 +187,9 @@ sub PythonStruct($$$$) $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; $self->indent; - $self->pidl("return ".$self->ConvertObjectToPython($e, $varname) . ";"); + $self->pidl("PyObject *py_$e->{NAME};"); + $self->ConvertObjectToPython($env, $e, $varname, "py_$e->{NAME}"); + $self->pidl("return py_$e->{NAME};"); $self->deindent; $self->pidl("}"); } @@ -243,7 +257,7 @@ sub PythonFunction($$$) { my ($self, $fn, $iface) = @_; - $self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args)"); + $self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); @@ -251,16 +265,38 @@ sub PythonFunction($$$) $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); $self->pidl("struct $fn->{NAME} r;"); $self->pidl("PyObject *result;"); + + my $env = GenerateFunctionInEnv($fn, "r."); my $result_size = 0; + my $args_format = ""; + my $args_string = ""; + my $args_names = ""; + foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep(/in/,@{$e->{DIRECTION}})) { - $self->pidl("PyObject *py_$e->{NAME};"); - } + $self->pidl("PyObject *py_$e->{NAME};"); if (grep(/out/,@{$e->{DIRECTION}})) { $result_size++; } + if (grep(/in/,@{$e->{DIRECTION}})) { + $args_format .= "O"; + $args_string .= ", &py_$e->{NAME}"; + $args_names .= "\"$e->{NAME}\", "; + } } + $self->pidl("const char *kwnames[] = {"); + $self->indent; + $self->pidl($args_names . "NULL"); + $self->deindent; + $self->pidl("};"); + + $self->pidl(""); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"$args_format:$fn->{NAME}\", discard_const_p(char *, kwnames)$args_string)) {"); + $self->indent; + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + if ($result_size > 0) { $self->pidl(""); $self->pidl("ZERO_STRUCT(r.out);"); @@ -279,11 +315,13 @@ sub PythonFunction($$$) $self->pidl("result = PyTuple_New($result_size);"); + $env = GenerateFunctionOutEnv($fn, "r."); my $i = 0; foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/out/,@{$e->{DIRECTION}})) { - $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPython($e, "r.out.$e->{NAME}") . ");"); + $self->ConvertObjectToPython($env, $e, "r.out.$e->{NAME}", "py_$e->{NAME}"); + $self->pidl("PyTuple_SetItem(result, $i, py_$e->{NAME});"); $i++; } @@ -485,9 +523,9 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } -sub convertObjectFromPythonData($$$$$$) +sub ConvertObjectFromPythonData($$$$$$) { - my ($self, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; + my ($self, $mem_ctx, $cvar, $ctype, $target, $fail) = @_; die("undef type for $cvar") unless(defined($ctype)); @@ -567,20 +605,45 @@ sub convertObjectFromPythonData($$$$$$) sub ConvertObjectFromPythonLevel($$$$$$$) { - my ($self, $mem_ctx, $e, $l, $var_name, $target, $fail) = @_; + my ($self, $mem_ctx, $py_var, $e, $l, $var_name, $fail) = @_; if ($l->{TYPE} eq "POINTER") { - $self->ConvertObjectFromPythonLevel($mem_ctx, $e, GetNextLevel($e, $l), get_value_of($var_name), $target, $fail); + if ($l->{POINTER_TYPE} ne "ref") { + $self->pidl("if ($py_var == Py_None) {"); + $self->indent; + $self->pidl("$var_name = NULL;"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; + } + $self->ConvertObjectFromPythonLevel($mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); + if ($l->{POINTER_TYPE} ne "ref") { + $self->deindent; + $self->pidl("}"); + } } elsif ($l->{TYPE} eq "ARRAY") { - $self->ConvertObjectFromPythonLevel($mem_ctx, $e, GetNextLevel($e, $l), $var_name."[i]", $target, $fail); + if (is_charset_array($e, $l)) { + $self->pidl("$var_name = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); + } else { + my $counter = "i"; + $self->pidl("$var_name = talloc_array($mem_ctx, FIXME, PyList_Length($py_var));"); + $self->pidl("for ($counter = 0; $counter < PyList_Length($py_var); $counter++) {"); + $self->indent; + $self->ConvertObjectFromPythonLevel($var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail); + $self->deindent; + $self->pidl("}"); + } } elsif ($l->{TYPE} eq "DATA") { + if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { $var_name = get_pointer_to($var_name); } - $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name, $target, $fail); + $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail); } elsif ($l->{TYPE} eq "SWITCH") { - $self->ConvertObjectFromPythonLevel($mem_ctx, $e, GetNextLevel($e, $l), get_value_of($var_name), $target, $fail); + $self->ConvertObjectFromPythonLevel($mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); + } elsif ($l->{TYPE} eq "SUBCONTEXT") { + $self->pidl("FIXME"); } else { die("unknown level type $l->{TYPE}"); } @@ -590,8 +653,7 @@ sub ConvertObjectFromPython($$$$$$) { my ($self, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; - $self->ConvertObjectFromPythonLevel($mem_ctx, $ctype, $ctype->{LEVELS}[0], - $cvar, $target, $fail); + $self->ConvertObjectFromPythonLevel($mem_ctx, $cvar, $ctype, $ctype->{LEVELS}[0], $target, $fail); } sub ConvertScalarToPython($$$) @@ -632,7 +694,7 @@ sub ConvertScalarToPython($$$) die("Unknown scalar type $ctypename"); } -sub ConvertObjectToPythonData($$$) +sub ConvertObjectToPythonData($$$$) { my ($self, $ctype, $cvar) = @_; @@ -681,30 +743,64 @@ sub ConvertObjectToPythonData($$$) sub ConvertObjectToPythonLevel($$$$) { - my ($self, $e, $l, $var_name) = @_; + my ($self, $env, $e, $l, $var_name, $py_var) = @_; if ($l->{TYPE} eq "POINTER") { - $self->ConvertObjectToPythonLevel($e, GetNextLevel($e, $l), get_value_of($var_name)); + if ($l->{POINTER_TYPE} ne "ref") { + $self->pidl("if ($var_name == NULL) {"); + $self->indent; + $self->pidl("$py_var = Py_None;"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; + } + $self->ConvertObjectToPythonLevel($env, $e, GetNextLevel($e, $l), get_value_of($var_name), $py_var); + if ($l->{POINTER_TYPE} ne "ref") { + $self->deindent; + $self->pidl("}"); + } } elsif ($l->{TYPE} eq "ARRAY") { - $self->ConvertObjectToPythonLevel($e, GetNextLevel($e, $l), $var_name."[i]"); + if (is_charset_array($e, $l)) { + $self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");"); + } else { + die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS})); + my $length = $l->{SIZE_IS}; + if (defined($l->{LENGTH_IS})) { + $length = $l->{LENGTH_IS}; + } + + $length = ParseExpr($length, $env, $e); + $self->pidl("$py_var = PyList_New($length);"); + my $counter = "i"; + $self->pidl("for ($counter = 0; $counter < $length; $counter++) {"); + $self->indent; + my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}"; + $self->pidl("PyObject *$member_var;"); + $self->ConvertObjectToPythonLevel($env, $e, GetNextLevel($e, $l), $var_name."[$counter]", $member_var); + $self->pidl("PyList_SetItem($py_var, $counter, $member_var);"); + $self->deindent; + $self->pidl("}"); + } } elsif ($l->{TYPE} eq "SWITCH") { - $self->ConvertObjectToPythonLevel($e, GetNextLevel($e, $l), $var_name); + $self->ConvertObjectToPythonLevel($env, $e, GetNextLevel($e, $l), $var_name, $py_var); } elsif ($l->{TYPE} eq "DATA") { if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { $var_name = get_pointer_to($var_name); } - $self->ConvertObjectToPythonData($l->{DATA_TYPE}, $var_name); + $self->pidl("$py_var = ".$self->ConvertObjectToPythonData($l->{DATA_TYPE}, $var_name) . ";"); + } elsif ($l->{TYPE} eq "SUBCONTEXT") { + $self->pidl("FIXME"); } else { die("Unknown level type $l->{TYPE} $var_name"); } } -sub ConvertObjectToPython($$$) +sub ConvertObjectToPython($$$$$) { - my ($self, $ctype, $cvar) = @_; + my ($self, $env, $ctype, $cvar, $py_var) = @_; - $self->ConvertObjectToPythonLevel($ctype, $ctype->{LEVELS}[0], $cvar); + $self->ConvertObjectToPythonLevel($env, $ctype, $ctype->{LEVELS}[0], $cvar, $py_var); } sub Parse($$$$$) -- cgit From 657e0cc4d09a89944445b17fd3fdc56e777917d0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 02:04:06 +0100 Subject: pidl/python: Fix more compile errors. (This used to be commit 2eb4526599ec6d3c604dd9b1f258496c82288284) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 58 +++++++++++++++------------- 1 file changed, 32 insertions(+), 26 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 9a3e82a94b..a2ad3c6508 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -149,7 +149,7 @@ sub FromPythonToUnionFunction($$$$$) } $self->indent; if ($e->{NAME}) { - $self->ConvertObjectFromPython($mem_ctx, $e, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); + $self->ConvertObjectFromPython({}, $mem_ctx, $e, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); } $self->pidl("break;"); $self->deindent; @@ -211,7 +211,7 @@ sub PythonStruct($$$$) if ($e->{ORIGINAL}->{POINTERS} > 0) { $self->pidl("talloc_free($varname);"); } - $self->ConvertObjectFromPython($mem_ctx, $e, "value", $varname, "return -1;"); + $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); @@ -307,7 +307,7 @@ sub PythonFunction($$$) foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$e->{DIRECTION}})) { - $self->ConvertObjectFromPython("mem_ctx", $e, "py_$e->{NAME}", "r.in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); + $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r.in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); @@ -557,11 +557,6 @@ sub ConvertObjectFromPythonData($$$$$$) return; } - if ($actual_ctype->{TYPE} eq "UNION") { - $self->pidl("$target = py_export_$ctype->{NAME}($cvar);"); - return; - } - if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "DATA_BLOB") { $self->pidl("$target = data_blob_talloc($mem_ctx, PyString_AsString($cvar), PyString_Size($cvar));"); return; @@ -603,9 +598,9 @@ sub ConvertObjectFromPythonData($$$$$$) } -sub ConvertObjectFromPythonLevel($$$$$$$) +sub ConvertObjectFromPythonLevel($$$$$$$$) { - my ($self, $mem_ctx, $py_var, $e, $l, $var_name, $fail) = @_; + my ($self, $env, $mem_ctx, $py_var, $e, $l, $var_name, $fail) = @_; if ($l->{TYPE} eq "POINTER") { if ($l->{POINTER_TYPE} ne "ref") { @@ -616,20 +611,25 @@ sub ConvertObjectFromPythonLevel($$$$$$$) $self->pidl("} else {"); $self->indent; } - $self->ConvertObjectFromPythonLevel($mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); if ($l->{POINTER_TYPE} ne "ref") { $self->deindent; $self->pidl("}"); } } elsif ($l->{TYPE} eq "ARRAY") { if (is_charset_array($e, $l)) { - $self->pidl("$var_name = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); + $self->pidl(get_pointer_to($var_name) . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); } else { - my $counter = "i"; - $self->pidl("$var_name = talloc_array($mem_ctx, FIXME, PyList_Length($py_var));"); - $self->pidl("for ($counter = 0; $counter < PyList_Length($py_var); $counter++) {"); + my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; + $self->pidl("{"); $self->indent; - $self->ConvertObjectFromPythonLevel($var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail); + $self->pidl("int $counter;"); + $self->pidl("$var_name = talloc_array($mem_ctx, FIXME, PyList_Size($py_var));"); + $self->pidl("for ($counter = 0; $counter < PyList_Size($py_var); $counter++) {"); + $self->indent; + $self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail); + $self->deindent; + $self->pidl("}"); $self->deindent; $self->pidl("}"); } @@ -641,7 +641,9 @@ sub ConvertObjectFromPythonLevel($$$$$$$) } $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail); } elsif ($l->{TYPE} eq "SWITCH") { - $self->ConvertObjectFromPythonLevel($mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); + $var_name = get_pointer_to($var_name); + my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); + $self->pidl("$var_name = py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var);"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { $self->pidl("FIXME"); } else { @@ -649,11 +651,11 @@ sub ConvertObjectFromPythonLevel($$$$$$$) } } -sub ConvertObjectFromPython($$$$$$) +sub ConvertObjectFromPython($$$$$$$) { - my ($self, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; + my ($self, $env, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; - $self->ConvertObjectFromPythonLevel($mem_ctx, $cvar, $ctype, $ctype->{LEVELS}[0], $target, $fail); + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $cvar, $ctype, $ctype->{LEVELS}[0], $target, $fail); } sub ConvertScalarToPython($$$) @@ -729,10 +731,6 @@ sub ConvertObjectToPythonData($$$$) return $self->ConvertScalarToPython($actual_ctype->{NAME}, $cvar); } - if ($actual_ctype->{TYPE} eq "UNION") { - return "py_import_$ctype->{NAME}($cvar)"; - } - if ($actual_ctype->{TYPE} eq "STRUCT") { # FIXME: if $cvar is not a pointer, do a talloc_dup() return "py_talloc_import(&$ctype->{NAME}_Type, $cvar)"; @@ -761,6 +759,7 @@ sub ConvertObjectToPythonLevel($$$$) } } elsif ($l->{TYPE} eq "ARRAY") { if (is_charset_array($e, $l)) { + $var_name = get_pointer_to($var_name); $self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");"); } else { die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS})); @@ -771,7 +770,10 @@ sub ConvertObjectToPythonLevel($$$$) $length = ParseExpr($length, $env, $e); $self->pidl("$py_var = PyList_New($length);"); - my $counter = "i"; + $self->pidl("{"); + $self->indent; + my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; + $self->pidl("int $counter;"); $self->pidl("for ($counter = 0; $counter < $length; $counter++) {"); $self->indent; my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}"; @@ -780,9 +782,13 @@ sub ConvertObjectToPythonLevel($$$$) $self->pidl("PyList_SetItem($py_var, $counter, $member_var);"); $self->deindent; $self->pidl("}"); + $self->deindent; + $self->pidl("}"); } } elsif ($l->{TYPE} eq "SWITCH") { - $self->ConvertObjectToPythonLevel($env, $e, GetNextLevel($e, $l), $var_name, $py_var); + $var_name = get_pointer_to($var_name); + my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); + $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($switch, $var_name);"); } elsif ($l->{TYPE} eq "DATA") { if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { -- cgit From 2afa1bee549ae119b1088c1e6affaec6f1997887 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 02:27:40 +0100 Subject: python/pidl: Fix assignment. (This used to be commit 2d2cb6486e6e1a31ae94223784e49fb4eea8bb26) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index a2ad3c6508..a7e1791793 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -322,7 +322,6 @@ sub PythonFunction($$$) if (grep(/out/,@{$e->{DIRECTION}})) { $self->ConvertObjectToPython($env, $e, "r.out.$e->{NAME}", "py_$e->{NAME}"); $self->pidl("PyTuple_SetItem(result, $i, py_$e->{NAME});"); - $i++; } } @@ -523,6 +522,16 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } +sub assign($$$) +{ + my ($self, $dest, $src) = @_; + if ($dest =~ /^\&/) { + $self->pidl("memcpy($dest, $src, sizeof(*$dest));"); + } else { + $self->pidl("$dest = $src;"); + } +} + sub ConvertObjectFromPythonData($$$$$$) { my ($self, $mem_ctx, $cvar, $ctype, $target, $fail) = @_; @@ -553,7 +562,7 @@ sub ConvertObjectFromPythonData($$$$$$) if ($actual_ctype->{TYPE} eq "STRUCT") { $self->pidl("PY_CHECK_TYPE($ctype->{NAME}, $cvar, $fail);"); - $self->pidl("$target = py_talloc_get_ptr($cvar);"); + $self->assign($target, "py_talloc_get_ptr($cvar)"); return; } @@ -590,7 +599,7 @@ sub ConvertObjectFromPythonData($$$$$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "pointer") { - $self->pidl("$target = PyCObject_AsVoidPtr($cvar);"); + $self->assign($target, "PyCObject_AsVoidPtr($cvar)"); return; } @@ -624,7 +633,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) $self->pidl("{"); $self->indent; $self->pidl("int $counter;"); - $self->pidl("$var_name = talloc_array($mem_ctx, FIXME, PyList_Size($py_var));"); + $self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_Size($py_var));"); $self->pidl("for ($counter = 0; $counter < PyList_Size($py_var); $counter++) {"); $self->indent; $self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail); @@ -645,7 +654,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); $self->pidl("$var_name = py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var);"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { - $self->pidl("FIXME"); + $self->pidl("#error Subcontext not yet supported"); } else { die("unknown level type $l->{TYPE}"); } @@ -686,9 +695,9 @@ sub ConvertScalarToPython($$$) return "PyString_FromString($cvar)"; } - if ($ctypename eq "string_array") { return "FIXME($cvar)"; } - - if ($ctypename eq "ipv4address") { return "FIXME($cvar)"; } + # Not yet supported + if ($ctypename eq "string_array") { return "PyCObject_FromVoidPtr($cvar)"; } + if ($ctypename eq "ipv4address") { return "PyCObject_FromVoidPtr($cvar)"; } if ($ctypename eq "pointer") { return "PyCObject_FromVoidPtr($cvar, talloc_free)"; } @@ -794,7 +803,8 @@ sub ConvertObjectToPythonLevel($$$$) Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { $var_name = get_pointer_to($var_name); } - $self->pidl("$py_var = ".$self->ConvertObjectToPythonData($l->{DATA_TYPE}, $var_name) . ";"); + my $conv = $self->ConvertObjectToPythonData($l->{DATA_TYPE}, $var_name); + $self->pidl("$py_var = $conv;"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { $self->pidl("FIXME"); } else { -- cgit From d5903fd75e9640831f0e78fc04d3ffa5ea3b1b4a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 02:48:50 +0100 Subject: pidl/python: Fix compilation of py_echo. (This used to be commit 5ee99ff31c80ece6861b2a0323d71170ef9346b9) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index a7e1791793..f569f013dc 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -384,7 +384,7 @@ sub PythonType($$$) $self->EnumAndBitmapConsts($d->{NAME}, $d->{DATA}); } - if ($actual_ctype->{TYPE} eq "UNION") { + if ($actual_ctype->{TYPE} eq "UNION" and defined($actual_ctype->{ELEMENTS})) { $self->pidl("PyObject *py_import_$d->{NAME}(int level, " .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; @@ -486,7 +486,7 @@ sub Interface($$$) $self->pidl(""); $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "NULL"); - $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args)"); + $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); @@ -496,6 +496,18 @@ sub Interface($$$) $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); + $self->pidl("const char *kwnames[] = {"); + $self->indent; + $self->pidl("\"binding\", NULL"); + $self->deindent; + $self->pidl("};"); + $self->pidl(""); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string)) {"); + $self->indent; + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); # FIXME: Arguments: binding string, credentials, loadparm context $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); -- cgit From db4ee4cce5f1fd84f3f0a331e769a70394126ca5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 03:59:36 +0100 Subject: python: Fix rpcecho tests. (This used to be commit ebb78ea4232c1614755844849580e3697b0a53fa) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index f569f013dc..266a092788 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -491,8 +491,8 @@ sub Interface($$$) $self->indent; $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); $self->pidl("const char *binding_string;"); - $self->pidl("struct cli_credentials *credentials;"); - $self->pidl("struct loadparm_context *lp_ctx;"); + $self->pidl("struct cli_credentials *credentials = NULL;"); + $self->pidl("struct loadparm_context *lp_ctx = NULL;"); $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); -- cgit From 3b16c532f21202696d54ef87f8fa74d066812898 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 05:16:51 +0100 Subject: pidl/python: Pass credentials and loadparm context when connecting using DCE/RPC. (This used to be commit 4c87af95310e4aaee3f2e2da02d0ea70ed1ec25b) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 59 ++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 266a092788..04649d3668 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -264,7 +264,7 @@ sub PythonFunction($$$) $self->pidl("NTSTATUS status;"); $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); $self->pidl("struct $fn->{NAME} r;"); - $self->pidl("PyObject *result;"); + $self->pidl("PyObject *result = Py_None;"); my $env = GenerateFunctionInEnv($fn, "r."); my $result_size = 0; @@ -313,21 +313,33 @@ sub PythonFunction($$$) $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); $self->handle_ntstatus("status", "NULL", "mem_ctx"); - $self->pidl("result = PyTuple_New($result_size);"); - $env = GenerateFunctionOutEnv($fn, "r."); my $i = 0; + if ($result_size > 1) { + $self->pidl("result = PyTuple_New($result_size);"); + } + foreach my $e (@{$fn->{ELEMENTS}}) { + my $py_name = "py_$e->{NAME}"; if (grep(/out/,@{$e->{DIRECTION}})) { - $self->ConvertObjectToPython($env, $e, "r.out.$e->{NAME}", "py_$e->{NAME}"); - $self->pidl("PyTuple_SetItem(result, $i, py_$e->{NAME});"); - $i++; + $self->ConvertObjectToPython($env, $e, "r.out.$e->{NAME}", $py_name); + if ($result_size > 1) { + $self->pidl("PyTuple_SetItem(result, $i, $py_name);"); + $i++; + } else { + $self->pidl("result = $py_name;"); + } } } if (defined($fn->{RETURN_TYPE})) { - $self->pidl("PyTuple_SetItem(result, $i, " . $self->ConvertObjectToPythonData($fn->{RETURN_TYPE}, "r.out.result") . ");"); + my $conv = $self->ConvertObjectToPythonData($fn->{RETURN_TYPE}, "r.out.result"); + if ($result_size > 1) { + $self->pidl("PyTuple_SetItem(result, $i, $conv);"); + } else { + $self->pidl("result = $conv;"); + } } $self->pidl("talloc_free(mem_ctx);"); @@ -446,6 +458,7 @@ sub Interface($$$) my $fn_name = $d->{NAME}; $fn_name =~ s/^$interface->{NAME}_//; + $fn_name =~ s/^$basename\_//; $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); } @@ -491,25 +504,47 @@ sub Interface($$$) $self->indent; $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); $self->pidl("const char *binding_string;"); - $self->pidl("struct cli_credentials *credentials = NULL;"); + $self->pidl("struct cli_credentials *credentials;"); $self->pidl("struct loadparm_context *lp_ctx = NULL;"); + $self->pidl("PyObject *py_lp_ctx = NULL, *py_credentials = Py_None;"); $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); $self->pidl("const char *kwnames[] = {"); $self->indent; - $self->pidl("\"binding\", NULL"); + $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", NULL"); $self->deindent; $self->pidl("};"); + $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);"); + $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);"); + $self->pidl(""); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"sO|O:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); + $self->indent; + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string)) {"); + $self->pidl("if (py_lp_ctx != NULL) {"); + $self->indent; + $self->pidl("lp_ctx = lp_from_py_object(py_lp_ctx);"); + $self->pidl("if (lp_ctx == NULL) {"); $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected loadparm context\");"); $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); + $self->deindent; + $self->pidl("}"); $self->pidl(""); - # FIXME: Arguments: binding string, credentials, loadparm context + $self->pidl("credentials = cli_credentials_from_py_object(py_credentials);"); + $self->pidl("if (credentials == NULL) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected credentials\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); $self->pidl(""); @@ -517,6 +552,8 @@ sub Interface($$$) $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); $self->handle_ntstatus("status", "NULL", "mem_ctx"); + $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;"); + $self->pidl("return (PyObject *)ret;"); $self->deindent; $self->pidl("}"); -- cgit From 4cfd90308c4dffebf7cebdcd8c11a7aa836ce23e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 06:05:12 +0100 Subject: pidl/python: Specify memory context explicitly when returning Python objects. (This used to be commit 9c72f652e0d3f14d5db4d3930f0d1f9a1875e93f) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 62 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 04649d3668..e0751d0c72 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -91,9 +91,9 @@ sub EnumAndBitmapConsts($$$) } } -sub FromUnionToPythonFunction($$$) +sub FromUnionToPythonFunction($$$$) { - my ($self, $type, $switch, $name) = @_; + my ($self, $mem_ctx, $type, $switch, $name) = @_; $self->pidl("PyObject *ret;"); $self->pidl(""); @@ -111,7 +111,7 @@ sub FromUnionToPythonFunction($$$) $self->indent; if ($e->{NAME}) { - $self->ConvertObjectToPython({}, $e, "$name->$e->{NAME}", "ret"); + $self->ConvertObjectToPython($mem_ctx, {}, $e, "$name->$e->{NAME}", "ret"); } else { $self->pidl("ret = Py_None;"); } @@ -182,13 +182,13 @@ sub PythonStruct($$$$) $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = py_talloc_get_type(obj, $cname);"); + $self->pidl("$cname *object = py_talloc_get_ptr(obj);"); foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; $self->indent; $self->pidl("PyObject *py_$e->{NAME};"); - $self->ConvertObjectToPython($env, $e, $varname, "py_$e->{NAME}"); + $self->ConvertObjectToPython("py_talloc_get_talloc_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); $self->pidl("return py_$e->{NAME};"); $self->deindent; $self->pidl("}"); @@ -202,7 +202,7 @@ sub PythonStruct($$$$) $self->pidl("static int py_$name\_setattr(PyObject *py_obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = py_talloc_get_type(py_obj, $cname);"); + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; foreach my $e (@{$d->{ELEMENTS}}) { $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); @@ -263,10 +263,10 @@ sub PythonFunction($$$) $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); - $self->pidl("struct $fn->{NAME} r;"); + $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); $self->pidl("PyObject *result = Py_None;"); - - my $env = GenerateFunctionInEnv($fn, "r."); + + my $env = GenerateFunctionInEnv($fn, "r->"); my $result_size = 0; my $args_format = ""; @@ -297,23 +297,19 @@ sub PythonFunction($$$) $self->deindent; $self->pidl("}"); - if ($result_size > 0) { - $self->pidl(""); - $self->pidl("ZERO_STRUCT(r.out);"); - } if ($fn->{RETURN_TYPE}) { $result_size++; } foreach my $e (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$e->{DIRECTION}})) { - $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r.in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); + $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); } } - $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, &r);"); + $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); $self->handle_ntstatus("status", "NULL", "mem_ctx"); - $env = GenerateFunctionOutEnv($fn, "r."); + $env = GenerateFunctionOutEnv($fn, "r->"); my $i = 0; if ($result_size > 1) { @@ -323,7 +319,7 @@ sub PythonFunction($$$) foreach my $e (@{$fn->{ELEMENTS}}) { my $py_name = "py_$e->{NAME}"; if (grep(/out/,@{$e->{DIRECTION}})) { - $self->ConvertObjectToPython($env, $e, "r.out.$e->{NAME}", $py_name); + $self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name); if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $py_name);"); $i++; @@ -334,7 +330,7 @@ sub PythonFunction($$$) } if (defined($fn->{RETURN_TYPE})) { - my $conv = $self->ConvertObjectToPythonData($fn->{RETURN_TYPE}, "r.out.result"); + my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result"); if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $conv);"); } else { @@ -397,10 +393,10 @@ sub PythonType($$$) } if ($actual_ctype->{TYPE} eq "UNION" and defined($actual_ctype->{ELEMENTS})) { - $self->pidl("PyObject *py_import_$d->{NAME}(int level, " .mapTypeName($d) . " *in)"); + $self->pidl("PyObject *py_import_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, " .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; - $self->FromUnionToPythonFunction($actual_ctype, "level", "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromUnionToPythonFunction("mem_ctx", $actual_ctype, "level", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -676,9 +672,11 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) } } elsif ($l->{TYPE} eq "ARRAY") { if (is_charset_array($e, $l)) { + $self->pidl("PY_CHECK_TYPE(PyUnicode, $py_var, $fail);"); $self->pidl(get_pointer_to($var_name) . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); } else { my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; + $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);"); $self->pidl("{"); $self->indent; $self->pidl("int $counter;"); @@ -754,9 +752,9 @@ sub ConvertScalarToPython($$$) die("Unknown scalar type $ctypename"); } -sub ConvertObjectToPythonData($$$$) +sub ConvertObjectToPythonData($$$$$) { - my ($self, $ctype, $cvar) = @_; + my ($self, $mem_ctx, $ctype, $cvar) = @_; die("undef type for $cvar") unless(defined($ctype)); @@ -797,9 +795,9 @@ sub ConvertObjectToPythonData($$$$) die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -sub ConvertObjectToPythonLevel($$$$) +sub ConvertObjectToPythonLevel($$$$$) { - my ($self, $env, $e, $l, $var_name, $py_var) = @_; + my ($self, $mem_ctx, $env, $e, $l, $var_name, $py_var) = @_; if ($l->{TYPE} eq "POINTER") { if ($l->{POINTER_TYPE} ne "ref") { @@ -810,7 +808,7 @@ sub ConvertObjectToPythonLevel($$$$) $self->pidl("} else {"); $self->indent; } - $self->ConvertObjectToPythonLevel($env, $e, GetNextLevel($e, $l), get_value_of($var_name), $py_var); + $self->ConvertObjectToPythonLevel($var_name, $env, $e, GetNextLevel($e, $l), get_value_of($var_name), $py_var); if ($l->{POINTER_TYPE} ne "ref") { $self->deindent; $self->pidl("}"); @@ -836,7 +834,7 @@ sub ConvertObjectToPythonLevel($$$$) $self->indent; my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}"; $self->pidl("PyObject *$member_var;"); - $self->ConvertObjectToPythonLevel($env, $e, GetNextLevel($e, $l), $var_name."[$counter]", $member_var); + $self->ConvertObjectToPythonLevel($var_name, $env, $e, GetNextLevel($e, $l), $var_name."[$counter]", $member_var); $self->pidl("PyList_SetItem($py_var, $counter, $member_var);"); $self->deindent; $self->pidl("}"); @@ -846,13 +844,13 @@ sub ConvertObjectToPythonLevel($$$$) } elsif ($l->{TYPE} eq "SWITCH") { $var_name = get_pointer_to($var_name); my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); - $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($switch, $var_name);"); + $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);"); } elsif ($l->{TYPE} eq "DATA") { if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { $var_name = get_pointer_to($var_name); } - my $conv = $self->ConvertObjectToPythonData($l->{DATA_TYPE}, $var_name); + my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name); $self->pidl("$py_var = $conv;"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { $self->pidl("FIXME"); @@ -861,11 +859,11 @@ sub ConvertObjectToPythonLevel($$$$) } } -sub ConvertObjectToPython($$$$$) +sub ConvertObjectToPython($$$$$$) { - my ($self, $env, $ctype, $cvar, $py_var) = @_; + my ($self, $mem_ctx, $env, $ctype, $cvar, $py_var) = @_; - $self->ConvertObjectToPythonLevel($env, $ctype, $ctype->{LEVELS}[0], $cvar, $py_var); + $self->ConvertObjectToPythonLevel($mem_ctx, $env, $ctype, $ctype->{LEVELS}[0], $cvar, $py_var); } sub Parse($$$$$) @@ -925,7 +923,7 @@ sub Parse($$$$$) } elsif ($cvar =~ /^".*"$/) { $py_obj = "PyString_FromString($cvar)"; } else { - $py_obj = $self->ConvertObjectToPythonData($ctype, $cvar); + $py_obj = $self->ConvertObjectToPythonData("NULL", $ctype, $cvar); } $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);"); -- cgit From e231e24d89dfe3faaf0f791dc5e0df5fa9c21590 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 06:23:13 +0100 Subject: pidl/python: Deal with arrays that are not pointers. (This used to be commit 7516af7c7262240df3b804dda962194a811d4e96) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index e0751d0c72..1483083e22 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -673,8 +673,14 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) } elsif ($l->{TYPE} eq "ARRAY") { if (is_charset_array($e, $l)) { $self->pidl("PY_CHECK_TYPE(PyUnicode, $py_var, $fail);"); + # FIXME: Use Unix charset setting rather than utf-8 $self->pidl(get_pointer_to($var_name) . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); } else { + my $pl = GetPrevLevel($e, $l); + if ($pl && $pl->{TYPE} eq "POINTER") { + $var_name = get_pointer_to($var_name); + } + my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);"); $self->pidl("{"); @@ -816,8 +822,14 @@ sub ConvertObjectToPythonLevel($$$$$) } elsif ($l->{TYPE} eq "ARRAY") { if (is_charset_array($e, $l)) { $var_name = get_pointer_to($var_name); + # FIXME: Use Unix charset setting rather than utf-8 $self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");"); } else { + my $pl = GetPrevLevel($e, $l); + if ($pl && $pl->{TYPE} eq "POINTER") { + $var_name = get_pointer_to($var_name); + } + die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS})); my $length = $l->{SIZE_IS}; if (defined($l->{LENGTH_IS})) { -- cgit From 30a2a43a7546b5336058559f5ffd74b1f799c05b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 13:26:01 +0100 Subject: pidl/python: Fix processing UUID-less interfaces, external typedefs and certain bitmap elements. (This used to be commit e65618fff3299193c27959e2cc5a3937837e1422) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 261 +++++++++++++-------------- source4/pidl/lib/Parse/Pidl/Typelist.pm | 16 +- 2 files changed, 137 insertions(+), 140 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 1483083e22..e538771624 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -9,7 +9,7 @@ use Exporter; @ISA = qw(Exporter); use strict; -use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias); +use Parse::Pidl::Typelist qw(hasType resolveType getType mapTypeName expandAlias); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred is_charset_array); use Parse::Pidl::CUtil qw(get_value_of get_pointer_to); @@ -84,7 +84,7 @@ sub EnumAndBitmapConsts($$$) return unless (defined($d->{ELEMENTS})); foreach my $e (@{$d->{ELEMENTS}}) { - $e =~ /^([A-Za-z0-9_]+)=(.*)$/; + $e =~ /^([A-Za-z0-9_]+)/; my $cname = $1; $self->register_constant($cname, $d, $cname); @@ -188,7 +188,7 @@ sub PythonStruct($$$$) my $varname = "object->$e->{NAME}"; $self->indent; $self->pidl("PyObject *py_$e->{NAME};"); - $self->ConvertObjectToPython("py_talloc_get_talloc_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); + $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); $self->pidl("return py_$e->{NAME};"); $self->deindent; $self->pidl("}"); @@ -428,133 +428,135 @@ sub Interface($$$) $self->PythonType($d, $interface, $basename); } - $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $interface->{NAME}_InterfaceType;\n"); - $self->pidl("typedef struct {"); - $self->indent; - $self->pidl("PyObject_HEAD"); - $self->pidl("struct dcerpc_pipe *pipe;"); - $self->deindent; - $self->pidl("} $interface->{NAME}_InterfaceObject;"); + if (defined $interface->{PROPERTIES}->{uuid}) { + $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $interface->{NAME}_InterfaceType;\n"); + $self->pidl("typedef struct {"); + $self->indent; + $self->pidl("PyObject_HEAD"); + $self->pidl("struct dcerpc_pipe *pipe;"); + $self->deindent; + $self->pidl("} $interface->{NAME}_InterfaceObject;"); - $self->pidl(""); + $self->pidl(""); - foreach my $d (@{$interface->{FUNCTIONS}}) { - next if not defined($d->{OPNUM}); - next if has_property($d, "nopython"); + foreach my $d (@{$interface->{FUNCTIONS}}) { + next if not defined($d->{OPNUM}); + next if has_property($d, "nopython"); - $self->PythonFunction($d, $interface->{NAME}); - } + $self->PythonFunction($d, $interface->{NAME}); + } - $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {"); - $self->indent; - foreach my $d (@{$interface->{FUNCTIONS}}) { - next if not defined($d->{OPNUM}); - next if has_property($d, "nopython"); + $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {"); + $self->indent; + foreach my $d (@{$interface->{FUNCTIONS}}) { + next if not defined($d->{OPNUM}); + next if has_property($d, "nopython"); - my $fn_name = $d->{NAME}; + my $fn_name = $d->{NAME}; - $fn_name =~ s/^$interface->{NAME}_//; - $fn_name =~ s/^$basename\_//; + $fn_name =~ s/^$interface->{NAME}_//; + $fn_name =~ s/^$basename\_//; - $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); - } - $self->pidl("{ NULL, NULL, 0, NULL }"); - $self->deindent; - $self->pidl("};"); - $self->pidl(""); + $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); + } + $self->pidl("{ NULL, NULL, 0, NULL }"); + $self->deindent; + $self->pidl("};"); + $self->pidl(""); - $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *interface = ($interface->{NAME}_InterfaceObject *)self;"); - $self->pidl("talloc_free(interface->pipe);"); - $self->pidl("PyObject_Del(self);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); + $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$interface->{NAME}_InterfaceObject *interface = ($interface->{NAME}_InterfaceObject *)self;"); + $self->pidl("talloc_free(interface->pipe);"); + $self->pidl("PyObject_Del(self);"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); - $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyObject *obj, char *name)"); - $self->pidl("{"); - $self->indent; - $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, obj, name);"); - $self->deindent; - $self->pidl("}"); + $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyObject *obj, char *name)"); + $self->pidl("{"); + $self->indent; + $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, obj, name);"); + $self->deindent; + $self->pidl("}"); - $self->pidl(""); + $self->pidl(""); - $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); - $self->indent; - $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); - $self->pidl(".tp_name = \"$interface->{NAME}\","); - $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); - $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); - $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); - $self->deindent; - $self->pidl("};"); + $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); + $self->indent; + $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); + $self->pidl(".tp_name = \"$interface->{NAME}\","); + $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); + $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); + $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); + $self->deindent; + $self->pidl("};"); - $self->pidl(""); + $self->pidl(""); - $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "NULL"); - $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); - $self->pidl("const char *binding_string;"); - $self->pidl("struct cli_credentials *credentials;"); - $self->pidl("struct loadparm_context *lp_ctx = NULL;"); - $self->pidl("PyObject *py_lp_ctx = NULL, *py_credentials = Py_None;"); - $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); - $self->pidl("NTSTATUS status;"); - $self->pidl(""); - $self->pidl("const char *kwnames[] = {"); - $self->indent; - $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", NULL"); - $self->deindent; - $self->pidl("};"); - $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);"); - $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);"); - $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"sO|O:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); - $self->indent; - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("if (py_lp_ctx != NULL) {"); - $self->indent; - $self->pidl("lp_ctx = lp_from_py_object(py_lp_ctx);"); - $self->pidl("if (lp_ctx == NULL) {"); - $self->indent; - $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected loadparm context\");"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); + $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "NULL"); + $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); + $self->pidl("const char *binding_string;"); + $self->pidl("struct cli_credentials *credentials;"); + $self->pidl("struct loadparm_context *lp_ctx = NULL;"); + $self->pidl("PyObject *py_lp_ctx = NULL, *py_credentials = Py_None;"); + $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); + $self->pidl("NTSTATUS status;"); + $self->pidl(""); + $self->pidl("const char *kwnames[] = {"); + $self->indent; + $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", NULL"); + $self->deindent; + $self->pidl("};"); + $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);"); + $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);"); + $self->pidl(""); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"sO|O:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); + $self->indent; + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("if (py_lp_ctx != NULL) {"); + $self->indent; + $self->pidl("lp_ctx = lp_from_py_object(py_lp_ctx);"); + $self->pidl("if (lp_ctx == NULL) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected loadparm context\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); - $self->pidl("credentials = cli_credentials_from_py_object(py_credentials);"); - $self->pidl("if (credentials == NULL) {"); - $self->indent; - $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected credentials\");"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); + $self->pidl("credentials = cli_credentials_from_py_object(py_credentials);"); + $self->pidl("if (credentials == NULL) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected credentials\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); - $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); - $self->pidl(""); + $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); + $self->pidl(""); - $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); - $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); - $self->handle_ntstatus("status", "NULL", "mem_ctx"); + $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); + $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); + $self->handle_ntstatus("status", "NULL", "mem_ctx"); - $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;"); + $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;"); - $self->pidl("return (PyObject *)ret;"); - $self->deindent; - $self->pidl("}"); - - $self->pidl(""); + $self->pidl("return (PyObject *)ret;"); + $self->deindent; + $self->pidl("}"); + + $self->pidl(""); + } $self->pidl_hdr("\n"); $self->pidl_hdr("#endif /* _HEADER_NDR_$interface->{NAME} */\n"); @@ -583,9 +585,7 @@ sub ConvertObjectFromPythonData($$$$$$) die("undef type for $cvar") unless(defined($ctype)); - if (ref($ctype) ne "HASH") { - $ctype = getType($ctype); - } + $ctype = resolveType($ctype); if (ref($ctype) ne "HASH") { $self->pidl("$target = FIXME($cvar);"); @@ -764,38 +764,21 @@ sub ConvertObjectToPythonData($$$$$) die("undef type for $cvar") unless(defined($ctype)); - if (ref($ctype) ne "HASH") { - if (not hasType($ctype)) { - if (ref($ctype) eq "HASH") { - return "py_import_$ctype->{TYPE}_$ctype->{NAME}($cvar)"; - } else { - return "py_import_$ctype($cvar)"; # best bet - } - } - - $ctype = getType($ctype); - } + $ctype = resolveType($ctype); my $actual_ctype = $ctype; if ($ctype->{TYPE} eq "TYPEDEF") { $actual_ctype = $ctype->{DATA}; - } - + } + if ($actual_ctype->{TYPE} eq "ENUM") { return $self->ConvertScalarToPython(Parse::Pidl::Typelist::enum_type_fn($actual_ctype), $cvar); - } - - if ($actual_ctype->{TYPE} eq "BITMAP") { + } elsif ($actual_ctype->{TYPE} eq "BITMAP") { return $self->ConvertScalarToPython(Parse::Pidl::Typelist::bitmap_type_fn($actual_ctype), $cvar); - } - - if ($actual_ctype->{TYPE} eq "SCALAR") { + } elsif ($actual_ctype->{TYPE} eq "SCALAR") { return $self->ConvertScalarToPython($actual_ctype->{NAME}, $cvar); - } - - if ($actual_ctype->{TYPE} eq "STRUCT") { - # FIXME: if $cvar is not a pointer, do a talloc_dup() - return "py_talloc_import(&$ctype->{NAME}_Type, $cvar)"; + } elsif ($actual_ctype->{TYPE} eq "STRUCT") { + return "py_talloc_import_ex(&$ctype->{NAME}_Type, $mem_ctx, $cvar)"; } die("unknown type ".mapTypeName($ctype) . ": $cvar"); diff --git a/source4/pidl/lib/Parse/Pidl/Typelist.pm b/source4/pidl/lib/Parse/Pidl/Typelist.pm index e54ef11b88..9e6c683f82 100644 --- a/source4/pidl/lib/Parse/Pidl/Typelist.pm +++ b/source4/pidl/lib/Parse/Pidl/Typelist.pm @@ -7,7 +7,7 @@ package Parse::Pidl::Typelist; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(hasType getType mapTypeName scalar_is_reference expandAlias +@EXPORT_OK = qw(hasType getType resolveType mapTypeName scalar_is_reference expandAlias mapScalarType addType typeIs is_scalar enum_type_fn bitmap_type_fn mapType typeHasBody ); @@ -95,6 +95,20 @@ sub addType($) $types{$t->{NAME}} = $t; } +sub resolveType($) +{ + my ($ctype) = @_; + + if (not hasType($ctype)) { + # assume struct typedef + return { TYPE => "TYPEDEF", NAME => $ctype, DATA => { TYPE => "STRUCT" } }; + } else { + return getType($ctype); + } + + return $ctype; +} + sub getType($) { my $t = shift; -- cgit From 7dd468ff2e5a4c4ce503e1b8e024bf91dcf7a412 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 14:48:59 +0100 Subject: python: Fix python code for winreg, add test. (This used to be commit bd3e6c41c42738fcfcc5cef4e65f0e219d358260) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index e538771624..c8505e9904 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -665,6 +665,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) $self->pidl("} else {"); $self->indent; } + $self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);"); $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); if ($l->{POINTER_TYPE} ne "ref") { $self->deindent; @@ -686,7 +687,9 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) $self->pidl("{"); $self->indent; $self->pidl("int $counter;"); - $self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_Size($py_var));"); + if (!$l->{IS_FIXED}) { + $self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_Size($py_var));"); + } $self->pidl("for ($counter = 0; $counter < PyList_Size($py_var); $counter++) {"); $self->indent; $self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail); @@ -697,8 +700,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) } } elsif ($l->{TYPE} eq "DATA") { - if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or - Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { + if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) { $var_name = get_pointer_to($var_name); } $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail); @@ -841,8 +843,7 @@ sub ConvertObjectToPythonLevel($$$$$) my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);"); } elsif ($l->{TYPE} eq "DATA") { - if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or - Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) { + if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) { $var_name = get_pointer_to($var_name); } my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name); -- cgit From 035599fa651409502a6894179d5cd8a026110ba1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 15:25:09 +0100 Subject: python: Be more pythonic - turn WERROR and NTSTATUS return codes into exceptions. (This used to be commit 16fc69b843e92ae62b15caf927335cc117156499) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index c8505e9904..9f6a7847b1 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -298,7 +298,7 @@ sub PythonFunction($$$) $self->pidl("}"); if ($fn->{RETURN_TYPE}) { - $result_size++; + $result_size++ unless ($fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "NTSTATUS"); } foreach my $e (@{$fn->{ELEMENTS}}) { @@ -329,7 +329,11 @@ sub PythonFunction($$$) } } - if (defined($fn->{RETURN_TYPE})) { + if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") { + $self->handle_ntstatus("r->out.result", "NULL", "mem_ctx"); + } elsif (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "WERROR") { + $self->handle_werror("r->out.result", "NULL", "mem_ctx"); + } elsif (defined($fn->{RETURN_TYPE})) { my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result"); if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $conv);"); @@ -345,6 +349,20 @@ sub PythonFunction($$$) $self->pidl(""); } +sub handle_werror($$$$) +{ + my ($self, $var, $retval, $mem_ctx) = @_; + + $self->pidl("if (!W_ERROR_IS_OK($var)) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, win_errstr($var));"); + $self->pidl("talloc_free($mem_ctx);") if ($mem_ctx); + $self->pidl("return $retval;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); +} + sub handle_ntstatus($$$$) { my ($self, $var, $retval, $mem_ctx) = @_; -- cgit From fa5397fbeda759ac66fc5d0a6bdfb60a070a7962 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 16:11:58 +0100 Subject: python: Build epmapper module. (This used to be commit 6cb78c7634de0f9ab327583844d7860d384356eb) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 83 +++++++++++++--------------- 1 file changed, 37 insertions(+), 46 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 9f6a7847b1..0d5237022a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -102,11 +102,7 @@ sub FromUnionToPythonFunction($$$$) $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - if (defined($e->{CASE})) { - $self->pidl("$e->{CASE}:"); - } else { - $self->pidl("default:"); - } + $self->pidl("$e->{CASE}:"); $self->indent; @@ -141,12 +137,8 @@ sub FromPythonToUnionFunction($$$$$) $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - if (defined($e->{CASE})) { - $self->pidl("$e->{CASE}:"); - } else { - $has_default = 1; - $self->pidl("default:"); - } + $self->pidl("$e->{CASE}:"); + if ($e->{CASE} eq "default") { $has_default = 1; } $self->indent; if ($e->{NAME}) { $self->ConvertObjectFromPython({}, $mem_ctx, $e, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); @@ -182,16 +174,18 @@ sub PythonStruct($$$$) $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = py_talloc_get_ptr(obj);"); - foreach my $e (@{$d->{ELEMENTS}}) { - $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); - my $varname = "object->$e->{NAME}"; - $self->indent; - $self->pidl("PyObject *py_$e->{NAME};"); - $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); - $self->pidl("return py_$e->{NAME};"); - $self->deindent; - $self->pidl("}"); + if ($#{$d->{ELEMENTS}} > -1) { + $self->pidl("$cname *object = py_talloc_get_ptr(obj);"); + foreach my $e (@{$d->{ELEMENTS}}) { + $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); + my $varname = "object->$e->{NAME}"; + $self->indent; + $self->pidl("PyObject *py_$e->{NAME};"); + $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); + $self->pidl("return py_$e->{NAME};"); + $self->deindent; + $self->pidl("}"); + } } $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); $self->pidl("return NULL;"); @@ -202,19 +196,21 @@ sub PythonStruct($$$$) $self->pidl("static int py_$name\_setattr(PyObject *py_obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); - my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; - foreach my $e (@{$d->{ELEMENTS}}) { - $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); - my $varname = "object->$e->{NAME}"; - $self->indent; - if ($e->{ORIGINAL}->{POINTERS} > 0) { - $self->pidl("talloc_free($varname);"); + if ($#{$d->{ELEMENTS}} > -1) { + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; + foreach my $e (@{$d->{ELEMENTS}}) { + $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); + my $varname = "object->$e->{NAME}"; + $self->indent; + if ($e->{ORIGINAL}->{POINTERS} > 0) { + $self->pidl("talloc_free($varname);"); + } + $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); + $self->pidl("return 0;"); + $self->deindent; + $self->pidl("}"); } - $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); - $self->pidl("return 0;"); - $self->deindent; - $self->pidl("}"); } $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); $self->pidl("return -1;"); @@ -591,7 +587,7 @@ sub assign($$$) { my ($self, $dest, $src) = @_; if ($dest =~ /^\&/) { - $self->pidl("memcpy($dest, $src, sizeof(*$dest));"); + $self->pidl("memcpy($dest, $src, sizeof(" . get_value_of($dest) . "));"); } else { $self->pidl("$dest = $src;"); } @@ -605,11 +601,6 @@ sub ConvertObjectFromPythonData($$$$$$) $ctype = resolveType($ctype); - if (ref($ctype) ne "HASH") { - $self->pidl("$target = FIXME($cvar);"); - return; - } - my $actual_ctype = $ctype; if ($ctype->{TYPE} eq "TYPEDEF") { $actual_ctype = $ctype->{DATA}; @@ -641,7 +632,7 @@ sub ConvertObjectFromPythonData($$$$$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { - $self->pidl("$target = FIXME($cvar);"); + $self->pidl("$target = PyString_AsString($cvar);"); return; } @@ -657,7 +648,7 @@ sub ConvertObjectFromPythonData($$$$$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "string_array") { - $self->pidl("$target = FIXME($cvar);"); + $self->pidl("$target = PyCObject_AsVoidPtr($cvar);"); return; } @@ -725,9 +716,9 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) } elsif ($l->{TYPE} eq "SWITCH") { $var_name = get_pointer_to($var_name); my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); - $self->pidl("$var_name = py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var);"); + $self->assign($var_name, "py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var)"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { - $self->pidl("#error Subcontext not yet supported"); + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail); } else { die("unknown level type $l->{TYPE}"); } @@ -753,7 +744,7 @@ sub ConvertScalarToPython($$$) } if ($ctypename eq "DATA_BLOB") { - return "PyString_FromStringAndSize($cvar->data, $cvar->length)"; + return "PyString_FromStringAndSize((char *)($cvar).data, ($cvar).length)"; } if ($ctypename eq "NTSTATUS") { @@ -770,7 +761,7 @@ sub ConvertScalarToPython($$$) # Not yet supported if ($ctypename eq "string_array") { return "PyCObject_FromVoidPtr($cvar)"; } - if ($ctypename eq "ipv4address") { return "PyCObject_FromVoidPtr($cvar)"; } + if ($ctypename eq "ipv4address") { return "PyString_FromString($cvar)"; } if ($ctypename eq "pointer") { return "PyCObject_FromVoidPtr($cvar, talloc_free)"; } @@ -867,7 +858,7 @@ sub ConvertObjectToPythonLevel($$$$$) my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name); $self->pidl("$py_var = $conv;"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { - $self->pidl("FIXME"); + $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var); } else { die("Unknown level type $l->{TYPE} $var_name"); } -- cgit From 860106b3f426a06eed6a681fa839dd89f339ba9a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 16:49:19 +0100 Subject: python: Move some convenience macros to a separate header rather than putting them in every generated py_* file. (This used to be commit 712274b9bdf524da125cbbe6e4bb475b21b1da66) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 0d5237022a..84b3405bb9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -886,20 +886,16 @@ sub Parse($$$$$) #include #include \"librpc/rpc/dcerpc.h\" #include \"scripting/python/pytalloc.h\" +#include \"scripting/python/pyrpc.h\" #include \"$hdr\" #include \"$ndr_hdr\" #include \"$py_hdr\" -#define PY_CHECK_TYPE(type, var, fail) \\ - if (!type ## _Check(var)) {\\ - PyErr_Format(PyExc_TypeError, \"Expected type %s\", type ## _Type.tp_name); \\ - fail; \\ - } "); foreach my $x (@$ndr) { - ($x->{TYPE} eq "INTERFACE") && $self->Interface($x, $basename); ($x->{TYPE} eq "IMPORT") && $self->Import(@{$x->{PATHS}}); + ($x->{TYPE} eq "INTERFACE") && $self->Interface($x, $basename); } $self->pidl("static PyMethodDef $basename\_methods[] = {"); -- cgit From 994e43e9ebd3922f2c3378edf0e73e912815230a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 18:01:54 +0100 Subject: python: Don't try to free const pointers. (This used to be commit b4754f4683e67a940f18a88e45c0878259f45b97) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 84b3405bb9..73442be59d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -203,7 +203,11 @@ sub PythonStruct($$$$) $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; $self->indent; - if ($e->{ORIGINAL}->{POINTERS} > 0) { + my $l = $e->{LEVELS}[0]; + my $nl = GetNextLevel($e, $l); + if ($l->{TYPE} eq "POINTER" and + not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and + not ($nl->{TYPE} eq "SCALAR" and $nl->{TYPE} eq "string")) { $self->pidl("talloc_free($varname);"); } $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); -- cgit From 134e38ac28b30b7fb3f4efcf9985c17ff2f070ad Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 18:24:10 +0100 Subject: python: Fix some corner cases handling scalars. (This used to be commit b662c98a9ad461a33a27a918c0d544a96433e48c) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 73442be59d..8ff909a455 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -207,7 +207,7 @@ sub PythonStruct($$$$) my $nl = GetNextLevel($e, $l); if ($l->{TYPE} eq "POINTER" and not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and - not ($nl->{TYPE} eq "SCALAR" and $nl->{TYPE} eq "string")) { + not ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}))) { $self->pidl("talloc_free($varname);"); } $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); @@ -668,8 +668,13 @@ sub ConvertObjectFromPythonData($$$$$$) sub ConvertObjectFromPythonLevel($$$$$$$$) { my ($self, $env, $mem_ctx, $py_var, $e, $l, $var_name, $fail) = @_; + my $nl = GetNextLevel($e, $l); if ($l->{TYPE} eq "POINTER") { + if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) { + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, $var_name, $fail); + return; + } if ($l->{POINTER_TYPE} ne "ref") { $self->pidl("if ($py_var == Py_None) {"); $self->indent; @@ -679,7 +684,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) $self->indent; } $self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);"); - $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, get_value_of($var_name), $fail); if ($l->{POINTER_TYPE} ne "ref") { $self->deindent; $self->pidl("}"); @@ -802,8 +807,13 @@ sub ConvertObjectToPythonData($$$$$) sub ConvertObjectToPythonLevel($$$$$) { my ($self, $mem_ctx, $env, $e, $l, $var_name, $py_var) = @_; + my $nl = GetNextLevel($e, $l); if ($l->{TYPE} eq "POINTER") { + if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) { + $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, $var_name, $py_var); + return; + } if ($l->{POINTER_TYPE} ne "ref") { $self->pidl("if ($var_name == NULL) {"); $self->indent; @@ -812,7 +822,7 @@ sub ConvertObjectToPythonLevel($$$$$) $self->pidl("} else {"); $self->indent; } - $self->ConvertObjectToPythonLevel($var_name, $env, $e, GetNextLevel($e, $l), get_value_of($var_name), $py_var); + $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, get_value_of($var_name), $py_var); if ($l->{POINTER_TYPE} ne "ref") { $self->deindent; $self->pidl("}"); -- cgit From d28eb21a984a733e8f1de51170e41ae7c879f7e9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 18:59:11 +0100 Subject: python: Compile security module, handle uint. (This used to be commit dee64344fb13aaed38a550ebb4048d0fa526d5b6) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 6 +++--- source4/pidl/lib/Parse/Pidl/Typelist.pm | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 8ff909a455..31b06d16b8 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -612,7 +612,7 @@ sub ConvertObjectFromPythonData($$$$$$) if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or $actual_ctype->{TYPE} eq "SCALAR" and ( - expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]+|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) { + expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]*|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) { $self->pidl("PY_CHECK_TYPE(PyInt, $cvar, $fail);"); $self->pidl("$target = PyInt_AsLong($cvar);"); return; @@ -748,7 +748,7 @@ sub ConvertScalarToPython($$$) $ctypename = expandAlias($ctypename); - if ($ctypename =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { + if ($ctypename =~ /^(char|u?int[0-9]*|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { return "PyInt_FromLong($cvar)"; } @@ -938,7 +938,7 @@ sub Parse($$$$$) } elsif ($cvar =~ /^".*"$/) { $py_obj = "PyString_FromString($cvar)"; } else { - $py_obj = $self->ConvertObjectToPythonData("NULL", $ctype, $cvar); + $py_obj = $self->ConvertObjectToPythonData("NULL", expandAlias($ctype), $cvar); } $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);"); diff --git a/source4/pidl/lib/Parse/Pidl/Typelist.pm b/source4/pidl/lib/Parse/Pidl/Typelist.pm index 9e6c683f82..8ba1ae47af 100644 --- a/source4/pidl/lib/Parse/Pidl/Typelist.pm +++ b/source4/pidl/lib/Parse/Pidl/Typelist.pm @@ -59,6 +59,7 @@ my %aliases = ( "boolean8" => "uint8", "boolean32" => "uint32", "DWORD" => "uint32", + "uint" => "uint32", "int" => "int32", "WORD" => "uint16", "char" => "uint8", -- cgit From 1530d7c3b0d02a2b75c1ee393209f69473f3c4af Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 20:09:18 +0100 Subject: python: Fix handling of pointer-less strings in function arguments. (This used to be commit cb2700094fc1fc3887d5254e5d42e035deefa5b9) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 31b06d16b8..2475925377 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -642,12 +642,12 @@ sub ConvertObjectFromPythonData($$$$$$) if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { - $self->pidl("$target = PyInt_AsLong($cvar);"); + $self->pidl("$target = NT_STATUS(PyInt_AsLong($cvar));"); return; } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { - $self->pidl("$target = PyInt_AsLong($cvar);"); + $self->pidl("$target = W_ERROR(PyInt_AsLong($cvar));"); return; } @@ -690,16 +690,16 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) $self->pidl("}"); } } elsif ($l->{TYPE} eq "ARRAY") { + my $pl = GetPrevLevel($e, $l); + if ($pl && $pl->{TYPE} eq "POINTER") { + $var_name = get_pointer_to($var_name); + } + if (is_charset_array($e, $l)) { $self->pidl("PY_CHECK_TYPE(PyUnicode, $py_var, $fail);"); # FIXME: Use Unix charset setting rather than utf-8 - $self->pidl(get_pointer_to($var_name) . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); + $self->pidl($var_name . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); } else { - my $pl = GetPrevLevel($e, $l); - if ($pl && $pl->{TYPE} eq "POINTER") { - $var_name = get_pointer_to($var_name); - } - my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);"); $self->pidl("{"); -- cgit From 39cc507d1b7b0454d8f380fc3127fa966a0f972c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 14:54:29 +0100 Subject: pidl: Fix imported function for ServerNDR and add test to make sure it doesn't regress again. (This used to be commit 0e036948307c8ca5013e20a17a10d109830e4df1) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- source4/pidl/tests/samba3-srv.pl | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 source4/pidl/tests/samba3-srv.pl (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 47312bc83d..ecc43ab896 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -12,7 +12,7 @@ use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(ParseExpr has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Samba4 qw(ElementStars DeclLong); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionOutEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionOutEnv); use vars qw($VERSION); $VERSION = '0.01'; diff --git a/source4/pidl/tests/samba3-srv.pl b/source4/pidl/tests/samba3-srv.pl new file mode 100644 index 0000000000..dc96518fd0 --- /dev/null +++ b/source4/pidl/tests/samba3-srv.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +# (C) 2008 Jelmer Vernooij +# Published under the GNU General Public License +use strict; +use warnings; + +use Test::More tests => 0; +use FindBin qw($RealBin); +use lib "$RealBin"; +use Util; +use Parse::Pidl::Util qw(MyDumper); +use Parse::Pidl::Samba3::ServerNDR; + + -- cgit From af163d258cfeee2a908e297256570a2bfcc8b651 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 15:06:46 +0100 Subject: pidl: Fix missing import for fatal(). (This used to be commit 6a9827454aaf4279ee85dc5d99d10f14e4c09eae) --- source4/pidl/lib/Parse/Pidl/Samba4.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4.pm b/source4/pidl/lib/Parse/Pidl/Samba4.pm index 5848543a60..d42e01cdb0 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4.pm @@ -12,6 +12,7 @@ require Exporter; use Parse::Pidl::Util qw(has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); +use Parse::Pidl qw(fatal); use strict; use vars qw($VERSION); -- cgit From 3e53ad6f4a5767fd1a26a35a0060b03a6e77161c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 15:07:00 +0100 Subject: pidl: Add simple test for ServerNDR. (This used to be commit 5b2ea43ed8613ac10ebe7feda0cf070c8079137a) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 4 ++++ source4/pidl/tests/samba3-srv.pl | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index ecc43ab896..ca9e7d15db 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -6,6 +6,10 @@ package Parse::Pidl::Samba3::ServerNDR; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(DeclLevel); + use strict; use Parse::Pidl qw(warning fatal); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); diff --git a/source4/pidl/tests/samba3-srv.pl b/source4/pidl/tests/samba3-srv.pl index dc96518fd0..d1e2bc9545 100644 --- a/source4/pidl/tests/samba3-srv.pl +++ b/source4/pidl/tests/samba3-srv.pl @@ -4,11 +4,15 @@ use strict; use warnings; -use Test::More tests => 0; +use Test::More tests => 1; use FindBin qw($RealBin); use lib "$RealBin"; use Util; -use Parse::Pidl::Util qw(MyDumper); -use Parse::Pidl::Samba3::ServerNDR; +use Parse::Pidl::Util qw(MyDumper has_property); +use Parse::Pidl::Samba3::ServerNDR qw(DeclLevel); +my $l = { TYPE => "DATA", DATA_TYPE => "uint32" }; +my $e = { FILE => "foo", LINE => 0, PROPERTIES => { }, TYPE => "uint32", + LEVELS => [ $l ] }; +is("uint32_t", DeclLevel($e, 0)); -- cgit From 2cf35f206817bfcc77a3f258fe220aac2b6f19a8 Mon Sep 17 00:00:00 2001 From: Julien Kerihuel Date: Fri, 18 Jan 2008 18:30:00 +0100 Subject: pidl: Add --version argument. (This used to be commit ed1e58e8b35bc971451f4e0a357daa903cd7820d) --- source4/pidl/lib/Parse/Pidl.pm | 2 +- source4/pidl/pidl | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl.pm b/source4/pidl/lib/Parse/Pidl.pm index 0c6e0e5727..c2c9463d03 100644 --- a/source4/pidl/lib/Parse/Pidl.pm +++ b/source4/pidl/lib/Parse/Pidl.pm @@ -9,7 +9,7 @@ package Parse::Pidl; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(warning error fatal); +@EXPORT_OK = qw(warning error fatal $VERSION); use strict; diff --git a/source4/pidl/pidl b/source4/pidl/pidl index 4dfd57dc20..220d62cd71 100755 --- a/source4/pidl/pidl +++ b/source4/pidl/pidl @@ -52,6 +52,10 @@ both marshalling/unmarshalling and debugging purposes). =item I<--help> Show list of available options. + +=item I<--version> + +Show pidl version =item I<--outputdir OUTNAME> @@ -403,7 +407,7 @@ use lib "$RealBin"; use lib "$RealBin/lib"; use Getopt::Long; use File::Basename; -use Parse::Pidl; +use Parse::Pidl qw ( $VERSION ); use Parse::Pidl::Util; ##################################################################### @@ -453,6 +457,7 @@ sub FileSave($$) my(@opt_incdirs) = (); my($opt_help) = 0; +my($opt_version) = 0; my($opt_parse_idl_tree) = 0; my($opt_dump_idl_tree); my($opt_dump_ndr_tree); @@ -483,7 +488,9 @@ my($opt_warn_compat) = 0; # display help text sub ShowHelp() { -print "perl IDL parser and code generator +print "perl IDL parser and code generator\n"; +ShowVersion(); +print" Copyright (C) Andrew Tridgell Copyright (C) Jelmer Vernooij @@ -491,6 +498,7 @@ Usage: $Script [options] [--] [...] Generic Options: --help this help page + --version show pidl version --outputdir=OUTDIR put output in OUTDIR/ [.] --warn-compat warn about incompatibility with other compilers --quiet be quiet @@ -528,9 +536,17 @@ Wireshark parsers: exit(0); } +######################################### +# Display version +sub ShowVersion() +{ + print "perl IDL version $VERSION\n"; +} + # main program my $result = GetOptions ( 'help|h|?' => \$opt_help, + 'version' => \$opt_version, 'outputdir=s' => \$opt_outputdir, 'dump-idl' => \$opt_dump_idl, 'dump-idl-tree:s' => \$opt_dump_idl_tree, @@ -565,6 +581,11 @@ if ($opt_help) { exit(0); } +if ($opt_version) { + ShowVersion(); + exit(0); +} + sub process_file($) { my $idl_file = shift; -- cgit