svn commit: samba r2411 - in branches/SAMBA_4_0/source/build/pidl: .

tpot at samba.org tpot at samba.org
Sat Sep 18 12:51:36 GMT 2004


Author: tpot
Date: 2004-09-18 12:51:36 +0000 (Sat, 18 Sep 2004)
New Revision: 2411

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

Log:
The other half of getting autogenerated code working using misc.idl:
use Python lists for arrays when marshaling and unmarshaling arrays.
This gets samr_SetSecurity() working.

Modified:
   branches/SAMBA_4_0/source/build/pidl/swig.pm


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-18 12:47:57 UTC (rev 2410)
+++ branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-18 12:51:36 UTC (rev 2411)
@@ -44,12 +44,41 @@
     my($prefix) = shift;
     my($result) = "";
 
-    if ($e->{POINTERS} != 0) {
-	$result .= "\ts->$prefix$e->{NAME} = talloc(mem_ctx, PyString_Size(PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\"))));\n";
+    my($array_len) = $e->{ARRAY_LEN};
+
+    if ($array_len eq "*") {
+	$array_len = util::has_property($e, "size_is");
     }
 
-    $result .= "\tmemcpy(s->$prefix$e->{NAME}, PyString_AsString(PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\"))), PyString_Size(PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\"))));\n";
+    if (!util::is_constant($array_len)) {
+	$array_len = "s->$prefix$array_len";
+    }
 
+    my($type) = $e->{TYPE};
+
+    if (!util::is_scalar_type($type)) {
+	$type = "struct $type";
+    }
+
+    if (!util::is_constant($e->{ARRAY_LEN})) {
+	$result .= "\ts->$prefix$e->{NAME} = talloc(mem_ctx, $array_len * sizeof($type));\n";
+    }
+
+    $result .= "\t{\n";
+
+    $result .= "\t\tint i;\n\n";
+    $result .= "\t\tfor (i = 0; i < $array_len; i++) {\n";
+    if (util::is_scalar_type($e->{TYPE})) {
+	$result .= "\t\t\ts->$prefix$e->{NAME}\[i\] = $e->{TYPE}_from_python(PyList_GetItem(PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\")), i));\n";
+    } else {
+	$result .= "\t\t\t$e->{TYPE}_from_python(mem_ctx, &s->$prefix$e->{NAME}\[i\], PyList_GetItem(PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\")), i));\n";
+    }
+    $result .= "\t\t}\n";
+
+    $result .= "\t}\n";
+
+#    $result .= "\tmemcpy(s->$prefix$e->{NAME}, PyString_AsString(PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\"))), PyString_Size(PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\"))));\n";
+
     return $result;
 }
 
@@ -82,12 +111,13 @@
 	}
     } else {
 	if ($e->{POINTERS} == 0) {
-	    $result .= "\t$e->{TYPE}_from_python(mem_ctx, &s->$prefix$e->{NAME}, $obj);\n";
-	} elsif ($e->{POINTERS} == 1) {
+	    if ($e->{ARRAY_LEN}) {
+		$result .= ArrayFromPython($e, $prefix);
+	    } else {
+		$result .= "\t$e->{TYPE}_from_python(mem_ctx, &s->$prefix$e->{NAME}, $obj);\n";
+	    }
+	} else {
 	    $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_ptr_from_python(mem_ctx, $obj);\n";
-	} else {
-	    $result .= "\t// Non-scalar type, multiple pointers\n";
-	    $result .= DebugElement($e);
 	}
     }
 
@@ -102,12 +132,37 @@
 
     my($array_len) = $e->{ARRAY_LEN};
 
+    if ($array_len eq "*") {
+	$array_len = util::has_property($e, "size_is");
+    }
+
     if (!util::is_constant($array_len)) {
 	$array_len = "s->$prefix$array_len";
     }
 
-    $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), PyString_FromStringAndSize((char *)s->$prefix$e->{NAME}, $array_len * sizeof($e->{TYPE})));\n";
+    my($type) = $e->{TYPE};
 
+    if (!util::is_scalar_type($type)) {
+	$type = "struct $type";
+    }
+
+    $result .= "\n\t{\n";
+    $result .= "\t\tPyObject *temp;\n";
+    $result .= "\t\tint i;\n\n";
+
+    $result .= "\t\ttemp = PyList_New($array_len);\n\n";
+    $result .= "\t\tfor (i = 0; i < $array_len; i++) {\n";
+    if (util::is_scalar_type($e->{TYPE})) {
+	$result .= "\t\t\tPyList_SetItem(temp, i, $e->{TYPE}_to_python(s->$prefix$e->{NAME}\[i\]));\n";
+    } else {
+	$result .= "\t\t\tPyList_SetItem(temp, i, $e->{TYPE}_ptr_to_python(mem_ctx, &s->$prefix$e->{NAME}\[i\]));\n";	
+    }
+    $result .= "\t\t}\n";
+
+    $result .= "\t\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), temp);\n";
+
+    $result .= "\t}\n";
+
     return $result;
 }
 
@@ -139,12 +194,13 @@
 	}
     } else {
 	if ($e->{POINTERS} == 0) {
-	    $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_ptr_to_python(mem_ctx, &s->$prefix$e->{NAME}));\n";
-	} elsif ($e->{POINTERS} == 1) {
+	    if ($e->{ARRAY_LEN}) {
+		$result .= ArrayToPython($e, $prefix);
+	    } else {
+		$result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_ptr_to_python(mem_ctx, &s->$prefix$e->{NAME}));\n";
+	    }
+	} else {
 	    $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_ptr_to_python(mem_ctx, s->$prefix$e->{NAME}));\n";
-	} else {
-	    $result .= "\t// Non-scalar type, multiple pointers\n";
-	    $result .= DebugElement($e);
 	}
     }
 



More information about the samba-cvs mailing list