gm2
[Top][All Lists]
Advanced

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

Re: [Gm2] cath exceptions raised in another module's init section


From: Iztok Kobal
Subject: Re: [Gm2] cath exceptions raised in another module's init section
Date: Thu, 07 Jan 2010 11:09:08 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.6) Gecko/20091210 SUSE/2.0.1-1.1.1 SeaMonkey/2.0.1

Breeden, Thomas (tmb) wrote:
Remember that by definition the init sections of imported modules are executed 
before the init section of the modules that import them (barring circularities).
I agree and I would like to point out that what Thomas wrote is valid when considering M2 perspective.

Yet, it is a slightly different considering the bytecode level perspective since BEGIN (that means intro of init body) of importing module's init body executes before executing init bodies of imported modules. So as a matter of fact, importing module would in fact have already been executed when an exception appeared in the init section of imported module.

Here follows an example of XDS-C translation of M2 stack (C translation/perspective does not differ much from bytecode perspective) where you can clearly see that if you have risen en exception within e.g. EventBuffer init body (EventBuffer_BEGIN() call) this would have basically happened within PCVsystemDLL_BEGIN() call and of course also within the main() function which represented PCVsystem.MOD body. So catching of exception thrown within imported module's init body could theoretically be performed wherever up the stack while I can not see what M2 syntax could really do it (that is - what Martin wants) except within the throwing init body :-\ . I mean, if I put the M2's TRY.EXCEPT syntax within the PCVsystemDLL's init body it would perform only after all imported modules' init bodies have been executed.


MODULE PCVsystem;
IMPORT PCVsystemDLL;
BEGIN
  RETURN
END PCVsystem.

DEFINITION MODULE PCVsystemDLL;
END PCVsystemDLL.

IMPLEMENTATION MODULE PCVsystemDLL;
IMPORT ASCII;
IMPORT Critical;
IMPORT DLL;
IMPORT Error;
IMPORT EventBuffer;
BEGIN (* DllMain *)
END PCVsystemDLL.

And now C:

/* PCVsystem.MOD translation: Generated by XDS Modula-2 to ANSI C v4.20 translator */
#define X2C_int32
#define X2C_index32
#ifndef X2C_H_
#include "X2C.h"
#endif
#define PCVsystem_C_
#ifndef PCVsystemDLL_H_
#include "PCVsystemDLL.h"
#endif
X2C_STACK_LIMIT(100000l)
extern int main(int argc, char **argv)
{
   X2C_BEGIN(&argc,argv,1,4000000l,8000000l);
   PCVsystemDLL_BEGIN();
   X2C_EXIT();
   return 0;
}
X2C_MAIN_DEFINITION

/* PCVsystemDLL.DEF translation: Generated by XDS Modula-2 to ANSI C v4.20 translator */
#ifndef PCVsystemDLL_H_
#define PCVsystemDLL_H_
#ifndef X2C_H_
#include "X2C.h"
#endif
extern void PCVsystemDLL_BEGIN(void);
#endif /* PCVsystemDLL_H_ */

/* PCVsystemDLL.MOD translation: Generated by XDS Modula-2 to ANSI C v4.20 translator */
#define X2C_int32
#define X2C_index32
#ifndef PCVsystemDLL_H_
#include "PCVsystemDLL.h"
#endif
#define PCVsystemDLL_C_
#ifndef ASCII_H_
#include "ASCII.h"
#endif
#ifndef Critical_H_
#include "Critical.h"
#endif
#ifndef SYSTEMCONSTANTS_H_
#include "SYSTEMCONSTANTS.h"
#endif
#ifndef DLL_H_
#include "DLL.h"
#endif
#ifndef Error_H_
#include "Error.h"
#endif
#ifndef EventBuffer_H_
#include "EventBuffer.h"
#endif
extern void PCVsystemDLL_BEGIN(void)
{
   static int PCVsystemDLL_init = 0;
   if (PCVsystemDLL_init) return;
   PCVsystemDLL_init = 1;
   EventBuffer_BEGIN();
   Error_BEGIN();
   DLL_BEGIN();
   Critical_BEGIN();
   ASCII_BEGIN();
/* DllMain */
}


So the initialization of the importing module has not even started when this 
exception occurs. I'd have to check ISO to be sure, but it seems iffy to 
transfer control to the exception part of a section that has not even started.

Tom
address@hidden

-----Original Message-----
From:address@hidden  [mailto:gm2-
address@hidden On Behalf Of Martin Kalbfuß
Sent: January 06, 2010 8:49 AM
To: GNU Modula-2
Subject: [Gm2] cath exceptions raised in another module's init section

Hi again.

I tried the following:

I raised an exception in the initialization section of an imported
module. Then I tried to catch this exception in the importing main
module. This didn't work. Is this the way it should be? When I throw an
exception in any other imported function, I can catch it in the
importing module.

I have the function InitSubSystem. It can fail. So I have to call it by
hand, to catch the exception. But the right place to put them would be
the initialization section of the SubSystem's module.

Thanks,

--
Martin Kalbfuß<address@hidden>



_______________________________________________
gm2 mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/gm2

_______________________________________________
gm2 mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/gm2





reply via email to

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