summaryrefslogtreecommitdiff
path: root/py/binary.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-06-02 16:04:26 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-06-02 16:35:56 +0300
commit62798831bea83f7c75810064115e7f3a65892ca5 (patch)
tree6dbe8f6159917ee41ec53e353b23ed4940444415 /py/binary.c
parentb55a59de4c988b3d783f4d6ddaa95ebcb2538c62 (diff)
modstruct: Add one more extension to typecodes - 'S', a pointer to C string.
Also, add comment with description of extension to CPython's typecodes.
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c5
1 files changed, 4 insertions, 1 deletions
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 <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
#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 {