pidl: Finish to fix the python generated code for 64bit integers
authorMatthieu Patou <mat@matws.net>
Mon, 21 Jun 2010 06:48:58 +0000 (10:48 +0400)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 25 Jun 2010 09:33:16 +0000 (11:33 +0200)
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
pidl/lib/Parse/Pidl/Samba4/Python.pm

index 4687a535c486592109aa8cfacb96cf84d1997147..4c5cc1b378fa491f712db0340c96d53e7f9232ef 100644 (file)
@@ -820,13 +820,40 @@ sub ConvertObjectFromPythonData($$$$$$;$)
                $actual_ctype = $actual_ctype->{DATA};
        }
 
-       if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or 
-               $actual_ctype->{TYPE} eq "SCALAR" and (
-               expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]*|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) {
+       if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP") {
                $self->pidl("PY_CHECK_TYPE(&PyInt_Type, $cvar, $fail);");
                $self->pidl("$target = PyInt_AsLong($cvar);");
                return;
        }
+       if ($actual_ctype->{TYPE} eq "SCALAR" ) {
+               if (expandAlias($actual_ctype->{NAME}) =~ /^(u?int64|hyper|dlong|udlong|udlongr|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) {
+                       $self->pidl("if (PyObject_TypeCheck($cvar, &PyLong_Type)) {");
+                       $self->indent;
+                       $self->pidl("$target = PyLong_AsLongLong($cvar);");
+                       $self->deindent;
+                       $self->pidl("} else {");
+                       $self->indent;
+                       $self->pidl("if (PyObject_TypeCheck($cvar, &PyInt_Type)) {");
+                       $self->indent;
+                       $self->pidl("$target = PyInt_AsLong($cvar);");
+                       $self->deindent;
+                       $self->pidl("} else {");
+                       $self->indent;
+                       $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type %s or %s\",\\");
+                       $self->pidl("  PyInt_Type.tp_name, PyLong_Type.tp_name);");
+                       $self->pidl($fail);
+                       $self->deindent;
+                       $self->pidl("}");
+                       $self->deindent;
+                       $self->pidl("}");
+                       return;
+               }
+               if (expandAlias($actual_ctype->{NAME}) =~ /^(char|u?int[0-9]*|time_t)$/) {
+                       $self->pidl("PY_CHECK_TYPE(&PyInt_Type, $cvar, $fail);");
+                       $self->pidl("$target = PyInt_AsLong($cvar);");
+                       return;
+               }
+       }
 
        if ($actual_ctype->{TYPE} eq "STRUCT" or $actual_ctype->{TYPE} eq "INTERFACE") {
                my $ctype_name = $self->use_type_variable($ctype);