From 58d92cefe266e423f05dec3a2fef91ebc870c350 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 28 Aug 2010 22:00:21 +1000 Subject: pidl-python: cope with NULL pointers in more places NULL is converted to Py_None --- lib/talloc/pytalloc.c | 20 ++++++++++++++++++++ lib/talloc/pytalloc.h | 4 ++++ 2 files changed, 24 insertions(+) (limited to 'lib') 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_ */ -- cgit