Skip to content

Commit 91232d3

Browse files
committed
binary: Rework array accessors. They work with native, not stdint types.
1 parent ca3dbb8 commit 91232d3

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

py/binary.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,26 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
109109
mp_int_t val = 0;
110110
switch (typecode) {
111111
case 'b':
112-
val = ((int8_t*)p)[index];
112+
val = ((signed char*)p)[index];
113113
break;
114114
case BYTEARRAY_TYPECODE:
115115
case 'B':
116-
val = ((uint8_t*)p)[index];
116+
val = ((unsigned char*)p)[index];
117117
break;
118118
case 'h':
119-
val = ((int16_t*)p)[index];
119+
val = ((short*)p)[index];
120120
break;
121121
case 'H':
122-
val = ((uint16_t*)p)[index];
122+
val = ((unsigned short*)p)[index];
123123
break;
124124
case 'i':
125-
case 'l':
126-
return mp_obj_new_int(((int32_t*)p)[index]);
125+
return mp_obj_new_int(((int*)p)[index]);
127126
case 'I':
127+
return mp_obj_new_int_from_uint(((unsigned int*)p)[index]);
128+
case 'l':
129+
return mp_obj_new_int(((long*)p)[index]);
128130
case 'L':
129-
return mp_obj_new_int_from_uint(((uint32_t*)p)[index]);
131+
return mp_obj_new_int_from_uint(((unsigned long*)p)[index]);
130132
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
131133
case 'q':
132134
case 'Q':
@@ -277,25 +279,29 @@ void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t v
277279
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val) {
278280
switch (typecode) {
279281
case 'b':
280-
((int8_t*)p)[index] = val;
282+
((signed char*)p)[index] = val;
281283
break;
282284
case BYTEARRAY_TYPECODE:
283285
case 'B':
284-
val = ((uint8_t*)p)[index] = val;
286+
((unsigned char*)p)[index] = val;
285287
break;
286288
case 'h':
287-
val = ((int16_t*)p)[index] = val;
289+
((short*)p)[index] = val;
288290
break;
289291
case 'H':
290-
val = ((uint16_t*)p)[index] = val;
292+
((unsigned short*)p)[index] = val;
291293
break;
292294
case 'i':
293-
case 'l':
294-
((int32_t*)p)[index] = val;
295+
((int*)p)[index] = val;
295296
break;
296297
case 'I':
298+
((unsigned int*)p)[index] = val;
299+
break;
300+
case 'l':
301+
((long*)p)[index] = val;
302+
break;
297303
case 'L':
298-
((uint32_t*)p)[index] = val;
304+
((unsigned long*)p)[index] = val;
299305
break;
300306
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
301307
case 'q':

0 commit comments

Comments
 (0)