diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7cb892c5ee..752795629c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,9 @@ +19990601-12:15 CET Eddie Runia + * tests/working/inifiles.prg + new Mab version installed + * tests/working/inherit.prg, source/rtl/classes.c + stackfree() bug disappeared (??) after using itemapi in classes.c + 19990601-09:50 CET Eddie Runia * include/cgi.ch, tests/working/testcgi.prg CGI test program added diff --git a/harbour/source/rtl/classes.c b/harbour/source/rtl/classes.c index 52d3135445..eb76a5781a 100644 --- a/harbour/source/rtl/classes.c +++ b/harbour/source/rtl/classes.c @@ -306,8 +306,7 @@ static HARBOUR ClassSel() { pClass = &pClasses[ wClass - 1 ]; wLimit = pClass->wHashKey * BUCKET; - ItemRelease( pReturn ); - _xfree( pReturn ); + hb_itemRelease( pReturn ); pReturn = hb_itemArrayNew( pClass->wMethods ); /* Create a transfer array */ for( wAt = 0; wAt < wLimit ; wAt++ ) @@ -315,17 +314,15 @@ static HARBOUR ClassSel() pMessage = (PDYNSYM) pClass->pMethods[ wAt ].pMessage; if( pMessage ) /* Hash Entry used ? */ { - pItem = hb_itemNew( NULL ); /* Add to array */ - pItem = hb_itemPutC( pItem, pMessage->pSymbol->szName ); + pItem = hb_itemPutC( NULL, pMessage->pSymbol->szName ); + /* Add to array */ hb_itemArrayPut( pReturn, ++wPos, pItem ); - ItemRelease( pItem ); - _xfree( pItem ); + hb_itemRelease( pItem ); } } } hb_itemReturn( pReturn ); - ItemRelease( pReturn ); - _xfree( pReturn ); + hb_itemRelease( pReturn ); } HARBOUR CLASSADD() /* hClass, cMessage, pFunction, nType, xInit */ @@ -547,11 +544,9 @@ void ReleaseClass( PCLASS pClass ) _xfree( pClass->szName ); _xfree( pClass->pMethods ); - hb_arrayRelease( pClass->pClassDatas ); - hb_arrayRelease( pClass->pInlines ); - /* hb_arrayRelease( pClass->pInitValues ); */ - _xfree( pClass->pClassDatas ); - _xfree( pClass->pInlines ); + hb_itemRelease( pClass->pClassDatas ); + hb_itemRelease( pClass->pInlines ); + /* hb_itemRelease( pClass->pInitValues ); */ } void ReleaseClasses( void ) @@ -724,8 +719,7 @@ HARBOUR OCLONE( void ) { PITEM pDstObject = hb_arrayClone( pSrcObject ); ItemCopy( &stack.Return, pDstObject ); /* OClone() returns the new object */ - ItemRelease( pDstObject ); - _xfree( pDstObject ); + hb_itemRelease( pDstObject ); } else _ret(); diff --git a/harbour/tests/working/inherit.prg b/harbour/tests/working/inherit.prg index 4dbdc5ca69..f9a7670996 100644 --- a/harbour/tests/working/inherit.prg +++ b/harbour/tests/working/inherit.prg @@ -105,7 +105,7 @@ return oFile:Instance() // mode for opening. Default "R" // Optional maximum blocksize // - function New( cFileName, cMode, nBlock ) +static function New( cFileName, cMode, nBlock ) local self := QSelf() // Get self @@ -133,7 +133,7 @@ return oFile:Instance() return self - function Run( xTxt, lCRLF ) +static function Run( xTxt, lCRLF ) local self := QSelf() local xRet @@ -149,7 +149,7 @@ return xRet // // Dispose -> Close the file handle // - function Dispose() +static function Dispose() local self := QSelf() @@ -169,7 +169,7 @@ return self // // Read a single line // - function Read() +static function Read() local self := QSelf() local cRet := "" @@ -226,7 +226,7 @@ return cRet // one or more strings // End with Carriage Return/Line Feed (Default == TRUE) // - function WriteLn( xTxt, lCRLF ) +static function WriteLn( xTxt, lCRLF ) local self := QSelf() local cBlock @@ -249,7 +249,7 @@ return cRet return self - function Write( xTxt ) +static function Write( xTxt ) local self := QSelf() @@ -265,7 +265,7 @@ return ::WriteLn( xTxt, .F. ) // // Go to a specified line number // - function Goto( nLine ) +static function Goto( nLine ) local self := QSelf() local nWhere := 1 diff --git a/harbour/tests/working/inifiles.prg b/harbour/tests/working/inifiles.prg index 0cf48d9407..433bcbf615 100644 --- a/harbour/tests/working/inifiles.prg +++ b/harbour/tests/working/inifiles.prg @@ -1,5 +1,6 @@ function Main() local i := TIniFile():New('harbour.ini') + local s qout(i:readstring('test', 'hello', 'not found')) qout(i:readstring('not', 'there', 'not found')) @@ -9,6 +10,16 @@ function Main() i:WriteString('', 'not', 'in section!') + qout('') + qout('Sections:') + s := i:ReadSections() + aeval(s, {|x| qout('[' + x + ']')}) + + qout('') + qout('[' + s[1] + ']') + s := i:ReadSection(s[1]) + aeval(s, {|x| qout(x)}) + i:Filename := 'harbour.new' i:Commit() // saves file return nil @@ -25,6 +36,8 @@ function TIniFile() oClass:AddMethod( "New", @New() ) // define this class objects methods oClass:AddMethod( "ReadString", @ReadString() ) oClass:AddMethod( "WriteString", @WriteString() ) + oClass:AddMethod( "ReadSection", @ReadSection() ) + oClass:AddMethod( "ReadSections", @ReadSections() ) oClass:AddMethod( "Commit", @Commit() ) oClass:Create() // builds this class @@ -46,12 +59,12 @@ static function New(cFileName) ::Contents := {} CurrArray := ::Contents - //if Hb_File(cFileName) + if Hb_File(cFileName) hFile := fopen(cFilename, 0) - //else - // hFile := fcreate(cFilename) - //endif + else + hFile := fcreate(cFilename) + endif cFile := space(255) do while (nPos := fread(hFile, @cFile, 255)) > 0 @@ -121,7 +134,7 @@ static procedure WriteString(cSection, cIdent, cString) local a, j, i if Empty(cIdent) - outerr('Must specifier an identifier') + outerr('Must specify an identifier') elseif Empty(cSection) j := AScan( ::Contents, {|x| x[1] == cIdent .and. ValType(x[2]) == 'C'} ) @@ -130,7 +143,6 @@ static procedure WriteString(cSection, cIdent, cString) ::Contents[j][2] := cString else -// a := aClone(::Contents) a := ::Contents /* QUESTION: Doing this directly on ::Contents didn't work! @@ -141,10 +153,10 @@ static procedure WriteString(cSection, cIdent, cString) a[1] := {cIdent, cString} ::Contents := a -// ::Contents := aClone(a) endif - elseif (i := AScan( ::Contents, {|x| x[1] == cSection})) > 0 + elseif (i := AScan( ::Contents, {|x| x[1] == cSection .and. ; + ValType(x[2]) == 'A'})) > 0 j := AScan( ::Contents[i][2], {|x| x[1] == cIdent} ) if j > 0 @@ -159,6 +171,37 @@ static procedure WriteString(cSection, cIdent, cString) endif return +static function ReadSection(cSection) + local Self := QSelf() + local i, j, aSection := {} + + if Empty(cSection) + outerr('Must specify a section') + + elseif (i := AScan( ::Contents, {|x| x[1] == cSection .and. ; + ValType(x[2]) == 'A'})) > 0 + + for j := 1 to Len(::Contents[i][2]) + + if ::Contents[i][2][j][1] <> NIL + AAdd(aSection, ::Contents[i][2][j][1]) + endif + next j + endif +return aSection + +static function ReadSections() + local Self := QSelf() + local i, aSections := {} + + for i := 1 to Len(::Contents) + + if ValType(::Contents[i][2]) == 'A' + AAdd(aSections, ::Contents[i][1]) + endif + next i +return aSections + static procedure Commit() local Self := QSelf() local i, j, hFile @@ -178,19 +221,17 @@ static procedure Commit() fwrite(hFile, ::Contents[i][2][j][2] + Chr(13) + Chr(10)) else - fwrite(hFile, ::Contents[i][2][j][1] + '=' +; + fwrite(hFile, ::Contents[i][2][j][1] + '=' + ; ::Contents[i][2][j][2] + Chr(13) + Chr(10)) endif - next //j + next j fwrite(hFile, Chr(13) + Chr(10)) elseif ValType(::Contents[i][2]) == 'C' - fwrite(hFile, ::Contents[i][1] + '=' + ::Contents[i][2] + Chr(13) +; - Chr(10)) + fwrite(hFile, ::Contents[i][1] + '=' + ::Contents[i][2] +; + Chr(13) + Chr(10)) endif - next //i + next i fclose(hFile) return - -