p-i- wrote:Thanks for the explanations.
I can see this is awkward in terms of creating a generic build.
My goal is still to be able to drop a wodge of C code into some C/C++project (on unspecified platform) and instantly have embedded Python.
I think this could eventually go in a /generic/ folder
But this issue seems to be a clear case of requiring separate machinery for non-gcc e.g. clang.
Is there any way around this?
If there were we would have used it.
p-i- wrote:I'm getting a little confused about Python-land vs C-land. This BSS_START to _end -- is this the space in which our C program stores its static data? Or is it where the embedded Python runtime stores it's static data? Or both?
BSS is where C stores uninitialized (or initialzed to zero) global data. DATA is where C stores initialized global data.
An example of this would be:
https://github.com/micropython/micropyt ... cept.c#L72
or
https://github.com/micropython/micropyt ... .c#L49-L51
These C variables may point to python objects from the heap, and the GC needs to know that the pointers exist so that it doesn't free the objects from the heap.
p-i- wrote:Would it be possible to get round this problem by (as dhylands suggested on IRC) manually keeping track of every external (C-land reference to a Python object), and then just throwing an array of these memory locations into the garbage collector?
That's essentially what's happening when you throw the contents of BSS at the garbage collector. In the more generic case (embedding micropython inside another program), the other program will have its own heap, and that heap may contain pointers to python objects. The GC needs to know about those, but it doesn't know where to look to find them.
p-i- wrote:Also, this garbage collector -- it is just for the Python runtime, yes? Or is it also being used to clean up unused C memory?
It's for the GC managed heap. If C code happens to allocate from it, then it covers that case as well. In MicroPython, there is no heap, other than the GC managed one, so all heap allocations come from the GC managed heap. For example:
https://github.com/micropython/micropyt ... int.c#L171