Skip to content

The assert in gc_free(...) and gc_realloc(...) will fail #4705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fei2020 opened this issue Apr 19, 2019 · 3 comments
Closed

The assert in gc_free(...) and gc_realloc(...) will fail #4705

fei2020 opened this issue Apr 19, 2019 · 3 comments

Comments

@fei2020
Copy link

fei2020 commented Apr 19, 2019

I embeb upy(HEAD: e0c6dfe) into my windows(vs2017 with Windows SDK10.0.17763.0 on windows10) application.

bool __pyDoString(const char* String) {
	nlr_buf_t nlr;
	if (nlr_push(&nlr) == 0) {
		qstr src_name = 1/*MP_QSTR_*/;
		mp_lexer_t *lex = mp_lexer_new_from_str_len(src_name, String, strlen(String), false);
		mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_FILE_INPUT);
		mp_obj_t module_fun = mp_compile(&pt, src_name, MP_EMIT_OPT_NONE, false);
		mp_call_function_0(module_fun);
		nlr_pop();
		return true;
	}
	else {// uncaught exception
		return false;
	}
	return false;
}

When I invoke __pyDoString in the main loop(i.e. invoked hundreds of times per second) the assert in gc_free(...) or gc_realloc(...) below often fails(some frames will fail). ATB_GET_KIND(block) is AT_FREE.

assert(ATB_GET_KIND(block) == AT_HEAD);

When I modify some macro configs in ports/windows/mpconfigport.h, the assert in gc_realloc(...) does not failed but gc_free(...) will be still. But I don't know which switcher influent it(sorry, I am not familiar with them. I just copy some macros from ports/minimal/mpconfigport.h).
When I set MICROPY_ENABLE_GC to 0, my application could work, but its process memory keep growing. memory leak when no GC?

I bind imgui be python interfaces with upy. __pyDoString(there is a example below) is used to invoke serveral imgui's window and button interfaces.

__pyDoString("import imgui\nimgui.Begin('python imgui')\nimgui.Text('python text')\nimgui.End()");

After I commented these two asserts, an assert fails in imgui. The assert failing signifies "Mismatched Begin()/End() calls.". But as you see, the py code string in __pyDoString has matched Begin()/End(). Is the code string broken in upy VM?
And if I just run __pyDoString("print('simple words')"), the 2 asserts will often both fail too.

The interesting thing is that emscripten version of my application seems to be working well with MICROPY_ENABLE_GC (1) and the 2 asserts commented(change to print the error. the errors of gc_free and gc_realloc will often both be printed.). It is strange that the assert in imgui doesnot failed like windows version. But I think there are some potential problems still. The mpconfigport.h of emscripten is based on minimal's.

@fei2020 fei2020 changed the title gc_free(...) and gc_realloc(...) could assert failed The assert in gc_free(...) and gc_realloc(...) will fail Apr 19, 2019
@stinos
Copy link
Contributor

stinos commented Apr 20, 2019

This is very likely a duplicate of #4652

@dpgeorge
Copy link
Member

If link-time optimisation is enabled then try disabling that.

@dpgeorge
Copy link
Member

dpgeorge commented May 7, 2019

Should be fixed by 34a7d7e

@dpgeorge dpgeorge closed this as completed May 7, 2019
tannewt added a commit to tannewt/circuitpython that referenced this issue Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants