- RTL: cleaned up remaining 'decr_ref' routines (not removed completely due to bootstrapping needs, but aliased to 'finalize' ones).

git-svn-id: trunk@20130 -
This commit is contained in:
sergei 2012-01-20 19:19:08 +00:00
parent 822cd6dec4
commit f136e44b6b
3 changed files with 39 additions and 124 deletions

View File

@ -26,7 +26,6 @@
{ export for internal usage }
Procedure int_Finalize (Data,TypeInfo: Pointer); [external name 'FPC_FINALIZE'];
Procedure int_Addref (Data,TypeInfo : Pointer); [external name 'FPC_ADDREF'];
Procedure int_DecRef (Data, TypeInfo : Pointer); [external name 'FPC_DECREF'];
Procedure int_Initialize (Data,TypeInfo: Pointer); [external name 'FPC_INITIALIZE'];
procedure int_FinalizeArray(data,typeinfo : pointer;count : longint); [external name 'FPC_FINALIZE_ARRAY'];

View File

@ -60,23 +60,6 @@ function fpc_dynarray_high(p : pointer) : tdynarrayindex;[Public,Alias:'FPC_DYNA
end;
{ releases and finalizes the data of a dyn. array and sets p to nil }
procedure fpc_dynarray_clear_internal(p : pointer;ti : pointer);
begin
if p=nil then
exit;
{ skip kind and name }
ti:=aligntoptr(ti+2+PByte(ti)[1]);
{ finalize all data }
int_finalizearray(p+sizeof(tdynarray),pdynarraytypedata(ti)^.elType2,pdynarray(p)^.high+1);
{ release the data }
freemem(p);
end;
procedure fpc_dynarray_clear(var p : pointer;ti : pointer); [Public,Alias:'FPC_DYNARRAY_CLEAR']; compilerproc;
var
realp : pdynarray;
@ -84,8 +67,15 @@ procedure fpc_dynarray_clear(var p : pointer;ti : pointer); [Public,Alias:'FPC_D
if (P=Nil) then
exit;
realp:=pdynarray(p-sizeof(tdynarray));
if realp^.refcount=0 then
HandleErrorFrame(204,get_frame);
if declocked(realp^.refcount) then
fpc_dynarray_clear_internal(p-sizeof(tdynarray),ti);
begin
ti:=aligntoptr(ti+2+PByte(ti)[1]);
int_finalizearray(p,pdynarraytypedata(ti)^.elType2,realp^.high+1);
freemem(realp);
end;
p:=nil;
end;
@ -93,29 +83,6 @@ procedure fpc_dynarray_clear(var p : pointer;ti : pointer); [Public,Alias:'FPC_D
Procedure fpc_dynarray_clear (var p : pointer;ti : pointer);[external name 'FPC_DYNARRAY_CLEAR'];
procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer); [Public,Alias:'FPC_DYNARRAY_DECR_REF']; compilerproc;
var
realp : pdynarray;
begin
if p=nil then
exit;
realp:=pdynarray(p-sizeof(tdynarray));
if realp^.refcount=0 then
HandleErrorFrame(204,get_frame);
{ decr. ref. count }
{ should we remove the array? }
if declocked(realp^.refcount) then
begin
fpc_dynarray_clear_internal(realp,ti);
p := nil;
end;
end;
{ provide local access to dynarr_decr_ref for dynarr_setlength }
procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer); [external name 'FPC_DYNARRAY_DECR_REF'];
procedure fpc_dynarray_incr_ref(p : pointer);[Public,Alias:'FPC_DYNARRAY_INCR_REF']; compilerproc;
var
realp : pdynarray;
@ -137,7 +104,7 @@ procedure fpc_dynarray_incr_ref(p : pointer); [external name 'FPC_DYNARRAY_INCR_
procedure fpc_dynarray_assign(var dest: Pointer; src: Pointer; ti: pointer);[public,alias:'FPC_DYNARRAY_ASSIGN']; compilerproc;
begin
fpc_dynarray_incr_ref(src);
fpc_dynarray_decr_ref(dest,ti);
fpc_dynarray_clear(dest,ti);
Dest:=Src;
end;
@ -163,6 +130,10 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
eletype : pointer;
begin
{ negative length is not allowed }
if dims[0]<0 then
HandleErrorFrame(201,get_frame);
{ skip kind and name }
ti:=aligntoptr(Pointer(pti)+2+PByte(pti)[1]);
@ -176,8 +147,6 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
{ not assigned yet? }
if not(assigned(p)) then
begin
if dims[0]<0 then
HandleErrorFrame(201,get_frame);
{ do we have to allocate memory? }
if dims[0] = 0 then
exit;
@ -187,20 +156,16 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
end
else
begin
realp:=pdynarray(p-sizeof(tdynarray));
newp := realp;
{ if the new dimension is 0, we've to release all data }
if dims[0]<=0 then
if dims[0]=0 then
begin
if dims[0]<0 then
HandleErrorFrame(201,get_frame);
if declocked(realp^.refcount) then
fpc_dynarray_clear_internal(realp,pti);
p:=nil;
fpc_dynarray_clear(p,pti);
exit;
end;
realp:=pdynarray(p-sizeof(tdynarray));
newp := realp;
if realp^.refcount<>1 then
begin
updatep := true;
@ -224,9 +189,7 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
{ it is, because it doesn't really matter }
{ if the array is now removed }
{ fpc_dynarray_decr_ref(p,ti); }
if declocked(realp^.refcount) then
fpc_dynarray_clear_internal(realp,pti);
fpc_dynarray_clear(p,pti);
end
else if dims[0]<>realp^.high+1 then
begin
@ -340,3 +303,10 @@ function fpc_dynarray_copy(psrc : pointer;ti : pointer;
procedure DynArraySetLength(var a: Pointer; typeInfo: Pointer; dimCnt: SizeInt; lengthVec: PSizeInt);
external name 'FPC_DYNARR_SETLENGTH';
{ obsolete but needed for bootstrapping }
procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer); [Public,Alias:'FPC_DYNARRAY_DECR_REF']; compilerproc;
begin
fpc_dynarray_clear(p,ti);
end;

View File

@ -135,23 +135,14 @@ begin
case PByte(TypeInfo)^ of
{$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
tkAstring :
begin
fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
PPointer(Data)^:=nil;
end;
fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
{$endif FPC_HAS_FEATURE_ANSISTRINGS}
{$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
tkUstring :
begin
fpc_UnicodeStr_Decr_Ref(PPointer(Data)^);
PPointer(Data)^:=nil;
end;
fpc_UnicodeStr_Decr_Ref(PPointer(Data)^);
{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
tkWstring :
begin
fpc_WideStr_Decr_Ref(PPointer(Data)^);
PPointer(Data)^:=nil;
end;
fpc_WideStr_Decr_Ref(PPointer(Data)^);
{$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
{$endif FPC_HAS_FEATURE_WIDESTRINGS}
tkArray :
@ -162,16 +153,10 @@ begin
tkRecord:
recordrtti(data,typeinfo,@int_finalize);
tkInterface:
begin
Intf_Decr_Ref(PPointer(Data)^);
PPointer(Data)^:=nil;
end;
Intf_Decr_Ref(PPointer(Data)^);
{$ifdef FPC_HAS_FEATURE_DYNARRAYS}
tkDynArray:
begin
fpc_dynarray_decr_ref(PPointer(Data)^,TypeInfo);
PPointer(Data)^:=nil;
end;
fpc_dynarray_clear(PPointer(Data)^,TypeInfo);
{$endif FPC_HAS_FEATURE_DYNARRAYS}
{$ifdef FPC_HAS_FEATURE_VARIANTS}
tkVariant:
@ -217,46 +202,6 @@ begin
end;
{ alias for internal use }
{ we use another name else the compiler gets puzzled because of the wrong forward def }
procedure fpc_systemDecRef (Data, TypeInfo : Pointer);[external name 'FPC_DECREF'];
Procedure fpc_DecRef (Data, TypeInfo : Pointer);[Public,alias : 'FPC_DECREF']; compilerproc;
begin
case PByte(TypeInfo)^ of
{ see AddRef for comment about below construct (JM) }
{$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
tkAstring:
fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
{$endif FPC_HAS_FEATURE_ANSISTRINGS}
{$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
tkWstring:
fpc_WideStr_Decr_Ref(PPointer(Data)^);
{$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
tkUString:
fpc_UnicodeStr_Decr_Ref(PPointer(Data)^);
{$endif FPC_HAS_FEATURE_WIDESTRINGS}
tkArray:
arrayrtti(data,typeinfo,@fpc_systemDecRef);
{$ifdef FPC_HAS_FEATURE_OBJECTS}
tkobject,
{$endif FPC_HAS_FEATURE_OBJECTS}
tkrecord:
recordrtti(data,typeinfo,@fpc_systemDecRef);
{$ifdef FPC_HAS_FEATURE_DYNARRAYS}
tkDynArray:
fpc_dynarray_decr_ref(PPointer(Data)^,TypeInfo);
{$endif FPC_HAS_FEATURE_DYNARRAYS}
tkInterface:
Intf_Decr_Ref(PPointer(Data)^);
{$ifdef FPC_HAS_FEATURE_VARIANTS}
tkVariant:
variant_clear(pvardata(data)^);
{$endif FPC_HAS_FEATURE_VARIANTS}
end;
end;
{ define alias for internal use in the system unit }
Function fpc_Copy_internal (Src, Dest, TypeInfo : Pointer) : SizeInt;[external name 'FPC_COPY'];
@ -376,13 +321,14 @@ procedure fpc_addref_array(data,typeinfo: pointer; count: SizeInt); [public,alia
int_addref(data+size*i,typeinfo);
end;
procedure fpc_decref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_DECREF_ARRAY']; compilerproc;
var
i, size: SizeInt;
{ The following two procedures are now obsolete, needed only for bootstrapping }
procedure fpc_decref (Data, TypeInfo : Pointer);[Public,alias : 'FPC_DECREF']; compilerproc;
begin
size:=RTTISize(typeinfo);
if size>0 then
for i:=0 to count-1 do
int_decref(data+size*i,typeinfo);
int_finalize(Data,TypeInfo);
end;
procedure fpc_decref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_DECREF_ARRAY']; compilerproc;
begin
int_finalizeArray(data,typeinfo,count);
end;