diff options
author | Tim Potter <tpot@samba.org> | 2004-09-19 05:28:59 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:58:50 -0500 |
commit | d384984e3541a527f36174459714a5f0cdbd8182 (patch) | |
tree | 4bf40fcc64ef5aa98b86c8c02cd30602740087f4 /source4/scripting | |
parent | a50931e7288131b92161a56dc52e22fa2fe6050b (diff) | |
download | samba-d384984e3541a527f36174459714a5f0cdbd8182.tar.gz samba-d384984e3541a527f36174459714a5f0cdbd8182.tar.bz2 samba-d384984e3541a527f36174459714a5f0cdbd8182.zip |
r2415: Throw a TypeError exception if a scalar value doesn't have the correct
type, or the argument to a to_python function isn't a dictionary.
(This used to be commit 0f58ffb142a9b8c5c745b3a2c93a1659ea8282e5)
Diffstat (limited to 'source4/scripting')
-rw-r--r-- | source4/scripting/swig/dcerpc.i | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/source4/scripting/swig/dcerpc.i b/source4/scripting/swig/dcerpc.i index 64d757c634..a09c3f2377 100644 --- a/source4/scripting/swig/dcerpc.i +++ b/source4/scripting/swig/dcerpc.i @@ -49,8 +49,13 @@ void set_ntstatus_exception(int status) /* Conversion functions for scalar types */ -uint8 uint8_from_python(PyObject *obj) +uint8 uint8_from_python(PyObject *obj, char *name) { + if (!PyInt_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name); + return 0; + } + return (uint8)PyInt_AsLong(obj); } @@ -59,8 +64,13 @@ PyObject *uint8_to_python(uint8 obj) return PyInt_FromLong(obj); } -uint16 uint16_from_python(PyObject *obj) +uint16 uint16_from_python(PyObject *obj, char *name) { + if (!PyInt_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name); + return 0; + } + return (uint16)PyInt_AsLong(obj); } @@ -69,8 +79,13 @@ PyObject *uint16_to_python(uint16 obj) return PyInt_FromLong(obj); } -uint32 uint32_from_python(PyObject *obj) +uint32 uint32_from_python(PyObject *obj, char *name) { + if (!PyInt_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name); + return 0; + } + return (uint32)PyInt_AsLong(obj); } @@ -79,8 +94,13 @@ PyObject *uint32_to_python(uint32 obj) return PyInt_FromLong(obj); } -int64 int64_from_python(PyObject *obj) +int64 int64_from_python(PyObject *obj, char *name) { + if (!PyInt_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name); + return 0; + } + return (int64)PyLong_AsLong(obj); } @@ -89,8 +109,13 @@ PyObject *int64_to_python(int64 obj) return PyLong_FromLong(obj); } -uint64 uint64_from_python(PyObject *obj) +uint64 uint64_from_python(PyObject *obj, char *name) { + if (!PyInt_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name); + return 0; + } + return (uint64)PyLong_AsLong(obj); } @@ -99,8 +124,13 @@ PyObject *uint64_to_python(uint64 obj) return PyLong_FromLong(obj); } -NTTIME NTTIME_from_python(PyObject *obj) +NTTIME NTTIME_from_python(PyObject *obj, char *name) { + if (!PyInt_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting integer value for %s", name); + return 0; + } + return (NTTIME)PyLong_AsLong(obj); } @@ -109,8 +139,13 @@ PyObject *NTTIME_to_python(NTTIME obj) return PyLong_FromLong(obj); } -HYPER_T HYPER_T_from_python(PyObject *obj) +HYPER_T HYPER_T_from_python(PyObject *obj, char *name) { + if (!PyInt_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting integer value for %s", name); + return 0; + } + return (HYPER_T)PyLong_AsLong(obj); } @@ -122,11 +157,16 @@ PyObject *HYPER_T_to_python(HYPER_T obj) /* Conversion functions for types that we don't want generated automatically. This is mostly security realted stuff in misc.idl */ -char *string_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj) +char *string_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj, char *name) { if (obj == Py_None) return NULL; + if (!PyString_Check(obj)) { + PyErr_Format(PyExc_TypeError, "Expecting string value for %s", name); + return 0; + } + return PyString_AsString(obj); } |