summaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-12-13 14:31:05 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-12-13 15:23:43 -0300
commit3d76e13ca4a74337d77d5e5308e9d264a3e39991 (patch)
tree95a710912c2c2b4e3186dea35eae4c2147ac7b4c /libshiboken
parent14a8ac8f5060a9dd05483e35c0d35593da88f36b (diff)
downloadshiboken-3d76e13ca4a74337d77d5e5308e9d264a3e39991.tar.gz
shiboken-3d76e13ca4a74337d77d5e5308e9d264a3e39991.tar.xz
shiboken-3d76e13ca4a74337d77d5e5308e9d264a3e39991.zip
Fixed/refactored Shiboken::warning function.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/helper.cpp15
-rw-r--r--libshiboken/helper.h2
2 files changed, 8 insertions, 9 deletions
diff --git a/libshiboken/helper.cpp b/libshiboken/helper.cpp
index 5213c514..23483daa 100644
--- a/libshiboken/helper.cpp
+++ b/libshiboken/helper.cpp
@@ -96,7 +96,7 @@ int* sequenceToIntArray(PyObject* obj, bool zeroTerminated)
}
-int warning(PyObject *category, int stacklevel, const char *format, ...)
+int warning(PyObject* category, int stacklevel, const char* format, ...)
{
va_list args;
va_start(args, format);
@@ -107,16 +107,15 @@ int warning(PyObject *category, int stacklevel, const char *format, ...)
va_copy(args2, args);
#endif
- // check the necessary memmory
- int result = vsnprintf(NULL, 0, format, args);
- char *message = (char*) malloc(result);
+ // check the necessary memory
+ int size = vsnprintf(NULL, 0, format, args) + 1;
+ char* message = new char[size];
+ int result = 0;
if (message) {
// format the message
- vsnprintf(message, result, format, args2);
+ vsnprintf(message, size, format, args2);
result = PyErr_WarnEx(category, message, stacklevel);
- free(message);
- } else {
- result = 0;
+ delete message;
}
va_end(args2);
va_end(args);
diff --git a/libshiboken/helper.h b/libshiboken/helper.h
index a76511d1..b2e25afa 100644
--- a/libshiboken/helper.h
+++ b/libshiboken/helper.h
@@ -112,7 +112,7 @@ class AutoArrayPointer
/**
* An utility function used to call PyErr_WarnEx with a formatted message.
*/
-LIBSHIBOKEN_API int warning(PyObject *category, int stacklevel, const char *format, ...);
+LIBSHIBOKEN_API int warning(PyObject* category, int stacklevel, const char* format, ...);
} // namespace Shiboken