svn commit: samba r15585 - in branches/SAMBA_4_0/source: build/smb_build pidl pidl/lib/Parse/Pidl/Samba4 scripting/swig

jelmer at samba.org jelmer at samba.org
Sat May 13 21:36:16 GMT 2006


Author: jelmer
Date: 2006-05-13 21:36:15 +0000 (Sat, 13 May 2006)
New Revision: 15585

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

Log:
Revive pidl's SWIG file generator. It now generates simple 
object oriented wrappers for the interfaces (still need to fix 
the actual function calls)

Modified:
   branches/SAMBA_4_0/source/build/smb_build/output.pm
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
   branches/SAMBA_4_0/source/pidl/pidl
   branches/SAMBA_4_0/source/scripting/swig/config.mk


Changeset:
Modified: branches/SAMBA_4_0/source/build/smb_build/output.pm
===================================================================
--- branches/SAMBA_4_0/source/build/smb_build/output.pm	2006-05-13 21:31:04 UTC (rev 15584)
+++ branches/SAMBA_4_0/source/build/smb_build/output.pm	2006-05-13 21:36:15 UTC (rev 15585)
@@ -19,6 +19,7 @@
 		if (substr($_, 0, 1) ne "\$") {
 			$_ = "$dir/$_";
 			s/([^\/\.]+)\/\.\.\///g;
+			s/([^\/\.]+)\/\.\.\///g;
 		}
 		push (@ret, $_);
 	}

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm	2006-05-13 21:31:04 UTC (rev 15584)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm	2006-05-13 21:36:15 UTC (rev 15585)
@@ -1,6 +1,7 @@
 ###################################################
 # Samba4 parser generator for swig wrappers
 # Copyright tpot at samba.org 2004,2005
+# Copyright jelmer at samba.org 2006
 # released under the GNU GPL
 
 package Parse::Pidl::Samba4::SWIG;
@@ -10,70 +11,100 @@
 
 use strict;
 
+my $ret = "";
+my $tabs = "";
+
 sub pidl($)
 {
-	print OUT shift;
+	my $p = shift;
+	$ret .= $tabs. $p . "\n";
 }
 
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteHeader($$$)
+sub indent() { $tabs.="\t"; }
+sub deindent() { $tabs = substr($tabs,0,-1); }
+
+sub ParseInterface($)
 {
-    my($idl) = shift;
-    my($input) = shift;
-    my($output) = shift;
+	my $if = shift;
 
-    open(IN, "<$input") || die "can't open $input for reading";
-    open(OUT, ">$output") || die "can't open $output for writing";    
+	pidl "\%{";
+	pidl "struct $if->{NAME} {";
+	indent;
+	pidl "struct dcerpc_pipe *pipe;";
+	deindent;
+	pidl "};";
+	pidl "%}";
+	pidl "";
 
-    pidl "%{\n";
-    pidl "#define data_in in\n";
-    pidl "#define data_out out\n";
-    pidl "%}\n\n";
-   
-    while(<IN>) {
+	# FIXME: Generate ignores for all manual functions
+		
+	pidl "\%extend $if->{NAME} {";
+	indent();
+	pidl "struct $if->{NAME} *$if->{NAME} (const char *binding, struct cli_credentials *cred = NULL, TALLOC_CTX *mem_ctx = NULL, struct event_context *event = NULL)";
+	pidl "{";
+	indent;
+	pidl "struct $if->{NAME} *ret = talloc(mem_ctx, struct $if->{NAME});";
+	pidl "NTSTATUS status;";
+	pidl "";
+	pidl "status = dcerpc_pipe_connect(mem_ctx, &ret->pipe, &dcerpc_table_$if->{NAME}, cred, event);";
+	pidl "if (NT_STATUS_IS_ERR(status)) {";
+	pidl "\tsamba_nt_status_exception(status);";
+	pidl "\treturn NULL;";
+	pidl "}";
+	pidl "";
+	pidl "return ret;";
+	deindent;
+	pidl "}";
+	pidl "";
+	pidl "~$if->{NAME}() {";
+	pidl "\ttalloc_free(self);";
+	pidl "}";
+	pidl "";
 
-	# Rename dom_sid2 to dom_sid as we don't care about the difference
-	# for the swig wrappers.
+	foreach (@{$if->{FUNCTIONS}}) {
+		pidl "/* $_->{NAME} */";
+	}
 
-	s/dom_sid2/dom_sid/g;
+	deindent();
+	pidl "}";
+	pidl "";
 
-	# Copy structure and union definitions
-
-	if (/^(struct|union) .*? {$/ .. /^\};$/) {
-	    s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword
-	    pidl $_;
-	    next;
+	foreach (@{$if->{TYPES}}) {
+		pidl "/* $_->{NAME} */";	
 	}
+	
+	pidl "";
+}
 
-	# Copy dcerpc functions
+sub Parse($$$$)
+{
+    my($ndr,$basename,$header,$gen_header) = @_;
 
-	pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/;
+	$ret = "";
 
-	# Copy interface definitions
+	pidl "/* This file is autogenerated by pidl. DO NOT EDIT */";
 
-        pidl $_ 
-	    if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/;
-    }
+	pidl "\%module $basename";
+	
+	pidl "";
 
-    close(OUT);   
-}
+	pidl "\%{";
+	pidl "#include \"includes.h\"";
+	pidl "#include \"$header\"";
+	pidl "%}";
+	pidl "\%include \"samba.i\"";
+	pidl "\%include \"$gen_header\"";
 
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteC($$$)
-{
-    my($idl) = shift;
-    my($input) = shift;
-    my($output) = shift;
+	pidl "";
 
-    open(IN, "<$input") || die "can't open $input for reading";
-    open(OUT, ">>$output") || die "can't open $output for writing";    
-   
-    while(<IN>) {
-    }
-
-    close(OUT);   
+	foreach (@$ndr) {
+		ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
+	}
+	#FIXME: Foreach ref pointer, set NONNULL
+	#FIXME: Foreach unique/full pointer, set MAYBENULL
+	#FIXME: Foreach [out] parameter, set OUTPARAM
+	#
+	return $ret;
 }
 
 1;

Modified: branches/SAMBA_4_0/source/pidl/pidl
===================================================================
--- branches/SAMBA_4_0/source/pidl/pidl	2006-05-13 21:31:04 UTC (rev 15584)
+++ branches/SAMBA_4_0/source/pidl/pidl	2006-05-13 21:36:15 UTC (rev 15585)
@@ -661,7 +661,7 @@
 		defined($opt_dump_ndr_tree) or defined($opt_samba3_header) or 
 	    defined($opt_samba3_parser) or defined($opt_samba3_server) or 
 		defined($opt_samba3_template) or defined($opt_samba3_client) or
-		defined($opt_samba3_ndr_client)) {
+		defined($opt_swig) or defined($opt_samba3_ndr_client)) {
 		require Parse::Pidl::NDR;
 		$ndr = Parse::Pidl::NDR::Parse($pidl);
 	}
@@ -691,6 +691,13 @@
 		FileSave($c_header, $hdrd);
 	}
 
+	if (defined($opt_swig)) {
+		  require Parse::Pidl::Samba4::SWIG;
+		  my($filename) = ($opt_swig or "$outputdir/$basename.i");
+		  my $code = Parse::Pidl::Samba4::SWIG::Parse($ndr, $basename, "$outputdir/ndr_$basename\_c.h", $gen_header);
+		  FileSave($filename, $code);
+	}
+
 	if (defined($opt_ejs)) {
 		require Parse::Pidl::Samba4::EJS;
 		my ($hdr,$prsr) = Parse::Pidl::Samba4::EJS::Parse($ndr, $h_filename);
@@ -735,11 +742,6 @@
 		FileSave($parser_fname, $parser);
 		FileSave($h_filename, $header);
 
-		if (defined($opt_swig)) {
-		  require Parse::Pidl::Samba4::SWIG;
-		  my($filename) = ($opt_swig or "$outputdir/$basename.i");
-		  Parse::Pidl::Samba4::SWIG::RewriteHeader($pidl, $h_filename, $filename);
-		}
 	}
 
 	if (defined($opt_eth_parser)) {

Modified: branches/SAMBA_4_0/source/scripting/swig/config.mk
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/config.mk	2006-05-13 21:31:04 UTC (rev 15584)
+++ branches/SAMBA_4_0/source/scripting/swig/config.mk	2006-05-13 21:36:15 UTC (rev 15585)
@@ -14,7 +14,7 @@
 .SUFFIXES: _wrap.c .i
 
 .i_wrap.c:
-	swig -python $<
+	swig -I$(srcdir)/scripting/swig -python $<
 
 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
 



More information about the samba-cvs mailing list