svn commit: samba r2336 - in branches/SAMBA_4_0/source: build/pidl scripting/swig scripting/swig/torture

tpot at samba.org tpot at samba.org
Tue Sep 14 12:19:59 GMT 2004


Author: tpot
Date: 2004-09-14 12:19:59 +0000 (Tue, 14 Sep 2004)
New Revision: 2336

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=2336&nolog=1

Log:
Add another conversion function to allow union arms that contain structures
not pointers to structures.  Do some renaming of hand-written functions 
as a result.

Include lsa interface before samr interface as samr depends on some lsa
structures.

Build up a nice hashed index of interfaces, functions, structs and
unions.

Add test for samr_Connect5() function which contains a union.

Modified:
   branches/SAMBA_4_0/source/build/pidl/swig.pm
   branches/SAMBA_4_0/source/scripting/swig/dcerpc.i
   branches/SAMBA_4_0/source/scripting/swig/torture/samr.py


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-14 10:42:52 UTC (rev 2335)
+++ branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-14 12:19:59 UTC (rev 2336)
@@ -8,8 +8,8 @@
 use strict;
 use Data::Dumper;
 
-my($res);
-my($name);
+my(%interfaces, %functions, %structs, %unions);
+my($res, $name);
 
 sub DebugElement($)
 {
@@ -75,7 +75,7 @@
 	    # Non-scalar type, no pointer
 	    $result .= DebugElement($e);
 	} elsif ($e->{POINTERS} == 1) {
-	    $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_from_python(mem_ctx, $obj);\n";
+	    $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_ptr_from_python(mem_ctx, $obj);\n";
 	} else {
 	    # Non-scalar type, multiple pointers
 	    $result .= DebugElement($e);
@@ -122,7 +122,7 @@
 	    # Non-scalar type, no pointer
 	    $result .= DebugElement($e);
 	} elsif ($e->{POINTERS} == 1) {
-	    $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_from_python(mem_ctx, obj);\n";
+	    $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_ptr_from_python(mem_ctx, obj);\n";
 	} else {
 	    # Non-scalar type, multiple pointers
 	    $result .= DebugElement($e);
@@ -140,7 +140,7 @@
 
     $res .= "/* Convert Python dict to struct $fn->{NAME}.in */\n\n";
 
-    $res .= "struct $fn->{NAME} *$fn->{NAME}_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)\n";
+    $res .= "struct $fn->{NAME} *$fn->{NAME}_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)\n";
     $res .= "{\n";
 
     $res .= "\tstruct $fn->{NAME} *s = talloc(mem_ctx, sizeof(struct $fn->{NAME}));\n\n";
@@ -177,7 +177,7 @@
 
     $res .= "%typemap(in) struct $fn->{NAME} * {\n";
     $res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(int) $fn->{NAME}\");\n\n";
-    $res .= "\t\$1 = $fn->{NAME}_from_python(mem_ctx, \$input);\n";
+    $res .= "\t\$1 = $fn->{NAME}_ptr_from_python(mem_ctx, \$input);\n";
     $res .= "}\n\n";
 
     # Output typemap
@@ -208,9 +208,9 @@
     my($s) = shift;
 
     $res .= "%{\n\n";
-    $res .= "/* Convert Python dict to struct $s->{NAME} */\n\n";
+    $res .= "/* Convert Python dict to struct $s->{NAME} pointer */\n\n";
     
-    $res .= "struct $s->{NAME} *$s->{NAME}_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)\n";
+    $res .= "struct $s->{NAME} *$s->{NAME}_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)\n";
     $res .= "{\n";
     $res .= "\tstruct $s->{NAME} *s = talloc(mem_ctx, sizeof(struct $s->{NAME}));\n\n";
 
@@ -222,6 +222,17 @@
     $res .= "\treturn s;\n";
     $res .= "}\n\n";
 
+    $res .= "/* Convert Python dict to struct $s->{NAME} */\n\n";
+    
+    $res .= "void $s->{NAME}_from_python(TALLOC_CTX *mem_ctx, struct $s->{NAME} *s, PyObject *obj)\n";
+    $res .= "{\n";
+
+    foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
+	$res .= XFromPython($e, "");
+    }
+
+    $res .= "}\n\n";
+
     $res .= "/* Convert struct $s->{NAME} to Python dict */\n\n";
 
     $res .= "PyObject *$s->{NAME}_to_python(TALLOC_CTX *mem_ctx, struct $s->{NAME} *s)\n";
@@ -247,20 +258,22 @@
     $res .= "%{\n\n";
     $res .= "/* Convert Python dict to union $u->{NAME} */\n\n";
 
-    $res .= "union $u->{NAME} *$u->{NAME}_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)\n";
+    $res .= "union $u->{NAME} *$u->{NAME}_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)\n";
     $res .= "{\n";
 
-    $res .= "\tunion $u->{NAME} *u = talloc(mem_ctx, sizeof(struct $u->{NAME}));\n";
+    $res .= "\tunion $u->{NAME} *u = talloc(mem_ctx, sizeof(union $u->{NAME}));\n";
     $res .= "\tPyObject *dict;\n\n";
 
     
     for my $e (@{$u->{DATA}{DATA}}) {
 	$res .= "\tif ((dict = PyDict_GetItem(obj, PyString_FromString(\"$e->{DATA}{NAME}\")))) {\n";
-#	if ($e->{DATA}{POINTERS} == 0) {
-#	    $res .= "\t\t// $e->{TYPE} pointers=$e->{DATA}{POINTERS}\n";
-#	} else {
-#	    $res .= "\t\t// $e->{TYPE} pointers=$e->{DATA}{POINTERS}\n";
-#	}
+	if ($e->{DATA}{POINTERS} == 0) {
+	    $res .= "\t\t$e->{DATA}{TYPE}_from_python(mem_ctx, &u->$e->{DATA}{NAME}, dict);\n";
+	} elsif ($e->{DATA}{POINTERS} == 1) {
+	    $res .= "\t\tu->$e->{DATA}{NAME} = $e->{DATA}{TYPE}_ptr_from_python(mem_ctx, dict);\n";
+	} else {
+	    $res .= "\t\t// $e->{DATA}{TYPE} pointers=$e->{DATA}{POINTERS}\n";
+	}
 
 	$res .= "\t\treturn u;\n";
 	$res .= "\t}\n\n";
@@ -316,6 +329,27 @@
 {
     my($idl) = shift;
 
+    # Make index of functions, structs and unions
+
+    %interfaces = ();
+    %functions = ();
+    %structs = ();
+    %unions = ();
+
+    foreach my $x (@{$idl}) {
+	my($iname) = $x->{NAME};
+	$interfaces{$iname} = $x->{PROPERTIES};
+	foreach my $i (@{$x->{INHERITED_DATA}}) {
+	    $functions{$iname}{$i->{NAME}} = $i if $i->{TYPE} eq "FUNCTION";
+	    if ($i->{TYPE} eq "TYPEDEF") {
+		$structs{$iname}{$i->{NAME}} = $i->{DATA} if $i->{DATA}{TYPE} eq "STRUCT";
+		$unions{$iname}{$i->{NAME}} = $i->{DATA} if $i->{DATA}{TYPE} eq "UNION";
+	    }
+	}
+    }
+
+    # Generate interface
+
     $res = "/* auto-generated by pidl */\n\n";
 
     foreach my $x (@{$idl}) {

Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-14 10:42:52 UTC (rev 2335)
+++ branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-14 12:19:59 UTC (rev 2336)
@@ -127,7 +127,7 @@
 	return PyString_FromStringAndSize((char *)handle, sizeof(*handle));
 }
 
-struct security_descriptor *security_descriptor_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
+struct security_descriptor *security_descriptor_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
 {
 	return NULL;
 }
@@ -137,7 +137,7 @@
 	return Py_None;
 }
 
-struct dom_sid2 *dom_sid2_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
+struct dom_sid2 *dom_sid2_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
 {
 	return NULL;
 }
@@ -163,7 +163,7 @@
 	return PyString_FromString(obj);
 }
 
-struct samr_Password *samr_Password_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
+struct samr_Password *samr_Password_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
 {
 	return NULL;
 }
@@ -228,5 +228,5 @@
                              const char *username,
                              const char *password);
 
+%include "librpc/gen_ndr/lsa.i"
 %include "librpc/gen_ndr/samr.i"
-%include "librpc/gen_ndr/lsa.i"

Modified: branches/SAMBA_4_0/source/scripting/swig/torture/samr.py
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/torture/samr.py	2004-09-14 10:42:52 UTC (rev 2335)
+++ branches/SAMBA_4_0/source/scripting/swig/torture/samr.py	2004-09-14 12:19:59 UTC (rev 2336)
@@ -42,6 +42,19 @@
 
     result = dcerpc.samr_Connect4(pipe, r)
     dcerpc.samr_Close(pipe, result)
+
+    print 'testing samr_Connect5'
+
+    r = {}
+    r['system_name'] = None
+    r['access_mask'] = 0x02000000
+    r['level'] = 1
+    r['info'] = {}
+    r['info']['info1'] = {}
+    r['info']['info1']['unknown1'] = 0
+    r['info']['info1']['unknown2'] = 0
+
+    result = dcerpc.samr_Connect5(pipe, r)
     
 # Connect to server
 



More information about the samba-cvs mailing list