[fpc-devel] Call initialisation of library automatically in unit-initialization?

Joost van der Sluis joost at cnoc.nl
Wed Dec 3 18:39:08 CET 2008

Op woensdag 03-12-2008 om 15:06 uur [tijdzone +0000], schreef Martin
> Joost van der Sluis wrote:
> > Op woensdag 03-12-2008 om 13:09 uur [tijdzone +0100], schreef Michael
> > Van Canneyt:
> >   
> >> On Wed, 3 Dec 2008, Joost van der Sluis wrote:
> >>
> >>     
> >>> When you use the MySQL client, you have to call myslq_library_init to
> >>> initialise the library, and mysql_library_end to de-initialize it again.
> >>>
> >>> When the library is dynamically loaded using mysqlXXdyn.pp, shall I call
> >>> these functions automatically? Or should we leave it to the programmer?
> >>> (I'm in favour of doing it automatically)
> >>>       
> >> Are there any options to these calls ?
> >>
> >> If there are, it is a no, I think ?
> >>     
> >
> > Didn't thought about that. And yes, there are options. They are in
> > practice only used with the embedded-mysql version. And iven in that
> > case I guess they are rarely used: 
> >   
> ....
> > So, what to do?
> >
> >   
> There is another option. You can keep track if the user called it. If 
> the user did not call it, but any other function is called, then call it 
> yourself
> procedure MaybeCallInit;
> begin
>   if InitCalled then exit;
>   DoCallInit(0, nil, nil);
>   InitCalled := True;
> end;

That's not possible, since the user can not call it before the library
is loaded. And this code should be placed in the code to load the

Besides, the init is not the problem, because MySQL will call it
automatically. But the finalization of the library, that's the real
point. (If it's not called, that introduces mem-leaks)

But to call the finalization and not the initialization is pretty bad
design, imho.

> Well it will be more complex, as if this is in a multi threaded 
> environment you have to keep track for each Thread. That is unless the 
> library is loaded and initialized before any threads are spawned...

These calls have to be called before all other threads are spawned. Or
else you're in trouble.


More information about the fpc-devel mailing list