From 7703b89ae57d76a3246db7489c77c9de848ea832 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Mon, 21 Jun 2010 10:48:58 +0400 Subject: [PATCH] pidl: Finish to fix the python generated code for 64bit integers Signed-off-by: Jelmer Vernooij --- pidl/lib/Parse/Pidl/Samba4/Python.pm | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 4687a535c48..4c5cc1b378f 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -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); -- 2.11.4.GIT