Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-10

CmdLine

26 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Daniël Mantione
to Micha Nelissen

Op Wed, 18 Oct 2006, schreef Micha Nelissen:

Hi, Does the CmdLine variable in the System unit exist for Delphi/TP/... compatibility ?

Delphi compatibility.

By the way, I have a patch ready which turns it into a property, which prevents some code being pulled in Hello World kind of apps.

Daniël

Reply by email

Peter Vreman
to Daniël Mantione
Show quoted text 7 lines
> Does the CmdLine variable in the System unit exist for Delphi/TP/... > compatibility ? Delphi compatibility. By the way, I have a patch ready which turns it into a property, which prevents some code being pulled in Hello World kind of apps.

That is the best solution. It will then also be readonly.

Reply by email

Michael Van Canneyt
to Peter Vreman
Peter Vreman wrote 9 lines
>> Does the CmdLine variable in the System unit exist for Delphi/TP/... >> compatibility ? > > Delphi compatibility. > > By the way, I have a patch ready which turns it into a property, which > prevents some code being pulled in Hello World kind of apps. That is the best solution. It will then also be readonly.

Do you get rid of the duplicate argc/argv and cmdline, then ?

Code like

{$if defined(MSWINDOWS) or defined(OS2)}
  { finally release the heap if possible, especially
    important for DLLs }
  for i:=0 to argc do
    sysfreemem(argv[i]);
  sysfreemem(argv);
{$endif}
{$if defined(LINUX) or defined(BSD)}
  sysfreemem(cmdline);
{$endif}

seems rather strange to me...

Michael.

Reply by email

Daniël Mantione
to Michael Van Canneyt

Op Wed, 18 Oct 2006, schreef Michael Van Canneyt:

Show quoted text 15 lines
On Wed, 18 Oct 2006, Peter Vreman wrote: > >> Does the CmdLine variable in the System unit exist for Delphi/TP/... > >> compatibility ? > > > > Delphi compatibility. > > > > By the way, I have a patch ready which turns it into a property, which > > prevents some code being pulled in Hello World kind of apps. > > That is the best solution. It will then also be readonly. Do you get rid of the duplicate argc/argv and cmdline, then ?

No. Because cmdline is a Pchar which points to the heap, it cannot be calculated on the fly; that would be a memory leak. Instead it is calculated on the first use. This means however that it still needs to be deallocated just like before.

Daniël

Show quoted text 20 lines
Code like {$if defined(MSWINDOWS) or defined(OS2)} { finally release the heap if possible, especially important for DLLs } for i:=0 to argc do sysfreemem(argv[i]); sysfreemem(argv); {$endif} {$if defined(LINUX) or defined(BSD)} sysfreemem(cmdline); {$endif} seems rather strange to me... Michael. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Daniël Mantione
to Micha Nelissen

Op Wed, 18 Oct 2006, schreef Micha Nelissen:

Show quoted text 6 lines
Daniël Mantione wrote: > By the way, I have a patch ready which turns it into a property, which > prevents some code being pulled in Hello World kind of apps. Would be nice if somehow smartlinking could be 'smartened' to optimize this out. (Conditional initialization for group of variables/functions?)

Yes :) I thought at least a hundred times about it during the last ten years, but I never came up with an idea that is both clean and doable in implementation.

Daniël

Reply by email

Micha Nelissen
to Daniël Mantione
Daniël Mantione wrote 9 lines
Op Wed, 18 Oct 2006, schreef Micha Nelissen: > Would be nice if somehow smartlinking could be 'smartened' to optimize > this out. (Conditional initialization for group of variables/functions?) Yes :) I thought at least a hundred times about it during the last ten years, but I never came up with an idea that is both clean and doable in implementation.

I thought there was already one ? 'unit export' or something alike, where you can re-export all types defined in another unit in this unit. If nothing is used from that unit, it is completely smartlinked out, including initialization/finalization.

Micha

Reply by email

Daniël Mantione
to Micha Nelissen

Op Wed, 18 Oct 2006, schreef Micha Nelissen:

Show quoted text 15 lines
Daniël Mantione wrote: > > Op Wed, 18 Oct 2006, schreef Micha Nelissen: > >> Would be nice if somehow smartlinking could be 'smartened' to optimize >> this out. (Conditional initialization for group of variables/functions?) > > Yes :) I thought at least a hundred times about it during the last ten > years, but I never came up with an idea that is both clean and doable in > implementation. I thought there was already one ? 'unit export' or something alike, where you can re-export all types defined in another unit in this unit. If nothing is used from that unit, it is completely smartlinked out, including initialization/finalization.

I have considered the use of units. But if you need a unit for something like cmdline, and start applying this technique to other things in the system unit, it becomes one mess of helper units.

I wasn't aware of this specific feature, but cleanness I don't think we should go this route.

Daniël

Reply by email

Micha Nelissen
to Daniël Mantione
Daniël Mantione wrote
I have considered the use of units. But if you need a unit for something like cmdline, and start applying this technique to other things in the system unit, it becomes one mess of helper units.

To be able to smartlink this situation, you *need* to group them somehow. Units are the least intrusive way, I think. They could be named silly/long, like system_cmdline etc...

Micha

Reply by email

Peter Vreman
to Micha Nelissen: Would be nice if somehow smartlinking could be 'smartened' to optimize this out.…
Show quoted text 6 lines
Daniël Mantione wrote: > By the way, I have a patch ready which turns it into a property, which > prevents some code being pulled in Hello World kind of apps. Would be nice if somehow smartlinking could be 'smartened' to optimize this out. (Conditional initialization for group of variables/functions?)

That is impossible. The linker is 'stupid' in that sence. And it also should not be trying to be smart. Otherwise it will fail in other situations. Maybe you remember what the (currently disabled) VMT optimizer did for the LCL. It removed methods that the LCL expected to be there.

Reply by email

Peter Vreman
to Micha Nelissen: I thought there was already one ? 'unit export' or something alike, where you can…
Show quoted text 12 lines
>> Would be nice if somehow smartlinking could be 'smartened' to optimize >> this out. (Conditional initialization for group of >> variables/functions?) > > Yes :) I thought at least a hundred times about it during the last ten > years, but I never came up with an idea that is both clean and doable in > implementation. I thought there was already one ? 'unit export' or something alike, where you can re-export all types defined in another unit in this unit. If nothing is used from that unit, it is completely smartlinked out, including initialization/finalization.

That is again not possible. Even if nothing is exported the initialization can do some specific os settings or update some system unit settings. Examples are the heaptrc and lineinfo units.

Reply by email

Daniël Mantione
to Peter Vreman: That is impossible. The linker is 'stupid' in that sence. And it also should not be…

Op Thu, 19 Oct 2006, schreef Peter Vreman:

Show quoted text 11 lines
> Daniël Mantione wrote: >> By the way, I have a patch ready which turns it into a property, which >> prevents some code being pulled in Hello World kind of apps. > > Would be nice if somehow smartlinking could be 'smartened' to optimize > this out. (Conditional initialization for group of variables/functions?) That is impossible. The linker is 'stupid' in that sence. And it also should not be trying to be smart. Otherwise it will fail in other situations. Maybe you remember what the (currently disabled) VMT optimizer did for the LCL. It removed methods that the LCL expected to be there.

Was this a bug or does there exist a fundamental problem with removing unused methods?

Daniël

Reply by email

Micha Nelissen
to Peter Vreman: That is impossible. The linker is 'stupid' in that sence. And it also should not be…
Peter Vreman wrote
That is impossible. The linker is 'stupid' in that sence. And it also should not be trying to be smart. Otherwise it will fail in other situations. Maybe you remember what the (currently disabled) VMT optimizer did for the LCL. It removed methods that the LCL expected to be there.

That's a bug in the LCL IMHO. We shouldn't be messing around with internals.

Micha

Reply by email

Marc Weustink
to Micha Nelissen
Micha Nelissen wrote 9 lines
Peter Vreman wrote: > That is impossible. The linker is 'stupid' in that sence. And it also > should not be trying to be smart. Otherwise it will fail in other > situations. Maybe you remember what the (currently disabled) VMT > optimizer > did for the LCL. It removed methods that the LCL expected to be there. That's a bug in the LCL IMHO. We shouldn't be messing around with internals.

It isn't really doing much with the internals. I've to admit that nowadays better solutions are available, but thats something different. The case shows that users can do this. There is no language construct that forbids it. So optimizing this with a smart linker may break such code. Problem only is till what level should a smart linker detect this. IMO, ppl will always be smarter and find a valid case where things get broken.

Marc

Reply by email

Vinzent Hoefler
to Marc Weustink: It isn't really doing much with the internals. I've to admit that nowadays better…
Marc Weustink wrote
The case shows that users can do this. There is no language construct that forbids it. So optimizing this with a smart linker may break such code.

Yes, it may. So what?

There's hell a lot of code that is generally possible within the language. Still it can be unportable, plain wrong, only work in certain situations etc. pp. Read: It still may break.

So "no language construct that forbids it" is no excuse, especially when you're digging around in internal compiler constructs.

Otherwise I'd expect some of my old code to work with FreePascal - where I outsmarted TPs heap manager to be able to free parts of dynamically allocated arrays.

IMO, ppl will always be smarter and find a valid case where things get broken.

This highly depends on your definition of "valid". My opinion: If it ain't guaranteed by the language, it ain't valid.

Vinzent.

Reply by email

Daniël Mantione
to Micha Nelissen: It reads/searches the VMT pointers themselves, right ? Is that supposed to work in the…

Op Thu, 19 Oct 2006, schreef Micha Nelissen:

Show quoted text 5 lines
Marc Weustink wrote: > It isn't really doing much with the internals. I've to admit that It reads/searches the VMT pointers themselves, right ? Is that supposed to work in the language ?

I don't know, but there should be a way to request the VMT-index of a virtual method, and then such a method should count as used. For example, calling virtual methods from assembler is a low level thing I'd rather like to be possible.

Daniël

Reply by email

Marc Weustink
to Vinzent Hoefler: Yes, it may. So what? There's hell a lot of code that is generally possible within the…
Vinzent Hoefler wrote 11 lines
On Thursday 19 October 2006 08:31, Marc Weustink wrote: > The case shows that users can do this. There is no language construct > that forbids it. So optimizing this with a smart linker may break > such code. Yes, it may. So what? There's hell a lot of code that is generally possible within the language. Still it can be unportable, plain wrong, only work in certain situations etc. pp. Read: It still may break.

I'm speaking about correct and portable code working in all situations. The only point is that the linker doesn't recognize the reference being used.

So "no language construct that forbids it" is no excuse, especially when you're digging around in internal compiler constructs.

I'm not digging in internal compiler constructs, I'm using a defined class layout and RTTI. No internal magic is used. (unless you define RTTI as internal)

Show quoted text 9 lines
Otherwise I'd expect some of my old code to work with FreePascal - where I outsmarted TPs heap manager to be able to free parts of dynamically allocated arrays. > IMO, ppl will always be smarter and find a valid case where things get > broken. This highly depends on your definition of "valid". My opinion: If it ain't guaranteed by the language, it ain't valid.

A valid case is a piece of code where you and I will agree on that is should work.
The only thing guaranteed by the language is that if you follow its definitions, it will compile. Nothing more nothing less.

Marc

Reply by email

Yury Sidorov
to Daniël Mantione: Op Wed, 18 Oct 2006, schreef Micha Nelissen: Delphi compatibility. By the way, I have a…

From: "Daniël Mantione"

Show quoted text 9 lines
> Hi, > > Does the CmdLine variable in the System unit exist for Delphi/TP/... > compatibility ? Delphi compatibility. By the way, I have a patch ready which turns it into a property, which prevents some code being pulled in Hello World kind of apps.

I already implemented optimization of CmdLine for smartlinking for WinCE some time ago. It is controlled by HAS_CMDLINE define. And CmdLine is declared as function in WinCE system unit.

CmdLine as property will be great, but I found that property getter/setter need to be declared before property declaration in the interface part. This will garbage a global namespace with private getters/setters.

Is it possible to make compiler to accept getters/setters not declared in the interface part, but implemented in the implementation?

Yury Sidorov.

Reply by email

peter green
to Yury Sidorov
Show quoted text 7 lines
CmdLine as property will be great, but I found that property getter/setter need to be declared before property declaration in the interface part. This will garbage a global namespace with private getters/setters. Is it possible to make compiler to accept getters/setters not declared in the interface part, but implemented in the implementation?

another way to solve this would be to allow use of public and private outside classes.

Reply by email

Daniël Mantione
to Yury Sidorov: From: "Daniël Mantione" I already implemented optimization of CmdLine for smartlinking…

Op Thu, 19 Oct 2006, schreef Yury Sidorov:

Show quoted text 10 lines
I already implemented optimization of CmdLine for smartlinking for WinCE some time ago. It is controlled by HAS_CMDLINE define. And CmdLine is declared as function in WinCE system unit. CmdLine as property will be great, but I found that property getter/setter need to be declared before property declaration in the interface part. This will garbage a global namespace with private getters/setters. Is it possible to make compiler to accept getters/setters not declared in the interface part, but implemented in the implementation?

I think it is not so easy, because the actual implementation (variable, function), affects code that uses the property. The implementation part of the unit does not necessarily have already been compiled when the unit is used.

Daniël

Reply by email

Yury Sidorov
to Daniël Mantione

From: "Daniël Mantione"

Show quoted text 15 lines
> I already implemented optimization of CmdLine for smartlinking for WinCE some > time ago. It is controlled by HAS_CMDLINE define. And CmdLine is declared as > function in WinCE system unit. > > CmdLine as property will be great, but I found that property getter/setter > need to be declared before property declaration in the interface part. This > will garbage a global namespace with private getters/setters. > > Is it possible to make compiler to accept getters/setters not declared in the > interface part, but implemented in the implementation? I think it is not so easy, because the actual implementation (variable, function), affects code that uses the property. The implementation part of the unit does not necessarily have already been compiled when the unit is used.

I see the following way to implement it:

For example the compiler was found the following declaration of global propery:

property DrawMode: integer read GetDrawMode write SetDrawMode;

If GetDrawMode and SetDrawMode was not declared before, the compiler assumes that declaration is standard:

procedure SetDrawMode(const Value: integer);
function GetDrawMode: integer;

The compiler can internally declare setter and getter and mark them like compilerproc (or in other way) to hide from global namespace.

Yury Sidorov.

Reply by email