Finding method with wrong argument in caso of int for char *

Dear CINT experts,

when looking for methods with ERTTI in CINT, one pattern is to check whether for a particular class name, method name and cprototype a G__InterfaceMethod is found. For example with root.

G__ClassInfo klass2( "TNamed" );
G__MethodInfo minfo2( klass->GetMethod( "SetName", "double", &offset ) );
if( minfo2->InterfaceMethod() ) { ... so something ... };

This works fine in the example above, but not, when trying with int:

long offset = 0;
G__ClassInfo klass( "TNamed" );
G__MethodInfo minfo( klass->GetMethod( "SetName", "int", &offset ) );
if( minfo->InterfaceMethod() ) { std::cout << "Found TNamed#SetName( int ): wrong?" << std::endl; };

Here, minfo->InterfaceMethod() will evaluate to true, although there is no TNamed::SetName( int ). The other way around, looking for a char* in TH1F::SetBinsLength( int ) works fine, meaning minfo->InterfaceMethod() is NULL. Similarly a double for char* returns NULL, as does a pointer (e.g. TH1F*).

Is this a bug, or is this not expected to work like this? Thanks in advance!

(As background: I am trying to reduce a sigsev in RubyRoot to an exception)

Cheers
Jan

Cheers,
Philippe

Hi Philippe,

thanks for your reply! I am a bit confused about the int to char* conversion, since this does not work with my compiler:


% cat main.cxx
#include "TNamed.h"
int main(int argc, char *argv[])
{
  TNamed * tn = new TNamed();
  tn->SetName( 1 );

  return 0;
}
% make
/usr/bin/gcc  -pthread -m32 -I/home/jschumac/root/root-head-svn/include -c main.cxx
main.cxx: In function ‘int main(int, char**)’:
main.cxx:6: error: invalid conversion from ‘int’ to ‘const char*’
main.cxx:6: error:   initializing argument 1 of ‘virtual void TNamed::SetName(const char*)’
make: *** [main.o] Fehler 1
% g++ --version
g++ (GCC) 4.2.3 20080102 (prerelease) (Debian 4.2.2-5)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The same happens with 3.3 for example. Also, I tried changing my example code to use G__ClassInfo::ExactMatch:

% cat finds_wrong_args
#include <ertti>
#include <iostream>

long offset = 0;
G__ClassInfo klass( "TNamed" );

G__MethodInfo minfo( klass->GetMethod( "SetName", "int", &offset, G__ClassInfo::ExactMatch ) );
if( minfo->InterfaceMethod() ) { std::cout << "Found TNamed#SetName( int ): wrong?" << std::endl; };

G__MethodInfo minfo2( klass->GetMethod( "SetName", "double", &offset, G__ClassInfo::ExactMatch ) );
if( !minfo2->InterfaceMethod() ) { std::cout << "Did not find TNamed#SetName( double ): fine." << std::endl; };

G__MethodInfo minfo4( klass->GetMethod( "SetName", "TH1F *", &offset, G__ClassInfo::ExactMatch ) );
if( !minfo4->InterfaceMethod() ) { std::cout << "Did not find TNamed#SetName( TH1F * ): fine." << std::endl; };

G__MethodInfo minfo5( klass->GetMethod( "TNamed", "int, int", &offset, G__ClassInfo::ExactMatch ) );
if( minfo5->InterfaceMethod() ) { std::cout << "Found TNamed#SetName( int, int ): wrong?" << std::endl; };
% root -l < finds_wrong_args
Note: File "iostream" already loaded
Found TNamed#SetName( int ): wrong?
Did not find TNamed#SetName( double ): fine.
Did not find TNamed#SetName( TH1F * ): fine.
Found TNamed#SetName( int, int ): wrong?

Apparently the conversion is still taking place. Compiling it in does not make a difference. Am I still going wrong?

Cheers
Jan

This is odd. I will need to look into this.
Cheers,
Philippe

Hi,

This problem has been fixed in ROOT v5.18/00

Cheers,
Philippe.