mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
r2416: More argument checks. Raise an exception instead of segfaulting if a
dictionary does not contain a required key.
(This used to be commit fc5443af9c
)
This commit is contained in:
parent
d384984e35
commit
6bc08531b2
@ -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";
|
||||
|
||||
|
@ -51,6 +51,11 @@ void set_ntstatus_exception(int status)
|
||||
|
||||
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 @@ PyObject *uint8_to_python(uint8 obj)
|
||||
|
||||
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 @@ PyObject *uint16_to_python(uint16 obj)
|
||||
|
||||
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 @@ PyObject *uint32_to_python(uint32 obj)
|
||||
|
||||
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 @@ PyObject *int64_to_python(int64 obj)
|
||||
|
||||
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 @@ PyObject *uint64_to_python(uint64 obj)
|
||||
|
||||
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 @@ PyObject *NTTIME_to_python(NTTIME obj)
|
||||
|
||||
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 @@ PyObject *HYPER_T_to_python(HYPER_T obj)
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user