summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-08-28 22:00:21 +1000
committerAndrew Tridgell <tridge@samba.org>2010-09-02 13:37:07 +1000
commit58d92cefe266e423f05dec3a2fef91ebc870c350 (patch)
tree5c7ca8b29709eb16bb9f2f62eb09045109f98697
parente7e39584a9dcfd7d98dc10b88baa53019a77e652 (diff)
downloadsamba-58d92cefe266e423f05dec3a2fef91ebc870c350.tar.gz
samba-58d92cefe266e423f05dec3a2fef91ebc870c350.tar.xz
samba-58d92cefe266e423f05dec3a2fef91ebc870c350.zip
pidl-python: cope with NULL pointers in more places
NULL is converted to Py_None
-rw-r--r--lib/talloc/pytalloc.c20
-rw-r--r--lib/talloc/pytalloc.h4
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/Python.pm14
3 files changed, 31 insertions, 7 deletions
diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
index ccf27f5fa0f..c9c6027fe08 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 cdcc57bf85d..caa388ac506 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 05c11be07f4..85ce2d64bae 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};