Prechádzať zdrojové kódy

* Use dyn array for input buffer

Michaël Van Canneyt 4 mesiacov pred
rodič
commit
2f3c0bc8bf
2 zmenil súbory, kde vykonal 28 pridanie a 39 odobranie
  1. 10 21
      compiler/finput.pas
  2. 18 18
      compiler/scanner.pas

+ 10 - 21
compiler/finput.pas

@@ -41,7 +41,7 @@ interface
          inc_path  : TPathStr;       { path if file was included with $I directive }
          next      : tinputfile;    { next file for reading }
 
-         buf          : pchar;      { buffer }
+         buf          : TAnsiCharDynArray;      { buffer }
          bufstart,                  { buffer start position in the file }
          bufsize,                   { amount of bytes in the buffer }
          maxbufsize   : longint;    { size in memory for the buffer }
@@ -277,7 +277,7 @@ uses
         if closed then
          exit;
         inc(bufstart,bufsize);
-        bufsize:=fileread(buf^,maxbufsize-1);
+        bufsize:=fileread(buf[0],maxbufsize-1);
         buf[bufsize]:=#0;
         endoffile:=fileeof;
       end;
@@ -293,7 +293,7 @@ uses
       { file }
         endoffile:=false;
         closed:=false;
-        Getmem(buf,MaxBufsize);
+        SetLength(buf,MaxBufsize);
         buf[0]:=#0;
         bufstart:=0;
         bufsize:=0;
@@ -305,11 +305,7 @@ uses
       begin
         if is_macro then
          begin
-           if assigned(buf) then
-            begin
-              Freemem(buf,maxbufsize);
-              buf:=nil;
-            end;
+           buf:=nil;
            name:='';
            path:='';
            closed:=true;
@@ -321,10 +317,7 @@ uses
            closed:=true;
          end;
         if assigned(buf) then
-          begin
-             Freemem(buf,maxbufsize);
-             buf:=nil;
-          end;
+          buf:=nil;
         bufstart:=0;
       end;
 
@@ -336,11 +329,7 @@ uses
         if not closed then
          begin
            fileclose;
-           if assigned(buf) then
-            begin
-              Freemem(buf,maxbufsize);
-              buf:=nil;
-            end;
+           buf:=nil;
            closed:=true;
          end;
       end;
@@ -366,7 +355,7 @@ uses
          exit;
         closed:=false;
       { get new mem }
-        Getmem(buf,maxbufsize);
+        SetLength(buf,maxbufsize);
       { restore state }
         fileseek(BufStart);
         bufsize:=0;
@@ -378,8 +367,8 @@ uses
     procedure tinputfile.setmacro(p:pchar;len:longint);
       begin
       { create new buffer }
-        getmem(buf,len+1);
-        move(p^,buf^,len);
+        SetLength(buf,len+1);
+        move(p^,buf[0],len);
         buf[len]:=#0;
       { reset }
         bufstart:=0;
@@ -439,7 +428,7 @@ uses
                 if endoffile then
                  break;
                 readbuf;
-                p:=buf;
+                p:=@buf[0];
                 c:=p^;
               end;
              if c in [#10,#13] then

+ 18 - 18
compiler/scanner.pas

@@ -3097,11 +3097,11 @@ type
         openinputfile:=inputfile.open;
       { load buffer }
 {$ifdef CHECK_INPUTPOINTER_LIMITS}
-        hidden_inputbuffer:=inputfile.buf;
-        hidden_inputpointer:=inputfile.buf;
+        hidden_inputbuffer:=PAnsiChar(inputfile.buf);
+        hidden_inputpointer:=PAnsiChar(inputfile.buf);
 {$else not CHECK_INPUTPOINTER_LIMITS}
-        inputbuffer:=inputfile.buf;
-        inputpointer:=inputfile.buf;
+        inputbuffer:=PAnsiChar(inputfile.buf);
+        inputpointer:=PAnsiChar(inputfile.buf);
 {$endif CHECK_INPUTPOINTER_LIMITS}
         inputstart:=inputfile.bufstart;
       { line }
@@ -3140,11 +3140,11 @@ type
         tempopeninputfile:=inputfile.tempopen;
       { reload buffer }
 {$ifdef CHECK_INPUTPOINTER_LIMITS}
-        hidden_inputbuffer:=inputfile.buf;
-        hidden_inputpointer:=inputfile.buf;
+        hidden_inputbuffer:=PAnsiChar(inputfile.buf);
+        hidden_inputpointer:=PAnsiChar(inputfile.buf);
 {$else not CHECK_INPUTPOINTER_LIMITS}
-        inputbuffer:=inputfile.buf;
-        inputpointer:=inputfile.buf;
+        inputbuffer:=PAnsiChar(inputfile.buf);
+        inputpointer:=PAnsiChar(inputfile.buf);
 {$endif CHECK_INPUTPOINTER_LIMITS}
         inputstart:=inputfile.bufstart;
       end;
@@ -3187,10 +3187,10 @@ type
     procedure tscannerfile.restoreinputfile;
       begin
 {$ifdef check_inputpointer_limits}
-        hidden_inputbuffer:=inputfile.buf;
+        hidden_inputbuffer:=PAnsiChar(inputfile.buf);
         hidden_inputpointer:=inputfile.saveinputpointer;
 {$else not check_inputpointer_limits}
-        inputbuffer:=inputfile.buf;
+        inputbuffer:=PAnsiChar(inputfile.buf);
         inputpointer:=inputfile.saveinputpointer;
 {$endif check_inputpointer_limits}
         lastlinepos:=inputfile.savelastlinepos;
@@ -3980,11 +3980,11 @@ type
               begin
                 readbuf;
 {$ifdef CHECK_INPUTPOINTER_LIMITS}
-                hidden_inputpointer:=buf;
-                hidden_inputbuffer:=buf;
+                hidden_inputpointer:=PAnsiChar(buf);
+                hidden_inputbuffer:=PAnsiChar(buf);
 {$else not CHECK_INPUTPOINTER_LIMITS}
-                inputpointer:=buf;
-                inputbuffer:=buf;
+                inputpointer:=PAnsiChar(buf);
+                inputbuffer:=PAnsiChar(buf);
 {$endif CHECK_INPUTPOINTER_LIMITS}
                 inputstart:=bufstart;
               { first line? }
@@ -4096,11 +4096,11 @@ type
            setmacro(p,len);
          { local buffer }
 {$ifdef CHECK_INPUTPOINTER_LIMITS}
-           hidden_inputbuffer:=buf;
-           hidden_inputpointer:=buf;
+           hidden_inputbuffer:=PAnsiChar(buf);
+           hidden_inputpointer:=PAnsiChar(buf);
 {$else not CHECK_INPUTPOINTER_LIMITS}
-           inputbuffer:=buf;
-           inputpointer:=buf;
+           inputbuffer:=PAnsiChar(buf);
+           inputpointer:=PAnsiChar(buf);
 {$endif CHECK_INPUTPOINTER_LIMITS}
            inputstart:=bufstart;
            ref_index:=fileindex;