summaryrefslogtreecommitdiff
path: root/py/binary.c
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-01-20 15:10:09 -0500
committerDan Halbert <halbert@halwitz.org>2019-01-20 15:12:34 -0500
commit7a09af73ec7f4a11a1404dff6276e09072d06983 (patch)
tree0cc43310b88a0dae09464aa9ad7a9e2c2bcf75a9 /py/binary.c
parentd2a7cd6c5aac4ef01b4503409a4bf47d4cdf31c3 (diff)
Improve struct compatibility with CPython
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/py/binary.c b/py/binary.c
index ca851c936..9c3a49e8f 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -49,7 +49,7 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
switch (struct_type) {
case '<': case '>':
switch (val_type) {
- case 'b': case 'B':
+ case 'b': case 'B': case 'x':
size = 1; break;
case 'h': case 'H':
size = 2; break;
@@ -79,7 +79,7 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
// particular (or any) ABI.
switch (val_type) {
case BYTEARRAY_TYPECODE:
- case 'b': case 'B':
+ case 'b': case 'B': case 'x':
align = size = 1; break;
case 'h': case 'H':
align = alignof(short);
@@ -126,6 +126,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
break;
case BYTEARRAY_TYPECODE:
case 'B':
+ case 'x': // value will be discarded
val = ((unsigned char*)p)[index];
break;
case 'h':
@@ -364,6 +365,8 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
case 'B':
((unsigned char*)p)[index] = val;
break;
+ case 'x':
+ ((unsigned char*)p)[index] = 0;
case 'h':
((short*)p)[index] = val;
break;