From 5dc95e00fa7620937b77484db904051893d88c6c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 16 Nov 2021 18:05:09 +0200 Subject: [PATCH] gstinfo: Add gst_debug_log_literal() function This takes a plain message string and not a format string, and as a result doesn't have to be passed through vasprintf() and lead to further unnecessary allocations. It can also contain literal `%` because of that. The new function is mostly useful for bindings that would have to pass a full string to GStreamer anyway and would do formatting themselves with language-specific functionality. Part-of: --- subprojects/gstreamer/gst/gstinfo.c | 55 +++++++++++++++++++++++++++++++++++++ subprojects/gstreamer/gst/gstinfo.h | 12 +++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/subprojects/gstreamer/gst/gstinfo.c b/subprojects/gstreamer/gst/gstinfo.c index 66eb50b..8360725 100644 --- a/subprojects/gstreamer/gst/gstinfo.c +++ b/subprojects/gstreamer/gst/gstinfo.c @@ -579,6 +579,54 @@ gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level, } /** + * gst_debug_log_literal: + * @category: category to log + * @level: level of the message is in + * @file: the file that emitted the message, usually the __FILE__ identifier + * @function: the function that emitted the message + * @line: the line from that the message was emitted, usually __LINE__ + * @object: (transfer none) (allow-none): the object this message relates to, + * or %NULL if none + * @message_string: a message string + * + * Logs the given message using the currently registered debugging handlers. + * + * Since: 1.20 + */ +void +gst_debug_log_literal (GstDebugCategory * category, GstDebugLevel level, + const gchar * file, const gchar * function, gint line, + GObject * object, const gchar * message_string) +{ + GstDebugMessage message; + LogFuncEntry *entry; + GSList *handler; + + g_return_if_fail (category != NULL); + +#ifdef GST_ENABLE_EXTRA_CHECKS + g_warn_if_fail (object == NULL || G_IS_OBJECT (object)); +#endif + + if (level > gst_debug_category_get_threshold (category)) + return; + + g_return_if_fail (file != NULL); + g_return_if_fail (function != NULL); + g_return_if_fail (message_string != NULL); + + message.message = (gchar *) message_string; + + handler = __log_functions; + while (handler) { + entry = handler->data; + handler = g_slist_next (handler); + entry->func (category, level, file, function, line, object, &message, + entry->user_data); + } +} + +/** * gst_debug_message_get: * @message: a debug message * @@ -2341,6 +2389,13 @@ gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level, { } +void +gst_debug_log_literal (GstDebugCategory * category, GstDebugLevel level, + const gchar * file, const gchar * function, gint line, + GObject * object, const gchar * message_string) +{ +} + const gchar * gst_debug_message_get (GstDebugMessage * message) { diff --git a/subprojects/gstreamer/gst/gstinfo.h b/subprojects/gstreamer/gst/gstinfo.h index 9d8d7f9..955a83d 100644 --- a/subprojects/gstreamer/gst/gstinfo.h +++ b/subprojects/gstreamer/gst/gstinfo.h @@ -368,11 +368,20 @@ void gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level, const gchar * file, const gchar * function, - gint line, + gint line, GObject * object, const gchar * format, va_list args) G_GNUC_NO_INSTRUMENT; +GST_API +void gst_debug_log_literal (GstDebugCategory * category, + GstDebugLevel level, + const gchar * file, + const gchar * function, + gint line, + GObject * object, + const gchar * message_string) G_GNUC_NO_INSTRUMENT; + /* do not use this function, use the GST_DEBUG_CATEGORY_INIT macro */ GST_API @@ -1496,6 +1505,7 @@ GST_TRACE (const char *format, ...) #if defined(__GNUC__) && __GNUC__ >= 3 # pragma GCC poison gst_debug_log # pragma GCC poison gst_debug_log_valist +# pragma GCC poison gst_debug_log_literal # pragma GCC poison _gst_debug_category_new #endif -- 2.7.4