Browse Source

* Optimization for smartlinking. Removed command line parsing in system unit initialization for wince. The parser is called when command line is accessed first time in program. It saves 1.55KB exe size, when command line is not used.

git-svn-id: trunk@4275 -
yury 19 years ago
parent
commit
7ccca2e438
2 changed files with 51 additions and 27 deletions
  1. 2 0
      rtl/inc/systemh.inc
  2. 49 27
      rtl/wince/system.pp

+ 2 - 0
rtl/inc/systemh.inc

@@ -322,7 +322,9 @@ const
   fmInOut  = $D7B3;
   fmInOut  = $D7B3;
   fmAppend = $D7B4;
   fmAppend = $D7B4;
   Filemode : byte = 2;
   Filemode : byte = 2;
+{$ifndef HAS_CMDLINE}
   CmdLine : PChar = nil;
   CmdLine : PChar = nil;
+{$endif HAS_CMDLINE}
 (* Value should be changed during system initialization as appropriate. *)
 (* Value should be changed during system initialization as appropriate. *)
 
 
   { assume that this program will not spawn other threads, when the
   { assume that this program will not spawn other threads, when the

+ 49 - 27
rtl/wince/system.pp

@@ -23,6 +23,7 @@ interface
 
 
 {$define WINCE_EXCEPTION_HANDLING}
 {$define WINCE_EXCEPTION_HANDLING}
 {$define DISABLE_NO_THREAD_MANAGER}
 {$define DISABLE_NO_THREAD_MANAGER}
+{$define HAS_CMDLINE}
 
 
 { include system-independent routine headers }
 { include system-independent routine headers }
 {$I systemh.inc}
 {$I systemh.inc}
@@ -54,9 +55,6 @@ const
   Thread_count : longint = 0;
   Thread_count : longint = 0;
 
 
 var
 var
-{ C compatible arguments }
-  argc : longint;
-  argv : ppchar;
 { WinCE Info }
 { WinCE Info }
   hprevinst,
   hprevinst,
   MainInstance,
   MainInstance,
@@ -181,6 +179,11 @@ function muls(s1,s2 : single) : single; compilerproc;
 function divs(s1,s2 : single) : single; compilerproc;
 function divs(s1,s2 : single) : single; compilerproc;
 {$endif CPUARM}
 {$endif CPUARM}
 
 
+function CmdLine: PChar;
+{ C compatible arguments }
+function argc: longint;
+function argv: ppchar;
+
 implementation
 implementation
 
 
 var
 var
@@ -556,6 +559,11 @@ begin
   GetCommandFile:=@ModuleName;
   GetCommandFile:=@ModuleName;
 end;
 end;
 
 
+var
+  Fargc: longint;
+  Fargv: ppchar;
+  FCmdLine: PChar;
+  
 procedure setup_arguments;
 procedure setup_arguments;
 var
 var
   arglen,
   arglen,
@@ -573,38 +581,38 @@ var
        begin
        begin
          oldargvlen:=argvlen;
          oldargvlen:=argvlen;
          argvlen:=(idx+8) and (not 7);
          argvlen:=(idx+8) and (not 7);
-         sysreallocmem(argv,argvlen*sizeof(pointer));
-         fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
+         sysreallocmem(Fargv,argvlen*sizeof(pointer));
+         fillchar(Fargv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
        end;
        end;
       { use realloc to reuse already existing memory }
       { use realloc to reuse already existing memory }
       { always allocate, even if length is zero, since }
       { always allocate, even if length is zero, since }
       { the arg. is still present!                     }
       { the arg. is still present!                     }
-      sysreallocmem(argv[idx],len+1);
+      sysreallocmem(Fargv[idx],len+1);
     end;
     end;
 
 
 begin
 begin
   { create commandline, it starts with the executed filename which is argv[0] }
   { create commandline, it starts with the executed filename which is argv[0] }
   { WinCE passes the command NOT via the args, but via getmodulefilename}
   { WinCE passes the command NOT via the args, but via getmodulefilename}
-  argv:=nil;
+  if FCmdLine <> nil then exit;
   argvlen:=0;
   argvlen:=0;
   pc:=getcommandfile;
   pc:=getcommandfile;
   Arglen:=0;
   Arglen:=0;
   while pc[Arglen] <> #0 do
   while pc[Arglen] <> #0 do
     Inc(Arglen);
     Inc(Arglen);
   allocarg(0,arglen);
   allocarg(0,arglen);
-  move(pc^,argv[0]^,arglen+1);
-  { Setup cmdline variable }
+  move(pc^,Fargv[0]^,arglen+1);
+  { Setup FCmdLine variable }
   arg:=PChar(GetCommandLine);
   arg:=PChar(GetCommandLine);
   count:=WideToAnsiBuf(PWideChar(arg), -1, nil, 0);
   count:=WideToAnsiBuf(PWideChar(arg), -1, nil, 0);
-  cmdline:=SysGetMem(arglen + count + 3);
-  cmdline^:='"';
-  move(pc^, (cmdline + 1)^, arglen);
-  (cmdline + arglen + 1)^:='"';
-  (cmdline + arglen + 2)^:=' ';
-  WideToAnsiBuf(PWideChar(arg), -1, cmdline + arglen + 3, count);
+  FCmdLine:=SysGetMem(arglen + count + 3);
+  FCmdLine^:='"';
+  move(pc^, (FCmdLine + 1)^, arglen);
+  (FCmdLine + arglen + 1)^:='"';
+  (FCmdLine + arglen + 2)^:=' ';
+  WideToAnsiBuf(PWideChar(arg), -1, FCmdLine + arglen + 3, count);
   { process arguments }
   { process arguments }
   count:=0;
   count:=0;
-  pc:=cmdline;
+  pc:=FCmdLine;
 {$IfDef SYSTEM_DEBUG_STARTUP}
 {$IfDef SYSTEM_DEBUG_STARTUP}
   Writeln(stderr,'WinCE GetCommandLine is #',pc,'#');
   Writeln(stderr,'WinCE GetCommandLine is #',pc,'#');
 {$EndIf }
 {$EndIf }
@@ -675,7 +683,7 @@ begin
         allocarg(count,arglen);
         allocarg(count,arglen);
         quote:=' ';
         quote:=' ';
         pc:=argstart;
         pc:=argstart;
-        arg:=argv[count];
+        arg:=Fargv[count];
         while (pc^<>#0) do
         while (pc^<>#0) do
          begin
          begin
            case pc^ of
            case pc^ of
@@ -740,17 +748,34 @@ begin
         arg^:=#0;
         arg^:=#0;
       end;
       end;
  {$IfDef SYSTEM_DEBUG_STARTUP}
  {$IfDef SYSTEM_DEBUG_STARTUP}
-     Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
+     Writeln(stderr,'dos arg ',count,' #',arglen,'#',Fargv[count],'#');
  {$EndIf SYSTEM_DEBUG_STARTUP}
  {$EndIf SYSTEM_DEBUG_STARTUP}
      inc(count);
      inc(count);
    end;
    end;
   { get argc and create an nil entry }
   { get argc and create an nil entry }
-  argc:=count;
+  Fargc:=count;
   allocarg(argc,0);
   allocarg(argc,0);
   { free unused memory }
   { free unused memory }
-  sysreallocmem(argv,(argc+1)*sizeof(pointer));
+  sysreallocmem(Fargv,(argc+1)*sizeof(pointer));
+end;
+
+function CmdLine: PChar;
+begin
+  setup_arguments;
+  Result:=FCmdLine;
 end;
 end;
 
 
+function argc: longint;
+begin
+  setup_arguments;
+  Result:=Fargc;
+end;
+
+function argv: ppchar;
+begin
+  setup_arguments;
+  Result:=Fargv;
+end;
 
 
 function paramcount : longint;
 function paramcount : longint;
 begin
 begin
@@ -759,19 +784,18 @@ end;
 
 
 function paramstr(l : longint) : string;
 function paramstr(l : longint) : string;
 begin
 begin
-  if (l>=0) and (l<argc) then
-    paramstr:=strpas(argv[l])
+  setup_arguments;
+  if (l>=0) and (l<Fargc) then
+    paramstr:=strpas(Fargv[l])
   else
   else
     paramstr:='';
     paramstr:='';
 end;
 end;
 
 
-
 procedure randomize;
 procedure randomize;
 begin
 begin
   randseed:=GetTickCount;
   randseed:=GetTickCount;
 end;
 end;
 
 
-
 {*****************************************************************************
 {*****************************************************************************
                          System Dependent Exit code
                          System Dependent Exit code
 *****************************************************************************}
 *****************************************************************************}
@@ -782,7 +806,7 @@ procedure ExitThread(Exitcode : longint); external 'coredll';
 
 
 Procedure system_exit;
 Procedure system_exit;
 begin
 begin
-  SysFreeMem(cmdline);
+  SysFreeMem(FCmdLine);
   { don't call ExitProcess inside
   { don't call ExitProcess inside
     the DLL exit code !!
     the DLL exit code !!
     This crashes Win95 at least PM }
     This crashes Win95 at least PM }
@@ -1694,8 +1718,6 @@ begin
   if not IsLibrary then
   if not IsLibrary then
     begin
     begin
       SysInitStdIO;
       SysInitStdIO;
-      { Arguments }
-      setup_arguments;
     end;
     end;
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;