Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 23561 - std.typecons.Unique!struct does not destroy struct … #8651

Merged
merged 3 commits into from
Dec 24, 2022

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Dec 16, 2022

…instance

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @ntrel! 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
23561 normal std.typecons.Unique!struct does not destroy struct instance

Testing this PR locally

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

dub run digger -- build "master + phobos#8651"

std/typecons.d Outdated
~this() @trusted
{
// context pointer doesn't exist when GC calls
if (&i > cast(void*) 1024)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way of checking for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Contributor Author

@ntrel ntrel Dec 17, 2022

Choose a reason for hiding this comment

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

destroy calls the destructor first, before nullifying the context pointer (I think). Then when the GC calls the destructor it segfaults when accessing i to increment it, because the context pointer is null.

Copy link
Contributor

Choose a reason for hiding this comment

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

This works for me:

Suggested change
if (&i > cast(void*) 1024)
if (this !is typeof(this).init)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I asked on the learn forum for a way that works well in general and @aG0aep6G suggested using tupleof[$-1], so I've used tupleof[0] as tupleof.length here is 1.

@ljmf00
Copy link
Member

ljmf00 commented Dec 23, 2022

Squash the commits before merge.

@dlang-bot dlang-bot merged commit d5c1067 into dlang:master Dec 24, 2022
@ntrel ntrel deleted the unique-dtor branch December 24, 2022 12:47
@ntrel
Copy link
Contributor Author

ntrel commented Dec 24, 2022

@ljmf00 Razvan has used auto-merge-squash.

ntrel added a commit to ntrel/phobos that referenced this pull request Dec 24, 2022
ntrel added a commit to ntrel/phobos that referenced this pull request Dec 24, 2022
@ntrel
Copy link
Contributor Author

ntrel commented Dec 24, 2022

Added a separate changelog with a note about the GC calling the destructor too: #8654.

@ibuclaw
Copy link
Member

ibuclaw commented Feb 25, 2023

This PR caused a regression https://issues.dlang.org/show_bug.cgi?id=23723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants