Sign in Join

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

Mailing lists / fpc-devel / 2006-10

Typed addresses by default

20 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Micha Nelissen

Hi,

Attached patch modifies compiler to enable typed addresses ({$T+}) for fpc and objfpc modes by default. It fixes the rtl and compiler to compile again. Most of these fixes are simple pointer to array vs. pointer to element of array changes, but some reveal ugly code IMHO ;-).

Anyway, any opinions on whether it is useful to enforce typed addresses by default ?

Micha

Reply by email

Florian Klaempfl
to Micha Nelissen
Show quoted text 9 lines
Hi, Attached patch modifies compiler to enable typed addresses ({$T+}) for fpc and objfpc modes by default. It fixes the rtl and compiler to compile again. Most of these fixes are simple pointer to array vs. pointer to element of array changes, but some reveal ugly code IMHO ;-). Anyway, any opinions on whether it is useful to enforce typed addresses by default ?

For me, it is ok, to apply it in objfpc and fpc mode. T- enforces sloppy programming which we don't want after all ;)

Show quoted text 879 lines
Micha ------------------------------------------------------------------------ Index: rtl/unix/unix.pp =================================================================== --- rtl/unix/unix.pp (revision 4765) +++ rtl/unix/unix.pp (working copy) @@ -858,7 +858,7 @@ end; textrec(f)(f).buffer; {Save the process ID - needed when closing } - pl:=@(textrec(f).userdata[2]); + pl:=pcint(@(textrec(f).userdata[2])); pl^:=pid; textrec(f); end; @@ -971,7 +971,7 @@ f:=pipi; end; {Save the process ID - needed when closing } - pl:=@(filerec(f).userdata[2]); + pl:=pcint(@(filerec(f).userdata[2])); pl^:=pid; end; POpen:=0; @@ -1034,11 +1034,11 @@ close(pipo); close(pipi); {Save the process ID - needed when closing } - pl:=@(textrec(StreamIn).userdata[2]); + pl:=pcint(@(textrec(StreamIn).userdata[2])); pl^:=pid; textrec(StreamIn); {Save the process ID - needed when closing } - pl:=@(textrec(StreamOut).userdata[2]); + pl:=pcint(@(textrec(StreamOut).userdata[2])); pl^:=pid; textrec(StreamOut); AssignStream:=Pid; @@ -1124,15 +1124,15 @@ Close(PipeOut); Close(PipeIn); // Save the process ID - needed when closing - pl := @(TextRec(StreamIn).userdata[2]); + pl := pcint(@(TextRec(StreamIn).userdata[2])); pl^ := pid; TextRec(StreamIn).closefunc := @PCloseText; // Save the process ID - needed when closing - pl := @(TextRec(StreamOut).userdata[2]); + pl := pcint(@(TextRec(StreamOut).userdata[2])); pl^ := pid; TextRec(StreamOut).closefunc := @PCloseText; // Save the process ID - needed when closing - pl := @(TextRec(StreamErr).userdata[2]); + pl := pcint(@(TextRec(StreamErr).userdata[2])); pl^ := pid; TextRec(StreamErr).closefunc := @PCloseText; AssignStream := pid; Index: rtl/unix/cthreads.pp =================================================================== --- rtl/unix/cthreads.pp (revision 4765) +++ rtl/unix/cthreads.pp (working copy) @@ -223,7 +223,7 @@ // don't create detached, we need to be able to join (waitfor) on // the newly created thread! //pthread_attr_setdetachstate(@thread_attr, PTHREAD_CREATE_DETACHED); - if pthread_create(@threadid, @thread_attr, @ThreadMain,ti) 0 then begin + if pthread_create(ppthread_t(@threadid), @thread_attr, @ThreadMain,ti) 0 then begin threadid := TThreadID(0); end; CBeginThread:=threadid; Index: rtl/unix/cwstring.pp =================================================================== --- rtl/unix/cwstring.pp (revision 4765) +++ rtl/unix/cwstring.pp (working copy) @@ -153,7 +153,7 @@ destpos:=pchar(dest); outleft:=outlength; lockiconv(lock_wide2ansi); - while iconv(iconv_wide2ansi,@srcpos,@srclen,@destpos,@outleft)=size_t(-1) do + while iconv(iconv_wide2ansi,ppchar(@srcpos),@srclen,@destpos,@outleft)=size_t(-1) do begin case fpgetCerrno of ESysEILSEQ: @@ -210,7 +210,7 @@ destpos:=pchar(dest); outleft:=outlength*2; lockiconv(lock_ansi2wide); - while iconv(iconv_ansi2wide,@srcpos,@len,@destpos,@outleft)=size_t(-1) do + while iconv(iconv_ansi2wide,@srcpos,psize(@len),@destpos,@outleft)=size_t(-1) do begin case fpgetCerrno of ESysEILSEQ: @@ -286,7 +286,7 @@ destpos:=pchar(dest); outleft:=outlength*4; lockiconv(lock_ansi2ucs4); - while iconv(iconv_ansi2ucs4,@srcpos,@len,@destpos,@outleft)=size_t(-1) do + while iconv(iconv_ansi2ucs4,@srcpos,psize(@len),@destpos,@outleft)=size_t(-1) do begin case fpgetCerrno of ESysE2BIG: Index: rtl/unix/sysdir.inc =================================================================== --- rtl/unix/sysdir.inc (revision 4765) +++ rtl/unix/sysdir.inc (working copy) @@ -32,7 +32,7 @@ exit; Move(s[1], Buffer, Length(s)); Buffer[Length(s)] := #0; - If Fpmkdir(@buffer, MODE_MKDIR)<0 Then + If Fpmkdir(@buffer[0], MODE_MKDIR)<0 Then Errno2Inoutres Else InOutRes:=0; @@ -49,7 +49,7 @@ exit; Move(s[1], Buffer, Length(s)); Buffer[Length(s)] := #0; - If Fprmdir(@buffer)<0 Then + If Fprmdir(@buffer[0])<0 Then Errno2Inoutres Else InOutRes:=0; @@ -64,7 +64,7 @@ exit; Move(s[1], Buffer, Length(s)); Buffer[Length(s)] := #0; - If Fpchdir(@buffer)<0 Then + If Fpchdir(@buffer[0])<0 Then Errno2Inoutres Else InOutRes:=0; @@ -93,7 +93,7 @@ begin dir:=''; {$ifdef usegetcwd} - if Fpgetcwd(@buf,sizeof(buf))nil then + if Fpgetcwd(@buf[0],sizeof(buf))nil then dir:=strpas(buf); {$else} thedir:=''; Index: rtl/unix/dos.pp =================================================================== --- rtl/unix/dos.pp (revision 4765) +++ rtl/unix/dos.pp (working copy) @@ -648,7 +648,7 @@ Move(f.SearchSpec[1], DirName[0], f.NamePos); DirName[f.NamePos] := #0; End; - f.DirPtr := fpopendir(@(DirName)); + f.DirPtr := fpopendir(@DirName[0]); If f.DirPtr nil Then begin ArrayPos:=FindLastUsed; @@ -673,7 +673,7 @@ if p=nil then FName:='' else - FName:=Strpas(@p^.d_name); + FName:=Strpas(@p^.d_name[0]); If FName='' Then Finished:=True Else @@ -767,7 +767,7 @@ LinAttr : longint; Begin DosError:=0; - if FPStat(@textrec(f).name,info)<0 then + if FPStat(@textrec(f).name[0],info)<0 then begin Attr:=0; DosError:=3; @@ -779,7 +779,7 @@ Attr:=$10 else Attr:=$0; - if fpAccess(@textrec(f).name,W_OK)<0 then + if fpAccess(@textrec(f).name[0],W_OK)<0 then Attr:=Attr or $1; if filerec(f).name[0]='.' then Attr:=Attr or $2; @@ -816,7 +816,7 @@ UnPackTime(Time,DT); modtime:=DTToUnixDate(DT); end; - if fputime(@filerec(f).name,@utim)<0 then + if fputime(@filerec(f).name[0],@utim)<0 then begin Time:=0; doserror:=3; Index: rtl/linux/gpm.pp =================================================================== --- rtl/linux/gpm.pp (revision 4765) +++ rtl/linux/gpm.pp (working copy) @@ -534,7 +534,7 @@ strcopy(addr.path, GPM_NODE_CTL); i:=sizeof(addr.family)+length(GPM_NODE_CTL); - if fpconnect(gpm_fd,@addr,i)<0 then + if fpconnect(gpm_fd,psockaddr(@addr),i)<0 then begin { gpm_report(GPM_PR_INFO,GPM_MESS_DOUBLE_S,GPM_NODE_CTL,strerror(errno));} {Well, try to open a chr device called /dev/gpmctl. This should Index: rtl/linux/unxfunc.inc =================================================================== --- rtl/linux/unxfunc.inc (revision 4765) +++ rtl/linux/unxfunc.inc (working copy) @@ -33,13 +33,13 @@ Function PClose(Var F:text) :cint; var - pl : ^cint; + pl : pcint; res : cint; pid : cint; begin fpclose(Textrec(F).Handle); { closed our side, Now wait for the other - this appears to be needed ?? } - pl:=@(textrec(f).userdata[2]); + pl:=pcint(@(textrec(f).userdata[2])); { avoid alignment error on sparc } move(pl^,pid,sizeof(pid)); fpwaitpid(pid,@res,0); @@ -54,7 +54,7 @@ begin fpclose(filerec(F).Handle); { closed our side, Now wait for the other - this appears to be needed ?? } - pl:=@(filerec(f).userdata[2]); + pl:=pcint(@(filerec(f).userdata[2])); { avoid alignment error on sparc } move(pl^,pid,sizeof(pid)); fpwaitpid(pid,@res,0); Index: rtl/linux/oldlinux.pp =================================================================== --- rtl/linux/oldlinux.pp (revision 4765) +++ rtl/linux/oldlinux.pp (working copy) @@ -2792,7 +2792,7 @@ sr.reg2:=Textrec(F).Handle; SysCall (syscall_nr_close,sr); { closed our side, Now wait for the other - this appears to be needed ?? } - pl:=@(textrec(f).userdata[2]); + pl:=plongint(@(textrec(f).userdata[2])); waitpid(pl^,@res,0); pclose:=res shr 8; end; @@ -2807,7 +2807,7 @@ sr.reg2:=FileRec(F).Handle; SysCall (Syscall_nr_close,sr); { closed our side, Now wait for the other - this appears to be needed ?? } - pl:=@(filerec(f).userdata[2]); + pl:=plongint(@(filerec(f).userdata[2])); waitpid(pl^,@res,0); pclose:=res shr 8; end; @@ -4516,7 +4516,7 @@ textrec(f)(f).buffer; end; {Save the process ID - needed when closing } - pl:=@(textrec(f).userdata[2]); + pl:=plongint(@(textrec(f).userdata[2])); pl^:=pid; textrec(f); end; @@ -4602,7 +4602,7 @@ f:=pipi; end; {Save the process ID - needed when closing } - pl:=@(filerec(f).userdata[2]); + pl:=plongint(@(filerec(f).userdata[2])); pl^:=pid; end; end; @@ -4666,11 +4666,11 @@ close(pipo); close(pipi); {Save the process ID - needed when closing } - pl:=@(textrec(StreamIn).userdata[2]); + pl:=plongint(@(textrec(StreamIn).userdata[2])); pl^:=pid; textrec(StreamIn); {Save the process ID - needed when closing } - pl:=@(textrec(StreamOut).userdata[2]); + pl:=plongint(@(textrec(StreamOut).userdata[2])); pl^:=pid; textrec(StreamOut); AssignStream:=Pid; @@ -4757,15 +4757,15 @@ Close(PipeOut); Close(PipeIn); // Save the process ID - needed when closing - pl := @(TextRec(StreamIn).userdata[2]); + pl := plongint(@(TextRec(StreamIn).userdata[2])); pl^ := pid; TextRec(StreamIn).closefunc := @PCloseText; // Save the process ID - needed when closing - pl := @(TextRec(StreamOut).userdata[2]); + pl := plongint(@(TextRec(StreamOut).userdata[2])); pl^ := pid; TextRec(StreamOut).closefunc := @PCloseText; // Save the process ID - needed when closing - pl := @(TextRec(StreamErr).userdata[2]); + pl := plongint(@(TextRec(StreamErr).userdata[2])); pl^ := pid; TextRec(StreamErr).closefunc := @PCloseText; AssignStream := pid; @@ -5059,15 +5059,15 @@ d:=Readdir(dirstream); while (dnil) do begin - name:=n+'/'+strpas(@(d^.name)); + name:=n+'/'+strpas(@(d^.name[0])); fstat(name,st); if linuxerror=0 then begin if ((st.mode and $E000)=$4000) and { if it is a directory } - (strpas(@(d^.name))'.') and { but not ., .. and fd subdirs } - (strpas(@(d^.name))'..') and - (strpas(@(d^.name))'') and - (strpas(@(d^.name))'fd') then + (strpas(@(d^.name[0]))'.') and { but not ., .. and fd subdirs } + (strpas(@(d^.name[0]))'..') and + (strpas(@(d^.name[0]))'') and + (strpas(@(d^.name[0]))'fd') then begin {we found a directory, search inside it} if mysearch(name) then begin {the device is here} Index: rtl/inc/mouse.inc =================================================================== --- rtl/inc/mouse.inc (revision 4765) +++ rtl/inc/mouse.inc (working copy) @@ -25,8 +25,8 @@ Procedure ClearMouseEventQueue; begin - ; - ; + ; + ; PendingMouseEvents:=0; FillChar(LastMouseEvent,sizeof(TMouseEvent),0); end; @@ -119,7 +119,7 @@ MouseEvent:=PendingMouseHead^; inc(PendingMouseHead); if PtrInt(PendingMouseHead)=Ptrint(@PendingMouseEvent)+sizeof(PendingMouseEvent) then - ; + ; dec(PendingMouseEvents); if (LastMouseEvent.xMouseEvent.x) or (LastMouseEvent.yMouseEvent.y) then @@ -162,7 +162,7 @@ PendingMouseTail^:=MouseEvent; inc(PendingMouseTail); if PtrInt(PendingMouseTail)=Ptrint(@PendingMouseEvent)+sizeof(PendingMouseEvent) then - ; + ; inc(PendingMouseEvents); end else Index: rtl/inc/variants.pp =================================================================== --- rtl/inc/variants.pp (revision 4765) +++ rtl/inc/variants.pp (working copy) @@ -3481,7 +3481,7 @@ function FindVarData(const V: Variant): PVarData; begin - ; + result:=pvardata(@V); while result^.vtype=varVariant or VarByRef do result:=PVarData(result^.VPointer); end; Index: rtl/inc/text.inc =================================================================== --- rtl/inc/text.inc (revision 4765) +++ rtl/inc/text.inc (working copy) @@ -939,7 +939,7 @@ inc(p);} while p<maxp do begin - ; + ; while (q^#0) and (p^q^) do inc(q); if p^=q^ then Index: rtl/inc/objects.pp =================================================================== --- rtl/inc/objects.pp (revision 4765) +++ rtl/inc/objects.pp (working copy) @@ -981,13 +981,14 @@ FUNCTION TObject.Is_Object(P:Pointer):Boolean; TYPE PVMT=^VMT; + PPVMT=^PVMT; VMT=RECORD Size,NegSize:Longint; ParentLink:PVMT; END; -VAR SP:^PVMT; Q:PVMT; +VAR SP:PPVMT; Q:PVMT; BEGIN - ; + SP:=PPVMT(@SELF); Q:=SP^; Is_Object:=False; While QNil Do Begin Index: rtl/inc/objpas.inc =================================================================== --- rtl/inc/objpas.inc (revision 4765) +++ rtl/inc/objpas.inc (working copy) @@ -303,7 +303,7 @@ FieldTable := PFieldTable((Pointer(CurClassType) + vmtFieldTable)^); if FieldTable nil then begin - FieldInfo := @FieldTable^.Fields; + FieldInfo := @FieldTable^.Fields[0]; for i := 0 to FieldTable^.FieldCount - 1 do begin if UpCase(FieldInfo^.Name) = UName then @@ -311,7 +311,7 @@ fieldaddress := Pointer(Self) + FieldInfo^.FieldOffset; exit; end; - FieldInfo := @FieldInfo^.Name + 1 + Length(FieldInfo^.Name); + FieldInfo := PFieldInfo(PByte(@FieldInfo^.Name) + 1 + Length(FieldInfo^.Name)); {$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} { align to largest field of TFieldInfo } FieldInfo := Align(FieldInfo, SizeOf(PtrUInt)); Index: rtl/inc/sockovl.inc =================================================================== --- rtl/inc/sockovl.inc (revision 4765) +++ rtl/inc/sockovl.inc (working copy) @@ -42,7 +42,7 @@ Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr ; var AddrLen :longint) : longint; begin - RecvFrom:=fprecvfrom(Sock,@buf,buflen,flags,@Addr,@AddrLen); + RecvFrom:=fprecvfrom(Sock,@buf,buflen,flags,@Addr,psocklen(@AddrLen)); end; Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean; @@ -57,7 +57,7 @@ Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; begin - Accept:=fpaccept(sock,@addr,@addrlen); + Accept:=fpaccept(sock,@addr,psocklen(@addrlen)); end; Function Connect(Sock:Longint;Const Addr;Addrlen:Longint): boolean; @@ -73,12 +73,12 @@ Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; begin - GetSocketName:=fpgetsockname(sock,@addr,@addrlen); + GetSocketName:=fpgetsockname(sock,@addr,psocklen(@addrlen)); end; Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; begin - GetPeerName:=fpgetPeerName(sock,@addr,@addrlen); + GetPeerName:=fpgetPeerName(sock,@addr,psocklen(@addrlen)); end; Function SetSocketOptions(Sock,Level,OptName:Longint;const OptVal;optlen:longint):Longint; @@ -88,12 +88,12 @@ Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint; begin - GetSocketOptions:=fpgetsockopt(Sock,Level,OptName,@OptVal,@OptLen); + GetSocketOptions:=fpgetsockopt(Sock,Level,OptName,@OptVal,psocklen(@OptLen)); end; Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint; begin - SocketPair:=fpsocketpair(domain,sockettype,protocol,@pair); + SocketPair:=fpsocketpair(domain,sockettype,protocol,@pair[1]); end; {****************************************************************************** Index: rtl/inc/dynarr.inc =================================================================== --- rtl/inc/dynarr.inc (revision 4765) +++ rtl/inc/dynarr.inc (working copy) @@ -340,18 +340,18 @@ procedure DynArraySetLength(var a: Pointer; typeInfo: Pointer; dimCnt: SizeInt; lengthVec: PSizeInt); var - preallocated : array[0..10] of PSizeInt; + preallocated : array[0..10] of SizeInt; i : SizeInt; p : PSizeInt; begin if dimCnt<=length(preallocated) then - + else getmem(p,sizeof(SizeInt)*dimCnt); for i:=0 to dimCnt-1 do p[i]:=lengthVec[dimCnt-1-i]; int_dynarray_setlength(a,typeInfo,dimCnt,p); - if then + if then freemem(p); end; Index: rtl/objpas/sysutils/sysstr.inc =================================================================== --- rtl/objpas/sysutils/sysstr.inc (revision 4765) +++ rtl/objpas/sysutils/sysstr.inc (working copy) @@ -1921,7 +1921,7 @@ Begin Buf[FloatToTextFmt(@Buf[0],Value,Pchar(Format))]:=#0; - Result:=StrPas(@Buf); + Result:=StrPas(@Buf[0]); End; function FormatCurr(const Format: string; Value: Currency): string; Index: rtl/objpas/sysutils/dati.inc =================================================================== --- rtl/objpas/sysutils/dati.inc (revision 4765) +++ rtl/objpas/sysutils/dati.inc (working copy) @@ -708,10 +708,10 @@ DecodeDateFully(DateTime, Year, Month, Day, DayOfWeek); DecodeTime(DateTime, Hour, Minute, Second, MilliSecond); ResultLen := 0; - ResultCurrent := @ResultBuffer; + ResultCurrent := @ResultBuffer[0]; StoreFormat(FormatStr); ResultBuffer[ResultLen] := #0; - result := StrPas(@ResultBuffer); + result := StrPas(@ResultBuffer[0]); end ; { DateTimeToString formats DateTime to the given format in FormatStr } Index: rtl/objpas/sysutils/sysuintf.inc =================================================================== --- rtl/objpas/sysutils/sysuintf.inc (revision 4765) +++ rtl/objpas/sysutils/sysuintf.inc (working copy) @@ -73,19 +73,20 @@ end; end; - function HexByte(p: PChar): Char; + function HexByte(p: PChar): Byte; begin - Result:=Char((HexChar(p[0]) shl 4) + HexChar(p[1])); + Result:=(HexChar(p[0]) shl 4) + HexChar(p[1]); end; var i: integer; - src, dest: PChar; + src: PChar; + dest: PByte; begin if ((Length(S)38) or (s[1]'{')) then raise EConvertError.CreateFmt(SInvalidGUID, [s]); - ; + ; src:=PChar(s); inc(src); for i:=0 to 3 do Index: rtl/objpas/typinfo.pp =================================================================== --- rtl/objpas/typinfo.pp (revision 4765) +++ rtl/objpas/typinfo.pp (working copy) @@ -500,7 +500,7 @@ hp:=GetTypeData(Typeinfo); // the class info rtti the property rtti follows immediatly pd:=aligntoptr(pointer(pointer(@hp^.UnitName)+Length(hp^.UnitName)+1)); - ; + Result:=PPropInfo(@pd^.PropList); for i:=1 to pd^.PropCount do begin // found a property of that name ? Index: compiler/cutils.pas =================================================================== --- compiler/cutils.pas (revision 4765) +++ compiler/cutils.pas (working copy) @@ -842,7 +842,7 @@ i:=1; len:=0; varcounter:=0; - ; + ; while i<=length(s) do begin if (s[i]='$') and (i<length(s)) then @@ -863,7 +863,7 @@ inc(i); until s[i]='}'; varvalues[varcounter]:=Pstring(varptr); - if varptr>@varvaluedata+maxdata then + if varptr>@varvaluedata[0]+maxdata then internalerrorproc(200411152); Pstring(varptr)^:=get_var_value(varname); inc(len,length(Pstring(varptr)^)); Index: compiler/cp8859_1.pas =================================================================== --- compiler/cp8859_1.pas (revision 4765) +++ compiler/cp8859_1.pas (working copy) @@ -270,7 +270,7 @@ unicodemap : tunicodemap = ( cpname : '8859-1'; - map : @map; + map : @map[0]; lastchar : 255; next : nil; internalmap : true Index: compiler/cp850.pas =================================================================== --- compiler/cp850.pas (revision 4765) +++ compiler/cp850.pas (working copy) @@ -270,7 +270,7 @@ unicodemap : tunicodemap = ( cpname : 'cp850'; - map : @map; + map : @map[0]; lastchar : 255; next : nil; internalmap : true Index: compiler/globals.pas =================================================================== --- compiler/globals.pas (revision 4765) +++ compiler/globals.pas (working copy) @@ -1816,7 +1816,7 @@ var p: pbyte; begin - p := @r; + p := pbyte(@r); {$ifdef CPU_ARM} inc(p,4); {$else} Index: compiler/ncal.pas =================================================================== --- compiler/ncal.pas (revision 4765) +++ compiler/ncal.pas (working copy) @@ -1411,12 +1411,14 @@ result:=vmttree; end; + type + pcallparanode = ^tcallparanode; procedure tcallnode.bind_parasym; var i : integer; pt : tcallparanode; - oldppt : ^tcallparanode; + oldppt : pcallparanode; varargspara, currpara : tparavarsym; used_by_callnode : boolean; @@ -1425,14 +1427,14 @@ temp : ttempcreatenode; begin pt:=tcallparanode(left); - ; + oldppt:=pcallparanode(@left); { flag all callparanodes that belong to the varargs } i:=paralength; while (i>procdefinition.maxparacount) do begin include(pt.callparaflags,cpf_varargs_para); - ; + oldppt:=pcallparanode(@pt.right); pt:=tcallparanode(pt.right); dec(i); end; @@ -1518,7 +1520,7 @@ if not assigned(pt) then internalerror(200310052); pt.parasym:=currpara; - ; + oldppt:=pcallparanode(@pt.right); pt:=tcallparanode(pt.right); end; Index: compiler/cp437.pas =================================================================== --- compiler/cp437.pas (revision 4765) +++ compiler/cp437.pas (working copy) @@ -270,7 +270,7 @@ unicodemap : tunicodemap = ( cpname : 'cp437'; - map : @map; + map : @map[0]; lastchar : 255; next : nil; internalmap : true Index: compiler/scanner.pas =================================================================== --- compiler/scanner.pas (revision 4765) +++ compiler/scanner.pas (working copy) @@ -269,12 +269,14 @@ if s='TP' then aktmodeswitches:=tpmodeswitches else - if s='FPC' then - aktmodeswitches:=fpcmodeswitches - else - if s='OBJFPC' then - aktmodeswitches:=objfpcmodeswitches - else + if s='FPC' then begin + aktmodeswitches:=fpcmodeswitches; + include(aktlocalswitches, cs_typed_addresses); + end else + if s='OBJFPC' then begin + aktmodeswitches:=objfpcmodeswitches; + include(aktlocalswitches, cs_typed_addresses); + end else if s='GPC' then aktmodeswitches:=gpcmodeswitches else Index: compiler/systems/t_emx.pas =================================================================== --- compiler/systems/t_emx.pas (revision 4765) +++ compiler/systems/t_emx.pas (working copy) @@ -115,7 +115,7 @@ end; var aout_str_size:longint; - aout_str_tab:array[0..2047] of byte; + aout_str_tab:array[0..2047] of char; aout_sym_count:longint; aout_sym_tab:array[0..5] of nlist; @@ -258,7 +258,7 @@ blockwrite(out_file,aout_text,aout_text_size); blockwrite(out_file,aout_treloc_tab,sizeof(reloc)*aout_treloc_count); blockwrite(out_file,aout_sym_tab,sizeof(aout_sym_tab[0])*aout_sym_count); - longint((@aout_str_tab)^):=aout_str_size; + plongint(@aout_str_tab)^:=aout_str_size; blockwrite(out_file,aout_str_tab,aout_str_size); end; Index: compiler/systems/t_os2.pas =================================================================== --- compiler/systems/t_os2.pas (revision 4765) +++ compiler/systems/t_os2.pas (working copy) @@ -115,7 +115,7 @@ end; var aout_str_size:longint; - aout_str_tab:array[0..2047] of byte; + aout_str_tab:array[0..2047] of char; aout_sym_count:longint; aout_sym_tab:array[0..5] of nlist; @@ -258,7 +258,7 @@ blockwrite(out_file,aout_text,aout_text_size); blockwrite(out_file,aout_treloc_tab,sizeof(reloc)*aout_treloc_count); blockwrite(out_file,aout_sym_tab,sizeof(aout_sym_tab[0])*aout_sym_count); - longint((@aout_str_tab)^):=aout_str_size; + plongint(@aout_str_tab)^:=aout_str_size; blockwrite(out_file,aout_str_tab,aout_str_size); end; Index: compiler/x86/aasmcpu.pas =================================================================== --- compiler/x86/aasmcpu.pas (revision 4765) +++ compiler/x86/aasmcpu.pas (working copy) @@ -1550,7 +1550,7 @@ ea_data : ea; begin len:=0; - ; + ; repeat c:=ord(codes^); inc(codes); @@ -1707,7 +1707,7 @@ $0, $A, $A, $B, $8, $4); var c : byte; - pb, + pb : pbyte; codes : pchar; bytes : array[0..3] of byte; rfield, @@ -1936,16 +1936,16 @@ if not process_ea(oper[opidx]^,ea_data,rfield) then Message(asmw_e_invalid_effective_address); - ; - pb^:=chr(ea_data.modrm); + ; + pb^:=ea_data.modrm; inc(pb); if ea_data.sib_present then begin - pb^:=chr(ea_data.sib); + pb^:=ea_data.sib; inc(pb); end; - s:=pb-pchar(@bytes); + ; objdata.writebytes(bytes,s); case ea_data.bytes of Index: compiler/nadd.pas =================================================================== --- compiler/nadd.pas (revision 4765) +++ compiler/nadd.pas (working copy) @@ -606,8 +606,8 @@ c2[0]:=char(byte(tordconstnode(right).value)); c2[1]:=#0; l2:=1; - ; - ; + ; + ; concatstrings:=true; end else if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then @@ -616,7 +616,7 @@ l1:=tstringconstnode(left).len; c2[0]:=char(byte(tordconstnode(right).value)); c2[1]:=#0; - ; + ; l2:=1; concatstrings:=true; end @@ -625,7 +625,7 @@ c1[0]:=char(byte(tordconstnode(left).value)); c1[1]:=#0; l1:=1; - ; + ; s2:=tstringconstnode(right).value_str; l2:=tstringconstnode(right).len; concatstrings:=true; Index: compiler/utils/fpcmkcfg.pp =================================================================== --- compiler/utils/fpcmkcfg.pp (revision 4765) +++ compiler/utils/fpcmkcfg.pp (working copy) @@ -82,7 +82,7 @@ AddToList(List,'BUILDDATE',DateToStr(Date)); AddToList(List,'BUILDTIME',TimeToStr(Time)); Cfg:=TStringList.Create; - Cfg.Text:=StrPas(Addr(DefaultConfig)); + Cfg.Text:=StrPas(Addr(DefaultConfig[0][1])); end; Procedure Done; @@ -190,9 +190,9 @@ begin case IDEBuildin of 1: - Cfg.Text:=StrPas(Addr(fpcfg)); + Cfg.Text:=StrPas(Addr(fpcfg[0][1])); 2: - Cfg.Text:=StrPas(Addr(fpini)); + Cfg.Text:=StrPas(Addr(fpini[0][1])); end; AddToList(List,'TEMPLATEFILE','builtin'); ------------------------------------------------------------------------ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote 12 lines
> Attached patch modifies compiler to enable typed addresses ({$T+}) > for > fpc and objfpc modes by default. It fixes the rtl and compiler to > compile again. Most of these fixes are simple pointer to array vs. > pointer to element of array changes, but some reveal ugly code > IMHO ;-). > Anyway, any opinions on whether it is useful to enforce typed > addresses > by default ? For me, it is ok, to apply it in objfpc and fpc mode. T- enforces sloppy programming which we don't want after all ;)

Can someone fix the testsuite failures resulting from this?

Jonas

Moderator hat on: please don't quote the entire (in this case 35KB) mail when replying.

Reply by email

Ivo Steinmann
to Florian Klaempfl: For me, it is ok, to apply it in objfpc and fpc mode. T- enforces sloppy programming…
Show quoted text 9 lines
> Hi, > > Attached patch modifies compiler to enable typed addresses ({$T+}) for > fpc and objfpc modes by default. It fixes the rtl and compiler to > compile again. Most of these fixes are simple pointer to array vs. > pointer to element of array changes, but some reveal ugly code IMHO ;-). > > Anyway, any opinions on whether it is useful to enforce typed addresses > by default ?

Well, it's a good idea to enable typed addresses by default, but I have got one problem with that. The pointer to an array of a type should be allowed to assign to the pointer of the same type.

Example

T: array[-10..10] of Integer;
P: PInteger;
// is not allowed now
P := @T;
// is not a replace for
P := @T[0];
// is a dirty replace
P := Pointer(@T);
// is the right replace
P := @T[Low(T)];

I request that "P := @T;" should be allowed, because a pointer type in objfpc mode are also treated as pointer to an array of that type, that means P[...] is allways allowed also.

greets
Ivo Steinmann (Aison)

Reply by email

Micha Nelissen
to Ivo Steinmann
Ivo Steinmann wrote 12 lines
Well, it's a good idea to enable typed addresses by default, but I have got one problem with that. The pointer to an array of a type should be allowed to assign to the pointer of the same type. Example T: array[-10..10] of Integer; P: PInteger; I request that "P := @T;" should be allowed, because a pointer type in objfpc mode are also treated as pointer to an array of that type, that means P[...] is allways allowed also.

Just a note, there will be 3 ways to write the same thing then:

P := T;
P := @T;
P := @T[Low(T)];

A bit odd, no ? Although in all cases it's quite clear what is meant, but I don't know if this "scales" to more complex expressions ?

Micha

Reply by email

Christian Iversen
to Micha Nelissen
Micha Nelissen wrote 17 lines
Ivo Steinmann wrote: > Well, it's a good idea to enable typed addresses by default, but I have > got one problem with that. The pointer to an array of a type should be > allowed to assign to the pointer of the same type. > > Example > > T: array[-10..10] of Integer; > P: PInteger; > > I request that "P := @T;" should be allowed, because a pointer type in > objfpc mode are also treated as pointer to an array of that type, that > means P[...] is allways allowed also. Just a note, there will be 3 ways to write the same thing then: P := T;

Is this really compatible? I think not.

P := @T;

Not compatible.

P := @T[Low(T)];

Too long :)

A bit odd, no ? Although in all cases it's quite clear what is meant, but I don't know if this "scales" to more complex expressions ?

This is not the same thing :)

Regards, Christian Iversen

Reply by email

Vincent Snijders
to Micha Nelissen: Just a note, there will be 3 ways to write the same thing then: P := T; P := @T; P :=…
Micha Nelissen wrote 19 lines
Ivo Steinmann wrote: > Well, it's a good idea to enable typed addresses by default, but I > have got one problem with that. The pointer to an array of a type > should be allowed to assign to the pointer of the same type. > > Example > > T: array[-10..10] of Integer; > P: PInteger; > > I request that "P := @T;" should be allowed, because a pointer type in > objfpc mode are also treated as pointer to an array of that type, that > means P[...] is allways allowed also. Just a note, there will be 3 ways to write the same thing then: P := T;

This only compiles without errors if Low(T)=0.

Show quoted text 5 lines
P := @T; P := @T[Low(T)]; A bit odd, no ? Although in all cases it's quite clear what is meant, but I don't know if this "scales" to more complex expressions ?

Vincent

Reply by email

Vincent Snijders
to Jonas Maebe: Can someone fix the testsuite failures resulting from this? Jonas Moderator hat on:…
Jonas Maebe wrote 18 lines
On 4 okt 2006, at 22:01, Florian Klaempfl wrote: >> Attached patch modifies compiler to enable typed addresses ({$T+}) for >> fpc and objfpc modes by default. It fixes the rtl and compiler to >> compile again. Most of these fixes are simple pointer to array vs. >> pointer to element of array changes, but some reveal ugly code IMHO >> ;-). >> Anyway, any opinions on whether it is useful to enforce typed addresses >> by default ? > > > For me, it is ok, to apply it in objfpc and fpc mode. T- enforces > sloppy programming which we don't want after all ;) Can someone fix the testsuite failures resulting from this?

Are there any testsuite failures with typeinfo. Lazarus crashes at startup when accessing the typeinfo. It could be that our code is wrong now, but maybe wrong typeinfo is generated.

rogram received signal SIGSEGV, Segmentation fault. $0081c8cb in TYPINFO_GETPROPINFOS$PTYPEINFO$PPROPLIST () (gdb) bt
#0 $0081c8cb in TYPINFO_GETPROPINFOS$PTYPEINFO$PPROPLIST () #1 $006e1e2c in
PROPEDITS_TDUMMYCLASSFORPROPTYPES_$__CREATE$$TDUMMYCLASSFORPROPTYPES () #2 $006df891 in PROPEDITS_INITPROPEDITS ()
#3 $006deac7 in PROPEDITS_init ()
#4 $007ff822 in fpc_initializeunits ()
#5 $007f189e in main ()

Vincent

Reply by email

Jonas Maebe
to Vincent Snijders
Vincent Snijders wrote
> Can someone fix the testsuite failures resulting from this? Are there any testsuite failures with typeinfo.

Yes. trtti1, trtti4 and trtti5 fail.

Lazarus crashes at startup when accessing the typeinfo. It could be that our code is wrong now, but maybe wrong typeinfo is generated.

Or that the code in the typeinfo unit is now broken.

Jonas

Reply by email

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote
Or that the code in the typeinfo unit is now broken.

typinfo unit is fixed. But there may be other similar problems elsewhere. I would advise to make {$t-} the default again, because this sort of hidden errors is hard to find unless you go over all @- statements in your program.

The problem was an "@shortstring_var + length(shortstring_var)" expression. With {$t+}, this added length(shortstring_var)*sizeof (shortstring_var) instead of only the length.

Jonas

Reply by email

Micha Nelissen
to Jonas Maebe
Jonas Maebe wrote 9 lines
On 5 okt 2006, at 15:41, Jonas Maebe wrote: > Or that the code in the typeinfo unit is now broken. typinfo unit is fixed. But there may be other similar problems elsewhere. I would advise to make {$t-} the default again, because this sort of hidden errors is hard to find unless you go over all @-statements in your program.

I will try to reread my patch with this info in mind.

Micha

Reply by email

Jonas Maebe
to Micha Nelissen
Micha Nelissen wrote 9 lines
Jonas Maebe wrote: > On 5 okt 2006, at 15:41, Jonas Maebe wrote: >> Or that the code in the typeinfo unit is now broken. > typinfo unit is fixed. But there may be other similar problems > elsewhere. I would advise to make {$t-} the default again, because > this sort of hidden errors is hard to find unless you go over all > @-statements in your program. I will try to reread my patch with this info in mind.

The problem is that this is something you did not patch, because it did not trigger a compiler error. You would have to go over all @- statements in the compiler, rtl, packages, fcl, lcl, lazarus, ... if you want to be sure that nothing got broken. And our users have to do the same with their own programs.

That's why I think it's better to not change the default {$t} setting, since it can introduce hidden bugs.

Jonas

Reply by email

Micha Nelissen
to Jonas Maebe: The problem is that this is something you did not patch, because it did not trigger a…
Jonas Maebe wrote
The problem is that this is something you did not patch, because it did not trigger a compiler error. You would have to go over all @-statements

Doing so now. There are actually not that many cases: only 324 :)

Command used:
$ (find -regex '.*\.\(pp\|pas\|inc\)' | xargs grep '@[^,]*+') | less

Possible problems:

./rtl/inc/variant.inc:
Result:=Pointer(ppointer(@variantmanager+i*sizeof(pointer))^)Pointer(@invalidvariantop);
./rtl/inc/variant.inc:
ppointer(@variantmanager+i*sizeof(pointer));
./rtl/inc/genset.inc:    FillChar((@dest+4)^,size-4,0);

Micha

Reply by email

Jonas Maebe
to Micha Nelissen
Micha Nelissen wrote 7 lines
Jonas Maebe wrote: > The problem is that this is something you did not patch, because > it did > not trigger a compiler error. You would have to go over all @- > statements Doing so now. There are actually not that many cases: only 324 :)

But this does not help users, third party packages etc. Breaking compilation of sloppy code is one thing, but introducing silent bugs is a whole other issue.

$ (find -regex '.*\.\(pp\|pas\|inc\)' | xargs grep '@[^,]*+') | less

Shouldn't that be '@[^,]+' ?

Jonas

Reply by email

Micha Nelissen
to Jonas Maebe
Jonas Maebe wrote
But this does not help users, third party packages etc. Breaking compilation of sloppy code is one thing, but introducing silent bugs is a whole other issue.

Hmm. What type is @X in {$T-} ? Is it a special type ? Maybe the compiler can give a warning when you do arithmetic on this kind of type ?

> $ (find -regex '.*\.\(pp\|pas\|inc\)' | xargs grep '@[^,]*+') | less Shouldn't that be '@[^,]+' ?

No, the idea is to find @expr+, so where you take the address *and* do arithmetic on the result. That's why there aren't that many cases of it.

Micha

Reply by email

Jonas Maebe
to Micha Nelissen
Micha Nelissen wrote 9 lines
Jonas Maebe wrote: > But this does not help users, third party packages etc. Breaking > compilation of sloppy code is one thing, but introducing silent > bugs is > a whole other issue. Hmm. What type is @X in {$T-} ? Is it a special type ? Maybe the compiler can give a warning when you do arithmetic on this kind of type ?

It's a plain void pointer (like when you would add a pointer() type cast around it).

Show quoted text 7 lines
>> $ (find -regex '.*\.\(pp\|pas\|inc\)' | xargs grep '@[^,]*+') | less > > Shouldn't that be '@[^,]+' ? No, the idea is to find @expr+, so where you take the address *and* do arithmetic on the result. That's why there aren't that many cases of it.

Shouldn't the + then be escaped normally? Or is it only "1 or more of the previous" in egrep?

Jonas

Reply by email

Micha Nelissen
to Jonas Maebe
Jonas Maebe wrote 8 lines
On 5 okt 2006, at 18:41, Micha Nelissen wrote: > No, the idea is to find @expr+, so where you take the address *and* do > arithmetic on the result. That's why there aren't that many cases of it. Shouldn't the + then be escaped normally? Or is it only "1 or more of the previous" in egrep?

It's only that in egrep, indeed. (Not that I can confirm this by reading the manual pages, of course, only by experimentation :-( ).

Micha

Reply by email

Florian Klaempfl
to Micha Nelissen
Show quoted text 7 lines
Jonas Maebe wrote: >> For me, it is ok, to apply it in objfpc and fpc mode. T- enforces >> sloppy programming which we don't want after all ;) > Can someone fix the testsuite failures resulting from this? I wanted to, but 'make TEST_FPC=~/path/ppc-dev full' in tests/ gave a compiler error: 'unit dom not found'.

Because of the some not yet resolved dependency trouble (fpcunit depends on xml stuff now), you've to run a make all in fpc/ before running the testsuite.

Reply by email