gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] ISO exceptions source


From: Gaius Mulley
Subject: Re: [Gm2] ISO exceptions source
Date: Thu, 24 Sep 2009 08:45:18 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Martin Kalbfuß <address@hidden> writes:

> Am Mittwoch, den 23.09.2009, 09:48 +0100 schrieb Gaius Mulley:
>> EXCEPTIONS.AllocateSource(Source);
>
> Thanks. I will have a look at it. When my code is OK then I think I
> found a bug.
>
> I switched on -Wpedantic
>
>
> PROCEDURE VectorAddition(Vector1, Vector2 : ARRAY OF REAL;
>                           VAR Result       : ARRAY OF REAL);
> VAR
>         Index  : CARDINAL;
>         Source : EXCEPTIONS.ExceptionSource;
> BEGIN
>         IF HIGH(Vector1) <> HIGH(Vector2) THEN
>            EXCEPTIONS.RAISE(Source, 1, 'Error: Vectors of different
> size');
>         END;
>         FOR Index := 0 TO HIGH(Vector1) DO
>             Result[Index] := Vector1[Index] + Vector2[Index];
>         END;
> END VectorAddition;
>
> --and he tells me:
>
> src/VectorMath.mod:39:2: error: variable (Source) is being used but is
> NEVER initialized in (VectorAddition)

Hi Martin,

this first warning looks correct - as Source should be declared in the
global module scope.  The Source in VectorAddition wont be initialised
before its use..


> --Another warning I get is:
>
> src/VectorMath.def:10:26: warning: unused parameter (Result) in
> procedure (VectorAddition)

and this warning looks incorrect.. as you say - I will look into this!
Many thanks for the report,

regards,
Gaius

> --And the implementation is:
>
> PROCEDURE VectorAddition(Vector1, Vector2 : ARRAY OF REAL;
>                          VAR Result       : ARRAY OF REAL);
> VAR
>         Index  : CARDINAL;
>         Source : EXCEPTIONS.ExceptionSource;
> BEGIN
>         IF HIGH(Vector1) <> HIGH(Vector2) THEN
>            EXCEPTIONS.AllocateSource(Source);
>            EXCEPTIONS.RAISE(Source, 1, 'Error: Vectors of different
> size');
>         END;
>         FOR Index := 0 TO HIGH(Vector1) DO
>             Result[Index] := Vector1[Index] + Vector2[Index];
>         END;
> END VectorAddition;
>
>
> Isn't allocating a global exception source incompatible with parallel
> processes because they could raise two exceptions in parallel and would
> use the same source?

no because each Coroutine has a notion of being in an exception state
and it knows which source caused the exception.

see gm2/gm2-libs-iso/EXCEPTIONS.def

PROCEDURE CurrentNumber (source: ExceptionSource): ExceptionNumber;
  (* If the current coroutine is in the exceptional execution state
     because of the raising of an exception from source, returns the
     corresponding number, and otherwise raises an exception.
  *)

hope this helps.

regards,
Gaius




reply via email to

[Prev in Thread] Current Thread [Next in Thread]