erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Fix up usage of NSGetSizeAndAlignment #487

Closed dmaclach closed 3 years ago

dmaclach commented 3 years ago

NSGetSizeAndAlignment is horribly documented IMHO. The alignp argument is the alignment of the type, not the aligned size of the type. On a 64 bit system this just "happens" to work for many types that aren't structs.

erikdoe commented 3 years ago

I'm a little intrigued by your comment about structs because the code in question will only ever be run for number types. Or are you saying that for now this change is purely cosmetic because on Intel and ARM 64-bit the alignment of a pointer is equal to the size of the type pointed to (provided it's not a struct)? That is, a 64-bit integer needs to be aligned on an 8-byte boundary whereas a 32-bit integer must be aligned on a 4-byte boundary?

erikdoe commented 3 years ago

In any case, I've accepted the change and even added a unit test because that bit of code was actually untested.

dmaclach commented 3 years ago

Yes.. this is "cosmetic" because as you said a 64-bit integer needs to be aligned on an 8-byte boundary whereas a 32-bit integer must be aligned on a 4-byte boundary. I ran into problems with it in totally different code (that did use structs) and when I did a search to see what other code could have the same issues I fixed this along the way.

erikdoe commented 3 years ago

And it is correct to distinguish between pointer size and alignment. If I remember correctly, on the Motorola 68k the requirement for 32-bit pointers was to be aligned on 2-byte boundaries. In that case the change would be more than cosmetic.