xsharp.eu • CloseAll
Page 1 of 1

CloseAll

Posted: Wed Apr 22, 2020 6:25 am
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 

CloseAll

Posted: Wed Apr 22, 2020 6:49 am
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

CloseAll

Posted: Wed Apr 22, 2020 6:56 am
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.

CloseAll

Posted: Wed Apr 22, 2020 7:18 am
by robert
Chris,
You are right of course.

I have changed it to:

Code: Select all

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

Robert