Skip to content

Conversation

@jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Jun 12, 2019

Replace uses of char* with void* in Arena's member variables. Instead,
cast to char* where needed in the implementation.

Certain compiler environments disallow std::hash<char*> specializations
to prevent hashing the pointer's value instead of the string contents.
Thus, compilation fails when std::unordered_map is keyed by char*.

Explicitly using void* is a workaround in such environments. For
consistency, void* is used throughout all member variables similarly to
the public interface.

Changes to this code are covered by src/test/allocator_tests.cpp.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

ACK 018c7d3, code change looks good, just 2 comments for your consideration.

@practicalswift
Copy link
Contributor

@jkczyz Nice first-time contribution! Welcome as a contributor!

What compiler is it that is failing to compile?

@jkczyz
Copy link
Contributor Author

jkczyz commented Jun 12, 2019

@practicalswift Thanks! My organization uses a customized STL. It provides a char* specialization for std::hash, which contains a static_assert that always fails. This is to prevent code from keying by pointers when keying by the pointed-to string is what is probably desired.

@practicalswift
Copy link
Contributor

@jkczyz Thanks for the clarification! Please squash into one commit.

Please report any other issues or warnings you encounter when using your organisations' compiler environment. Diversity in testing is good :-)

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 12, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK theStack, jonatack, achow101
Concept ACK laanwj
Stale ACK promag

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@jkczyz jkczyz force-pushed the 2019-06-arena-key branch from f954a1b to 102b565 Compare June 12, 2019 23:33
@laanwj
Copy link
Member

laanwj commented Jun 13, 2019

Concept ACK

@sipa can you please comment on this? you seem to have a good grasp around subtle issues with regard to UB around pointer casts

@fanquake fanquake requested a review from sipa July 30, 2019 06:08
@sipa
Copy link
Member

sipa commented Jul 30, 2019

My understanding is that casting something to void* and then back to the correct pointer type before use is always fine.

Will review the code soon.

@fanquake
Copy link
Member

@jkczyz Can you rebase this. @sipa Could you follow up after that?

Replace uses of char* with void* in Arena's member variables. Instead,
cast to char* where needed in the implementation.

Certain compiler environments disallow std::hash<char*> specializations
to prevent hashing the pointer's value instead of the string contents.
Thus, compilation fails when std::unordered_map is keyed by char*.

Explicitly using void* is a workaround in such environments. For
consistency, void* is used throughout all member variables similarly to
the public interface.
@jkczyz
Copy link
Contributor Author

jkczyz commented Nov 21, 2019

@jkczyz Can you rebase this. @sipa Could you follow up after that?

Done.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Code-review ACK f36d1d5

The member variables of the Arena class are changed from char* to void* and casts in the code to char* are done whenever pointer arithmetic is involved (which wouldn't work with void*). LGTM.

My understanding is that casting something to void* and then back to the correct pointer type before use is always fine.

That would also be my understanding.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK f36d1d5 review, debug build, unit tests, checked clang 15 raises "error: arithmetic on a pointer to void" without the conversions here from the generic void* pointer back to char*

some references

@achow101
Copy link
Member

achow101 commented Feb 3, 2023

This PR has had a couple of acks for a while now and could be ready to merge. Is this change still relevant and valid?

@achow101
Copy link
Member

ACK f36d1d5

@DrahtBot DrahtBot requested a review from promag February 23, 2023 20:32
@jkczyz
Copy link
Contributor Author

jkczyz commented Feb 23, 2023

This PR has had a couple of acks for a while now and could be ready to merge. Is this change still relevant and valid?

I'm not longer employed with the organization in questions, FWIW. This patch was required to compile in their environment as noted in #16195 (comment).

@achow101 achow101 merged commit c033720 into bitcoin:master Feb 23, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 25, 2023
f36d1d5 Use void* throughout support/lockedpool.h (Jeffrey Czyz)

Pull request description:

  Replace uses of char* with void* in Arena's member variables. Instead,
  cast to char* where needed in the implementation.

  Certain compiler environments disallow std::hash<char*> specializations
  to prevent hashing the pointer's value instead of the string contents.
  Thus, compilation fails when std::unordered_map is keyed by char*.

  Explicitly using void* is a workaround in such environments. For
  consistency, void* is used throughout all member variables similarly to
  the public interface.

  Changes to this code are covered by src/test/allocator_tests.cpp.

ACKs for top commit:
  achow101:
    ACK f36d1d5
  theStack:
    Code-review ACK f36d1d5
  jonatack:
    ACK f36d1d5 review, debug build, unit tests, checked clang 15 raises "error: arithmetic on a pointer to void"  without the conversions here from the generic void* pointer back to char*

Tree-SHA512: f9074e6d29ef78c795a512a6e00e9b591e2ff34165d09b73eae9eef25098c59e543c194346fcd4e83185a39c430d43744b6f7f9d1728a132843c67bd27ea5189
@bitcoin bitcoin locked and limited conversation to collaborators Feb 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants