* Use proper critical sections.

- Remove sysutils dependency by turning exception into runerror, which is
    converted into exception anyway if user decides to use sysutils.

git-svn-id: trunk@5471 -
This commit is contained in:
daniel 2006-11-25 07:32:36 +00:00
parent b77a5016ca
commit 76cf70bdbd
3 changed files with 19 additions and 21 deletions

View File

@ -73,4 +73,4 @@ Const
SVarArrayBounds = 'Variant array bounds error'; SVarArrayBounds = 'Variant array bounds error';
SVarArrayCreate = 'Variant array cannot be created'; SVarArrayCreate = 'Variant array cannot be created';
SVarNotArray = 'Variant doesn''t contain an array'; SVarNotArray = 'Variant doesn''t contain an array';
SVarArrayBounds = 'iconv error';

View File

@ -306,6 +306,7 @@ begin
228 : E:=EExternalException.Create(SExternalException); 228 : E:=EExternalException.Create(SExternalException);
229 : E:=EIntfCastError.Create(SIntfCastError); 229 : E:=EIntfCastError.Create(SIntfCastError);
230 : E:=ESafecallException.Create(SSafecallException); 230 : E:=ESafecallException.Create(SSafecallException);
231 : E:=EConvertError.Create(SiconvError);
232 : E:=ENoThreadSupport.Create(SNoThreadSupport); 232 : E:=ENoThreadSupport.Create(SNoThreadSupport);
else else
E:=Exception.CreateFmt (SUnKnownRunTimeError,[Errno]); E:=Exception.CreateFmt (SUnKnownRunTimeError,[Errno]);

View File

@ -35,7 +35,6 @@ Uses
ctypes, ctypes,
unix, unix,
unixtype, unixtype,
sysutils,
initc; initc;
Const Const
@ -120,6 +119,9 @@ var
lock_ansi2wide : integer = -1; lock_ansi2wide : integer = -1;
lock_wide2ansi : integer = -1; lock_wide2ansi : integer = -1;
iconv_lock : TRTLcriticalsection;
{
procedure lockiconv(var lockcount: integer); procedure lockiconv(var lockcount: integer);
begin begin
while interlockedincrement(lockcount) <> 0 do begin while interlockedincrement(lockcount) <> 0 do begin
@ -132,7 +134,8 @@ procedure unlockiconv(var lockcount: integer);
begin begin
interlockeddecrement(lockcount); interlockeddecrement(lockcount);
end; end;
}
procedure Wide2AnsiMove(source:pwidechar;var dest:ansistring;len:SizeInt); procedure Wide2AnsiMove(source:pwidechar;var dest:ansistring;len:SizeInt);
var var
outlength, outlength,
@ -153,7 +156,7 @@ procedure Wide2AnsiMove(source:pwidechar;var dest:ansistring;len:SizeInt);
srcpos:=source; srcpos:=source;
destpos:=pchar(dest); destpos:=pchar(dest);
outleft:=outlength; outleft:=outlength;
lockiconv(lock_wide2ansi); entercriticalsection(iconv_lock);
while iconv(iconv_wide2ansi,ppchar(@srcpos),@srclen,@destpos,@outleft)=size_t(-1) do while iconv(iconv_wide2ansi,ppchar(@srcpos),@srclen,@destpos,@outleft)=size_t(-1) do
begin begin
case fpgetCerrno of case fpgetCerrno of
@ -179,13 +182,11 @@ procedure Wide2AnsiMove(source:pwidechar;var dest:ansistring;len:SizeInt);
destpos:=pchar(dest)+outoffset; destpos:=pchar(dest)+outoffset;
end; end;
else else
begin leavecriticalsection(iconv_lock);
unlockiconv(lock_wide2ansi); runerror(231);
raise EConvertError.Create('iconv error '+IntToStr(fpgetCerrno));
end;
end; end;
end; end;
unlockiconv(lock_wide2ansi); leavecriticalsection(iconv_lock);
// truncate string // truncate string
setlength(dest,length(dest)-outleft); setlength(dest,length(dest)-outleft);
end; end;
@ -210,7 +211,7 @@ procedure Ansi2WideMove(source:pchar;var dest:widestring;len:SizeInt);
srcpos:=source; srcpos:=source;
destpos:=pchar(dest); destpos:=pchar(dest);
outleft:=outlength*2; outleft:=outlength*2;
lockiconv(lock_ansi2wide); entercriticalsection(iconv_lock);
while iconv(iconv_ansi2wide,@srcpos,psize(@len),@destpos,@outleft)=size_t(-1) do while iconv(iconv_ansi2wide,@srcpos,psize(@len),@destpos,@outleft)=size_t(-1) do
begin begin
case fpgetCerrno of case fpgetCerrno of
@ -235,13 +236,11 @@ procedure Ansi2WideMove(source:pchar;var dest:widestring;len:SizeInt);
destpos:=pchar(dest)+outoffset; destpos:=pchar(dest)+outoffset;
end; end;
else else
begin leavecriticalsection(iconv_lock);
unlockiconv(lock_ansi2wide); runerror(231);
raise EConvertError.Create('iconv error '+IntToStr(fpgetCerrno));
end;
end; end;
end; end;
unlockiconv(lock_ansi2wide); leavecriticalsection(iconv_lock);
// truncate string // truncate string
setlength(dest,length(dest)-outleft div 2); setlength(dest,length(dest)-outleft div 2);
end; end;
@ -286,7 +285,7 @@ procedure Ansi2UCS4Move(source:pchar;var dest:UCS4String;len:SizeInt);
srcpos:=source; srcpos:=source;
destpos:=pchar(dest); destpos:=pchar(dest);
outleft:=outlength*4; outleft:=outlength*4;
lockiconv(lock_ansi2ucs4); entercriticalsection(iconv_lock);
while iconv(iconv_ansi2ucs4,@srcpos,psize(@len),@destpos,@outleft)=size_t(-1) do while iconv(iconv_ansi2ucs4,@srcpos,psize(@len),@destpos,@outleft)=size_t(-1) do
begin begin
case fpgetCerrno of case fpgetCerrno of
@ -301,13 +300,11 @@ procedure Ansi2UCS4Move(source:pchar;var dest:UCS4String;len:SizeInt);
destpos:=pchar(dest)+outoffset; destpos:=pchar(dest)+outoffset;
end; end;
else else
begin leavecriticalsection(iconv_lock);
unlockiconv(lock_ansi2ucs4); runerror(231);
raise EConvertError.Create('iconv error '+IntToStr(fpgetCerrno));
end;
end; end;
end; end;
unlockiconv(lock_ansi2ucs4); leavecriticalsection(iconv_lock);
// truncate string // truncate string
setlength(dest,length(dest)-outleft div 4); setlength(dest,length(dest)-outleft div 4);
end; end;