From: Stefan Metzmacher Date: Tue, 9 May 2017 06:42:21 +0000 (+0200) Subject: pidl/Python: make use of pyrpc_PyStr_AsString() in ConvertStringFromPythonData() X-Git-Url: http://git.samba.org/?p=metze%2Fsamba%2Fwip.git;a=commitdiff_plain;h=a62e9100e362f71e28a7ca8eab5eb3f3869b1579 pidl/Python: make use of pyrpc_PyStr_AsString() in ConvertStringFromPythonData() This reduces the amount of generated code a lot. Signed-off-by: Stefan Metzmacher --- diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 1eaf8e7a9d0c..032ddf74984e 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -1671,47 +1671,10 @@ sub ConvertStringFromPythonData($$$$$) { my ($self, $mem_ctx, $py_var, $target, $fail) = @_; - $self->pidl("{"); - $self->indent; - $self->pidl("const char *test_str;"); - $self->pidl("const char *talloc_str;"); - $self->pidl("PyObject *unicode = NULL;"); - $self->pidl("if (PyUnicode_Check($py_var)) {"); - $self->indent; - # FIXME: Use Unix charset setting rather than utf-8 - $self->pidl("unicode = PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\");"); - $self->pidl("if (unicode == NULL) {"); - $self->indent; - $self->pidl("PyErr_NoMemory();"); - $self->pidl("$fail"); - $self->deindent; - $self->pidl("}"); - - $self->pidl("test_str = PyBytes_AS_STRING(unicode);"); - $self->deindent; - $self->pidl("} else if (PyBytes_Check($py_var)) {"); - $self->indent; - $self->pidl("test_str = PyBytes_AS_STRING($py_var);"); - $self->deindent; - $self->pidl("} else {"); + $self->pidl("$target = pyrpc_PyStr_AsString($mem_ctx, $py_var);"); + $self->pidl("if (PyErr_Occurred() != NULL) {"); $self->indent; - $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected string or unicode object, got %s\", Py_TYPE($py_var)->tp_name);"); - $self->pidl("$fail"); - $self->deindent; - $self->pidl("}"); - $self->pidl("talloc_str = talloc_strdup($mem_ctx, test_str);"); - $self->pidl("if (unicode != NULL) {"); - $self->indent; - $self->pidl("Py_DECREF(unicode);"); - $self->deindent; - $self->pidl("}"); - $self->pidl("if (talloc_str == NULL) {"); - $self->indent; - $self->pidl("PyErr_NoMemory();"); - $self->pidl("$fail"); - $self->deindent; - $self->pidl("}"); - $self->pidl("$target = talloc_str;"); + $self->pidl($fail); $self->deindent; $self->pidl("}"); } @@ -1919,6 +1882,11 @@ sub ConvertObjectFromPythonLevel($$$$$$$$$) $self->pidl($fail); $self->deindent; $self->pidl("}"); + } elsif ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::is_scalar($nl->{DATA_TYPE}) + and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) { + $self->pidl("/* $var_name = pyrpc_*() will directly follow */"); + } elsif ($nl->{TYPE} eq "ARRAY" and is_charset_array($e, $nl)) { + $self->pidl("/* $var_name = pyrpc_PyStr_AsString() will directly follow */"); } else { $self->pidl("$var_name = NULL;"); }