* removed a lot of memory leaks when an error is encountered (caused by

procinfo and pstringcontainers). There are still plenty left though :)
This commit is contained in:
Jonas Maebe 2000-01-11 17:16:04 +00:00
parent f8e779a438
commit edf419d5a7
8 changed files with 301 additions and 14 deletions

View File

@ -388,6 +388,26 @@ unit cobjects;
end; end;
{$endif BUFFEREDFILE} {$endif BUFFEREDFILE}
{$ifdef fixLeaksOnError}
PStackItem = ^TStackItem;
TStackItem = record
next: PStackItem;
data: pointer;
end;
PStack = ^TStack;
TStack = object
constructor init;
destructor done;
procedure push(p: pointer);
function pop: pointer;
function top: pointer;
function isEmpty: boolean;
private
head: PStackItem;
end;
{$endif fixLeaksOnError}
function getspeedvalue(const s : string) : longint; function getspeedvalue(const s : string) : longint;
{ releases the string p and assignes nil to p } { releases the string p and assignes nil to p }
@ -448,6 +468,63 @@ unit cobjects;
show; show;
end; end;
{*****************************************************************************
Stack
*****************************************************************************}
{$ifdef fixLeaksOnError}
constructor TStack.init;
begin
head := nil;
end;
procedure TStack.push(p: pointer);
var s: PStackItem;
begin
new(s);
s^.data := p;
s^.next := head;
head := s;
end;
function TStack.pop: pointer;
var s: PStackItem;
begin
pop := top;
if assigned(head) then
begin
s := head^.next;
dispose(head);
head := s;
end
end;
function TStack.top: pointer;
begin
if not isEmpty then
top := head^.data
else top := NIL;
end;
function TStack.isEmpty: boolean;
begin
isEmpty := head = nil;
end;
destructor TStack.done;
var temp: PStackItem;
begin
while head <> nil do
begin
temp := head^.next;
dispose(head);
head := temp;
end;
end;
{$endif fixLeaksOnError}
{$ifndef OLDSPEEDVALUE} {$ifndef OLDSPEEDVALUE}
@ -2318,7 +2395,11 @@ end;
end. end.
{ {
$Log$ $Log$
Revision 1.50 2000-01-07 01:14:23 peter Revision 1.51 2000-01-11 17:16:04 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.50 2000/01/07 01:14:23 peter
* updated copyright to 2000 * updated copyright to 2000
Revision 1.49 1999/12/22 01:01:48 peter Revision 1.49 1999/12/22 01:01:48 peter

View File

@ -322,13 +322,24 @@ begin
Writeln('Repetitive firstpass = '+tostr(firstpass_several)+'/'+tostr(total_of_firstpass)); Writeln('Repetitive firstpass = '+tostr(firstpass_several)+'/'+tostr(total_of_firstpass));
{$endif newcg} {$endif newcg}
{$endif EXTDEBUG} {$endif EXTDEBUG}
{$ifdef fixLeaksOnError}
{$ifdef tp}
do_stop;
{$else tp}
do_stop();
{$endif tp}
{$endif fixLeaksOnError}
end; end;
end. end.
{ {
$Log$ $Log$
Revision 1.44 2000-01-11 16:56:22 jonas Revision 1.45 2000-01-11 17:16:04 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.44 2000/01/11 16:56:22 jonas
- removed call to do_stop at the end of compile() since it obviously breaks the - removed call to do_stop at the end of compile() since it obviously breaks the
automatic compiling of units. Make cycle worked though! 8) automatic compiling of units. Make cycle worked though! 8)

View File

@ -164,7 +164,17 @@ implementation
implementation implementation
uses uses
systems,globals,files,strings,cresstr; systems,globals,files,strings,cresstr
{$ifdef fixLeaksOnError}
,comphook
{$endif fixLeaksOnError}
;
{$ifdef fixLeaksOnError}
var procinfoStack: TStack;
hcodegen_old_do_stop: tstopprocedure;
{$endif fixLeaksOnError}
{***************************************************************************** {*****************************************************************************
override the message calls to set codegenerror override the message calls to set codegenerror
@ -321,12 +331,19 @@ implementation
so it must not be reset to zero before this storage !} so it must not be reset to zero before this storage !}
{ new procinfo } { new procinfo }
new(procinfo,init); new(procinfo,init);
{$ifdef fixLeaksOnError}
procinfoStack.push(procinfo);
{$endif fixLeaksOnError}
end; end;
procedure codegen_doneprocedure; procedure codegen_doneprocedure;
begin begin
{$ifdef fixLeaksOnError}
if procinfo <> procinfoStack.pop then
writeln('problem with procinfoStack!');
{$endif fixLeaksOnError}
dispose(procinfo,done); dispose(procinfo,done);
procinfo:=nil; procinfo:=nil;
end; end;
@ -401,11 +418,40 @@ implementation
typ:=p; typ:=p;
end; end;
{$endif newcg} {$endif newcg}
{$ifdef fixLeaksOnError}
procedure hcodegen_do_stop; {$ifdef tp} far; {$endif tp}
var p: pprocinfo;
begin
p := pprocinfo(procinfoStack.pop);
while p <> nil Do
begin
dispose(p,done);
p := pprocinfo(procinfoStack.pop);
end;
procinfoStack.done;
do_stop := hcodegen_old_do_stop;
{$ifdef tp}
do_stop;
{$else tp}
do_stop();
{$endif tp}
end;
begin
hcodegen_old_do_stop := do_stop;
do_stop := {$ifdef tp}@{$endif}hcodegen_do_stop;
procinfoStack.init;
{$endif fixLeaksOnError}
end. end.
{ {
$Log$ $Log$
Revision 1.53 2000-01-07 01:14:27 peter Revision 1.54 2000-01-11 17:16:04 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.53 2000/01/07 01:14:27 peter
* updated copyright to 2000 * updated copyright to 2000
Revision 1.52 1999/12/09 23:18:04 pierre Revision 1.52 1999/12/09 23:18:04 pierre

View File

@ -25,7 +25,11 @@ unit pbase;
interface interface
uses uses
cobjects,tokens,globals,symtable; cobjects,tokens,globals,symtable
{$ifdef fixLeaksOnError}
,comphook
{$endif fixLeaksOnError}
;
const const
{ true, if we are after an assignement } { true, if we are after an assignement }
@ -53,6 +57,12 @@ unit pbase;
{ true, if we should ignore an equal in const x : 1..2=2 } { true, if we should ignore an equal in const x : 1..2=2 }
ignore_equal : boolean; ignore_equal : boolean;
{$ifdef fixLeaksOnError}
{ not worth it to make a pstack, there's only one data field (a pointer). }
{ in the interface, because pmodules and psub also use it for their names }
var strContStack: TStack;
pbase_old_do_stop: tstopprocedure;
{$endif fixLeaksOnError}
function tokenstring(i : ttoken):string; function tokenstring(i : ttoken):string;
@ -156,11 +166,39 @@ unit pbase;
idlist:=sc; idlist:=sc;
end; end;
{$ifdef fixLeaksOnError}
procedure pbase_do_stop; {$ifdef tp} far; {$endif tp}
var names: PStringContainer;
begin
names := PStringContainer(strContStack.pop);
while names <> nil do
begin
dispose(names,done);
names := PStringContainer(strContStack.pop);
end;
strContStack.done;
do_stop := pbase_old_do_stop;
{$ifdef tp}
do_stop;
{$else tp}
do_stop();
{$endif tp}
end;
begin
strContStack.init;
pbase_old_do_stop := do_stop;
do_stop := {$ifndef tp}@{$endif}pbase_do_stop;
{$endif fixLeaksOnError}
end. end.
{ {
$Log$ $Log$
Revision 1.28 2000-01-07 01:14:28 peter Revision 1.29 2000-01-11 17:16:04 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.28 2000/01/07 01:14:28 peter
* updated copyright to 2000 * updated copyright to 2000
Revision 1.27 1999/11/06 14:34:21 peter Revision 1.27 1999/11/06 14:34:21 peter

View File

@ -134,6 +134,9 @@ unit pdecl;
begin begin
{ read identifiers } { read identifiers }
sc:=idlist; sc:=idlist;
{$ifdef fixLeaksOnError}
strContStack.push(sc);
{$endif fixLeaksOnError}
{ read type declaration, force reading for value and const paras } { read type declaration, force reading for value and const paras }
if (token=_COLON) or (varspez=vs_value) then if (token=_COLON) or (varspez=vs_value) then
begin begin
@ -248,6 +251,10 @@ unit pdecl;
end; end;
end; end;
{$ifdef fixLeaksOnError}
if PStringContainer(strContStack.pop) <> sc then
writeln('problem with strContStack in pdecl (1)');
{$endif fixLeaksOnError}
dispose(sc,done); dispose(sc,done);
tokenpos:=storetokenpos; tokenpos:=storetokenpos;
end; end;
@ -304,6 +311,10 @@ unit pdecl;
st^.defowner^.owner^.insert(new(pvarsym,init(s,tt))); st^.defowner^.owner^.insert(new(pvarsym,init(s,tt)));
end; end;
end; end;
{$ifdef fixLeaksOnError}
if strContStack.pop <> sc then
writeln('problem with strContStack in pdecl (2)');
{$endif fixLeaksOnError}
dispose(sc,done); dispose(sc,done);
tokenpos:=filepos; tokenpos:=filepos;
end; end;
@ -345,6 +356,9 @@ unit pdecl;
begin begin
C_name:=orgpattern; C_name:=orgpattern;
sc:=idlist; sc:=idlist;
{$ifdef fixLeaksOnError}
strContStack.push(sc);
{$endif fixLeaksOnError}
consume(_COLON); consume(_COLON);
if (m_gpc in aktmodeswitches) and if (m_gpc in aktmodeswitches) and
not(is_record or is_object or is_threadvar) and not(is_record or is_object or is_threadvar) and
@ -372,6 +386,10 @@ unit pdecl;
s:=sc^.get_with_tokeninfo(tokenpos); s:=sc^.get_with_tokeninfo(tokenpos);
if not sc^.empty then if not sc^.empty then
Message(parser_e_absolute_only_one_var); Message(parser_e_absolute_only_one_var);
{$ifdef fixLeaksOnError}
if strContStack.pop <> sc then
writeln('problem with strContStack in pdecl (3)');
{$endif fixLeaksOnError}
dispose(sc,done); dispose(sc,done);
aktvarsym:=new(pvarsym,init_C(s,target_os.Cprefix+C_name,tt)); aktvarsym:=new(pvarsym,init_C(s,target_os.Cprefix+C_name,tt));
{$ifdef INCLUDEOK} {$ifdef INCLUDEOK}
@ -392,6 +410,10 @@ unit pdecl;
s:=sc^.get_with_tokeninfo(declarepos); s:=sc^.get_with_tokeninfo(declarepos);
if not sc^.empty then if not sc^.empty then
Message(parser_e_absolute_only_one_var); Message(parser_e_absolute_only_one_var);
{$ifdef fixLeaksOnError}
if strContStack.pop <> sc then
writeln('problem with strContStack in pdecl (4)');
{$endif fixLeaksOnError}
dispose(sc,done); dispose(sc,done);
{ parse the rest } { parse the rest }
if token=_ID then if token=_ID then
@ -506,6 +528,10 @@ unit pdecl;
s:=sc^.get_with_tokeninfo(declarepos); s:=sc^.get_with_tokeninfo(declarepos);
if not sc^.empty then if not sc^.empty then
Message(parser_e_absolute_only_one_var); Message(parser_e_absolute_only_one_var);
{$ifdef fixLeaksOnError}
if strContStack.pop <> sc then
writeln('problem with strContStack in pdecl (5)');
{$endif fixLeaksOnError}
dispose(sc,done); dispose(sc,done);
{ defaults } { defaults }
is_dll:=false; is_dll:=false;
@ -1182,7 +1208,11 @@ unit pdecl;
end. end.
{ {
$Log$ $Log$
Revision 1.177 2000-01-10 11:14:19 peter Revision 1.178 2000-01-11 17:16:05 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.177 2000/01/10 11:14:19 peter
* fixed memory leak with options, you must use StopOptions instead of * fixed memory leak with options, you must use StopOptions instead of
Stop Stop
* fixed memory leak with forward resolving, make_ref is now false * fixed memory leak with forward resolving, make_ref is now false

View File

@ -57,7 +57,6 @@ unit pmodules;
{$endif GDB} {$endif GDB}
scanner,pbase,psystem,pdecl,psub,parser; scanner,pbase,psystem,pdecl,psub,parser;
procedure create_objectfile; procedure create_objectfile;
begin begin
{ create the .s file and assemble it } { create the .s file and assemble it }
@ -935,7 +934,11 @@ unit pmodules;
end; end;
var var
{$ifdef fixLeaksOnError}
names : Pstringcontainer;
{$else fixLeaksOnError}
names : Tstringcontainer; names : Tstringcontainer;
{$endif fixLeaksOnError}
st : psymtable; st : psymtable;
unitst : punitsymtable; unitst : punitsymtable;
{$ifdef GDB} {$ifdef GDB}
@ -1157,11 +1160,22 @@ unit pmodules;
{ Compile the unit } { Compile the unit }
codegen_newprocedure; codegen_newprocedure;
gen_main_procsym(current_module^.modulename^+'_init',potype_unitinit,st); gen_main_procsym(current_module^.modulename^+'_init',potype_unitinit,st);
{$ifdef fixLeaksOnError}
new(names,init);
strContStack.push(names);
names^.insert('INIT$$'+current_module^.modulename^);
names^.insert(target_os.cprefix+current_module^.modulename^+'_init');
compile_proc_body(names^,true,false);
if names <> PstringContainer(strContStack.pop) then
writeln('Problem with strContStack in pmodules (1)');
dispose(names,done);
{$else fixLeaksOnError}
names.init; names.init;
names.insert('INIT$$'+current_module^.modulename^); names.insert('INIT$$'+current_module^.modulename^);
names.insert(target_os.cprefix+current_module^.modulename^+'_init'); names.insert(target_os.cprefix+current_module^.modulename^+'_init');
compile_proc_body(names,true,false); compile_proc_body(names,true,false);
names.done; names.done;
{$endif fixLeaksOnError}
codegen_doneprocedure; codegen_doneprocedure;
{ avoid self recursive destructor call !! PM } { avoid self recursive destructor call !! PM }
@ -1176,11 +1190,22 @@ unit pmodules;
{ Compile the finalize } { Compile the finalize }
codegen_newprocedure; codegen_newprocedure;
gen_main_procsym(current_module^.modulename^+'_finalize',potype_unitfinalize,st); gen_main_procsym(current_module^.modulename^+'_finalize',potype_unitfinalize,st);
{$ifdef fixLeaksOnError}
new(names,init);
strContStack.push(names);
names^.insert('FINALIZE$$'+current_module^.modulename^);
names^.insert(target_os.cprefix+current_module^.modulename^+'_finalize');
compile_proc_body(names^,true,false);
if names <> PstringContainer(strContStack.pop) then
writeln('Problem with strContStack in pmodules (2)');
dispose(names,done);
{$else fixLeaksOnError}
names.init; names.init;
names.insert('FINALIZE$$'+current_module^.modulename^); names.insert('FINALIZE$$'+current_module^.modulename^);
names.insert(target_os.cprefix+current_module^.modulename^+'_finalize'); names.insert(target_os.cprefix+current_module^.modulename^+'_finalize');
compile_proc_body(names,true,false); compile_proc_body(names,true,false);
names.done; names.done;
{$endif fixLeaksOnError}
codegen_doneprocedure; codegen_doneprocedure;
end; end;
@ -1328,7 +1353,11 @@ unit pmodules;
var var
st : psymtable; st : psymtable;
hp : pmodule; hp : pmodule;
{$ifdef fixLeaksOnError}
names : Pstringcontainer;
{$else fixLeaksOnError}
names : Tstringcontainer; names : Tstringcontainer;
{$endif fixLeaksOnError}
begin begin
DLLsource:=islibrary; DLLsource:=islibrary;
IsExe:=true; IsExe:=true;
@ -1435,16 +1464,32 @@ unit pmodules;
from the bootstrap code.} from the bootstrap code.}
codegen_newprocedure; codegen_newprocedure;
gen_main_procsym('main',potype_proginit,st); gen_main_procsym('main',potype_proginit,st);
{$ifdef fixLeaksOnError}
new(names,init);
strContStack.push(names);
names^.insert('program_init');
names^.insert('PASCALMAIN');
names^.insert(target_os.cprefix+'main');
{$ifdef m68k}
if target_info.target=target_m68k_PalmOS then
names^.insert('PilotMain');
{$endif m68k}
compile_proc_body(names^,true,false);
if names <> PstringContainer(strContStack.pop) then
writeln('Problem with strContStack in pmodules (1)');
dispose(names,done);
{$else fixLeaksOnError}
names.init; names.init;
names.insert('program_init'); names.insert('program_init');
names.insert('PASCALMAIN'); names.insert('PASCALMAIN');
names.insert(target_os.cprefix+'main'); names.insert(target_os.cprefix+'main');
{$ifdef m68k} {$ifdef m68k}
if target_info.target=target_m68k_PalmOS then if target_info.target=target_m68k_PalmOS then
names.insert('PilotMain'); names.insert('PilotMain');
{$endif} {$endif m68k}
compile_proc_body(names,true,false); compile_proc_body(names,true,false);
names.done; names.done;
{$endif fixLeaksOnError}
{ avoid self recursive destructor call !! PM } { avoid self recursive destructor call !! PM }
aktprocsym^.definition^.localst:=nil; aktprocsym^.definition^.localst:=nil;
@ -1471,11 +1516,22 @@ unit pmodules;
{ Compile the finalize } { Compile the finalize }
codegen_newprocedure; codegen_newprocedure;
gen_main_procsym(current_module^.modulename^+'_finalize',potype_unitfinalize,st); gen_main_procsym(current_module^.modulename^+'_finalize',potype_unitfinalize,st);
{$ifdef fixLeaksOnError}
new(names,init);
strContStack.push(names);
names^.insert('FINALIZE$$'+current_module^.modulename^);
names^.insert(target_os.cprefix+current_module^.modulename^+'_finalize');
compile_proc_body(names^,true,false);
if names <> PstringContainer(strContStack.pop) then
writeln('Problem with strContStack in pmodules (1)');
dispose(names,done);
{$else fixLeaksOnError}
names.init; names.init;
names.insert('FINALIZE$$'+current_module^.modulename^); names.insert('FINALIZE$$'+current_module^.modulename^);
names.insert(target_os.cprefix+current_module^.modulename^+'_finalize'); names.insert(target_os.cprefix+current_module^.modulename^+'_finalize');
compile_proc_body(names,true,false); compile_proc_body(names,true,false);
names.done; names.done;
{$endif fixLeaksOnError}
codegen_doneprocedure; codegen_doneprocedure;
end; end;
@ -1561,7 +1617,11 @@ unit pmodules;
end. end.
{ {
$Log$ $Log$
Revision 1.179 2000-01-11 09:52:07 peter Revision 1.180 2000-01-11 17:16:05 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.179 2000/01/11 09:52:07 peter
* fixed placing of .sl directories * fixed placing of .sl directories
* use -b again for base-file selection * use -b again for base-file selection
* fixed group writing for linux with smartlinking * fixed group writing for linux with smartlinking

View File

@ -45,7 +45,6 @@ procedure parse_var_proc_directives(var sym : psym);
procedure parse_object_proc_directives(var sym : pprocsym); procedure parse_object_proc_directives(var sym : pprocsym);
procedure read_proc; procedure read_proc;
implementation implementation
uses uses
@ -1797,6 +1796,9 @@ begin
oldprocinfo:=procinfo; oldprocinfo:=procinfo;
{ create a new procedure } { create a new procedure }
new(names,init); new(names,init);
{$ifdef fixLeaksOnError}
strContStack.push(names);
{$endif fixLeaksOnError}
codegen_newprocedure; codegen_newprocedure;
with procinfo^ do with procinfo^ do
begin begin
@ -1908,6 +1910,10 @@ begin
consume(_SEMICOLON); consume(_SEMICOLON);
end; end;
{ close } { close }
{$ifdef fixLeaksOnError}
if names <> strContStack.pop then
writeln('problem with strContStack in psub!');
{$endif fixLeaksOnError}
dispose(names,done); dispose(names,done);
codegen_doneprocedure; codegen_doneprocedure;
{ Restore old state } { Restore old state }
@ -1933,7 +1939,11 @@ end.
{ {
$Log$ $Log$
Revision 1.40 2000-01-07 01:14:31 peter Revision 1.41 2000-01-11 17:16:06 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.40 2000/01/07 01:14:31 peter
* updated copyright to 2000 * updated copyright to 2000
Revision 1.39 1999/12/22 01:01:52 peter Revision 1.39 1999/12/22 01:01:52 peter

View File

@ -333,6 +333,9 @@ uses
end end
else varspez:=vs_value; else varspez:=vs_value;
sc:=idlist; sc:=idlist;
{$ifdef fixLeaksOnError}
strContStack.push(sc);
{$endif fixLeaksOnError}
if token=_COLON then if token=_COLON then
begin begin
consume(_COLON); consume(_COLON);
@ -367,6 +370,10 @@ uses
hp2^.paratype:=tt; hp2^.paratype:=tt;
propertyparas^.insert(hp2); propertyparas^.insert(hp2);
until false; until false;
{$ifdef fixLeaksOnError}
if strContStack.pop <> sc then
writeln('problem with strContStack in ptype');
{$endif fixLeaksOnError}
dispose(sc,done); dispose(sc,done);
until not try_to_consume(_SEMICOLON); until not try_to_consume(_SEMICOLON);
dec(testcurobject); dec(testcurobject);
@ -1510,7 +1517,11 @@ uses
end. end.
{ {
$Log$ $Log$
Revision 1.13 2000-01-07 01:14:34 peter Revision 1.14 2000-01-11 17:16:06 jonas
* removed a lot of memory leaks when an error is encountered (caused by
procinfo and pstringcontainers). There are still plenty left though :)
Revision 1.13 2000/01/07 01:14:34 peter
* updated copyright to 2000 * updated copyright to 2000
Revision 1.12 1999/11/30 10:40:52 peter Revision 1.12 1999/11/30 10:40:52 peter