* return 0 for length(pchar(0)), like Kylix does (using corrected and

multi-platform version of patch in r12461, which caused the i386 version
    of fpc_pchar_length to return 0 in all cases, which used tabs, and did
    not include a test case)

git-svn-id: trunk@12464 -
This commit is contained in:
Jonas Maebe 2009-01-01 22:02:17 +00:00
parent 8046f82416
commit 22aacd2a60
6 changed files with 26 additions and 2 deletions

1
.gitattributes vendored
View File

@ -8083,6 +8083,7 @@ tests/test/units/system/tjmp.pp svneol=native#text/plain
tests/test/units/system/tmem.pp svneol=native#text/plain
tests/test/units/system/todd.pp svneol=native#text/plain
tests/test/units/system/tparam.pp svneol=native#text/plain
tests/test/units/system/tpchlen.pp svneol=native#text/plain
tests/test/units/system/tpi.pp svneol=native#text/plain
tests/test/units/system/trandom.pp svneol=native#text/plain
tests/test/units/system/trdtxt01.pp svneol=native#text/plain

View File

@ -439,7 +439,9 @@ end;
function fpc_Pchar_length(p:Pchar):longint;assembler;nostackframe;[public,alias:'FPC_PCHAR_LENGTH'];compilerproc;
asm
cmp r0,#0
mov r1,r0
beq .Ldone
.Lnextchar:
(*Are we aligned?*)
tst r1,#3
@ -462,6 +464,7 @@ asm
(*Dirty trick: we need to subtract 1 extra because we have counted the
terminating 0, due to the known carry flag sbc can do this.*)
sbc r0,r1,r0
.Ldone:
mov pc,lr
.L01010101:
.long 0x01010101

View File

@ -1037,12 +1037,15 @@ asm
{$endif}
movl $0xffffffff,%ecx
xorl %eax,%eax
test %edi,%edi
jz .LStrLenDone
cld
repne
scasb
movl $0xfffffffe,%eax
subl %ecx,%eax
movl saveedi,%edi
.LStrLenDone:
end;
{$endif FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}

View File

@ -112,7 +112,10 @@ function libc_pchar_length(p:pchar):size_t; cdecl; external 'c' name 'strlen';
function fpc_pchar_length(p:pchar):longint;[public,alias:'FPC_PCHAR_LENGTH']; compilerproc;
begin
fpc_pchar_length:=libc_pchar_length(p);
if assigned(p) then
fpc_pchar_length:=libc_pchar_length(p)
else
fpc_pchar_length:=0;
end;
{$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}

View File

@ -1187,7 +1187,9 @@ function fpc_pchar_length(p:pchar):longint;[public,alias:'FPC_PCHAR_LENGTH']; co
var i : longint;
begin
i:=0;
while p[i]<>#0 do inc(i);
if assigned(p) then
while p[i]<>#0 do
inc(i);
exit(i);
end;

View File

@ -0,0 +1,12 @@
procedure test(p: pchar; len: longint);
begin
if (length(p)<>len) then
halt(1);
end;
begin
test(nil,0);
test(#0,0);
test('a',1);
test('hello',5);
end.