[Gambas-devel] Early auto-instance

tobi tobias at ...692...
Sat May 12 21:14:04 CEST 2012


On Sat, 12 May 2012, tobi wrote:
> 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
> 
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. Discussions 
> will include endpoint security, mobile security and the latest in malware 
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel
> 

Oops!
I also auto-create a Window object so the parent is to be optional... This solution wouldn't prevent
me from manually auto-creating the Screen class. I tend to remove the GB_AUTO_CREATABLE() statement
from both descriptions :/





More information about the Devel mailing list