diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2010-02-18 13:59:22 -0200 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2010-02-18 14:02:47 -0200 |
commit | 01d4e01928987984c2d6b04f13794ce6776f7f67 (patch) | |
tree | e802513cfdd876356e17756dbae25bec2ddc2c10 /libshiboken | |
parent | 9dac886d87f546bd9d2ed3162192c0af5f733b74 (diff) |
Write a verbose error messages when the function arguments don't match.
This will increase the binding size, so there's an option to disable
verbose error messages. "--disable-verbose-error-messages"
Reviewed by Renato Araújo <renato.filho@openbossa.org> and Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/basewrapper.cpp | 38 | ||||
-rw-r--r-- | libshiboken/basewrapper.h | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index dc86fa831..05276b7fa 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -37,6 +37,7 @@ #include <algorithm> #include "autodecref.h" #include "typeresolver.h" +#include <string> namespace Shiboken { @@ -365,6 +366,43 @@ PyAPI_FUNC(void) init_shiboken() } // extern "C" +void setErrorAboutWrongArguments(PyObject* args, const char* funcName, const char** cppOverloads) +{ + std::string msg; + std::string params; + if (args) { + if (PyTuple_Check(args)) { + for (int i = 0, max = PyTuple_Size(args); i < max; ++i) { + if (i) + params += ", "; + params += PyTuple_GET_ITEM(args, i)->ob_type->tp_name; + } + } else { + params = args->ob_type->tp_name; + } + } + + if (!cppOverloads) { + msg = "'" + std::string(funcName) + "' called with wrong argument types: " + params; + } else { + msg = "'" + std::string(funcName) + "' called with wrong argument types:\n "; + msg += funcName; + msg += '('; + msg += params; + msg += ")\n"; + msg += "Supported signatures:"; + for (int i = 0; cppOverloads[i]; ++i) { + msg += "\n "; + msg += funcName; + msg += '('; + msg += cppOverloads[i]; + msg += ')'; + } + } + PyErr_SetString(PyExc_TypeError, msg.c_str()); + +} + } // namespace Shiboken diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h index e8ea7cc1b..d64dadfca 100644 --- a/libshiboken/basewrapper.h +++ b/libshiboken/basewrapper.h @@ -255,8 +255,8 @@ void SbkBaseWrapper_Dealloc(PyObject* self) } LIBSHIBOKEN_API PyAPI_FUNC(void) SbkBaseWrapper_Dealloc_PrivateDtor(PyObject* self); - LIBSHIBOKEN_API bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr); +LIBSHIBOKEN_API void setErrorAboutWrongArguments(PyObject* args, const char* funcName, const char** cppOverloads); } // namespace Shiboken |