From: Troy G. <tro...@gm...> - 2010-11-30 15:45:52
|
I have a char array in Objective C with this: char[] {0, 37, 0, 0}. This is later passed to the readInt__ method in java_io_DataInputStream. This results in 9472 through the Simulator. On the Java side, I wrote a test and this results in 2424832. It appears the byte order is being reversed since Java reads and writes everything in byte order. It seems like the following code needs to be reversed to match Java. So instead of p being p[0] = 0, p[1] = 25, p[2] = 0, p[3] = 0 it would be p[0] = 0, p[1] = 0, p[2] = 25, p[3] = 0. This would correctly convert on the iPhone. I posted what the new method could look like although I didn't test it. *original* - (int) readInt__ { int d; unsigned char* p = (unsigned char*) &d; for (int i = 0; i < 4; i++) { int v = [target read__]; *p++ = (unsigned char) v; } return d; } to *new* - (int) readInt__ { int d; unsigned char* p = (unsigned char*) &d; for (int i = 4; i > 0; i--) { int v = [target read__]; p[i-1] = (unsigned char) v; } return d; } * * * * |
From: Arno P. <ar...@pu...> - 2010-11-30 18:07:19
|
interesting point. Can you please verify that this works now? If so, I will commit the patch. Arno On 11/30/10 7:45 AM, Troy Gaines wrote: > I have a char array in Objective C with this: char[] {0, 37, 0, 0}. > This is later passed to the readInt__ method in java_io_DataInputStream. > > This results in 9472 through the Simulator. On the Java side, I wrote a > test and this results in 2424832. It appears the byte order is being > reversed since Java reads and writes everything in byte order. It > seems like the following code needs to be reversed to match Java. > > So instead of p being p[0] = 0, p[1] = 25, p[2] = 0, p[3] = 0 it would > be p[0] = 0, p[1] = 0, p[2] = 25, p[3] = 0. This would correctly > convert on the iPhone. I posted what the new method could look like > although I didn't test it. > > *original* > > - (int) readInt__ > { > int d; > unsigned char* p = (unsigned char*) &d; > for (int i = 0; i < 4; i++) { > int v = [target read__]; > *p++ = (unsigned char) v; > } > > return d; > } > > to > > *new* > > - (int) readInt__ > { > int d; > unsigned char* p = (unsigned char*) &d; > for (int i = 4; i > 0; i--) { > int v = [target read__]; > p[i-1] = (unsigned char) v; > } > > return d; > } > > * > * > * > * > > > > ------------------------------------------------------------------------------ > Increase Visibility of Your 3D Game App& Earn a Chance To Win $500! > Tap into the largest installed PC base& get more eyes on your game by > optimizing for Intel(R) Graphics Technology. Get started today with the > Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. > http://p.sf.net/sfu/intelisp-dev2dev > > > > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |
From: Troy G. <tro...@gm...> - 2010-11-30 19:02:27
|
I'll write a test to validate and validate. On a related but separate note, has this project considered (if it doesn't already have them) unit tests to validate behavior on some of these classes? I could see it becoming more important especially on classes that we're implementing by hand. Thanks again for all your help! On Tue, Nov 30, 2010 at 12:06 PM, Arno Puder <ar...@pu...> wrote: > > interesting point. Can you please verify that this works now? If so, I > will commit the patch. > > Arno > > > On 11/30/10 7:45 AM, Troy Gaines wrote: > > I have a char array in Objective C with this: char[] {0, 37, 0, 0}. > > This is later passed to the readInt__ method in > java_io_DataInputStream. > > > > This results in 9472 through the Simulator. On the Java side, I wrote a > > test and this results in 2424832. It appears the byte order is being > > reversed since Java reads and writes everything in byte order. It > > seems like the following code needs to be reversed to match Java. > > > > So instead of p being p[0] = 0, p[1] = 25, p[2] = 0, p[3] = 0 it would > > be p[0] = 0, p[1] = 0, p[2] = 25, p[3] = 0. This would correctly > > convert on the iPhone. I posted what the new method could look like > > although I didn't test it. > > > > *original* > > > > - (int) readInt__ > > { > > int d; > > unsigned char* p = (unsigned char*) &d; > > for (int i = 0; i < 4; i++) { > > int v = [target read__]; > > *p++ = (unsigned char) v; > > } > > > > return d; > > } > > > > to > > > > *new* > > > > - (int) readInt__ > > { > > int d; > > unsigned char* p = (unsigned char*) &d; > > for (int i = 4; i > 0; i--) { > > int v = [target read__]; > > p[i-1] = (unsigned char) v; > > } > > > > return d; > > } > > > > * > > * > > * > > * > > > > > > > > > ------------------------------------------------------------------------------ > > Increase Visibility of Your 3D Game App& Earn a Chance To Win $500! > > Tap into the largest installed PC base& get more eyes on your game by > > optimizing for Intel(R) Graphics Technology. Get started today with the > > Intel(R) Software Partner Program. Five $500 cash prizes are up for > grabs. > > http://p.sf.net/sfu/intelisp-dev2dev > > > > > > > > _______________________________________________ > > xmlvm-users mailing list > > xml...@li... > > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > > ------------------------------------------------------------------------------ > Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! > Tap into the largest installed PC base & get more eyes on your game by > optimizing for Intel(R) Graphics Technology. Get started today with the > Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. > http://p.sf.net/sfu/intelisp-dev2dev > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > |
From: Troy G. <tro...@gm...> - 2010-12-01 03:21:11
|
### Eclipse Workspace Patch 1.0 #P xmlvm Index: src/xmlvm2objc/compat-lib/objc/java_io_DataInputStream.m =================================================================== --- src/xmlvm2objc/compat-lib/objc/java_io_DataInputStream.m (revision 1253) +++ src/xmlvm2objc/compat-lib/objc/java_io_DataInputStream.m (working copy) @@ -51,10 +51,11 @@ int d; unsigned char* p = (unsigned char*) &d; - for (int i = 0; i < 4; i++) { + for (int i = 4; i > 0; i--) { int v = [target read__]; - *p++ = (unsigned char) v; + p[i-1] = (unsigned char) v; } + return d; } @@ -73,10 +74,11 @@ float f; unsigned char* p = (unsigned char*) &f; - for (int i = 0; i < 4; i++) { + for (int i = 4; i > 0; i--) { int v = [target read__]; - *p++ = (unsigned char) v; + p[i-1] = (unsigned char) v; } + return f; } @@ -85,10 +87,11 @@ double d; unsigned char* p = (unsigned char*) &d; - for (int i = 0; i < 8; i++) { + for (int i = 8; i > 0; i--) { int v = [target read__]; - *p++ = (unsigned char) v; + p[i-1] = (unsigned char) v; } + return d; } |
From: Panayotis K. <pan...@pa...> - 2010-12-01 07:21:55
|
On Dec 1, 2010, at 5:20 AM, Troy Gaines wrote: > Ok, I attached a patch file. I ended up changing readInt__, readFloat__ and readDouble__ as well. These all compared out with my Java vs. Objective C test. > > Thanks. Probably the problem was that, Java is internally always Big Endian? |
From: Troy G. <tro...@gm...> - 2010-12-01 12:27:28
|
Yep and going to iPhone which is little endian. On Dec 1, 2010, at 1:21 AM, Panayotis Katsaloulis <pan...@pa...> wrote: > > On Dec 1, 2010, at 5:20 AM, Troy Gaines wrote: > >> Ok, I attached a patch file. I ended up changing readInt__, readFloat__ and readDouble__ as well. These all compared out with my Java vs. Objective C test. >> >> Thanks. > > Probably the problem was that, Java is internally always Big Endian? > > > ------------------------------------------------------------------------------ > Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! > Tap into the largest installed PC base & get more eyes on your game by > optimizing for Intel(R) Graphics Technology. Get started today with the > Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. > http://p.sf.net/sfu/intelisp-dev2dev > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |