pidl-Python: Fix code generated for WERROR type
authorKamen Mazdrashki <kamenim@samba.org>
Fri, 8 Oct 2010 01:18:31 +0000 (04:18 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Fri, 8 Oct 2010 01:23:14 +0000 (04:23 +0300)
The bug was that we return Tuple(werr, werr_string) for WERROR type.
But when we set values for WERROR we expect to get PyInt.
Thus, we were unable to execute code like:
obj1.werror = obj2.werror

pidl/lib/Parse/Pidl/Samba4/Python.pm

index cf554f5c0cf3d97f361fd61d4cba75cd3cade26b..5d09d66c5514fd10211a7aef40fac9ee7f6d46d2 100644 (file)
@@ -942,7 +942,29 @@ sub ConvertObjectFromPythonData($$$$$$;$)
        }
 
        if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") {
+               $self->pidl("if (PyTuple_Check($cvar)) {");
+               $self->indent;
+               $self->pidl("$cvar = PyTuple_GetItem($cvar, 0);");
+               $self->deindent;
+               $self->pidl("}");
+
+               $self->pidl("if (PyLong_Check($cvar)) {");
+               $self->indent;
+               $self->pidl("$target = W_ERROR(PyLong_AsLongLong($cvar));");
+               $self->deindent;
+               $self->pidl("} else if (PyInt_Check($cvar)) {");
+               $self->indent;
                $self->pidl("$target = W_ERROR(PyInt_AsLong($cvar));");
+               $self->deindent;
+               $self->pidl("} else {");
+               $self->indent;
+               $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type %s or %s or %s\",\\");
+               $self->pidl("  PyInt_Type.tp_name, PyLong_Type.tp_name, PyTuple_Type.tp_name);");
+               $self->pidl($fail);
+               $self->deindent;
+               $self->pidl("}");
+
+#              $self->pidl("$target = W_ERROR(PyInt_AsLong($cvar));");
                return;
        }