summaryrefslogtreecommitdiff
path: root/source4/build
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2004-09-18 08:41:26 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:49 -0500
commitb02b2fa3473a8249a8a69eb5cc08ab207503ecd0 (patch)
treedbded1e57786bb35171182978caaa2ce7bbe5c2f /source4/build
parent4a6313a543c7be6b7f4e1b68b23bc8fa62be70b2 (diff)
downloadsamba-b02b2fa3473a8249a8a69eb5cc08ab207503ecd0.tar.gz
samba-b02b2fa3473a8249a8a69eb5cc08ab207503ecd0.tar.bz2
samba-b02b2fa3473a8249a8a69eb5cc08ab207503ecd0.zip
r2408: Tridge suggested that all the structures from misc.idl (policy handles,
sids, security descriptors and acls) can be automatically generated instead of hand-written. Fix up the swig wrapper generator and helper routines to do this. (Only works for policy handles right now though and arrays are to be converted into lists instead of being binary blobs). Fix up wrapper generation for modules that don't define an interface (e.g misc.idl). (This used to be commit 160dc90921ecc136a25ae88e5c28800ddda5722a)
Diffstat (limited to 'source4/build')
-rw-r--r--source4/build/pidl/swig.pm102
1 files changed, 71 insertions, 31 deletions
diff --git a/source4/build/pidl/swig.pm b/source4/build/pidl/swig.pm
index 0b48537d6f..dcd3efa698 100644
--- a/source4/build/pidl/swig.pm
+++ b/source4/build/pidl/swig.pm
@@ -38,6 +38,21 @@ sub DebugElement($)
return $result;
}
+sub ArrayFromPython($$)
+{
+ my($e) = shift;
+ 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";
+ }
+
+ $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;
+}
+
sub XFromPython($$)
{
my($e) = shift;
@@ -47,13 +62,8 @@ sub XFromPython($$)
# Special cases
- if (($e->{TYPE} eq "policy_handle" || $e->{TYPE} eq "string") && $e->{POINTERS} == 1) {
- $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_ptr_from_python(mem_ctx, $obj);\n";
- return $result;
- }
-
if ($e->{TYPE} eq "string" && $e->{POINTERS} == 1) {
- $result .= "\ts->$prefix$e->{NAME} = policy_handle_ptr_from_python(mem_ctx, $obj);\n";
+ $result .= "\ts->$prefix$e->{NAME} = string_ptr_from_python(mem_ctx, $obj);\n";
return $result;
}
@@ -62,23 +72,21 @@ sub XFromPython($$)
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);
+ $result .= ArrayFromPython($e, $prefix);
} else {
$result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_from_python($obj);\n";
}
} else {
- # Pointer to scalar
+ $result .= "\t// Pointer to scalar\n";
$result .= DebugElement($e);
}
} else {
if ($e->{POINTERS} == 0) {
- # Non-scalar type, no pointer
- $result .= DebugElement($e);
+ $result .= "\t$e->{TYPE}_from_python(mem_ctx, &s->$prefix$e->{NAME}, $obj);\n";
} elsif ($e->{POINTERS} == 1) {
$result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_ptr_from_python(mem_ctx, $obj);\n";
} else {
- # Non-scalar type, multiple pointers
+ $result .= "\t// Non-scalar type, multiple pointers\n";
$result .= DebugElement($e);
}
}
@@ -86,19 +94,31 @@ sub XFromPython($$)
return $result;
}
-sub XToPython($$)
+sub ArrayToPython($$)
{
my($e) = shift;
my($prefix) = shift;
my($result) = "";
- # Special cases
+ my($array_len) = $e->{ARRAY_LEN};
- if ($e->{TYPE} eq "policy_handle" && $e->{POINTERS} == 1) {
- $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), policy_handle_ptr_to_python(mem_ctx, s->$prefix$e->{NAME}));\n";
- return $result;
+ 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";
+
+ return $result;
+}
+
+sub XToPython($$)
+{
+ my($e) = shift;
+ my($prefix) = shift;
+ my($result) = "";
+
+ # Special cases
+
if ($e->{TYPE} eq "string" && $e->{POINTERS} == 1) {
$result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), string_ptr_to_python(mem_ctx, s->$prefix$e->{NAME}));\n";
return $result;
@@ -109,23 +129,21 @@ sub XToPython($$)
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);
+ $result .= ArrayToPython($e, $prefix);
} else {
$result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_to_python(s->$prefix$e->{NAME}));\n";
}
} else {
- # Pointer to scalar
+ $result .= "\t// Pointer to scalar\n";
$result .= DebugElement($e);
}
} else {
if ($e->{POINTERS} == 0) {
- # Non-scalar type, no pointer
- $result .= DebugElement($e);
+ $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_ptr_to_python(mem_ctx, &s->$prefix$e->{NAME}));\n";
} elsif ($e->{POINTERS} == 1) {
$result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_ptr_to_python(mem_ctx, s->$prefix$e->{NAME}));\n";
} else {
- # Non-scalar type, multiple pointers
+ $result .= "\t// Non-scalar type, multiple pointers\n";
$result .= DebugElement($e);
}
}
@@ -234,7 +252,7 @@ sub ParseStruct($)
$res .= "}\n\n";
- $res .= "/* Convert struct $s->{NAME} to Python dict */\n\n";
+ $res .= "/* Convert struct $s->{NAME} pointer to Python dict */\n\n";
$res .= "PyObject *$s->{NAME}_ptr_to_python(TALLOC_CTX *mem_ctx, struct $s->{NAME} *s)\n";
$res .= "{\n";
@@ -257,7 +275,7 @@ sub ParseUnion($)
my($u) = shift;
$res .= "%{\n\n";
- $res .= "/* Convert Python dict to union $u->{NAME} */\n\n";
+ $res .= "/* Convert Python dict to union $u->{NAME} pointer */\n\n";
$res .= "union $u->{NAME} *$u->{NAME}_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)\n";
$res .= "{\n";
@@ -283,13 +301,33 @@ sub ParseUnion($)
$res .= "\treturn NULL;\n";
$res .= "}\n\n";
- $res .= "/* Convert union $u->{NAME} to Python dict */\n\n";
+ $res .= "/* Convert union $u->{NAME} pointer to Python dict */\n\n";
$res .= "PyObject *$u->{NAME}_ptr_to_python(TALLOC_CTX *mem_ctx, union $u->{NAME} *u)\n";
$res .= "{\n";
$res .= "\treturn PyDict_New();\n";
$res .= "}\n\n";
+ $res .= "/* Convert Python dict to union $u->{NAME} */\n\n";
+
+ $res .= "void $u->{NAME}_from_python(TALLOC_CTX *mem_ctx, union $u->{NAME} *u, PyObject *obj)\n";
+ $res .= "{\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->{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;\n";
+ $res .= "\t}\n\n";
+ }
+ $res .= "}\n";
+
$res .= "\n%}\n\n";
}
@@ -317,11 +355,13 @@ sub ParseHeader($)
{
my($hdr) = shift;
- $name = $hdr->{NAME};
- $res .= "#define DCERPC_" . uc($name) . "_UUID \"$hdr->{PROPERTIES}->{uuid}\"\n";
- $res .= "const int DCERPC_" . uc($name) . "_VERSION = " . $hdr->{PROPERTIES}->{version} . ";\n";
- $res .= "#define DCERPC_" . uc($name) . "_NAME \"" . $name . "\"\n";
- $res .= "\n";
+ if ($hdr->{PROPERTIES}{uuid}) {
+ $name = $hdr->{NAME};
+ $res .= "#define DCERPC_" . uc($name) . "_UUID \"$hdr->{PROPERTIES}->{uuid}\"\n";
+ $res .= "const int DCERPC_" . uc($name) . "_VERSION = " . $hdr->{PROPERTIES}->{version} . ";\n";
+ $res .= "#define DCERPC_" . uc($name) . "_NAME \"" . $name . "\"\n";
+ $res .= "\n";
+ }
ParseInheritedData($hdr->{INHERITED_DATA});
}