[fpc-devel] Call initialisation of library automatically in unit-initialization?
Joost van der Sluis
joost at cnoc.nl
Thu Dec 4 20:59:56 CET 2008
Op woensdag 03-12-2008 om 18:39 uur [tijdzone +0100], schreef Joost van
der Sluis:
> Op woensdag 03-12-2008 om 15:06 uur [tijdzone +0000], schreef Martin
> Friebe:
> > 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
> library.
>
> 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.
Because the library-handle is also reference counted it's quite
difficult for the programmer to call these functions at the right
moment.
So I've decided to call them automatical, and add the parameters to the
InitialiseMySQL procedure, so that they are passed to the library-init
function.
Joost.
More information about the fpc-devel
mailing list