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 Alignment of Hashed Structs #287

Merged
merged 4 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
- [Layout] Extract layout implementation code into it's own subcategories [Michael Schneider] (https://github.com/maicki)[#272](https://github.com/TextureGroup/Texture/pull/272)
- [Fix] Fix a potential crash when cell nodes that need layout are deleted during the same runloop. [Adlai Holler](https://github.com/Adlai-Holler) [#279](https://github.com/TextureGroup/Texture/pull/279)
- [Batch fetching] Add ASBatchFetchingDelegate that takes scroll velocity and remaining time into account [Huy Nguyen](https://github.com/nguyenhuy) [#281](https://github.com/TextureGroup/Texture/pull/281)

- [Fix] Fix a major regression in our image node contents caching. [Adlai Holler](https://github.com/Adlai-Holler) [#287](https://github.com/TextureGroup/Texture/pull/287)
5 changes: 4 additions & 1 deletion Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ - (BOOL)isEqual:(id)object

- (NSUInteger)hash
{
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
struct {
NSUInteger imageHash;
CGSize backingSize;
CGRect imageDrawRect;
BOOL isOpaque;
NSInteger isOpaque;
NSUInteger backgroundColorHash;
void *willDisplayNodeContentWithRenderingContext;
void *didDisplayNodeContentWithRenderingContext;
void *imageModificationBlock;
#pragma clang diagnostic pop
} data = {
_image.hash,
_backingSize,
Expand Down
3 changes: 3 additions & 0 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ @implementation ASTextNodeRendererKey

- (NSUInteger)hash
{
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
struct {
size_t attributesHash;
CGSize constrainedSize;
#pragma clang diagnostic pop
} data = {
_attributes.hash(),
_constrainedSize
Expand Down
5 changes: 5 additions & 0 deletions Source/Private/ASHashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
* _bounds.size
* };
* return ASHashBytes(&data, sizeof(data));
*
* @warning: If a struct has padding, any fields that are intiailized in {}
* will have garbage data for their padding, which will break this hash! Either
* use `pragma clang diagnostic warning "-Wpadded"` around your struct definition
* or manually initialize the fields of your struct (`myStruct.x = 7;` etc).
*/
NSUInteger ASHashBytes(void *bytes, size_t length);

Expand Down
3 changes: 3 additions & 0 deletions Source/TextKit/ASTextKitAttributes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

size_t ASTextKitAttributes::hash() const
{
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
struct {
NSUInteger attrStringHash;
NSUInteger truncationStringHash;
Expand All @@ -35,6 +37,7 @@
NSUInteger shadowColorHash;
CGFloat shadowOpacity;
CGFloat shadowRadius;
#pragma clang diagnostic pop
} data = {
[attributedString hash],
[truncationAttributedString hash],
Expand Down