Re: ::ROOT::Shadow

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Tue, 20 Feb 2007 17:41:21 +0100


Hi Margar,

sorry for being that slow in answering! CINT has problems understanding pointers to arrays. You can hide it like this:

#ifndef __CINT__
/* the real version */
typedef int (*IntArrayPtr)[gn1][gn2];
#else
/* a fake version for CINT */
typedef void* IntArrayPtr;
#endif

Cheers, Axel.

Margar Simonyan wrote:
> Dear developers
>
> ROOT crashes when I try to compile with ACLiC my class as defined below but with g++ it works out of box.
> MyClass is simple example demonstrating the problem. In reality I need to have pointer to 2 dimensional array of
> integers and need to be able to set the value with (member) function. To archive the goal I simply define "new" type with typedef.
>
> In ROOT after invoking
> .L MyClass.cpp++
> I get
>
> Info in <TUnixSystem::ACLiC>: creating shared library /programs/root/root/mylib//home/margar/root/cpp/macros/MyClass_cpp.so
> Fatal: sizeof(::MyClass) == sizeof(::ROOT::Shadow::MyClass) violated at line 62 of `/programs/root/root/mylib/home/margar/root/cpp/macros/filemazksT.cxx'
> aborting
> (no debugging symbols found)
> Using host libthread_db library "/lib/tls/libthread_db.so.1".
> Attaching to program: /proc/3720/exe, process 3720
> (no debugging symbols found)...done.
> (no debugging symbols found)...done.
>
> I look at temporary file crated by ACLiC and have difficulties to understand in detail, but it in general the problem is caused by the following (wrong ?) redeclaration of MyClass (see below), somehow int was replaced by void. After that there is a line
>
> R__ASSERT(sizeof(::MyClass) == sizeof(::ROOT::Shadow::MyClass));
>
> at which actual crash happens.
> Could you help to overcome the problem.
>
> Thanks,
> Margar
>
>
> namespace ROOT {
> namespace Shadow {
> #if !(defined(R__ACCESS_IN_SYMBOL) || defined(R__USE_SHADOW_CLASS))
> typedef ::MyClass MyClass;
> #else
> class MyClass {
> public:
> //friend XX;
> void* ptr[3][4]; //
> };
> #endif
>
> } // of namespace Shadow
> } // of namespace ROOT
> // END OF SHADOWS
>
>
>
>
>
> #include <iostream>
>
> const int gn1 = 3, gn2 = 4;
> typedef int (*IntArrayPtr)[gn1][gn2];
>
> class MyClass
> { public: MyClass();
> ~MyClass();
> void SetPointer(int a[][4]);
> void Print() const;
> private:
> IntArrayPtr ptr;
> static const int n1 = 3;
> static const int n2 = 4;
> };
>
> MyClass::MyClass()
> { ptr = 0; }
> MyClass::~MyClass()
> {}
> void MyClass::SetPointer(int a[][4])
> { ptr = (IntArrayPtr)a; }
>
> void MyClass::Print() const
> { for(int i = 0; i < n1; i++)
> { for(int j = 0; j < n2; j++)
> { std::cout<<(*ptr)[i][j]<<std::endl;
> }
> }
> }
>
> int main()
> { const int n1 = 3, n2 = 4;
> int a[n1][n2];
> for(int i = 0; i < n1; i++)
> { for(int j = 0; j < n2; j++)
> { a[i][j] = i+j; }
> }
>
> MyClass c;
> c.SetPointer(a);
> c.Print();
> }
>
>
>
Received on Tue Feb 20 2007 - 17:41:19 CET

This archive was generated by hypermail 2.2.0 : Tue Feb 20 2007 - 23:50:01 CET