Skip to content

Commit 7e66b85

Browse files
committed
modstruct: Raise NotImplementedError for unsupported repeat specification.
1 parent aaf7c5b commit 7e66b85

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

py/modstruct.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <assert.h>
2929
#include <string.h>
3030

31+
#include "py/runtime.h"
3132
#include "py/builtin.h"
3233
#include "py/objtuple.h"
3334
#include "py/binary.h"
@@ -104,7 +105,9 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
104105
}
105106
if (cnt > 1) {
106107
// TODO: count spec support only for string len
107-
assert(*fmt == 's');
108+
if (*fmt != 's') {
109+
mp_not_implemented("count>1");
110+
}
108111
}
109112

110113
mp_uint_t sz;
@@ -140,7 +143,9 @@ STATIC mp_obj_t struct_unpack(mp_obj_t fmt_in, mp_obj_t data_in) {
140143
}
141144
if (sz > 1) {
142145
// TODO: size spec support only for string len
143-
assert(*fmt == 's');
146+
if (*fmt != 's') {
147+
mp_not_implemented("count>1");
148+
}
144149
}
145150
mp_obj_t item;
146151
if (*fmt == 's') {
@@ -173,7 +178,9 @@ STATIC mp_obj_t struct_pack(mp_uint_t n_args, const mp_obj_t *args) {
173178
}
174179
if (sz > 1) {
175180
// TODO: size spec support only for string len
176-
assert(*fmt == 's');
181+
if (*fmt != 's') {
182+
mp_not_implemented("count>1");
183+
}
177184
}
178185

179186
if (*fmt == 's') {

0 commit comments

Comments
 (0)