Hi, Nirbhay! On May 18, Nirbhay Choubey wrote: > > > > Besides, this simply reading THD pointer from somewhere, while, in > > fact, it's unambigously defined by 'this'. > > > > Can you use TABLE::in_use pointer? > > I am not sure about it. There are some methods that use THD > without directly accessing TABLE. > > > Or that pointer arithmetics, even (as above). > > I turned that into a macro, but its gives the following warning : > > warning: invalid access to non-static data member > ‘Open_tables_state::temporary_tables’ of NULL object [-Winvalid-offsetof] > #define CURRENT_THD ((THD *)(((char*)this) - offsetof(THD, > temporary_tables))) > > I believe offsetof is not considered safe for non-PODs?
Yes. It works de facto unless you use virtual inheritance, and we don't use it yet. There is even a my_offsetof() macro that is used to shut this warning up. Still, it's, of course, a hack, best avoided. > OTOH, I can change the class methods to accept THD * as a parameter. > and that way we can get rid of caching this this redundant pointer. A > bit ugly but works. As far as I can see, you can either inherit THD from Temporary_tables (and then use THD *thd=static_cast<THD*>(this)) or simply make your Temporary_tables a part of THD, not a separate class. In the second case you can still keep all the implementation in temporary_tables.cc, but temporary_tables.h will be merged into sql_class.h Regards, Sergei Chief Architect MariaDB and [email protected] _______________________________________________ Mailing list: https://launchpad.net/~maria-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~maria-developers More help : https://help.launchpad.net/ListHelp

