diff options
-rw-r--r-- | lib/talloc/pytalloc.c | 20 | ||||
-rw-r--r-- | lib/talloc/pytalloc.h | 4 | ||||
-rw-r--r-- | pidl/lib/Parse/Pidl/Samba4/Python.pm | 14 |
3 files changed, 31 insertions, 7 deletions
diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c index ccf27f5fa0..c9c6027fe0 100644 --- a/lib/talloc/pytalloc.c +++ b/lib/talloc/pytalloc.c @@ -106,5 +106,25 @@ static void py_cobject_talloc_free(void *ptr) PyObject *PyCObject_FromTallocPtr(void *ptr) { + if (ptr == NULL) { + Py_RETURN_NONE; + } return PyCObject_FromVoidPtr(ptr, py_cobject_talloc_free); } + +PyObject *PyString_FromString_check_null(const char *ptr) +{ + if (ptr == NULL) { + Py_RETURN_NONE; + } + return PyString_FromString(ptr); +} + +PyObject *PyUnicode_Decode_check_null(const void *ptr, size_t len, + const char *charset, const char *options) +{ + if (ptr == NULL) { + Py_RETURN_NONE; + } + return PyUnicode_Decode(ptr, len, charset, options); +} diff --git a/lib/talloc/pytalloc.h b/lib/talloc/pytalloc.h index cdcc57bf85..caa388ac50 100644 --- a/lib/talloc/pytalloc.h +++ b/lib/talloc/pytalloc.h @@ -54,4 +54,8 @@ PyObject *py_talloc_default_repr(PyObject *py_obj); PyObject *PyCObject_FromTallocPtr(void *); +PyObject *PyString_FromString_check_null(const char *ptr); +PyObject *PyUnicode_Decode_check_null(const void *ptr, size_t len, + const char *charset, const char *options); + #endif /* _PY_TALLOC_H_ */ diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 05c11be07f..85ce2d64ba 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -873,7 +873,7 @@ sub ConvertObjectFromPythonData($$$$$$;$) my $ctype_name = $self->use_type_variable($ctype); unless (defined ($ctype_name)) { error($location, "Unable to determine origin of type `" . mapTypeName($ctype) . "'"); - $self->pidl("PyErr_SetString(PyExc_TypeError, \"Can not convert C Type " . mapTypeName($ctype) . " to Python\");"); + $self->pidl("PyErr_SetString(PyExc_TypeError, \"Can not convert C Type " . mapTypeName($ctype) . " from Python\");"); return; } $self->pidl("PY_CHECK_TYPE($ctype_name, $cvar, $fail);"); @@ -895,12 +895,12 @@ sub ConvertObjectFromPythonData($$$$$$;$) if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { $self->pidl("$target = PyString_AsString($cvar);"); return; - } + } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "dnsp_name") { $self->pidl("$target = PyString_AsString($cvar);"); return; - } + } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { @@ -1050,13 +1050,13 @@ sub ConvertScalarToPython($$$) } if (($ctypename eq "string" or $ctypename eq "nbt_string" or $ctypename eq "nbt_name" or $ctypename eq "wrepl_nbt_name")) { - return "PyString_FromString($cvar)"; + return "PyString_FromString_check_null($cvar)"; } # Not yet supported if ($ctypename eq "string_array") { return "PyCObject_FromTallocPtr($cvar)"; } - if ($ctypename eq "ipv4address") { return "PyString_FromString($cvar)"; } - if ($ctypename eq "dnsp_name") { return "PyString_FromString($cvar)"; } + if ($ctypename eq "ipv4address") { return "PyString_FromString_check_null($cvar)"; } + if ($ctypename eq "dnsp_name") { return "PyString_FromString_check_null($cvar)"; } if ($ctypename eq "pointer") { return "PyCObject_FromTallocPtr($cvar)"; } @@ -1139,7 +1139,7 @@ sub ConvertObjectToPythonLevel($$$$$$) if (is_charset_array($e, $l)) { # FIXME: Use Unix charset setting rather than utf-8 - $self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");"); + $self->pidl("$py_var = PyUnicode_Decode_check_null($var_name, strlen($var_name), \"utf-8\", \"ignore\");"); } else { die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS})); my $length = $l->{SIZE_IS}; |