| 5456 | } |
| 5457 | |
| 5458 | bool asCContext::CleanStackFrame(bool catchException) |
| 5459 | { |
| 5460 | bool exceptionCaught = false; |
| 5461 | asSTryCatchInfo *tryCatchInfo = 0; |
| 5462 | |
| 5463 | if (m_currentFunction == 0) |
| 5464 | return false; |
| 5465 | |
| 5466 | if (m_currentFunction->funcType == asFUNC_SCRIPT && m_currentFunction->scriptData == 0) |
| 5467 | { |
| 5468 | asCString msg; |
| 5469 | msg.Format(TXT_FUNC_s_RELEASED_BEFORE_CLEANUP, m_currentFunction->name.AddressOf()); |
| 5470 | m_engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, msg.AddressOf()); |
| 5471 | return false; |
| 5472 | } |
| 5473 | |
| 5474 | // Clean object variables on the stack |
| 5475 | // If the stack memory is not allocated or the program pointer |
| 5476 | // is not set, then there is nothing to clean up on the stack frame |
| 5477 | if( !m_isStackMemoryNotAllocated && m_regs.programPointer ) |
| 5478 | { |
| 5479 | // If the exception occurred while calling a function it is necessary |
| 5480 | // to clean up the arguments that were put on the stack. |
| 5481 | CleanArgsOnStack(); |
| 5482 | |
| 5483 | // Check if this function will catch the exception |
| 5484 | // Try blocks can be nested, so use the innermost block |
| 5485 | if (catchException && m_currentFunction->scriptData) |
| 5486 | { |
| 5487 | asUINT currPos = asUINT(m_regs.programPointer - m_currentFunction->scriptData->byteCode.AddressOf()); |
| 5488 | |
| 5489 | for (asUINT n = 0; n < m_currentFunction->scriptData->tryCatchInfo.GetLength(); n++) |
| 5490 | { |
| 5491 | if (currPos >= m_currentFunction->scriptData->tryCatchInfo[n].tryPos && |
| 5492 | currPos < m_currentFunction->scriptData->tryCatchInfo[n].catchPos) |
| 5493 | { |
| 5494 | tryCatchInfo = &m_currentFunction->scriptData->tryCatchInfo[n]; |
| 5495 | exceptionCaught = true; |
| 5496 | } |
| 5497 | if (currPos < m_currentFunction->scriptData->tryCatchInfo[n].tryPos) |
| 5498 | break; |
| 5499 | } |
| 5500 | } |
| 5501 | |
| 5502 | // Restore the stack pointer |
| 5503 | if( !exceptionCaught ) |
| 5504 | m_regs.stackPointer += m_currentFunction->scriptData->variableSpace; |
| 5505 | |
| 5506 | // Determine which object variables that are really live ones |
| 5507 | asCArray<int> liveObjects; |
| 5508 | DetermineLiveObjects(liveObjects, 0); |
| 5509 | |
| 5510 | for (asUINT n = 0; n < m_currentFunction->scriptData->variables.GetLength(); n++) |
| 5511 | { |
| 5512 | int pos = m_currentFunction->scriptData->variables[n]->stackOffset; |
| 5513 | |
| 5514 | // If the exception was caught, then only clean up objects within the try block |
| 5515 | if (exceptionCaught) |
nothing calls this directly
no test coverage detected