According to http://docs.python.org/2/library/struct.html there are indicators 
to be put at the beginning of the format string to indicate that we want 
elements in standard size instead of native size.  "=" selects native byte 
order with python standard size and no alignment restrictions.

So, maybe it should be:
struct.unpack("=LHHBBBBBBBB", DepexFile.read(16))

But then the code that builds the "DepexFile" needs to be updated as well.

I guess to be truly portable, we would need to pick an endianness as well and 
then fix all structure references in all of the python files.

Here are what my two python installs show for the size of "L" and "l":

ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v.1500 64 bit (AMD64)] on 
win32
>>> struct.calcsize("L")
4
>>> struct.calcsize("l")
4
>>> struct.calcsize("=L")
4
>>> struct.calcsize("=l")
4

Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
>>> struct.calcsize("L")
8
>>> struct.calcsize("l")
8
>>> struct.calcsize("=L")
4
>>> struct.calcsize("=l")
4

Garrett Kirkendall
SMTS Firmware Engineer
AMD Technology & Engineering
7171 Southwest Parkway
Austin, TX, 78735
U.S.A.
O: +(1) 512 602 3255

  Visit us at: Facebook | amd.com

-----Original Message-----
From: Andrew Fish [mailto:[email protected]]
Sent: Wednesday, July 17, 2013 12:32 PM
To: [email protected]
Cc: [email protected]
Subject: [edk2-buildtools] struct.unpack("LHHBBBBBBBB", DepexFile.read(16)) 
fails on OS X 64-bit Python as the size is 20.

I was trying to run a build report and I started to get failures parsing binary 
Depex files. I tracked it down to struct.unpack("LHHBBBBBBBB", 
DepexFile.read(16))  throwing an error that the size required was 20 not 16.

After digging around I found out that struct.calcsize ("L") == 8 for 64-bit 
version of Python, so the Python documentation is misleading about the sizeof 
"L". It looks like "I" is a more portable way to represent a 32-bit number.

~/edk2(master)>python
Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 
4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" 
or "license" for more information.
>>> import struct
>>> struct.calcsize ("L")
8
>>> struct.calcsize ("I")
4

Thanks,

Andrew Fish






------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics Get end-to-end 
visibility with application monitoring from AppDynamics Isolate bottlenecks and 
diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-buildtools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-buildtools-devel



------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-buildtools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-buildtools-devel

Reply via email to