gstinfo: Add gst_debug_log_literal() function
authorSebastian Dröge <sebastian@centricular.com>
Tue, 16 Nov 2021 16:05:09 +0000 (18:05 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 16 Nov 2021 16:32:55 +0000 (16:32 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1356>

subprojects/gstreamer/gst/gstinfo.c
subprojects/gstreamer/gst/gstinfo.h

index 66eb50b..8360725 100644 (file)
@@ -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)
 {
index 9d8d7f9..955a83d 100644 (file)
@@ -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