-
Notifications
You must be signed in to change notification settings - Fork 907
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
Add equal / operator == method #192
Conversation
I hate to say this, but changing AnyStruct::getDataSection() to return a uint64_t array rather than a byte array violates C++ aliasing rules and so won't work. The only pointer type that is allowed to alias other data is char (including unsigned char). You cannot actually read or write the contents of a struct's data section as a uint64_t array. For example, say you have:
And then you wrote:
Will the value of This is why the Another problem with representing the data section as a uint64_t array is that it might lead to endianness-dependent application code. |
I actually wasn't considering saving people from endianness-dependent code, I totally forgot about aliasing rules. Both very good points. I changed that primarily for chopping off zeroed words at the end of structs (for canonicalization). There's no point in chopping off a byte at a time - it'll have no functional difference, but probably be a little slower. In my hashing implementation, I have very similar code, except it uses a nasty series of casts to get there. Note that, aliasing rules aside, what I'm doing with the result should be safe (comparing it with 0) - since that's a completely endianness-independent operation. Perhaps Is there room for some sort of middle-ground here, where we can do certain safe operations on them as complete words, but not break aliasing rules? |
I went ahead and reverted back to the original |
WireHelpers::followFars(ptr, refTarget, sgmt); | ||
return ptr->kind() == WirePointer::Kind::LIST; | ||
PointerType PointerReader::getPointerType() const { | ||
if(pointer->isNull()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous code for isNull() also returned true if pointer
itself was null, but you've removed that check here. Better add it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, not sure how I missed that.
Thanks for working on this! I've added a bunch of comments. Sorry for the delay -- it's crunch time at Sandstorm. |
Not a problem. I'm rooting for Sandstorm. I think I took care of everything. I also renamed I squashed the history, since it didn't seem particularly important. I still have the original commits, if you'd prefer (they're actually meaningfully separated this time). |
Hi Joshua, It's pretty difficult for me to iterate on a large code review like this if I can't see the incremental changes. Would you mind un-smashing them? Sorry I didn't see this earlier. |
(That is to say, the incremental commits from the last time I reviewed the code -- I don't want to re-read the stuff I've seen already.) |
@kentonv no problem. I'll keep that in mind in the future. Pushed. |
Beautiful, much easier to follow, especially with a commit for every comment like that. Just the one comment left about placement of KJ_UNREACHABLE. |
Add equal / operator == method
Thanks! |
This is a "simplest thing that could possibly work" implementation. I'm fully expecting to reorganize the code, change the types around, etc - after hearing feedback. I'll also clean up the git history at that point, which has rather unhelpful commit messages right now.