summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-05-10 18:07:08 +0100
committerDamien George <damien.p.george@gmail.com>2014-05-10 18:07:08 +0100
commit9597771fe4c0aa42f20514d7315e706bf6dc51cf (patch)
tree811bea0200ab4d3a2b35d244ff92251fbd83e299 /py/emitbc.c
parent7db57bf6b227f33d66493ab3252621ed0895d995 (diff)
downloadmicropython-9597771fe4c0aa42f20514d7315e706bf6dc51cf.tar.gz
micropython-9597771fe4c0aa42f20514d7315e706bf6dc51cf.zip
py, emitters: Fix dummy_data size for bytecode and thumb.
Thumb uses a bit less RAM, bytecode uses a tiny bit more, to avoid overflow of the dummy buffer in certain cases. Addresses issue #599.
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index e9c3b164fa..bfd378b5e5 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -44,6 +44,9 @@
#if !MICROPY_EMIT_CPYTHON
+#define BYTES_FOR_INT ((BYTES_PER_WORD * 8 + 6) / 7)
+#define DUMMY_DATA_SIZE (BYTES_FOR_INT)
+
struct _emit_t {
pass_kind_t pass;
int stack_size;
@@ -62,7 +65,7 @@ struct _emit_t {
uint bytecode_offset;
uint bytecode_size;
byte *code_base; // stores both byte code and code info
- byte dummy_data[8];
+ byte dummy_data[DUMMY_DATA_SIZE];
};
STATIC void emit_bc_rot_two(emit_t *emit);
@@ -152,7 +155,7 @@ STATIC void emit_write_bytecode_byte_byte(emit_t* emit, byte b1, uint b2) {
STATIC void emit_write_bytecode_uint(emit_t* emit, uint num) {
// We store each 7 bits in a separate byte, and that's how many bytes needed
- byte buf[(BYTES_PER_WORD * 8 + 6) / 7];
+ byte buf[BYTES_FOR_INT];
byte *p = buf + sizeof(buf);
// We encode in little-ending order, but store in big-endian, to help decoding
do {
@@ -171,7 +174,7 @@ STATIC void emit_write_bytecode_byte_int(emit_t* emit, byte b1, machine_int_t nu
emit_write_bytecode_byte(emit, b1);
// We store each 7 bits in a separate byte, and that's how many bytes needed
- byte buf[(BYTES_PER_WORD * 8 + 6) / 7];
+ byte buf[BYTES_FOR_INT];
byte *p = buf + sizeof(buf);
// We encode in little-ending order, but store in big-endian, to help decoding
do {