svn commit: samba r2416 - in branches/SAMBA_4_0/source: build/pidl scripting/swig

tpot at samba.org tpot at samba.org
Sun Sep 19 08:58:57 GMT 2004


Author: tpot
Date: 2004-09-19 08:58:56 +0000 (Sun, 19 Sep 2004)
New Revision: 2416

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=2416&nolog=1

Log:
More argument checks.  Raise an exception instead of segfaulting if a 
dictionary does not contain a required key.

Modified:
   branches/SAMBA_4_0/source/build/pidl/swig.pm
   branches/SAMBA_4_0/source/scripting/swig/dcerpc.i


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-19 05:28:59 UTC (rev 2415)
+++ branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-19 08:58:56 UTC (rev 2416)
@@ -219,7 +219,7 @@
     $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 @@
 
     $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 @@
     $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 @@
     $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 @@
     $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 @@
     $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 @@
     $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";
 

Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-19 05:28:59 UTC (rev 2415)
+++ branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-19 08:58:56 UTC (rev 2416)
@@ -51,6 +51,11 @@
 
 uint8 uint8_from_python(PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return 0;
+	}
+
 	if (!PyInt_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
 		return 0;
@@ -66,6 +71,11 @@
 
 uint16 uint16_from_python(PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return 0;
+	}
+
 	if (!PyInt_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
 		return 0;
@@ -81,6 +91,11 @@
 
 uint32 uint32_from_python(PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return 0;
+	}
+
 	if (!PyInt_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
 		return 0;
@@ -96,6 +111,11 @@
 
 int64 int64_from_python(PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return 0;
+	}
+
 	if (!PyInt_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
 		return 0;
@@ -111,6 +131,11 @@
 
 uint64 uint64_from_python(PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return 0;
+	}
+
 	if (!PyInt_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
 		return 0;
@@ -126,6 +151,11 @@
 
 NTTIME NTTIME_from_python(PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return 0;
+	}
+
 	if (!PyInt_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting integer value for %s", name);
 		return 0;
@@ -141,6 +171,11 @@
 
 HYPER_T HYPER_T_from_python(PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return 0;
+	}
+
 	if (!PyInt_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting integer value for %s", name);
 		return 0;
@@ -159,12 +194,17 @@
 
 char *string_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj, char *name)
 {
+	if (obj == NULL) {
+		PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
+		return NULL;
+	}
+
 	if (obj == Py_None)
 		return NULL;
 
 	if (!PyString_Check(obj)) {
 		PyErr_Format(PyExc_TypeError, "Expecting string value for %s", name);
-		return 0;
+		return NULL;
 	}
 
 	return PyString_AsString(obj);



More information about the samba-cvs mailing list