Hi Andrew,

Thanks for your explanation. The patch is attached according to your comments.

Thanks,
Dennis

From: Andrew Fish [mailto:[email protected]]
Sent: Thursday, January 09, 2014 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [edk2-buildtools] Portability bug in BuildReport.py

This statement is not portable in Python and it crashes on a Mac since it tries 
to read 20 bytes.

struct.unpack("LHHBBBBBBBB", DepexFile.read(16))

The problem with unpack() is this form uses native size and alignment and 
unsigned long is a different size on Windows and Mac OS (64-bit Python).  To 
make this code portable we need to prefix with an = or <

struct.unpack("=LHHBBBBBBBB", DepexFile.read(16))

I've run into this issue before, and comes about from reading this table 
(http://docs.python.org/2/library/struct.html):

Format

C Type

Python type

Standard size

Notes

x

pad byte

no value





c

char

string of length 1

1



b

signed char

integer

1

(3)

B

unsigned char

integer

1

(3)

?

_Bool

bool

1

(1)

h

short

integer

2

(3)

H

unsigned short

integer

2

(3)

i

int

integer

4

(3)

I

unsigned int

integer

4

(3)

l

long

integer

4

(3)

L

unsigned long

integer

4

(3)

q

long long

integer

8

(2), (3)

Q

unsigned long long

integer

8

(2), (3)

f

float

float

4

(4)

d

double

float

8

(4)

s

char[]

string





p

char[]

string





P

void *

integer



(5), (3)


With out noticing that you need to  use = to get the "Standard size":



By default, C types are represented in the machine's native format and byte 
order, and properly aligned by skipping pad bytes if necessary (according to 
the rules used by the C compiler).

Alternatively, the first character of the format string can be used to indicate 
the byte order, size and alignment of the packed data, according to the 
following table:
Character

Byte order

Size

Alignment

@

native

native

native

=

native

standard

none

<

little-endian

standard

none

>

big-endian

standard

none

!

network (= big-endian)

standard

none


If the first character is not one of these, '@' is assumed.

Attachment: BuildReport.py.patch
Description: BuildReport.py.patch

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
edk2-buildtools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-buildtools-devel

Reply via email to