Search found 54 matches

by BramPeeters
Wed Sep 12, 2018 2:22 pm
Forum: Development of MicroPython
Topic: Bug in execute_from_str
Replies: 13
Views: 7701

Re: Bug in execute_from_str

In my codebase it sure does ... void mp_lexer_free(mp_lexer_t *lex) { if (lex) { lex->reader.close(lex->reader.data); vstr_clear(&lex->vstr); m_del(uint16_t, lex->indent_level, lex->alloc_indent_level); m_del_obj(mp_lexer_t, lex); <============= } } #define m_del_obj(type, ptr) (m_del(type, ptr, 1))...
by BramPeeters
Wed Sep 12, 2018 2:17 pm
Forum: Development of MicroPython
Topic: Exiting the script after creating threads will crash the system ?
Replies: 6
Views: 4082

Exiting the script after creating threads will crash the system ?

Hi, After analyzing execute_from_str, it seems that it is not allowed to create some helper threads and then exit the script, because the entire bytecode (or whatever you call the output of the compilation process) will be cleaned up by the garbage collector as there is no longer a reference to it. ...
by BramPeeters
Wed Sep 12, 2018 2:16 pm
Forum: Development of MicroPython
Topic: Bug in execute_from_str
Replies: 13
Views: 7701

Re: Bug in execute_from_str

Because mp_parse 'frees' it. So 'collected' is the wrong word, it is explicitly freed by the code, not by the GC.

Code: Select all

mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) 
{
    ....
    mp_lexer_free(lex); <====== 

    return parser.tree;
}
by BramPeeters
Wed Sep 12, 2018 2:12 pm
Forum: Development of MicroPython
Topic: Bug in execute_from_str
Replies: 13
Views: 7701

Re: Bug in execute_from_str

But 'lex' itself is collected, so you are dereferencing a memory address that no longer contains a valid value
You do not even get to the qstring anymore....
by BramPeeters
Wed Sep 12, 2018 1:37 pm
Forum: Development of MicroPython
Topic: Bug in execute_from_str
Replies: 13
Views: 7701

Bug in execute_from_str

mp_obj_t execute_from_str(const char *str) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_lexer_t *lex = mp_lexer_new_from_str_len(0/*MP_QSTR_*/, str, strlen(str), false); mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_FILE_INPUT); mp_obj_t module_fun = mp_compile(&pt, lex->source_name, MP_EMIT_OPT_NO...
by BramPeeters
Wed Sep 12, 2018 12:37 pm
Forum: Development of MicroPython
Topic: Access 'class' data from instance or class methods
Replies: 0
Views: 1187

Access 'class' data from instance or class methods

Hi, Class methods (cfr MP_DEFINE_CONST_CLASSMETHOD_OBJ) have a first argument 'class' when being called. In none of the code where MP_DEFINE_CONST_CLASSMETHOD_OBJ is used in the micropython codebase, something seems to be done with this first argument (which means that all these could be replaced by...
by BramPeeters
Wed Sep 12, 2018 8:42 am
Forum: Development of MicroPython
Topic: [SOLVED]garbage collector + stack of startup task
Replies: 30
Views: 16694

Re: garbage collector + stack of startup task

If you call gc_collect(), the correct stack is correctly taken into account so your entire first example is incorrect. Ok some progress, now we are on the same page talking about the entire stack and the objects currently referenced from it and not some object that at some point in the past was on ...
by BramPeeters
Tue Sep 11, 2018 11:33 pm
Forum: Development of MicroPython
Topic: [SOLVED]garbage collector + stack of startup task
Replies: 30
Views: 16694

Re: garbage collector + stack of startup task

Ok, thanks for the elaboration. I now fully understand what you are saying, and i should absolutely recheck my code to see if I do stuff like that but that is a problem you will have with any thread/stack (no matter where it is located). (I have threading enabled and have several threads running) Th...
by BramPeeters
Tue Sep 11, 2018 9:41 pm
Forum: Development of MicroPython
Topic: [SOLVED]garbage collector + stack of startup task
Replies: 30
Views: 16694

Re: garbage collector + stack of startup task

Ok seriously I do not know what to make from your replies, either I am having a brain fart and there is something I am missing in which case i apologize or you do not understand what I am trying to point out (or you are having a bad day and you are just trolling with me here). Assuming you are serio...
by BramPeeters
Tue Sep 11, 2018 7:53 pm
Forum: Development of MicroPython
Topic: [SOLVED]garbage collector + stack of startup task
Replies: 30
Views: 16694

Re: garbage collector + stack of startup task

(also: after moving the stack to the GC heap which is in external sram, the lexer is now dead slow ( 9 seconds which triggers my watchdog versus 3s with the stack still in internal memory of the microcontroller) so i am still not out of the woods :( )