-
Notifications
You must be signed in to change notification settings - Fork 135
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
Serialization bug on 64 bit architecture for "repeated uint32" fields #8
Comments
Thank You. I see it today or tomorrow. |
We've ran into a similar issue when running on 64-bit architectures. Sorry, I don't have any test code to reproduce, but we have fixed the issue by "merging" in some of the code from Synapse's fork: https://gitlab.synapse.com/rachelbl/protobuf-objc/tree/master Specifically, long and long long (as well as their unsigned brethren) are used throughout the code. We maneuvered around the issue by doing the following replacements: long replaced with int32_t That fixed the problem for us. Hope that helps! Let me know if you'd like more details. |
Some more information. Take a look at PBArray.m and you will see this: static PBArrayValueTypeInfo PBValueTypes[] =
{
{ sizeof(id), NULL},
{ sizeof(BOOL), PBArraySetBoolValue },
{ sizeof(long), PBArraySetInt32Value },
{ sizeof(unsigned long), PBArraySetUInt32Value },
{ sizeof(long long), PBArraySetInt64Value },
{ sizeof(unsigned long long), PBArraySetUInt64Value },
{ sizeof(Float32), PBArraySetFloatValue },
{ sizeof(Float64), PBArraySetDoubleValue },
}; On 32-bit and 64-bit architectures, the values of long and unsigned long are different. You can test this by running this code on both 32 and 64 bit simulators: - (void)testPrimitiveSizes {
NSLog(@"sizeof(id): %lu", sizeof(id));
NSLog(@"sizeof(BOOL): %lu", sizeof(BOOL));
NSLog(@"sizeof(long): %lu", sizeof(long));
NSLog(@"sizeof(unsigned long): %lu", sizeof(unsigned long));
NSLog(@"sizeof(long long): %lu", sizeof(long long));
NSLog(@"sizeof(unsigned long long): %lu", sizeof(unsigned long long));
NSLog(@"sizeof(Float32): %lu", sizeof(Float32));
NSLog(@"sizeof(Float64): %lu", sizeof(Float64));
} Output on 32 bit looks like this:
And on 64 bit output looks like this:
You can see now that this becomes a problem because the PBArrayValueTypeSize(type) and PBArrayValueTypeSetter(type) functions won't work right. The fix is to use the explicit integer types in place of longs everywhere in the code, because this error isn't limited to the PBArray class. |
No, this test all okay 32 bit: 64 bit: This is my example.
Log for 32 and 64 bit system(iPhone5S, iPhone Simulator Retina (4-inch 64-bit),iPhone Retina (4-inch 32-bit)):
I can not repeat the problem. |
Damn, I suspect this is because I am running a slightly older release. The last commit I have from you is Apr 19th 2014 (link). I was a bit scared to update to your latest code, because a colleague of mine had pulled it, and he said there were compile errors. He plans to retry tomorrow and update this existing issue with the information: #4 |
I confirmed that your test exhibits the broken behavior on my system with a "iPhone Retina (4-inch 64-bit)" target: 2014-06-05 17:33:47.729 Test[44188:60b] 23 This probably confirms that the issue is the version of protobuf-objc that I'm using. BTW, I had a warning on your NSAssert so I commented it out (I'm on Xcode 5.1.1). |
oups...
And now, when this task created(#4) i am using two branches (master and arm64beta). Arm64beta branch contained fixes for arm64 architecture. One month ago I am merged two branches in master. You need to update your protobuf compiller:
and update runtime library
If the problem persists after the update let me know. we will continue to deal. I use this version every day at work and at home, on all possible devices and I haven't any problems. |
Hi @alexeyxo, I'm the aforementioned colleague of @daj I can confirm that the 64-bit issues we were seeing are resolved in the latest from the master branch. As @daj mentioned, there were other problems I ran in to when trying the latest code which caused me to balk at using it. I've now worked around both of them. All of our tests are passing. I've opened two new issues to track these problems: I believe this issue can be closed. Thanks! |
We've written an automated test (included below) that you can use to reproduce the problem. Please let us know if we've made a mistake with how we're using the field!
In the short term, the workaround I'm planning is to change to "repeated uint64" fields, which work fine.
Here's an example "test.proto" file:
Here's the test that reproduces the problem:
The test passes fine when run with a 32 bit target (e.g. "iPhone Retina (4-inch)"), but fails when run on a 64 bit target (e.g. "iPhone Retina (4-inch 64-bit)") the final line with this error message:
The text was updated successfully, but these errors were encountered: