comp.lang.ada
 help / color / mirror / Atom feed
* [AdaControl] Limiting where objects of a specific type can be declared
@ 2017-03-14 13:24 Jacob Sparre Andersen
  2017-03-14 13:47 ` J-P. Rosen
  0 siblings, 1 reply; 2+ messages in thread
From: Jacob Sparre Andersen @ 2017-03-14 13:24 UTC (permalink / raw)


On a project I'm working on, we have a type with some ugly C backing,
which means that declaring local variables of the type results in memory
leaks.

The solution to this is to remember to declare variables of this type as
global variables in a package.

The fast way to check for this with this AdaControl rule:

    check entities (local SQL.Statement_Type);


This looks good until AdaControl finds a clever programmer writing:

    procedure Something (...) is
       Stmt : SQL.Statement_Type renames Global_Stmt;
    begin

Since this declaration doesn't leak memory, I don't want to stop the
programmer from using it.


The next interesting declaration AdaControl finds is a main program,
which declares a global variable for later use:

    procedure Main is
       Stmt : SQL.Statement_Type;
    begin
       [...]
    end Main;

In this case the solution may simply be to ignore this group of utility
programs, when running AdaControl, but a modification to the rule would
be nice, as that would reduce the amount of thinking involved in
deciding which units to check and which not to check.


What do we do?  (Besides phasing out the problematic library.)

Greetings,

Jacob
-- 
                      CAUTION
               BLADE EXTREMELY SHARP
                KEEP OUT OF CHILDREN

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [AdaControl] Limiting where objects of a specific type can be declared
  2017-03-14 13:24 [AdaControl] Limiting where objects of a specific type can be declared Jacob Sparre Andersen
@ 2017-03-14 13:47 ` J-P. Rosen
  0 siblings, 0 replies; 2+ messages in thread
From: J-P. Rosen @ 2017-03-14 13:47 UTC (permalink / raw)


Le 14/03/2017 à 14:24, Jacob Sparre Andersen a écrit :
> The fast way to check for this with this AdaControl rule:
> 
>     check entities (local SQL.Statement_Type);
> 
> 
> This looks good until AdaControl finds a clever programmer writing:
> 
>     procedure Something (...) is
>        Stmt : SQL.Statement_Type renames Global_Stmt;
>     begin
> 
> Since this declaration doesn't leak memory, I don't want to stop the
> programmer from using it.
There is a subtility here: you are asking to check all local usages of
type Statement_Type, which certainly applies here. What you /want/ is to
check all local declarations of variables whose type is Statement_Type.

Alternatively, you can use:
check object_declarations (type, variable SQL.Statement_Type);

but this will give you all variables of type Statement_Type, including
the global ones.

I take it as an enhancement suggestion to be able to specify a location
for the above rule.

Of course, it is always possible to disable the line.

> The next interesting declaration AdaControl finds is a main program,
> which declares a global variable for later use:
> 
>     procedure Main is
>        Stmt : SQL.Statement_Type;
>     begin
>        [...]
>     end Main;
> 
> In this case the solution may simply be to ignore this group of utility
> programs, when running AdaControl, but a modification to the rule would
> be nice, as that would reduce the amount of thinking involved in
> deciding which units to check and which not to check.
Since there is nothing special to a main program in Ada, this is clearly
a local usage... Disabling is probably the best thing to do.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-14 13:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 13:24 [AdaControl] Limiting where objects of a specific type can be declared Jacob Sparre Andersen
2017-03-14 13:47 ` J-P. Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox