On December 5, 2019 3:09:40 PM GMT+01:00, "Martin Liška" <mli...@suse.cz> wrote:
>On 12/5/19 2:53 PM, Richard Biener wrote:
>> On December 5, 2019 2:03:58 PM GMT+01:00, "Martin Liška"
><mli...@suse.cz> wrote:
>>> On 12/5/19 1:59 PM, Richard Biener wrote:
>>>> Isn't there ggc_alloc <T> for this?  Also ggc_alloc_no_dtor<T> in
>>> case you
>>>> want to handle finalization yourself.
>>>
>>> No, if I see correctly it only calls Dtor:
>> 
>> But its odd to handle finalization but not construction here and not
>finalization in your new wrapper.
>
>No, ggc_new calls ggc_alloc that will eventually call destructor for
>types
>with non-trivial destructors.
>
>Alternative solution would be to no come up with ggc_alloc and call
>default
>ctor in ggc_alloc. But that's too restrictive as all types must have
>default
>constructor. That's not desirable to me.

Isn't there std::default_constructible? Also after your patch it's far from 
obvious which api to use. 

Richard. 

>Martin
>
>> 
>> That doesn't look like a good API. I see Honza approved the change
>but maybe you can fix the actual issue without this new API for the
>moment.
>> 
>> Richard.
>> 
>>> template<typename T>
>>> inline T *
>>> ggc_alloc (ALONE_CXX_MEM_STAT_INFO)
>>> {
>>>    if (need_finalization_p<T> ())
>>> return static_cast<T *> (ggc_internal_alloc (sizeof (T),
>finalize<T>,
>>> 0, 1
>>>                                              PASS_MEM_STAT));
>>>    else
>>>     return static_cast<T *> (ggc_internal_alloc (sizeof (T), NULL,
>0, 1
>>>                                              PASS_MEM_STAT));
>>> }
>>>
>>> ...
>>>
>>> /* Allocate a chunk of memory of SIZE bytes.  Its contents are
>>> undefined.  */
>>>
>>> void *
>>> ggc_internal_alloc (size_t size, void (*f)(void *), size_t s, size_t
>n
>>>                 MEM_STAT_DECL)
>>> {
>>> ...
>>>
>>> The function is generic, it does not know about type T. That's why
>it
>>> does not (and can't call) ctor.
>>>
>>> Martin
>> 

Reply via email to