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

Test string pointers validity and explain safety #12

Closed

Conversation

lo48576
Copy link
Contributor

@lo48576 lo48576 commented Aug 26, 2019

wrt #10 (comment).

Added StringInterner::assert_internal_str_refs_validity() and helper function StringInterner::max_capacity(), that are enabled only in test bulid.
This detects dangling pointer and overlooked interned strings, and panics if something wrong.
Using this assertion in tests, it will be possible to detect dangling pointers once it appears.

It will be hard to test every possible case, so I added a test for typical case in which the pointer can be modified or invalidated: when interning new string (and specifically when reallocation happens), and when being cloned.
It is tests::internal_str_refs_validity::intern_reallocate_clone().

Additionally, I added a comment to explain why the uses of InternalStrRefare safe, for future contributors and reviewers.

@coveralls
Copy link

coveralls commented Aug 26, 2019

Coverage Status

Coverage decreased (-1.1%) to 93.778% when pulling da8b0f3 on lo48576:feature/assert-string-pointer-validity into 9ca8921 on Robbepop:master.

@lo48576 lo48576 force-pushed the feature/assert-string-pointer-validity branch from cb856a5 to e1a46cb Compare August 26, 2019 10:07
@codecov-io
Copy link

codecov-io commented Aug 26, 2019

Codecov Report

Merging #12 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #12   +/-   ##
=======================================
  Coverage   94.43%   94.43%           
=======================================
  Files           2        2           
  Lines         413      413           
=======================================
  Hits          390      390           
  Misses         23       23

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ca8921...da8b0f3. Read the comment docs.

@lo48576 lo48576 force-pushed the feature/assert-string-pointer-validity branch 2 times, most recently from b8c1ed3 to e2b943c Compare August 26, 2019 17:33
Copy link
Owner

@Robbepop Robbepop left a comment

Choose a reason for hiding this comment

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

Thanks for the huge comment describing the safety guarantees of the unsafe code parts.
I am not sure whether it should be a normal // comment of a doc comment (and where to put it then).
Also it was sometimes hard to read due to some writing mistakes here and there. Please fix them and we can merge.
Rest looks fine.

@lo48576
Copy link
Contributor Author

lo48576 commented Aug 27, 2019

I used normal // comment because it is documentation for developers (and code readers), but not for usual library users.
(Internal uses of unsafes are not visible to users, and they would have nothing to do with it when they use the crate.)

@lo48576 lo48576 force-pushed the feature/assert-string-pointer-validity branch from e2b943c to da8b0f3 Compare August 27, 2019 08:15
@lo48576
Copy link
Contributor Author

lo48576 commented Aug 27, 2019

Fixed some sentences, but I won't notice some kind of mistakes and unnatural English, because it's not my native tongue...
I'm happy if you could point out such parts to be fixed 🙏

@lo48576
Copy link
Contributor Author

lo48576 commented May 8, 2021

Closing this as outdated.

@lo48576 lo48576 closed this May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants