gm2
[Top][All Lists]
Advanced

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

Re: [Gm2] ISO exceptions source


From: Martin Kalbfuß
Subject: Re: [Gm2] ISO exceptions source
Date: Thu, 24 Sep 2009 14:05:21 +0200

Thanks,

I will use a global souce then. But I copied the wrong code version for
my bug report. I produced a small Program to show the problem.

++++

MODULE Bug;

IMPORT EXCEPTIONS;

VAR bug : EXCEPTIONS.ExceptionSource;

PROCEDURE DoSomething;
BEGIN
        EXCEPTIONS.RAISE(bug, 1, "");
END DoSomething;

BEGIN
        EXCEPTIONS.AllocateSource(bug);
        DoSomething;
END Bug.

++++

compiled with:

gm2 -c -Wpedantic -fiso Bug.mod

Error message:

Bug.mod:5:5: error: variable (bug) is being used but is NEVER
initialized in (Bug)
Bug.mod:5:5: error: variable (bug) is being used but is NEVER
initialized in (Bug)


Am Donnerstag, den 24.09.2009, 08:45 +0100 schrieb Gaius Mulley:
> 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]