| 73 | } |
| 74 | |
| 75 | int asCReader::Read(bool *wasDebugInfoStripped) |
| 76 | { |
| 77 | TimeIt("asCReader::Read"); |
| 78 | |
| 79 | // Before starting the load, make sure that |
| 80 | // any existing resources have been freed |
| 81 | module->InternalReset(); |
| 82 | |
| 83 | // Call the inner method to do the actual loading |
| 84 | int r = ReadInner(); |
| 85 | if( r < 0 ) |
| 86 | { |
| 87 | // Something went wrong while loading the bytecode, so we need |
| 88 | // to clean-up whatever has been created during the process. |
| 89 | |
| 90 | // Make sure none of the loaded functions attempt to release |
| 91 | // references that have not yet been increased |
| 92 | asUINT i; |
| 93 | for( i = 0; i < module->m_scriptFunctions.GetLength(); i++ ) |
| 94 | if( !dontTranslate.MoveTo(0, module->m_scriptFunctions[i]) ) |
| 95 | if( module->m_scriptFunctions[i]->scriptData ) |
| 96 | module->m_scriptFunctions[i]->scriptData->byteCode.SetLength(0); |
| 97 | |
| 98 | asCSymbolTable<asCGlobalProperty>::iterator it = module->m_scriptGlobals.List(); |
| 99 | for( ; it; it++ ) |
| 100 | if( (*it)->GetInitFunc() ) |
| 101 | if( (*it)->GetInitFunc()->scriptData ) |
| 102 | (*it)->GetInitFunc()->scriptData->byteCode.SetLength(0); |
| 103 | |
| 104 | module->InternalReset(); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | // Init system functions properly |
| 109 | engine->PrepareEngine(); |
| 110 | |
| 111 | // Initialize the global variables (unless requested not to) |
| 112 | if( engine->ep.initGlobalVarsAfterBuild ) |
| 113 | r = module->ResetGlobalVars(0); |
| 114 | |
| 115 | if( wasDebugInfoStripped ) |
| 116 | *wasDebugInfoStripped = noDebugInfo; |
| 117 | } |
| 118 | |
| 119 | // Clean up the loaded string constants |
| 120 | for (asUINT n = 0; n < usedStringConstants.GetLength(); n++) |
| 121 | engine->stringFactory->ReleaseStringConstant(usedStringConstants[n]); |
| 122 | usedStringConstants.SetLength(0); |
| 123 | |
| 124 | return r; |
| 125 | } |
| 126 | |
| 127 | int asCReader::Error(const char *msg) |
| 128 | { |
no test coverage detected