{
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("}");
}
$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;");
}