Yengine temp file delete was still bad in case of script errors

httptests
UbitUmarov 2018-03-09 21:33:39 +00:00
parent cf5ec5d29c
commit c723a1be16
3 changed files with 53 additions and 51 deletions

View File

@ -835,17 +835,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine
// Do both global functions, script-defined class static methods and
// script-defined instance methods, as we handle the differences
// during compilation of the functions/methods themselves.
for(int pass = 0; pass < 2; pass++)
{
// headers
foreach(TokenDeclVar declFunc in tokenScript.variablesStack)
{
if(declFunc.retType != null)
{
if(pass == 0)
GenerateMethodHeader(declFunc);
else
GenerateMethodBody(declFunc);
}
}
foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues)
{
@ -855,13 +850,26 @@ namespace OpenSim.Region.ScriptEngine.Yengine
foreach(TokenDeclVar declFunc in sdtClass.members)
{
if((declFunc.retType != null) && ((declFunc.sdtFlags & ScriptReduce.SDT_ABSTRACT) == 0))
{
if(pass == 0)
GenerateMethodHeader(declFunc);
else
}
}
}
// now bodies
foreach(TokenDeclVar declFunc in tokenScript.variablesStack)
{
if(declFunc.retType != null)
GenerateMethodBody(declFunc);
}
}
foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues)
{
if(sdType is TokenDeclSDTypeClass)
{
TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType;
foreach(TokenDeclVar declFunc in sdtClass.members)
{
if((declFunc.retType != null) && ((declFunc.sdtFlags & ScriptReduce.SDT_ABSTRACT) == 0))
GenerateMethodBody(declFunc);
}
}
}

View File

@ -90,45 +90,43 @@ namespace OpenSim.Region.ScriptEngine.Yengine
// Create object file one way or another.
try
{
objFileStream = File.Create (tmpFileName);
// Create abstract syntax tree from raw tokens.
TokenScript tokenScript = ScriptReduce.Reduce(tokenBegin);
if (tokenScript == null)
{
m_log.Warn ("[YEngine]: reduction errors on " + m_ScriptObjCodeKey + " (" + m_CameFrom + ")");
PrintCompilerErrors();
objFileStream.Close();
return null;
}
// Compile abstract syntax tree to write object file.
BinaryWriter objFileWriter = new BinaryWriter (objFileStream);
using(BinaryWriter objFileWriter = new BinaryWriter(File.Create(tmpFileName)))
{
bool ok = ScriptCodeGen.CodeGen(tokenScript, objFileWriter, sourceHash);
if (!ok)
{
m_log.Warn ("[YEngine]: compile error on " + m_ScriptObjCodeKey + " (" + m_CameFrom + ")");
PrintCompilerErrors ();
objFileWriter.Close ();
return null;
}
objFileWriter.Close ();
}
// File has been completely written.
// If there is an old one laying around, delete it now.
// Then re-open the new file for reading from the beginning.
if (File.Exists (objFileName))
File.Replace (tmpFileName, objFileName, null);
if (File.Exists(objFileName))
File.Replace(tmpFileName, objFileName, null);
else
File.Move (tmpFileName, objFileName);
File.Move(tmpFileName, objFileName);
objFileStream = File.OpenRead (objFileName);
objFileStream = File.OpenRead(objFileName);
}
finally
{
// In case something went wrong writing temp file, delete it.
try
{
if(File.Exists(tmpFileName))
File.Delete (tmpFileName);
}
catch
@ -169,7 +167,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
private void PrintCompilerErrors ()
{
m_log.Info ("[YEngine]: - " + m_Part.GetWorldPosition () + " " + m_DescName);
foreach (string error in m_CompilerErrors) {
foreach (string error in m_CompilerErrors)
{
m_log.Info ("[YEngine]: - " + error);
}
}

View File

@ -399,8 +399,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
* Start event handler.
*
* Input:
* eventCode = code of event to be processed
* ehArgs = arguments for the event handler
* newEventCode = code of event to be processed
* newEhArgs = arguments for the event handler
*
* Caution:
* It is up to the caller to make sure ehArgs[] is correct for
@ -409,15 +409,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine
* from ehArgs[] and will throw an array bounds or cast exception
* if it can't.
*/
private Exception StartEventHandler(ScriptEventCode eventCode, object[] ehArgs)
private Exception StartEventHandler(ScriptEventCode newEventCode, object[] newEhArgs)
{
// We use this.eventCode == ScriptEventCode.None to indicate we are idle.
// So trying to execute ScriptEventCode.None might make a mess.
if(eventCode == ScriptEventCode.None)
if(newEventCode == ScriptEventCode.None)
return new Exception("Can't process ScriptEventCode.None");
// Silly to even try if there is no handler defined for this event.
if(((int)eventCode >= 0) && (m_ObjCode.scriptEventHandlerTable[this.stateCode, (int)eventCode] == null))
if(((int)newEventCode >= 0) && (m_ObjCode.scriptEventHandlerTable[this.stateCode, (int)newEventCode] == null))
return null;
// The microthread shouldn't be processing any event code.
@ -427,8 +427,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
// Save eventCode so we know what event handler to run in the microthread.
// And it also marks us busy so we can't be started again and this event lost.
this.eventCode = eventCode;
this.ehArgs = ehArgs;
this.eventCode = newEventCode;
this.ehArgs = newEhArgs;
// This calls ScriptUThread.Main() directly, and returns when Main() [indirectly]
// calls Suspend() or when Main() returns, whichever occurs first.
@ -834,17 +834,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine
switch(this.callMode)
{
// Now we are ready to suspend the microthread.
// This is like a longjmp() to the most recent StartEx() or ResumeEx()
// with a simultaneous setjmp() so ResumeEx() can longjmp() back here.
// the script event handler wants to hibernate
// capture stack frames and unwind to Start() or Resume()
// Now we are ready to suspend or resume.
case CallMode_NORMAL:
m_CheckRunPhase = "suspending";
callMode = XMRInstance.CallMode_SAVE;
stackFrames = null;
throw new StackHibernateException();
throw new StackHibernateException(); // does not return
// We get here when the script state has been read in by MigrateInEventHandler().
// Since the stack is completely restored at this point, any subsequent calls