[Gambas-devel] Early auto-instance

tobi tobias at ...692...
Sat May 12 21:05:37 CEST 2012


Hi,

I have a compilation unit that provides a function which in turn depends on the state of an object.
The default object is the auto-instance of a class (it is just a simple buffered output) but the
auto-instance of a class seems to be created on-the-fly when first requested. Now this auto-instance
may not be created normally before I need to take actions depending on its state (call the exported
function by another piece of code)... I thought of having

GB.AutoCreate(GB.FindClass("Screen"), 0);

called from within the GB_INIT() of my component to ensure that there exists a valid object. The
program works now but I get a segfault:

Program received signal SIGSEGV, Segmentation fault.
MEMORY_clear_cache () at ../share/gb_alloc_temp.h:96
96                              next = *((void **)ptr);
(gdb) print ptr
$1 = (void *) 0x123

when the program is going to exit. Is there somehting, I should keep in mind when manually creating
this auto-instance?

Another point: This is provisional only; I will have to rewrite it anyway when I make Screen a true
creatable class. So there is my next question regarding coding style in gambas: Is it common to save
a pointer to another gambas object (the parent object) when creating? This would solve the
auto-instance problem as my Screen class (which is to auto-create earlily) is reference during
instanciation of the Window object and the latter is the object which calls the function in question
(which depends on the active Screen class to enable buffered output on screen). That sounds tricky,
so I wanted to ask if it is considered good style in gambas or if there are other ways to do it. The
place I knew to look for was the gb.qt4 component which delegates the parent object stuff to qt
itself...

Regards,
Tobi





More information about the Devel mailing list