From 62798831bea83f7c75810064115e7f3a65892ca5 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 2 Jun 2014 16:04:26 +0300 Subject: modstruct: Add one more extension to typecodes - 'S', a pointer to C string. Also, add comment with description of extension to CPython's typecodes. --- py/binary.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'py/binary.c') diff --git a/py/binary.c b/py/binary.c index cec237446..833d9c85a 100644 --- a/py/binary.c +++ b/py/binary.c @@ -26,6 +26,7 @@ #include #include +#include #include #include "misc.h" @@ -75,7 +76,7 @@ int mp_binary_get_size(char struct_type, char val_type, uint *palign) { case 'q': case 'Q': // TODO: This is for x86 align = sizeof(int); size = sizeof(long long); break; - case 'P': case 'O': + case 'P': case 'O': case 'S': align = size = sizeof(void*); break; } } @@ -161,6 +162,8 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) { *ptr += size; if (val_type == 'O') { return (mp_obj_t)val; + } else if (val_type == 'S') { + return mp_obj_new_str((char*)val, strlen((char*)val), false); } else if (is_signed(val_type)) { return mp_obj_new_int(val); } else { -- cgit v1.2.3