[fpc-pascal] with no if assigned() there are bugs

Pierre Free Pascal pierre at freepascal.org
Wed Sep 21 14:27:24 CEST 2016



> -----Message d'origine-----
> De : fpc-pascal-bounces at lists.freepascal.org [mailto:fpc-pascal-
> bounces at lists.freepascal.org] De la part de Martin
> Envoyé : mercredi 21 septembre 2016 12:38
> À : FPC-Pascal users discussions
> Objet : Re: [fpc-pascal] with no if assigned() there are bugs
> 
> On 21/09/2016 09:05, Mark Morgan Lloyd wrote:
> >
> > Presumably this would be an assertion that something is assigned. A
> > related test is that an object is a specific subtype before using it
> > as such
> >
> >   Assert(PageControl1.ActivePage.Controls[0] is TSynEdit);
> >   syn := TSynEdit(PageControl1.ActivePage.Controls[0]);
> 
> The problem is that even a test like that would NOT catch all cases.
> 
> syn.destroy;
> Assert(syn is TSynEdit);
> 
> In this case, it is very likely that "syn is TSynEdit" still returns
> true. (no assertion thrown)
> 
> Simply because "syn.destroy;" does not wipe the memory clean.
> (depending
> on mem manager)
> 
> Using -gh
> And (optionally) setting the environment HEAPTRC="keepreleased" (that
> is
> for debugging only)
> http://www.freepascal.org/docs-html/rtl/heaptrc/environment.html
> will help.

   There is also the -gc option:
      -gc        Generate checks for pointers

  This is another debugging option, that is not used very often,
so that it might not always work correctly, but it could be worth a try in
your case.

  It probably does not work well if threads are used, but in principle,
it calls checkpointer function before any pointer dereference.
  The exact action of checkpointer depends on the operating system,
the code is also in heaptrc.pp unit.

 In the hope it will be useful,

Pierre Muller



More information about the fpc-pascal mailing list