Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
ecca53bd
Commit
ecca53bd
authored
Aug 10, 2014
by
Paul Sokolovsky
Browse files
py: binary.c: Properly implement alignment for native unpacked structs.
parent
2831a8f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/binary.c
View file @
ecca53bd
...
...
@@ -26,6 +26,7 @@
#include
<stdint.h>
#include
<stdlib.h>
#include
<stddef.h>
#include
<string.h>
#include
<assert.h>
...
...
@@ -37,6 +38,10 @@
// Helpers to work with binary-encoded data
#ifndef alignof
#define alignof(type) offsetof(struct { char c; type t; }, t)
#endif
int
mp_binary_get_size
(
char
struct_type
,
char
val_type
,
uint
*
palign
)
{
int
size
=
0
;
int
align
=
1
;
...
...
@@ -68,16 +73,20 @@ int mp_binary_get_size(char struct_type, char val_type, uint *palign) {
case
'b'
:
case
'B'
:
align
=
size
=
1
;
break
;
case
'h'
:
case
'H'
:
align
=
size
=
sizeof
(
short
);
break
;
align
=
alignof
(
short
);
size
=
sizeof
(
short
);
break
;
case
'i'
:
case
'I'
:
align
=
size
=
sizeof
(
int
);
break
;
align
=
alignof
(
int
);
size
=
sizeof
(
int
);
break
;
case
'l'
:
case
'L'
:
align
=
size
=
sizeof
(
long
);
break
;
align
=
alignof
(
long
);
size
=
sizeof
(
long
);
break
;
case
'q'
:
case
'Q'
:
// TODO: This is for x86
align
=
sizeof
(
int
);
size
=
sizeof
(
long
long
);
break
;
align
=
alignof
(
long
long
);
size
=
sizeof
(
long
long
);
break
;
case
'P'
:
case
'O'
:
case
'S'
:
align
=
size
=
sizeof
(
void
*
);
break
;
align
=
alignof
(
void
*
);
size
=
sizeof
(
void
*
);
break
;
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment