CloseAll

This forum is meant for questions and discussions about the X# language and tools
Post Reply
Serggio
Posts: 46
Joined: Sun May 14, 2017 5:03 pm
Location: Ukraine

CloseAll

Post by Serggio »

There is a problem in CloseAll implementation in Runtime/XSharp.Core/RDD/Workareas.prg
If an exception is raised while closing a particular work area the further work areas would omit getting closed due to Result turns into False and that's ok, but after the cycle Aliases and Cargo arrays would get cleaned regardless of whether all the areas were closed.

Code: Select all

PUBLIC METHOD CloseAll() AS LOGIC
	LOCAL lResult := TRUE AS LOGIC
	BEGIN LOCK RDDs      
		RuntimeState.LastRddError := NULL
		FOREACH VAR element IN Aliases
			VAR nArea := element:Value -1
			IF RDDs[nArea] != NULL
				VAR oRdd := RDDs[nArea]
				TRY
					lResult := lResult .AND. oRdd:Close()
				CATCH e AS Exception
					lResult := FALSE
					RuntimeState.LastRddError  := e
				END TRY
    			RDDs[nArea] 	:= NULL
			ENDIF              
		NEXT
		Aliases:Clear()
		cargo:Clear()
		iCurrentWorkarea := 1
	END LOCK                       
	RETURN lResult 
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

CloseAll

Post by robert »

Serggio,

All workareas will be closed and removed from the RDDs, Aliases and cargo array as far as I can see in that code.
Maybe the workarea object that fails to close is not completely closed, but it is no longer linked to a workarea number or alias.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

CloseAll

Post by Chris »

Robert,

I think Serggio is right, after lResult becomes FALSE, then in this code:

lResult := lResult .AND. oRdd:Close()

the next time oRdd:Close() will never be executed, because the expression is already evaluated to false by checking lResutl (FALSE) and the CLR does not evaluate the 2nd expression.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

CloseAll

Post by robert »

Chris,
You are right of course.

I have changed it to:

Code: Select all

IF ! oRdd:Close()
   lResult := FALSE
ENDIF

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply