[Kde-windows] KDE/kdelibs/win

Ralf Habacker ralf.habacker at freenet.de
Mon Oct 17 23:38:59 CEST 2005


Am Montag, 17. Oktober 2005 20:12 schrieb Jarosław Staniek:
> Ralf Habacker said the following, On 2005-10-17 19:41:
> > Am Montag, 17. Oktober 2005 18:34 schrieb Jarosław Staniek:
> >>Ralf Habacker said the following, On 2005-10-17 18:06:
> >>>Am Montag, 17. Oktober 2005 16:59 schrieb Jarosław Staniek:
> >>>>Ralf Habacker said the following, On 2005-10-17 16:47:
> >>>>>SVN commit 471384 by habacker:
> >>>>>
> >>>>>don't need this stuff for qt4, dcopserver runs without it
> >>>>>
> >>>>>D             bootstrap.cpp
> >>>>
> >>>>Hm?
> >>>>bootstrap.cpp is not only for qeventloop. Look at the code and docs...
> >>>>More code like this will go here too. Or have you moved this somewhere?
> >>>
> >>>You mean this bootstrap stuff which is called  before main and requires
> >>>special hacking of the main function ?
> >>>
> >>>The eventloop startup is obsolate , but I have overseen that there will
> >>>be directories created and the HOME var set in win95 case, sorry. I have
> >>>readded this file without the qeventloop stuff.
> >>>
> >>>BTW: Should KDE really  support win95 ?
> >>
> >>KDE? I never worked on KDE for windows but on kdelibs.
> >>Read explanation here, again (hmm, offline currently):
> >>http://wiki.kde.org/tiki-index.php?page=KDElibs+for+win32
> >>
> >>>And what about the network startup
> >>>stuff ? KICE calls it too and QT as far as I can see too ?
> >>
> >>which one 'network startup'?
> >
> > KDEWIN32_EXPORT void kde_bootstrap()
> > {
> > 	...
> > 	WSADATA wsadata;
> > 	WSAStartup(MAKEWORD(2,2),&wsadata);
> >
> > This function starts up networking.
>
> I guess this was for dcop. So now can be removed (better: commented out).
>
> > See
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/
> >winsock/wsastartup_2.asp
> >
> >>>BTW2: I think that there is a better way to create pre/after main
> >>>functions. You can create a class and create a global instance of this.
> >>>This instance will be created and the constructor be called before main.
> >>>
> >>>
> >>>#include <stdio.h>
> >>>
> >>>class KDEbootstrap {
> >>>public:
> >>>	KDEbootstrap();
> >>>	~KDEbootstrap();
> >>>};
> >>>
> >>>
> >>>KDEbootstrap::KDEbootstrap()
> >>>{
> >>>	printf("bootstrap created\n");
> >>>	// stuff called before main
> >>>}
> >>>
> >>>KDEbootstrap::~KDEbootstrap()
> >>>{
> >>>	printf("bootstrap delete\n");
> >>>	// stuff called after main
> >>>}
> >>>
> >>>KDEbootstrap bootstrap;
> >>
> >>We dont want to require devs to put
> >>
> >>KDEbootstrap bootstrap;
> >>
> >>into application code (e.g. main.cpp).
> >>
> >>
> >>So where do you want to put it? My candidate could be KInstance....
> >
> > See the updated bootsrap.cpp (kde_bootstrap() may be directly included
> > into the constructor and kde_destroy() in the destructor)
>
> First, read dfaure answer - existing solution doesn't break anything:
> developers cannot see a difference...
>
> Now note it's dangerous to rely on static members destruction: you never
> know in which order destructors are called. With kdemain() it's always
> deterministic. SO here I'd vote for not using KDEbootstrap object, unles
> you know something annoing our devs..

The testcase below illustrate the recent implementation, showing that 
kde_bootstrap will be called after all global object instantiation, which 
will be to late and kde_destroy() before all global object destruction. 

 TestClass stands for any external class, whch has global objects. They are 
initialised before main().  kde_bootstrap() setup a env var like the recent 
implementation setting HOME. If you compile and run the testcase, the env var 
in 
TestClass::TestClass() isn't set.  

I have appended  another testcase (c++constructor-order.zip), which shows the 
ordering of global constructor and destructor. 
on mingw constructors are called in reverse order and destructors in normal 
order based on the file sequence. 

C:\Daten\kde4\kdelibs\test\constructor>scons
scons: Reading SConscript files ...
win32
win32
scons: done reading SConscript files.
scons: Building targets ...
g++ -o first.o -c first.cpp
g++ -o main.o -c main.cpp
g++ -o second.o -c second.cpp
g++ -o third.o -c third.cpp
g++ -o test.exe first.o second.o third.o main.o
scons: done building targets.

C:\Daten\kde4\kdelibs\test\constructor>test
ThirdClass created (null)
SecondClass created (null)
FirstClass created (null)
main
FirstClass deleted
SecondClass deleted
ThirdClass deleted


----------------------------------------------------------------------------------


#include <stdio.h>
#include <stdlib.h>

class TestClass {
public:
	TestClass();
	~TestClass();
};

TestClass::TestClass()
{
	printf("testclass created %s\n",getenv("MYHOME"));
	// stuff called before main
}

TestClass::~TestClass()
{
	printf("testclass delete\n");
	// stuff called after main
}

TestClass Testclass;


void	kde_bootstrap()
{
	// set env var
	putenv("MYHOME=---a home path----");
}


int kdemain()
{
	printf("main %s\n",getenv("MYHOME"));
}


void	kde_destroy()
{
}


int main()
{
	kde_bootstrap();
	int ret = kdemain();
	kde_destroy();
	return ret;
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: c++-constructor-order.zip
Type: application/x-zip
Size: 1350 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-windows/attachments/20051017/c4472017/attachment.bin 


More information about the Kde-windows mailing list