mirror of
https://github.com/samba-team/samba.git
synced 2025-01-27 14:04:05 +03:00
r2289: Autogenerate some more attractive looking stubs for converting
function argument structures and idl structures to and from Python dictionaries.
This commit is contained in:
parent
b8fe29dc7a
commit
e4729949c6
@ -15,27 +15,52 @@ sub ParseFunction($)
|
||||
{
|
||||
my($fn) = shift;
|
||||
|
||||
$res .= "%{\n\n";
|
||||
|
||||
$res .= "/* Convert Python dict to struct $fn->{NAME}.in */\n\n";
|
||||
|
||||
$res .= "int python_to_$fn->{NAME}(TALLOC_CTX *mem_ctx, struct $fn->{NAME} *s, PyObject *obj)\n";
|
||||
$res .= "{\n";
|
||||
|
||||
foreach my $e (@{$fn->{DATA}}) {
|
||||
if (util::has_property($e, "in")) {
|
||||
$res .= "\t// $e->{TYPE} $e->{NAME}\n";
|
||||
}
|
||||
}
|
||||
|
||||
$res .= "\n";
|
||||
$res .= "\treturn True;\n";
|
||||
$res .= "}\n\n";
|
||||
|
||||
$res .= "/* Convert struct $fn->{NAME}.out to Python dict */\n\n";
|
||||
|
||||
$res .= "int $fn->{NAME}_to_python(TALLOC_CTX *mem_ctx, PyObject *obj, struct $fn->{NAME} *s)\n";
|
||||
$res .= "{\n";
|
||||
|
||||
foreach my $e (@{$fn->{DATA}}) {
|
||||
if (util::has_property($e, "out")) {
|
||||
$res .= "\t// $e->{TYPE} $e->{NAME}\n";
|
||||
}
|
||||
}
|
||||
|
||||
$res .= "\n";
|
||||
$res .= "\treturn True;\n";
|
||||
$res .= "}\n\n";
|
||||
|
||||
$res .= "%}\n\n";
|
||||
|
||||
# Input typemap
|
||||
|
||||
$res .= "%typemap(in) struct $fn->{NAME} * (struct $fn->{NAME} temp) {\n";
|
||||
# $res .= "\tif (!PyDict_Check(\$input)) {\n";
|
||||
# $res .= "\t\tPyErr_SetString(PyExc_TypeError, \"dict arg expected\");\n";
|
||||
# $res .= "\t\treturn NULL;\n";
|
||||
# $res .= "\t}\n\n";
|
||||
$res .= "\tmemset(&temp, 0, sizeof(temp));\n";
|
||||
# foreach my $e (@{$fn->{DATA}}) {
|
||||
# if (util::has_property($e, "in")) {
|
||||
# $res .= "\ttemp.in.$e->{NAME} = $e->{TYPE}_from_python(PyDict_GetItem(\$input, PyString_FromString(\"$e->{NAME}\")));\n";
|
||||
# }
|
||||
# }
|
||||
|
||||
# $res .= "\n";
|
||||
$res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(int) $fn->{NAME}\");\n\n";
|
||||
$res .= "\tpython_to_$fn->{NAME}(mem_ctx, &temp, \$input);\n";
|
||||
$res .= "\t\$1 = &temp;\n";
|
||||
$res .= "}\n\n";
|
||||
|
||||
# Output typemap
|
||||
|
||||
$res .= "%typemap(argout) struct $fn->{NAME} * {\n";
|
||||
$res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(argout) $fn->{NAME}\");\n\n";
|
||||
$res .= "\tlong status = PyLong_AsLong(resultobj);\n";
|
||||
$res .= "\tPyObject *dict;\n";
|
||||
$res .= "\n";
|
||||
@ -46,14 +71,8 @@ sub ParseFunction($)
|
||||
$res .= "\n";
|
||||
$res .= "\tdict = PyDict_New();\n";
|
||||
|
||||
# foreach my $e (@{$fn->{DATA}}) {
|
||||
# if (util::has_property($e, "out")) {
|
||||
# $res .= "\t// PyDict_SetItem(dict, PyString_FromString(\"$e->{NAME}\"),\n";
|
||||
# $res .= "\t//\t$e->{TYPE}_to_python(\$1->out.$e->{NAME}));\n";
|
||||
# }
|
||||
# }
|
||||
$res .= "\t$fn->{NAME}_to_python(mem_ctx, dict, \$1);\n";
|
||||
|
||||
$res .= "\n";
|
||||
$res .= "\tresultobj = dict;\n";
|
||||
$res .= "}\n\n";
|
||||
|
||||
@ -68,11 +87,32 @@ sub ParseStruct($)
|
||||
my($s) = shift;
|
||||
|
||||
$res .= "%{\n\n";
|
||||
$res .= "\t/* $s->{NAME} */\n\n";
|
||||
$res .= "/* Convert Python dict to struct $s->{NAME} */\n\n";
|
||||
|
||||
$res .= "int python_to_$s->{NAME}(TALLOC_CTX *mem_ctx, struct $s->{NAME} *s, PyObject *obj)\n";
|
||||
$res .= "{\n";
|
||||
|
||||
foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
|
||||
$res .= "\t// $e->{TYPE} $e->{NAME}\n";
|
||||
}
|
||||
|
||||
$res .= "\n";
|
||||
$res .= "\treturn TRUE;\n";
|
||||
$res .= "}\n\n";
|
||||
|
||||
$res .= "/* Convert struct $s->{NAME} to Python dict */\n\n";
|
||||
|
||||
$res .= "int $s->{NAME}_to_python(TALLOC_CTX *mem_ctx, PyObject *obj, struct $s->{NAME} *s)\n";
|
||||
$res .= "{\n";
|
||||
|
||||
foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
|
||||
$res .= "\t// $e->{TYPE} $e->{NAME}\n";
|
||||
}
|
||||
|
||||
$res .= "\n";
|
||||
$res .= "\treturn TRUE;\n";
|
||||
$res .= "}\n";
|
||||
|
||||
$res .= "\n%}\n\n";
|
||||
}
|
||||
|
||||
@ -111,7 +151,7 @@ sub ParseHeader($)
|
||||
sub Parse($)
|
||||
{
|
||||
my($idl) = shift;
|
||||
|
||||
|
||||
$res = "/* auto-generated by pidl */\n\n";
|
||||
|
||||
foreach my $x (@{$idl}) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user