diff options
Diffstat (limited to 'libshiboken/helper.cpp')
-rw-r--r-- | libshiboken/helper.cpp | 29 |
1 files changed, 29 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 |