diff options
author | Renato Filho <renato.filho@openbossa.org> | 2011-06-02 13:08:20 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:24 -0300 |
commit | 48c3f893b3024071bafe04412d52f0086b396f2b (patch) | |
tree | b98a7dd8df52a77816c3770366ba868ffa48cae1 /libshiboken | |
parent | 0e6d4cc1d151724f56c6ccf8c431077e2c778b26 (diff) |
Created Shiboken::warning function.
This is a help function to make able call python warning with formatted strings.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/helper.cpp | 29 | ||||
-rw-r--r-- | libshiboken/helper.h | 6 |
2 files changed, 35 insertions, 0 deletions
diff --git a/libshiboken/helper.cpp b/libshiboken/helper.cpp index 7359acf01..99b176447 100644 --- a/libshiboken/helper.cpp +++ b/libshiboken/helper.cpp @@ -21,6 +21,7 @@ */ #include "helper.h" +#include <stdarg.h> namespace Shiboken { @@ -97,4 +98,32 @@ int* sequenceToIntArray(PyObject* obj, bool zeroTerminated) return array; } + +int warning(PyObject *category, int stacklevel, const char *format, ...) +{ + va_list args; + va_start(args, format); +#if _WIN32 + va_list args2 = args; +#else + va_list args2; + va_copy(args2, args); +#endif + + // check the necessary memmory + int result = vsnprintf(NULL, 0, format, args); + char *message = (char*) malloc(result); + if (message) { + // format the message + vsnprintf(message, result, format, args2); + result = PyErr_WarnEx(category, message, stacklevel); + free(message); + } else { + result = 0; + } + va_end(args2); + va_end(args); + return result; +} + } // namespace Shiboken diff --git a/libshiboken/helper.h b/libshiboken/helper.h index 52b41270f..b5e0b624e 100644 --- a/libshiboken/helper.h +++ b/libshiboken/helper.h @@ -92,6 +92,12 @@ LIBSHIBOKEN_API bool sequenceToArgcArgv(PyObject* argList, int* argc, char*** ar */ LIBSHIBOKEN_API int* sequenceToIntArray(PyObject* obj, bool zeroTerminated = false); + +/** + * An utility function used to call PyErr_WarnEx with a formatted message. + */ +LIBSHIBOKEN_API int warning(PyObject *category, int stacklevel, const char *format, ...); + } // namespace Shiboken #endif // HELPER_H |