Re: [fpc-pascal] ptop and comma.

2020-02-24 Thread fredvs via fpc-pascal
Hello Bart.

OK, I did try your idea, changing the original code with this (see 2 last
lines):

procedure TPToP.Usage(ECode: word);
begin
  writeLn('ptop : Usage : ');
  writeLn('ptop [-v] [-i indent] [-b bufsize ][-c optsfile][-l linesize]
infile outfile');
  writeLn(' converts infile to outfile.');
  writeLn(' -c : read options from optsfile');
  writeLn(' -i : Set number of indent spaces.');
  writeLn(' -l : Set maximum output linesize.');
  writeLn(' -b : Use buffers of size bufsize');
  writeLn(' -v : be verbose');
  writeLn('ptop -g ofile');
  writeLn(' generate default options file');
  writeLn('ptop -h : This help');
  ExitCode := ECode; // this change instead of halt(ECode);
  Terminate;   // this change instead of halt(ECode);
end;

Is it what you are thinking?
Indeed, no more memory leak and error preserved with this.

Heap dump by heaptrc unit of ptop
29 memory blocks allocated : 2242/2280
29 memory blocks freed : 2242/2280
0 unfreed memory blocks : 0
True heap size : 131072
True free heap : 131072

Fre;D




-
Many thanks ;-)
--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] ptop and comma.

2020-02-24 Thread fredvs via fpc-pascal
>If you really dislike the memory leak (since it's not "nice
>programming"), maybe you can set ExitCode before calling terminate?
>(Untested idea (TM))

Hello Bart.

Thanks for that constructive and respectful answer that gives solution.

Indeed, I **really** dont like programs that generate memory leak and all
the bla-bla that try to to convince me that it is not important, that the OS
will remove it, ... etc dont work on me.

I will test your idea.

Thanks.

Fre;D






-
Many thanks ;-)
--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] ptop and comma.

2020-02-24 Thread Bart via fpc-pascal
On Mon, Feb 24, 2020 at 10:11 AM Sven Barth via fpc-pascal
 wrote:

> You are wrong. Halt() sets the error code provided as parameter. Terminate by 
> itself does not.
> Terminate leads to the destructor being called while Halt exists the program 
> in a hard way. But as Tomas wrote, when a program terminates all memory is 
> returned to the OS so that is not really a problem.

If you really dislike the memory leak (since it's not "nice
programming"), maybe you can set ExitCode before calling terminate?
(Untested idea (TM))


-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] ptop and comma.

2020-02-24 Thread Sven Barth via fpc-pascal
fredvs via fpc-pascal  schrieb am Mo., 24.
Feb. 2020, 02:10:

> Tomas Hajny-2 wrote
> > The difference between your version and the original one is that the
> > original finishes the program with some error code thus allowing some
> > error checking in case the program was called from some script, etc.,
> > whereas your version finishes with a result of 0 even if the processing
> > encountered some errors.
>
> No, I dont think so, all error code are still there.
> Even more, if the user dont use a filename as parameter, help-messages are
> displayed.
>

You are wrong. Halt() sets the error code provided as parameter. Terminate
by itself does not.


> And also I dont see what it could have to do with the memory leak.
>

Terminate leads to the destructor being called while Halt exists the
program in a hard way. But as Tomas wrote, when a program terminates all
memory is returned to the OS so that is not really a problem.

Regards,
Sven

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal