summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/build/pidl/swig.pm104
-rw-r--r--source4/scripting/swig/dcerpc.i40
2 files changed, 136 insertions, 8 deletions
diff --git a/source4/build/pidl/swig.pm b/source4/build/pidl/swig.pm
index 59eb493bf2..f03467177e 100644
--- a/source4/build/pidl/swig.pm
+++ b/source4/build/pidl/swig.pm
@@ -11,6 +11,98 @@ use Data::Dumper;
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 @@ sub ParseFunction($)
$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 @@ sub ParseFunction($)
$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 @@ sub ParseStruct($)
$res .= "{\n";
foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
- $res .= "\t// $e->{TYPE} $e->{NAME}\n";
+ $res .= XFromPython($e, "");
}
$res .= "\n";
@@ -106,7 +194,7 @@ sub ParseStruct($)
$res .= "{\n";
foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
- $res .= "\t// $e->{TYPE} $e->{NAME}\n";
+ $res .= XToPython($e, "");
}
$res .= "\n";
diff --git a/source4/scripting/swig/dcerpc.i b/source4/scripting/swig/dcerpc.i
index 10dc4721e6..fb4870d819 100644
--- a/source4/scripting/swig/dcerpc.i
+++ b/source4/scripting/swig/dcerpc.i
@@ -52,41 +52,81 @@ uint8 uint8_from_python(PyObject *obj)
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;