proto-1.0 94: Make the `any__best_memory' fast when using gcc-3

Index: ChangeLog from Simon Odou <simon@lrde.epita.fr> * mlc/any.hh: Make the `any__best_memory' fast when using gcc-3. any.hh | 18 ++++++++++++++++++ 1 files changed, 18 insertions Index: mlc/any.hh --- mlc/any.hh (revision 93) +++ mlc/any.hh (working copy) @@ -108,20 +108,36 @@ // "best memory" version of 'any' + // FIXME: + // We should test with autotools if the compiler allows us to write a + // static_cast or not (diamond inheritance problem). gcc-2.95 gives a + // different adress but not gcc-3. + // On Mac OS X, the compilation fails with a strange link error if you + // try to use the offset computation. template <typename E> struct any <E, dispatch_policy::best_memory> { E& exact() { +# if defined __GNUC__ && __GNUC__ >= 3 + return static_cast<E&>(*this); +# else return *(E*)((char*)this - exact_offset); +# endif } const E& exact() const { +# if defined __GNUC__ && __GNUC__ >= 3 + return static_cast<const E&>(*this); +# else return *(const E*)((const char*)this - exact_offset); +# endif } +# if not defined __GNUC__ || __GNUC__ < 3 static const int exact_offset; static const E exact_obj; static const any_mem(E)& ref_exact_obj; +# endif protected: any() {} @@ -137,11 +153,13 @@ any__best_memory() : super() {} }; +# if not defined __GNUC__ || __GNUC__ < 3 template <typename E> const E any_mem(E)::exact_obj = E(); template <typename E> const any_mem(E)& any_mem(E)::ref_exact_obj = any_mem(E)::exact_obj; template <typename E> const int any_mem(E)::exact_offset = (const char*)(void*)(&any_mem(E)::ref_exact_obj) - (const char*)(void*)(&any_mem(E)::exact_obj); +# endif // "simple" version of 'any'

Le 22-03-2005, Simon Odou <simon@lrde.epita.fr> a écrit :
* mlc/any.hh: Make the `any__best_memory' fast when using gcc-3.
The main goal of this patch is to make this prototype working on Mac OS X !

Simon Odou <simon@lrde.epita.fr> wrote:
{ E& exact() { +# if defined __GNUC__ && __GNUC__ >= 3 + return static_cast<E&>(*this); +# else return *(E*)((char*)this - exact_offset); +# endif } const E& exact() const { +# if defined __GNUC__ && __GNUC__ >= 3 + return static_cast<const E&>(*this); +# else return *(const E*)((const char*)this - exact_offset); +# endif }
Vous n'avez pas déjà un header spécifique qui factorise les fonctionnalités de gcc par version (du genre, la disponibilité de __attribute__ etc) ? C'est le genre de trucs qui mériteraient d'y être. Ça prends vite le chemin de la redondance sinon. -- Didier Verna, didier@lrde.epita.fr, http://www.lrde.epita.fr/~didier EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (1) 44 08 01 85 94276 Le Kremlin-Bicêtre, France Fax.+33 (1) 53 14 59 22 didier@xemacs.org

On 2005-03-22, Didier Verna <didier@lrde.epita.fr> wrote:
Simon Odou <simon@lrde.epita.fr> wrote:
{ E& exact() { +# if defined __GNUC__ && __GNUC__ >= 3 + return static_cast<E&>(*this); +# else return *(E*)((char*)this - exact_offset); +# endif } const E& exact() const { +# if defined __GNUC__ && __GNUC__ >= 3 + return static_cast<const E&>(*this); +# else return *(const E*)((const char*)this - exact_offset); +# endif }
Vous n'avez pas déjà un header spécifique qui factorise les fonctionnalités de gcc par version (du genre, la disponibilité de __attribute__ etc) ? C'est le genre de trucs qui mériteraient d'y être. Ça prends vite le chemin de la redondance sinon.
Non on n'a pas ce header spécifique et oui on devrait ! Mais dans ce cas, comme l'indique le FIXME, il faut surtout écrire un test dédié dans les autotools. -- Simon Odou simon@lrde.epita.fr
participants (4)
-
Didier Verna
-
Simon Odou
-
Simon Odou
-
Simon Odou