Comments (8)
Thank You. I see it today or tomorrow.
from protobuf-objc.
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
unsigned long replaced with uint32_t
long long replaced with int64_t
unsigned long long replaced with uint64_t
That fixed the problem for us. Hope that helps! Let me know if you'd like more details.
from protobuf-objc.
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:
sizeof(id): 4
sizeof(BOOL): 1
sizeof(long): 4
sizeof(unsigned long): 4
sizeof(long long): 8
sizeof(unsigned long long): 8
sizeof(Float32): 4
sizeof(Float64): 8
And on 64 bit output looks like this:
sizeof(id): 8
sizeof(BOOL): 1
sizeof(long): 8
sizeof(unsigned long): 8
sizeof(long long): 8
sizeof(unsigned long long): 8
sizeof(Float32): 4
sizeof(Float64): 8
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.
from protobuf-objc.
No, this test all okay
In the 64-bit runtime, the alignment of all 64-bit integer types changes from 4 bytes to 8 bytes.
32 bit:
long = 4
64 bit:
long = 8
This is my example.
message Person {
repeated uint32 myfield = 1;
}
PersonBuilder *builder = [Person builder];
NSArray *arr = @[[NSNumber numberWithUnsignedInteger:23],[NSNumber numberWithUnsignedInteger:25]];
[builder setMyfieldArray:arr];
Person *person = [builder build];
NSAssert(([person.myfield uint32AtIndex:0] == arr[0]), @"NOT EQUALS");
NSLog(@"%lu",[person.myfield uint32AtIndex:0]);
Person *person2 = [Person parseFromData:person.data];
NSLog(@"%lu",[person2.myfield uint32AtIndex:1]);
if ([person.myfield uint32AtIndex:1] == [person2.myfield uint32AtIndex:1]) {
NSLog(@"OK");
}
Log for 32 and 64 bit system(iPhone5S, iPhone Simulator Retina (4-inch 64-bit),iPhone Retina (4-inch 32-bit)):
2014-06-06 03:31:02.282 Proto[4464:60b] 23
2014-06-06 03:31:06.045 Proto[4464:60b] 25
2014-06-06 03:31:08.338 Proto[4464:60b] OK
I can not repeat the problem.
Any ideas?
from protobuf-objc.
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
from protobuf-objc.
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
2014-06-05 17:33:47.731 Test[44188:60b] 285174134
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).
from protobuf-objc.
oups...
At first(was 3am):
NSAssert(([person.myfield uint32AtIndex:0] == [arr[0] unsignedIntegerValue]), @"NOT EQUALS");
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:
git clone [email protected]:alexeyxo/protobuf-objc.git
./build.sh
and update runtime library
/src/runtime/ProtocolBuffers.xcodeproj
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.
from protobuf-objc.
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!
from protobuf-objc.
Related Issues (20)
- Fail to build - newer version of protoc HOT 2
- Build Fail #import <ProtocolBuffers/ProtocolBuffers.h> Not Found HOT 3
- Encode Delimited HOT 1
- Bug feedback
- Did this has the Nano version? thks HOT 1
- Zombie object HOT 1
- Pod version must be 3 numbers long
- Duplicate symbol cause clang error HOT 2
- How to get extentions HOT 1
- InvalidProtocolBuffer thrown when serialising array data
- Are packages and options available? HOT 8
- objectivec-descriptor.proto incorrect import
- "repeated" fields with 0 elements should produce empty NSArray, not nil
- Runtime is too old.
- When I. / scripts/build.sh, this error occurred HOT 1
- Can't build protobuf-objc compiler HOT 1
- fatal error: too many errors emitted, stopping now [-ferror-limit=]
- your protobuf version is too old!!!!!!
- case sensitive in import protobuf header file
- <!-- This is the repository for IPython command line, if you can try to make sure this question/bug/feature belong here and not on one of the Jupyter repositories. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-objc.