[Kde-windows] KDE/kdelibs/win

Ralf Habacker ralf.habacker at freenet.de
Tue Oct 18 08:32:04 CEST 2005


Am Montag, 17. Oktober 2005 23:38 schrieb Ralf Habacker:
> 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

no problem here, I mean that the stuff we are talking about is for win 95 and 
the question was intended to ask general, if windows 95 should be support or 
not (I prefer not, because of the huge gdi resource problems, to which we 
will be faced) 

> > >>>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/winsoc
> > >k/ winsock/wsastartup_2.asp

After reading some more docs I recognized, that QT only calls WSAStartup if an 
application uses  network related classes like QTcpServer (call is used only 
in QT/4.0.1/src/network)  or if an application uses kICE. Any other 
applications will not start network. This explains the problem I had with 
winsock gethostbyname(), which does not return a valid hostname for the first 
time before kICE was setup. Seems that there are some more thoughts to deal 
with required. 

> > >>>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
>
This let me assume, that using a global object in kdewin32, which will be the 
last library on the link line, would be run first

Any infos about msvc order  ? 

BTW: If the global object ordering will be a problem on other compilers, a  
complete other approach for problems like the HOME env var on windows 95 is 
to redefine the getenv() function and do the required initialisation on the 
first call. This  will be independent off any global objects and it is 
guarantated that HOME will be set before. 

Regards
 Ralf 


> ---------------------------------------------------------------------------
>-------
>
>
> #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;
> }



More information about the Kde-windows mailing list