jimmij
September 4, 2007, 8:19pm
1
With this code:
void bug5()
{
string s = "one";
cout<<("two[0]>"+s).c_str()<<endl;
}
I get:
Error: G__getvariable: expression bug5.C:4:
Error: > Illegal operator for pointer 3 bug5.C:4:
Error: non class,struct,union object $(“two[0]>”+s) used with . or → bug5.C:4:
(class G__CINT_ENDL)166374312
*** Interpreter error recovered ***
The problem occurs only when character ‘>’ is after ‘[’ or ‘]’.
pcanal
September 5, 2007, 6:49am
2
Hi,
I can indeed reproduce this problem. However there is a simple (C++ legal and recommended ) solution: do not call c_str() :
void bug5()
{
string s = "one";
cout<<("two[0]>"+s)<<endl;
}
works in both interpreted and compiled code and does exactly what you wanted
Cheers,
Philippe.
jimmij
September 5, 2007, 2:47pm
3
Hello Philippe,
Thanks for reply.
The above example was just simplest program to reproduce this bug.
In real life I want to do something more useful:
for(int i=0; i<10; i++){
TCut cut1 = ("tab[0]>"+toString(i)).c_str();
tree->Draw("var",cut1);
}
Where “toString()” is a function which changes int to string:
template<typename T> std::string toString(const T& x)
{
std::ostringstream oss;
oss << x;
return oss.str();
}
As you see I need to use c_str() because constructor of TCut needs const char* instead of string.
pcanal
September 5, 2007, 3:46pm
4
In this case use a intermediary variable:
for(int i=0; i<10; i++){
std::string temp = ("tab[0]>"+toString(i));
TCut cut1 = temp.c_str();
tree->Draw("var",cut1);
}
Cheers,
Philippe
jimmij
September 5, 2007, 4:21pm
5
Hi,
Yes it works… almost
template<typename T> std::string toString(const T& x)
{
std::ostringstream oss;
oss << x;
return oss.str();
}
void bug6()
{
for(int i=0; i<2; i++){
string temp = ("var1/var2"+toString(i)+"&&var2/var3"+toString(i));
}
}
When I run first time above program it is ok, but when I run it second time then it gives error:
*** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/30864/exe, process 30864
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
[Thread debugging using libthread_db enabled]
[New Thread -1208785216 (LWP 30864)]
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
0x008307a2 in _dl_sysinfo_int80 ()
from /lib/ld-linux.so.2
#1 0x00ea97d3 in __waitpid_nocancel () from /lib/tls/libc.so.6
#2 0x00e53649 in do_system () from /lib/tls/libc.so.6
#3 0x0085d8bd in system () from /lib/tls/libpthread.so.0
#4 0x002c11ff in TUnixSystem::Exec () from /opt/install/root/lib/libCore.so
#5 0x002c6991 in TUnixSystem::StackTrace ()
from /opt/install/root/lib/libCore.so
#6 0x002c35f1 in TUnixSystem::DispatchSignals ()
from /opt/install/root/lib/libCore.so
#7 0x002c36f8 in SigHandler () from /opt/install/root/lib/libCore.so
#8 0x002c28d1 in sighandler () from /opt/install/root/lib/libCore.so
#9
#10 0x00e89dac in memcpy () from /lib/tls/libc.so.6
#11 0x007b9a31 in std::string::_Rep::_M_clone () from /usr/lib/libstdc++.so.6
#12 0x007b9f2e in std::string::reserve () from /usr/lib/libstdc++.so.6
#13 0x007ba83d in std::string::append () from /usr/lib/libstdc++.so.6
#14 0x004128eb in std::operator+<char, std::char_traits, std::allocator > () from /opt/install/root/lib/libCore.so
#15 0x003df91b in G__G__Base2__0_124 () from /opt/install/root/lib/libCore.so
#16 0x008f74b7 in Cint::G__ExceptionWrapper ()
from /opt/install/root/lib/libCint.so
#17 0x009abff1 in G__call_cppfunc () from /opt/install/root/lib/libCint.so
#18 0x0099323e in G__interpret_func () from /opt/install/root/lib/libCint.so
#19 0x00982571 in G__getfunction () from /opt/install/root/lib/libCint.so
#20 0x009c6652 in G__overloadopr () from /opt/install/root/lib/libCint.so
#21 0x009c6fe6 in G__bstore () from /opt/install/root/lib/libCint.so
#22 0x0096ad25 in G__getexpr () from /opt/install/root/lib/libCint.so
#23 0x00981bbc in G__getfunction () from /opt/install/root/lib/libCint.so
#24 0x00968458 in G__getitem () from /opt/install/root/lib/libCint.so
#25 0x0096ae47 in G__getexpr () from /opt/install/root/lib/libCint.so
#26 0x00959c1f in G__define_var () from /opt/install/root/lib/libCint.so
#27 0x00a1885e in G__defined_type () from /opt/install/root/lib/libCint.so
#28 0x009d1a88 in G__exec_statement () from /opt/install/root/lib/libCint.so
#29 0x009d35f8 in G__exec_loop () from /opt/install/root/lib/libCint.so
#30 0x009d3d54 in G__exec_for () from /opt/install/root/lib/libCint.so
#31 0x009d1677 in G__exec_statement () from /opt/install/root/lib/libCint.so
#32 0x00993e56 in G__interpret_func () from /opt/install/root/lib/libCint.so
#33 0x00982571 in G__getfunction () from /opt/install/root/lib/libCint.so
#34 0x00968458 in G__getitem () from /opt/install/root/lib/libCint.so
#35 0x0096ae47 in G__getexpr () from /opt/install/root/lib/libCint.so
#36 0x00973166 in G__calc_internal () from /opt/install/root/lib/libCint.so
#37 0x009dce4f in G__process_cmd () from /opt/install/root/lib/libCint.so
#38 0x00296140 in TCint::ProcessLine () from /opt/install/root/lib/libCore.so
#39 0x0029621b in TCint::ProcessLineSynch ()
from /opt/install/root/lib/libCore.so
#40 0x00210bcd in TApplication::ProcessFile ()
from /opt/install/root/lib/libCore.so
#41 0x0020f026 in TApplication::ProcessLine ()
from /opt/install/root/lib/libCore.so
#42 0x00719f71 in TRint::HandleTermInput ()
from /opt/install/root/lib/libRint.so
#43 0x007186f8 in TTermInputHandler::Notify ()
from /opt/install/root/lib/libRint.so
#44 0x0071a79a in TTermInputHandler::ReadNotify ()
from /opt/install/root/lib/libRint.so
#45 0x002bfb8a in TUnixSystem::CheckDescriptors ()
from /opt/install/root/lib/libCore.so
#46 0x002c3b48 in TUnixSystem::DispatchOneEvent ()
from /opt/install/root/lib/libCore.so
#47 0x002601bc in TSystem::InnerLoop () from /opt/install/root/lib/libCore.so
#48 0x0026015b in TSystem::Run () from /opt/install/root/lib/libCore.so
#49 0x0020f1e2 in TApplication::Run () from /opt/install/root/lib/libCore.so
#50 0x00718e86 in TRint::Run () from /opt/install/root/lib/libRint.so
#51 0x08048d36 in main ()
Root > Function bug6() busy flag cleared
Any idea?
pcanal
September 6, 2007, 12:48am
6
Hi,
You are unfortunately tickled one of the known issue with CINT’s handling of the temporary objects. We will address this issue (and many other ) once we have completed CINT merge with Reflex. In the meantime, you can either simplify the expression or simply add a few #include statement and load your script via ACLiC (.L myscript.C+)
Cheers,
Philippe