[vlc-devel] [PATCH 1/4] objects: allow setting the output for DumpStructure

Steve Lhomme robux4 at ycbcr.xyz
Wed Mar 13 09:01:15 CET 2019


using stdout by default
---
 src/misc/objects.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index 1f92381c26..481536d258 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -85,7 +85,7 @@ static bool ObjectHasChild(vlc_object_t *obj)
     return false;
 }
 
-static void PrintObjectPrefix(vlc_object_t *obj, bool last)
+static void PrintObjectPrefix(vlc_object_t *obj, FILE *output, bool last)
 {
     vlc_object_t *parent = vlc_object_parent(obj);
     const char *str;
@@ -93,33 +93,33 @@ static void PrintObjectPrefix(vlc_object_t *obj, bool last)
     if (parent == NULL)
         return;
 
-    PrintObjectPrefix(parent, false);
+    PrintObjectPrefix(parent, output, false);
 
     if (ObjectIsLastChild(obj, parent))
         str = last ? " \xE2\x94\x94" : "  ";
     else
         str = last ? " \xE2\x94\x9C" : " \xE2\x94\x82";
 
-    fputs(str, stdout);
+    fputs(str, output);
 }
 
-static void PrintObject(vlc_object_t *obj)
+static void PrintObject(vlc_object_t *obj, FILE *output)
 {
     vlc_object_internals_t *priv = vlc_internals(obj);
 
     int canc = vlc_savecancel ();
 
-    PrintObjectPrefix(obj, true);
-    printf("\xE2\x94\x80\xE2\x94%c\xE2\x95\xB4%p %s, %u refs\n",
+    PrintObjectPrefix(obj, output, true);
+    fprintf(output, "\xE2\x94\x80\xE2\x94%c\xE2\x95\xB4%p %s, %u refs\n",
            ObjectHasChild(obj) ? 0xAC : 0x80,
            (void *)obj, vlc_object_typename(obj), atomic_load(&priv->refs));
 
     vlc_restorecancel (canc);
 }
 
-static void DumpStructure(vlc_object_t *obj, unsigned level)
+static void DumpStructure(vlc_object_t *obj, FILE *output, unsigned level)
 {
-    PrintObject(obj);
+    PrintObject(obj, output);
 
     if (unlikely(level > 100))
     {
@@ -131,7 +131,7 @@ static void DumpStructure(vlc_object_t *obj, unsigned level)
 
     vlc_mutex_assert(&tree_lock);
     vlc_children_foreach(priv, vlc_internals(obj))
-        DumpStructure(vlc_externals(priv), level + 1);
+        DumpStructure(vlc_externals(priv), output, level + 1);
 }
 
 /**
@@ -148,7 +148,7 @@ static int TreeCommand (vlc_object_t *obj, char const *cmd,
 
     flockfile(stdout);
     vlc_mutex_lock(&tree_lock);
-    DumpStructure(obj, 0);
+    DumpStructure(obj, stdout, 0);
     vlc_mutex_unlock(&tree_lock);
     funlockfile(stdout);
     return VLC_SUCCESS;
-- 
2.17.1



More information about the vlc-devel mailing list