Ignore:
Timestamp:
Mar 15, 2008, 1:20:13 PM (17 years ago)
Author:
dai_9181
Message:

関数の戻り値の構造体など、一時メモリに保持された構造体のメンバに直接アクセスした場合、その一時メモリの解放が正常に行われないバグを修正(まずは32bit版のみ)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler32/NumOpe.cpp

    r429 r435  
    140140    return true;
    141141}
    142 bool TermMemberOpe( const Type &leftType, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar )
     142bool TermMemberOpe( const Type &leftType, bool &isNeedHeapFreeStructure, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar )
    143143{
    144144    const CClass &objClass = leftType.GetClass();
     
    222222        // メンバが見つかったとき
    223223
     224        if( isNeedHeapFreeStructure )
     225        {
     226            if( !leftType.IsStruct() )
     227            {
     228                SetError();
     229            }
     230
     231            // 親となる構造体が一時メモリに存在していた場合、後ほど解放する必要がある
     232            compiler.codeGenerator.op_AddNeedFreeTempStructure( useReg );
     233            isNeedHeapFreeStructure = false;
     234        }
     235
    224236        //オブジェクトポインタをecxにコピー
    225237        compiler.codeGenerator.op_mov_RR( REG_ECX, useReg );
     
    271283                bool dummyIsVariable;
    272284                RELATIVE_VAR dummyRelativeVar;
    273                 TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar );
     285                TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar );
    274286
    275287                // 戻り値のオブジェクトインスタンスのインデクサを呼び出す
     
    278290                sprintf( temp2, "%s.%s", termLeft, methodName );
    279291                Type classType = resultType;
    280                 return TermMemberOpe( classType, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar );
     292                return TermMemberOpe( classType, isNeedHeapFreeStructure, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar );
    281293            }
    282294
     
    336348    return false;
    337349}
    338 bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess )
     350bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess )
    339351{
    340352    char parameter[VN_SIZE];
     
    377389        }
    378390
    379         if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){
     391        if( !TermOpe( termLeft, baseType, leftType, isLiteral, isNeedHeapFreeStructure, &isClassName ) ){
    380392            goto globalArea;
    381393        }
     
    395407        }
    396408
    397         return TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar );
     409        return TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar );
    398410    }
    399411globalArea:
     
    492504
    493505
    494             if(resultType.IsStruct()){
     506            if(resultType.IsStruct())
     507            {
    495508                //構造体が戻ったときはヒープ領域にインスタンスが格納されている
    496509                //※後にfreeする必要あり
    497510                // TODO: 解放はGCに任せる
    498                 *pbUseHeap = 1;
     511                isNeedHeapFreeStructure = true;
    499512            }
    500513
     
    603616
    604617
    605         if(resultType.IsStruct()){
     618        if(resultType.IsStruct())
     619        {
    606620            //構造体が戻ったときはヒープ領域にインスタンスが格納されている
    607621            //※後にfreeする必要あり
    608622            // TODO: 解放はGCに任せる
    609             *pbUseHeap = 1;
     623            isNeedHeapFreeStructure = true;
    610624        }
    611625
     
    623637}
    624638
    625 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess )
     639bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess )
    626640{
    627641    RELATIVE_VAR relativeVar;
    628642    bool isVariable = false;
    629     bool result = _TermOpe( term, baseType, resultType, isLiteral, pbUseHeap, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess );
     643    bool result = _TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructure, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess );
    630644
    631645    if( isVariable )
     
    641655bool TermOpeOnlyVariable( const char *term, Type &resultType, RELATIVE_VAR &relativeVar, bool isWriteAccess )
    642656{
    643     bool isLiteral, isVariable = false;
    644     bool result = _TermOpe( term, Type(), resultType, isLiteral, NULL, NULL, false, isVariable, relativeVar, isWriteAccess );
     657    bool isLiteral, isVariable = false, isNeedHeapFreeStructure = false;
     658    bool result = _TermOpe( term, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, isVariable, relativeVar, isWriteAccess );
    645659
    646660    if( !isVariable )
     
    823837    bool isNothing_stack[255];
    824838    LONG_PTR index_stack[255];
    825     BOOL bUseHeap[255];
     839    bool isNeedHeapFreeStructureStack[255];
    826840    _int64 i64data;
    827841    for(i=0,sp=0;i<pnum;i++){
     
    845859                else{
    846860                    //オーバーロードされたオペレータを呼び出す
    847                     i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp);
     861                    i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,isNeedHeapFreeStructureStack,sp);
    848862                    if(i2==0){
    849863                        if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
     
    867881                index_stack[sp]=-1;
    868882                isNothing_stack[sp] = false;
    869                 bUseHeap[sp]=0;
     883                isNeedHeapFreeStructureStack[sp] = false;
    870884
    871885                char *term;
     
    954968
    955969                    bool isLiteral;
    956                     if( TermOpe( term, baseType, resultType, isLiteral, &bUseHeap[sp] ) ){
     970                    if( TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructureStack[sp] ) ){
    957971                        if(resultType.IsNull()){
    958972                            //戻り値が存在しないとき
     
    12601274    }
    12611275
    1262     if(pbUseHeap) *pbUseHeap=bUseHeap[0];
     1276    if(pbUseHeap) *pbUseHeap = isNeedHeapFreeStructureStack[0];
    12631277
    12641278    resultType.SetType( type_stack[0], index_stack[0] );
Note: See TracChangeset for help on using the changeset viewer.