summaryrefslogtreecommitdiff
path: root/source4/build
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2004-09-19 08:58:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:50 -0500
commit6bc08531b22895cf7ac7c0579a9445491b315b18 (patch)
tree4204dfa02e1a7f9c23e427df39f2927c03855253 /source4/build
parentd384984e3541a527f36174459714a5f0cdbd8182 (diff)
downloadsamba-6bc08531b22895cf7ac7c0579a9445491b315b18.tar.gz
samba-6bc08531b22895cf7ac7c0579a9445491b315b18.tar.bz2
samba-6bc08531b22895cf7ac7c0579a9445491b315b18.zip
r2416: More argument checks. Raise an exception instead of segfaulting if a
dictionary does not contain a required key. (This used to be commit fc5443af9c271baf189ebe0b098e190b5eda4e14)
Diffstat (limited to 'source4/build')
-rw-r--r--source4/build/pidl/swig.pm39
1 files changed, 30 insertions, 9 deletions
diff --git a/source4/build/pidl/swig.pm b/source4/build/pidl/swig.pm
index 8c8efc0f86..071f49d399 100644
--- a/source4/build/pidl/swig.pm
+++ b/source4/build/pidl/swig.pm
@@ -219,7 +219,7 @@ sub ParseFunction($)
$res .= "\tstruct $fn->{NAME} *s;\n\n";
$res .= "\tif (!PyDict_Check(obj)) {\n";
- $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for %s\", name);\n";
+ $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n";
$res .= "\t\treturn NULL;\n";
$res .= "\t}\n\n";
@@ -257,7 +257,11 @@ sub ParseFunction($)
$res .= "%typemap(in) struct $fn->{NAME} * {\n";
$res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(int) $fn->{NAME}\");\n\n";
- $res .= "\t\$1 = $fn->{NAME}_ptr_from_python(mem_ctx, \$input, \"<function params>\");\n";
+ $res .= "\t\$1 = $fn->{NAME}_ptr_from_python(mem_ctx, \$input, \"<function params>\");\n\n";
+
+ $res .= "\tif (PyErr_Occurred())\n";
+ $res .= "\t\t\treturn NULL;\n\n";
+
$res .= "}\n\n";
# Output typemap
@@ -268,9 +272,6 @@ sub ParseFunction($)
$res .= "\tPyObject *dict;\n";
$res .= "\n";
- $res .= "\tif (PyErr_Occurred())\n";
- $res .= "\t\t\treturn NULL;\n\n";
-
$res .= "\tif (status != 0) {\n";
$res .= "\t\tset_ntstatus_exception(status);\n";
$res .= "\t\treturn NULL;\n";
@@ -298,12 +299,17 @@ sub ParseStruct($)
$res .= "{\n";
$res .= "\tstruct $s->{NAME} *s;\n\n";
+ $res .= "\tif (obj == NULL) {\n";
+ $res .= "\t\tPyErr_Format(PyExc_ValueError, \"Expecting key '%s'\", name);\n";
+ $res .= "\t\treturn NULL;\n";
+ $res .= "\t}\n\n";
+
$res .= "\tif (obj == Py_None) {\n";
$res .= "\t\treturn NULL;\n";
$res .= "\t}\n\n";
$res .= "\tif (!PyDict_Check(obj)) {\n";
- $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for %s\", name);\n";
+ $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n";
$res .= "\t\treturn NULL;\n";
$res .= "\t}\n\n";
@@ -322,8 +328,13 @@ sub ParseStruct($)
$res .= "void $s->{NAME}_from_python(TALLOC_CTX *mem_ctx, struct $s->{NAME} *s, PyObject *obj, char *name)\n";
$res .= "{\n";
+ $res .= "\tif (obj == NULL) {\n";
+ $res .= "\t\tPyErr_Format(PyExc_ValueError, \"Expecting key '%s'\", name);\n";
+ $res .= "\t\treturn;\n";
+ $res .= "\t}\n\n";
+
$res .= "\tif (!PyDict_Check(obj)) {\n";
- $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for %s\", name);\n";
+ $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n";
$res .= "\t\treturn;\n";
$res .= "\t}\n\n";
@@ -369,8 +380,13 @@ sub ParseUnion($)
$res .= "\tunion $u->{NAME} *u;\n";
$res .= "\tPyObject *dict;\n\n";
+ $res .= "\tif (obj == NULL) {\n";
+ $res .= "\t\tPyErr_Format(PyExc_ValueError, \"Expecting key '%s'\", name);\n";
+ $res .= "\t\treturn NULL;\n";
+ $res .= "\t}\n\n";
+
$res .= "\tif (!PyDict_Check(obj)) {\n";
- $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for %s\", name);\n";
+ $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n";
$res .= "\t\treturn NULL;\n";
$res .= "\t}\n\n";
@@ -412,8 +428,13 @@ sub ParseUnion($)
$res .= "{\n";
$res .= "\tPyObject *dict;\n\n";
+ $res .= "\tif (obj == NULL) {\n";
+ $res .= "\t\tPyErr_Format(PyExc_ValueError, \"Expecting key '%s'\", name);\n";
+ $res .= "\t\treturn;\n";
+ $res .= "\t}\n\n";
+
$res .= "\tif (!PyDict_Check(obj)) {\n";
- $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for %s\", name);\n";
+ $res .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n";
$res .= "\t\treturn;\n";
$res .= "\t}\n\n";