aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/helper.cpp29
-rw-r--r--libshiboken/helper.h6
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