From c1b52fde97b4cb13086a343a7fe4cd256941ee72 Mon Sep 17 00:00:00 2001
From: Enric Tejedor Saavedra <enric.tejedor.saavedra@cern.ch>
Date: Tue, 11 Dec 2018 15:04:18 +0100
Subject: [PATCH] [Exp PyROOT] Use TInterpreter::ToString also in pretty
 printing experimental

---
 .../PyROOT/src/GenericPyz.cxx                    | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/bindings/pyroot_experimental/PyROOT/src/GenericPyz.cxx b/bindings/pyroot_experimental/PyROOT/src/GenericPyz.cxx
index 0d86847b762..601bdd16d01 100644
--- a/bindings/pyroot_experimental/PyROOT/src/GenericPyz.cxx
+++ b/bindings/pyroot_experimental/PyROOT/src/GenericPyz.cxx
@@ -1,4 +1,4 @@
-// Author: Stefan Wunsch CERN  06/2018
+// Author: Stefan Wunsch, Enric Tejedor CERN  06/2018
 // Original PyROOT code by Wim Lavrijsen, LBL
 
 /*************************************************************************
@@ -16,9 +16,6 @@
 #include "TInterpreter.h"
 #include "TInterpreterValue.h"
 
-#include <sstream>
-#include <algorithm>
-
 using namespace CPyCppyy;
 
 std::string GetCppName(CPPInstance *self)
@@ -29,15 +26,8 @@ std::string GetCppName(CPPInstance *self)
 PyObject *ClingPrintValue(CPPInstance *self)
 {
    const std::string className = GetCppName(self);
-   std::stringstream code;
-   code << "*((" << className << "*)" << self->GetObject() << ")";
-
-   auto value = gInterpreter->MakeInterpreterValue();
-   std::string pprint = "";
-   if (gInterpreter->Evaluate(code.str().c_str(), *value) == 1 /*success*/)
-      pprint = value->ToTypeAndValueString().second;
-   pprint.erase(std::remove(pprint.begin(), pprint.end(), '\n'), pprint.end());
-   return CPyCppyy_PyUnicode_FromString(pprint.c_str());
+   auto printResult = gInterpreter->ToString(className.c_str(), self->GetObject());
+   return CPyCppyy_PyUnicode_FromString(printResult.c_str());
 }
 
 ////////////////////////////////////////////////////////////////////////////
-- 
GitLab