Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Fix issue 20049 - object.destroy doesn't propagate attributes #2674

Merged
merged 5 commits into from
Jul 14, 2019

Conversation

ShigekiKarita
Copy link
Contributor

A declaration of rt_finalize in object.d have not match to its implementation

extern (C) void rt_finalize(void* p, bool det = true) nothrow

Because of this mismatch, we could not destroy class objects in nothrow.

PS. This issue is found in mir-algorithm libmir/mir-algorithm#208

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 14, 2019

Thanks for your pull request and interest in making D better, @ShigekiKarita! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
20049 major object.destroy doesn't propagate attributes

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "stable + druntime#2674"

@9il
Copy link
Member

9il commented Jul 14, 2019

Copy link
Contributor

@JinShil JinShil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears rt_finalize is indeed nothrow:

extern (C) void rt_finalize(void* p, bool det = true) nothrow

@thewilsonator
Copy link
Contributor

If this fixes the linked issue please change the commit title to "Fix issue 20049 - [rest of title]".

Also please target stable.

@JinShil
Copy link
Contributor

JinShil commented Jul 14, 2019

Also, please add a test case to help prevent a regression.

@ShigekiKarita
Copy link
Contributor Author

Thanks. Just a moment. I'll fix that.

@ShigekiKarita ShigekiKarita changed the base branch from master to stable July 14, 2019 06:57
@dlang-bot dlang-bot added the Enhancement New functionality label Jul 14, 2019
@ShigekiKarita ShigekiKarita changed the title Fix declaration of rt_finalize in object.d by adding nothrow Fix issue 20049 - object.destroy doesn't propagate attributes Jul 14, 2019
@thewilsonator
Copy link
Contributor

You've pulled all of masters commits along with it. You need to rebase your commit on top of stable in addition to retargeting the branch in GitHub.

@ShigekiKarita
Copy link
Contributor Author

@JinShil I added the regression test. Can you check if it is correctly placed (test/exceptions/src/nothrow_dtor.d)?

@JinShil
Copy link
Contributor

JinShil commented Jul 14, 2019

@ShigekiKarita Can you just add a unittest in object.d just below the destroy implementation? I think something like this should work:

// Test to ensure proper behavior of `nothrow` destructors
unittest
{
    class C
    {
        static int dtorCount = 0;
        this() nothrow {}
        ~this() nothrow { dtorCount++; }
    }

    auto c = new C;
    destroy(c);
    assert(C.dtorCount == 1);
}

Edit:
Actually you might need something like this:

unittest
{
    class C
    {
        static int dtorCount = 0;
        this() nothrow {}
        ~this() nothrow { dtorCount++; }
    }

    void test() nothrow
    {
        auto c = new C;
        destroy(c);
        assert(C.dtorCount == 1);
    }
    
    test();
}

@ShigekiKarita
Copy link
Contributor Author

ShigekiKarita commented Jul 14, 2019

Thanks. I think nothrow unittest is also fine. This is because current dmd+druntime (2.087.0) cannot compile that.

src/object.d Outdated
@@ -882,6 +882,21 @@ nothrow @safe @nogc unittest
}
}

// Test to ensure proper behavior of `nothrow` destructors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reference the buzilla issue number, otherwise looks good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@dlang-bot dlang-bot merged commit bb0bce7 into dlang:stable Jul 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Enhancement New functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants