2010/6/15 Basile Starynkevitch <bas...@starynkevitch.net>:
>   /*** NOTE: june 2010.
>
>        GCC 4.6 has a new typed garbage collected allocator; so any
>        GTY-ed struct FOO_ST should be allocated using ggc_alloc_FOO_ST
>        or ggc_alloc_cleared_FOO_ST.
>   ***/
>   #if BUILDING_GCC_VERSION >= 4006 && defined(ggc_alloc_typed)
>   #define MELT_HAS_TYPED_GGC_ALLOC 1
>   #else
>   #define MELT_HAS_TYPED_GGC_ALLOC 0
>   #endif
>
> By the way, perhaps defined(ggc_alloc_typed) would be enough above.

There is no guarantee ggc_alloc_typed won't change for 4.7 or even
4.6. If you really want to pursue this, perhaps try checking for a
typed allocator of a well-known GCC data type:
#if defined (ggc_alloc_rtx_def)
...

But then again, it may become a function instead of macro in 4.7,
breaking the test.

>  #if MELT_HAS_TYPED_GGC_ALLOC
>        struct meltobject_st *dst =
>          ggc_alloc_cleared_meltobject_st (oblen * sizeof 
> (src->obj_vartab[0]));
>  #else /*!MELT_HAS_TYPED_GGC_ALLOC*/
>        struct meltobject_st *dst = (struct meltobject_st *)
>          ggc_alloc_cleared (offsetof (struct meltobject_st,
>                                       obj_vartab) +
>                             oblen * sizeof (src->obj_vartab[0]));
>  #endif /*MELT_HAS_TYPED_GGC_ALLOC*/

I'd say, use a common ggc_alloc_cleared_meltobject_st which is made by
gengtype in 4.6+ and provide its suitable definition yourself for 4.5.

-- 
Laurynas

Reply via email to