Hi Ron and Walter. The problem can be exploited by many different syntax errors. When syntax error appears we cannot trust that our expression destructor is executed because we do not know where exactly the error was detected by bison and if all sub expressions created so far have internal bindings which allow to free them all. Bison has %destructor directive which can help to resolve such problems with memory leaks but it needs well defined grammar rules which do not overwrite expressions on the bison stack and expressions which are still on bison stack do have internal bindings used in their destructors. In [x]Harbour none of the above is true so %destructor cannot be used.
I left this note in harbour.y: /* We cannot use destructors for expressions. The internal bison logic cannot detect properly if the expression was used or not in our grammar definition so it's possible that destructors will never be executed or executed for expressions which we freed ourselves. %destructor { HB_COMP_EXPR_FREE( $$ ); } Argument ArgList ElemList ... */ For this example you can change grammar rules just to force execution of expression destructor. But it's not general solution because in a while someone else may create other example with completely different code with syntax syntax error, i.e.: &( "a[1" ) // one not freed expression or &( "a(b(c(d(e" ) // four not freed expressions The simplest solution for this problem is implementing garbage collector for generated expressions in macrocompiler and also in compiler if you ever plan to add support for runtime PRG code compilation and evaluation. I implemented such GC-es in Harbour about 10 years ago so you can port them to xharbour. BTW There are many other things which should be fixed in xHarbour macrocompiler. Just look at ChangeLog in Harbour for modifications related to macro/macro.y best regards, Przemek On Wed, 20 Apr 2016, Walter Negro wrote: > Hi, Ron > > I'm fine, many responsability, working with xHarbour. > > Adding debug to parser I have this sequence: > > > *** New Macro: >>>(file_alias = $1)<<< Len: 17 > Starting parse > Entering state 0 > Reading a token: > Reducing Delimiter: '(' As: 40 > Passing through: 40 > Returning: 40 > Next token is token '(' () > Shifting token '(' () > Entering state 23 > Reading a token: > Checking 4 Streams for E At: >e_alias = $1)< > Token: "FILE_ALIAS" Ommited: ' ' > Pre-Scaning Words for Token: FILE_ALIAS at Positions: 1-1 > iLenMatch 10 > iKeyLen: 5 iLen2Match: 10 comparing: [FILE_ALIAS] with: [FIELD?WS?->] > Trying Next Word Pattern... [FILE_ALIAS] > [FIELD?WS?->] > Continue with: [HAS] > Reducing Element: "FILE_ALIAS" > Element "FILE_ALIAS" is 258 > Passing through: 258 > Returning: 258 > Next token is token IDENTIFIER () > Shifting token IDENTIFIER () > Entering state 86 > Reducing stack by rule 8 (line 379): > $1 = token IDENTIFIER () > -> $$ = nterm IdentName () > Stack now 0 23 > Entering state 26 > Reading a token: > Checking 28 Selfs for = At: >= $1)< > Reducing Delimiter: '=' As: 1085 > Returning Dont Reduce 61 > Returning: 61 > Next token is token '=' () > Reducing stack by rule 30 (line 533): > $1 = nterm IdentName () > -> $$ = nterm Variable () > Stack now 0 23 > Entering state 38 > Next token is token '=' () > Reducing stack by rule 109 (line 820): > $1 = nterm Variable () > -> $$ = nterm SimpleExpression () > Stack now 0 23 > Entering state 57 > Reducing stack by rule 126 (line 839): > $1 = nterm SimpleExpression () > -> $$ = nterm Expression () > Stack now 0 23 > Entering state 106 > Next token is token '=' () > Shifting token '=' () > Entering state 197 > Reading a token: > Reducing Delimiter: '$' As: 1060 > Returning Dont Reduce 36 > Returning: 36 > Next token is token '$' () > Error: popping token '=' () > Stack now 0 23 106 > Error: popping nterm Expression () > Stack now 0 23 > Error: popping token '(' () > Stack now 0 > Shifting token error () > Entering state 1 > Reducing stack by rule 7 (line 359): > $1 = token error () > Cleanup: discarding lookahead token '$' () > Stack now 0 > > source\vm\fm.c:971: HB_TR_ERROR Block 1 00923AA8 (size 11) MAIN(10), > "FILE_ALIAS." > source\vm\fm.c:971: HB_TR_ERROR Block 2 00A5A2D0 (size 40) MAIN(10), > "A83A92000000000010D6E80000000000010002008000000000000000010000001A00000000000000" > > > Testing several expression to force error and reduce stack by rule 7, i > found that other expression free memory using s_Pending. > > If code is: > > file_alias = $1 > > the stack is reduced by rule 6 > > I test adding a rule > > | '(' Expression error > > similar to > > | Expression error > > and the parser reduce in this rule instead of rule > > | error > > and now no more memory leaks, but is this a correct solution? > > Thank you > > > > > *Walter Negro* > Desarrollo e Investigación > VsTour - Softmagic S.R.L. > ( 54 ) ( 11 ) 5218-6616 > Av. Corrientes 2294 Piso 7 Of.33 > C1046AAN - Buenos Aires - Argentina > wne...@vstour.com > -------------------------------------------------------------------------------- > *:: VSTour.COM <http://www.vstour.com> :: * > > 2016-04-19 16:53 GMT-03:00 Ron Pinkas <ron.pin...@xharbour.com>: > > > Hey Walter, :-) > > > > (How are you?) > > > > How much memory, and what is stored int it? > > > > We need to follow the EXPRESSION TREE, and find which element is not > > released. > > > > It should be a Parenthesized Exp, which has a single element, being an > > EQUATION where the left side is the IDENTIFIER file_alias, and the right > > side is where the syntax error occurs as $ was encountered. > > > > We must be sure that the pending expression (the Parenthesis ) is released > > as well as the expression of the current token (the $ operator). > > > > Ron > > > > > On Apr 7, 2016, at 12:35 AM, Walter Negro <wne...@vstour.com> wrote: > > > > > > > > > Procedure Main() > > > > > > TRY > > > // ? &( "file_alias = $1" ) // No memory leaks > > > ? &( "(file_alias = $1)" ) // Memory leaks > > > CATCH > > > ? "Catched" > > > END > > > > > > Return > > > > > > --------------------------- > > > This code > > > &( "file_alias = $1" ) > > > > > > End in the rule (macro.y) > > > Main : Expression error > > > > > > --------------------------- > > > This code > > > &( "(file_alias = $1)" ) > > > > > > End in the rule (macro.y) > > > Main : error > > > > > > I not understand how to fix the rule or > > > > > > Walter Negro ------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! https://ad.doubleclick.net/ddm/clk/302982198;130105516;z _______________________________________________ xHarbour-developers mailing list xHarbour-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xharbour-developers