Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
July 22, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
phobos commit, revision 1776 user: andrei msg: Simplified scoped() http://www.dsource.org/projects/phobos/changeset/1776 |
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsource.org | The implementation is still incomplete. It doesn't call base class dtors. This unittest should pass: unittest { class A { static bool dead; ~this() { dead = true; } } class B : A { static bool dead; ~this() { dead = true; } } { auto b = scoped!B; } assert(B.dead); assert(A.dead); } A less severe problem is that it doesn't delete the object's monitor if one was allocated. Please refer to rt_finalize for correct destruction sequence. Essentially, Scoped dtor should do what rt_finalize does except there is no need to catch destructor exceptions and I'm not sure about collectHandler. Sean, please comment? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100723/f89bdde8/attachment.html> |
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Samukha | Why not just call rt_finalize? How an object is finalized may vary by compiler.
Sent from my iPhone
On Jul 23, 2010, at 2:17 AM, Max Samukha <maxsamukha at gmail.com> wrote:
>
> The implementation is still incomplete. It doesn't call base class dtors. This unittest should pass:
>
> unittest
> {
> class A { static bool dead; ~this() { dead = true; } }
> class B : A { static bool dead; ~this() { dead = true; } }
> {
> auto b = scoped!B;
> }
> assert(B.dead);
> assert(A.dead);
> }
>
> A less severe problem is that it doesn't delete the object's monitor if one was allocated.
>
> Please refer to rt_finalize for correct destruction sequence. Essentially, Scoped dtor should do what rt_finalize does except there is no need to catch destructor exceptions and I'm not sure about collectHandler. Sean, please comment?
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | I thought __dtor() does everything needed. Seems like I was mistaken? Sean, how do I call rt_finalize?
Andrei
Sean Kelly wrote:
> Why not just call rt_finalize? How an object is finalized may vary by compiler.
>
> Sent from my iPhone
>
> On Jul 23, 2010, at 2:17 AM, Max Samukha <maxsamukha at gmail.com> wrote:
>
>> The implementation is still incomplete. It doesn't call base class dtors. This unittest should pass:
>>
>> unittest
>> {
>> class A { static bool dead; ~this() { dead = true; } }
>> class B : A { static bool dead; ~this() { dead = true; } }
>> {
>> auto b = scoped!B;
>> }
>> assert(B.dead);
>> assert(A.dead);
>> }
>>
>> A less severe problem is that it doesn't delete the object's monitor if one was allocated.
>>
>> Please refer to rt_finalize for correct destruction sequence. Essentially, Scoped dtor should do what rt_finalize does except there is no need to catch destructor exceptions and I'm not sure about collectHandler. Sean, please comment?
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | On Fri, Jul 23, 2010 at 4:59 PM, Sean Kelly <sean at invisibleduck.org> wrote: > Why not just call rt_finalize? How an object is finalized may vary by compiler. > Absolutely. Don't know why I misread rt_finalize and concluded it ate dtor exceptions. I may be stupid. On Fri, Jul 23, 2010 at 5:33 PM, Andrei Alexandrescu <andrei at erdani.com>wrote: > I thought __dtor() does everything needed. Seems like I was mistaken? Sean, how do I call rt_finalize? > I'll dare to answer for Sean: extern (C) void rt_finalize(void* p, bool det = true); ... rt_finalize(Scoped_store.ptr); Works for me here. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100723/1b719bbf/attachment.html> |
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Samukha | OK, thanks Max. I just committed a fix. I didn't use rt_finalize which uses indirect calls. Instead I rolled the destructor calls during compilation. (This is possible because scoped() knows the exact type of the object.) http://www.dsource.org/projects/phobos/changeset/1777 Andrei On 07/23/2010 10:20 AM, Max Samukha wrote: > > > On Fri, Jul 23, 2010 at 4:59 PM, Sean Kelly <sean at invisibleduck.org <mailto:sean at invisibleduck.org>> wrote: > > Why not just call rt_finalize? How an object is finalized may vary > by compiler. > > > Absolutely. Don't know why I misread rt_finalize and concluded it ate dtor exceptions. I may be stupid. > > On Fri, Jul 23, 2010 at 5:33 PM, Andrei Alexandrescu <andrei at erdani.com <mailto:andrei at erdani.com>> wrote: > > I thought __dtor() does everything needed. Seems like I was > mistaken? Sean, how do I call rt_finalize? > > > I'll dare to answer for Sean: > > extern (C) void rt_finalize(void* p, bool det = true); > ... > rt_finalize(Scoped_store.ptr); > > Works for me here. > > > > _______________________________________________ > phobos mailing list > phobos at puremagic.com > http://lists.puremagic.com/mailman/listinfo/phobos |
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Here's the signature:
extern (C) void rt_finalize(void* p, bool det = true)
"det" is true if it's a deterministic finalization (ie. not during a GC collection). The function basically just calls __dtor and frees the monitor (and stomps on the memory with T.classinfo.init, as you requested).
If you look in src/rt/lifetime.d, _d_delclass() does a bit more by calling the custom deallocator, etc, though I think that's all destined for removal?
On Jul 23, 2010, at 7:33 AM, Andrei Alexandrescu wrote:
> I thought __dtor() does everything needed. Seems like I was mistaken? Sean, how do I call rt_finalize?
>
> Andrei
>
> Sean Kelly wrote:
>> Why not just call rt_finalize? How an object is finalized may vary by compiler. Sent from my iPhone On Jul 23, 2010, at 2:17 AM, Max Samukha <maxsamukha at gmail.com> wrote:
>>> The implementation is still incomplete. It doesn't call base class dtors. This unittest should pass:
>>>
>>> unittest
>>> {
>>> class A { static bool dead; ~this() { dead = true; } }
>>> class B : A { static bool dead; ~this() { dead = true; } }
>>> {
>>> auto b = scoped!B;
>>> }
>>> assert(B.dead);
>>> assert(A.dead);
>>> }
>>>
>>> A less severe problem is that it doesn't delete the object's monitor if one was allocated.
>>>
>>> Please refer to rt_finalize for correct destruction sequence. Essentially, Scoped dtor should do what rt_finalize does except there is no need to catch destructor exceptions and I'm not sure about collectHandler. Sean, please comment?
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Yup, found that and stole all I could from it. The nice thing about scoped() is that it knows exactly the type it needs to destroy (the dynamic type == the static type) so it doesn't need to access the ClassInfo etc. It statically walks up the inheritance tree and destroys everything in sight. Then it destroys that mutex thing.
Thanks,
Andrei
Sean Kelly wrote:
> Here's the signature:
>
> extern (C) void rt_finalize(void* p, bool det = true)
>
> "det" is true if it's a deterministic finalization (ie. not during a GC collection). The function basically just calls __dtor and frees the monitor (and stomps on the memory with T.classinfo.init, as you requested).
>
> If you look in src/rt/lifetime.d, _d_delclass() does a bit more by calling the custom deallocator, etc, though I think that's all destined for removal?
>
> On Jul 23, 2010, at 7:33 AM, Andrei Alexandrescu wrote:
>
>> I thought __dtor() does everything needed. Seems like I was mistaken? Sean, how do I call rt_finalize?
>>
>> Andrei
>>
>> Sean Kelly wrote:
>>> Why not just call rt_finalize? How an object is finalized may vary by compiler. Sent from my iPhone On Jul 23, 2010, at 2:17 AM, Max Samukha <maxsamukha at gmail.com> wrote:
>>>> The implementation is still incomplete. It doesn't call base class dtors. This unittest should pass:
>>>>
>>>> unittest
>>>> {
>>>> class A { static bool dead; ~this() { dead = true; } }
>>>> class B : A { static bool dead; ~this() { dead = true; } }
>>>> {
>>>> auto b = scoped!B;
>>>> }
>>>> assert(B.dead);
>>>> assert(A.dead);
>>>> }
>>>>
>>>> A less severe problem is that it doesn't delete the object's monitor if one was allocated.
>>>>
>>>> Please refer to rt_finalize for correct destruction sequence. Essentially, Scoped dtor should do what rt_finalize does except there is no need to catch destructor exceptions and I'm not sure about collectHandler. Sean, please comment?
>>>> _______________________________________________
>>>> phobos mailing list
>>>> phobos at puremagic.com
>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
July 23, 2010 [phobos] phobos commit, revision 1776 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Fri, Jul 23, 2010 at 8:19 PM, Andrei Alexandrescu <andrei at erdani.com>wrote: > Yup, found that and stole all I could from it. The nice thing about scoped() is that it knows exactly the type it needs to destroy (the dynamic type == the static type) so it doesn't need to access the ClassInfo etc. It statically walks up the inheritance tree and destroys everything in sight. Then it destroys that mutex thing. > > Thanks, > > Andrei > > Looks great. If you replaced that 'emplace' call with direct code to avoid the redundant size and alignment checks, it would be nearly perfect. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100723/bc782b73/attachment.html> |
Copyright © 1999-2021 by the D Language Foundation