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

tpot at samba.org tpot at samba.org
Sun Sep 12 10:13:24 GMT 2004


Author: tpot
Date: 2004-09-12 10:13:24 +0000 (Sun, 12 Sep 2004)
New Revision: 2295

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

Log:
Convert simple scalar types and policy handles between dcerpc function
call request and response structures.

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


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-12 06:38:00 UTC (rev 2294)
+++ branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-12 10:13:24 UTC (rev 2295)
@@ -11,6 +11,98 @@
 my($res);
 my($name);
 
+sub DebugElement($)
+{
+    my($e) = shift;
+    my($result) = "";
+
+    $result .= "\t// $e->{TYPE} $e->{NAME} ";
+
+    $result .= "(scalar) " 
+	if util::is_scalar_type($e->{TYPE});
+
+    $result .= "pointers=$e->{POINTERS} " 
+	if $e->{POINTERS} > 0;
+
+    my($size_is) = util::has_property($e, "size_is");
+    $result .= "size_is=" . $size_is . " " if $size_is;
+
+    my($length_is) = util::has_property($e, "length_is");
+    $result .= "length_is=" . $length_is . " " if $length_is;
+
+    $result .= "array_len=" . $e->{ARRAY_LEN} . " " if $e->{ARRAY_LEN};
+
+    $result .= "\n";
+
+    return $result;
+}
+
+sub XFromPython($$)
+{
+    my($e) = shift;
+    my($prefix) = shift;
+    my($result) = "";
+
+    # Special cases
+
+    if ($e->{TYPE} eq "policy_handle" && $e->{POINTERS} == 1) {
+	$result .= "\ts->$prefix$e->{NAME} = policy_handle_from_python(obj);";
+	return $result;
+    }
+
+    if (util::is_scalar_type($e->{TYPE})) {
+	if ($e->{POINTERS} == 0) {
+	    if ($e->{ARRAY_LEN}) {
+		# pointer to scalar with array len property
+		$result .= DebugElement($e);
+	    } else {
+		$result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_from_python(obj);\n";
+	    }
+	} else {
+	    # Pointer to scalar
+	    $result .= DebugElement($e);
+	}
+    } else {
+	# Non-scalar type
+	$result .= DebugElement($e);
+    }
+
+    return $result;
+}
+
+sub XToPython($$)
+{
+    my($e) = shift;
+    my($prefix) = shift;
+    my($result) = "";
+
+    # Special cases
+
+    if ($e->{TYPE} eq "policy_handle" && $e->{POINTERS} == 1) {
+	$result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), policy_handle_to_python(s->$prefix$e->{NAME}));\n";
+	return $result;
+    }
+
+    if (util::is_scalar_type($e->{TYPE})) {
+	if ($e->{POINTERS} == 0) {
+	    if ($e->{ARRAY_LEN}) {
+		# pointer to scalar with array len property
+		$result .= DebugElement($e);
+	    } else {
+		$result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_to_python(s->$prefix$e->{NAME}));\n";
+	    }
+	} else {
+	    # Pointer to scalar
+	    $result .= DebugElement($e);
+	}
+    } else {
+	# Non-scalar type
+	$result .= DebugElement($e);
+    }
+
+    return $result;
+}
+
 sub ParseFunction($)
 {
     my($fn) = shift;
@@ -23,9 +115,7 @@
     $res .= "{\n";
 
     foreach my $e (@{$fn->{DATA}}) {
-	if (util::has_property($e, "in")) {
-	    $res .= "\t// $e->{TYPE} $e->{NAME}\n";
-	}
+	$res .= XFromPython($e, "in.") if util::has_property($e, "in")
     }
 
     $res .= "\n";
@@ -38,9 +128,7 @@
     $res .= "{\n";
 
     foreach my $e (@{$fn->{DATA}}) {
-	if (util::has_property($e, "out")) {
-	    $res .= "\t// $e->{TYPE} $e->{NAME}\n";
-	}
+	$res .= XToPython($e, "out.") if util::has_property($e, "out")
     }
 
     $res .= "\n";
@@ -93,7 +181,7 @@
     $res .= "{\n";
 
     foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
-	$res .= "\t// $e->{TYPE} $e->{NAME}\n";
+	$res .= XFromPython($e, "");
     }
 
     $res .= "\n";
@@ -106,7 +194,7 @@
     $res .= "{\n";
 
     foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
-	$res .= "\t// $e->{TYPE} $e->{NAME}\n";
+	$res .= XToPython($e, "");
     }
 
     $res .= "\n";

Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-12 06:38:00 UTC (rev 2294)
+++ branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-12 10:13:24 UTC (rev 2295)
@@ -52,41 +52,81 @@
 	return (uint8)PyInt_AsLong(obj);
 }
 
+PyObject *uint8_to_python(uint8 obj)
+{
+	return PyInt_FromLong(obj);
+}
+
 uint16 uint16_from_python(PyObject *obj)
 {
 	return (uint16)PyInt_AsLong(obj);
 }
 
+PyObject *uint16_to_python(uint16 obj)
+{
+	return PyInt_FromLong(obj);
+}
+
 uint32 uint32_from_python(PyObject *obj)
 {
 	return (uint32)PyInt_AsLong(obj);
 }
 
+PyObject *uint32_to_python(uint32 obj)
+{
+	return PyInt_FromLong(obj);
+}
+
 int64 int64_from_python(PyObject *obj)
 {
 	return (int64)PyLong_AsLong(obj);
 }
 
+PyObject *int64_to_python(int64 obj)
+{
+	return PyLong_FromLong(obj);
+}
+
 uint64 uint64_from_python(PyObject *obj)
 {
 	return (uint64)PyLong_AsLong(obj);
 }
 
+PyObject *uint64_to_python(uint64 obj)
+{
+	return PyLong_FromLong(obj);
+}
+
 NTTIME NTTIME_from_python(PyObject *obj)
 {
 	return (NTTIME)PyLong_AsLong(obj);
 }
 
+PyObject *NTTIME_to_python(NTTIME obj)
+{
+	return PyLong_FromLong(obj);
+}
+
 HYPER_T HYPER_T_from_python(PyObject *obj)
 {
 	return (HYPER_T)PyLong_AsLong(obj);
 }
 
+PyObject *HYPER_T_to_python(HYPER_T obj)
+{
+	return PyLong_FromLong(obj);
+}
+
 struct policy_handle *policy_handle_from_python(PyObject *obj)
 {
 	return (struct policy_handle *)PyString_AsString(obj);
 }
 
+PyObject *policy_handle_to_python(struct policy_handle *handle)
+{
+	return PyString_FromStringAndSize((char *)handle, sizeof(*handle));
+}
+
 struct security_descriptor *security_descriptor_from_python(PyObject *obj)
 {
 	return NULL;



More information about the samba-cvs mailing list