基线重置,修复了一些 bug
This commit is contained in:
1 parent
b02bedae9a
commit
45e78ad107
2421 files changed
+13195
-19306
No files matched your search
+10
-7
@@ -66,20 +66,23 @@ def strncat(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
|
||||
|
||||
# String length function
|
||||
def strlen(src: str) -> t.CSizeT | t.CExport:
|
||||
export def strlen(src: str) -> t.CSizeT:
|
||||
length: t.CSizeT = 0
|
||||
for _ in src:
|
||||
length += 1
|
||||
return length
|
||||
|
||||
# String comparison function
|
||||
# 注意:str1[0] - str2[0] 是 i8 减法会回绕(0xFF 表示 -1),返回前必须
|
||||
# int() 提升到 i32 再相减(与下方 memcmp 的 int(p1[i]) - int(p2[i]) 一致),
|
||||
# 否则 strcmp("abc","abd") 返回 255 而非 -1(StringTest Test 4 根因)。
|
||||
def strcmp(str1: str, str2: str) -> int:
|
||||
while str1[0] != '\0' and str2[0] != '\0':
|
||||
if str1[0] != str2[0]:
|
||||
return str1[0] - str2[0]
|
||||
return int(str1[0]) - int(str2[0])
|
||||
str1 += 1
|
||||
str2 += 1
|
||||
return str1[0] - str2[0]
|
||||
return int(str1[0]) - int(str2[0])
|
||||
|
||||
def samestr(str1: str, str2: str) -> bool:
|
||||
return strcmp(str1, str2) == 0
|
||||
@@ -90,12 +93,12 @@ def strncmp(str1: str, str2: str, n: t.CSizeT) -> int:
|
||||
i: t.CSizeT = 0
|
||||
while str1[0] != '\0' and str2[0] != '\0' and i < n:
|
||||
if str1[0] != str2[0]:
|
||||
return str1[0] - str2[0]
|
||||
return int(str1[0]) - int(str2[0])
|
||||
str1 += 1
|
||||
str2 += 1
|
||||
i += 1
|
||||
if i < n:
|
||||
return str1[0] - str2[0]
|
||||
return int(str1[0]) - int(str2[0])
|
||||
return 0
|
||||
|
||||
|
||||
@@ -164,7 +167,7 @@ def strspn(s: str, skip: str = " ") -> int:
|
||||
return si
|
||||
|
||||
# Memory set function
|
||||
def memset(ptr: t.CVoid | t.CPtr, value: int, num: t.CSizeT) -> t.CVoid | t.CPtr | t.CExport:
|
||||
export def memset(ptr: t.CVoid | t.CPtr, value: int, num: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
# Original implementation:
|
||||
# p: BYTEPTR = BYTEPTR(ptr)
|
||||
# i: t.CSizeT
|
||||
@@ -197,7 +200,7 @@ def memset32(ptr: t.CVoid | t.CPtr, value: t.CUInt32T, count: t.CSizeT) -> t.CVo
|
||||
|
||||
|
||||
# Memory copy function
|
||||
def memcpy(dest: t.CVoid | t.CPtr, src: t.CVoid | t.CPtr, num: t.CSizeT) -> t.CVoid | t.CPtr | t.CExport:
|
||||
export def memcpy(dest: t.CVoid | t.CPtr, src: t.CVoid | t.CPtr, num: t.CSizeT) -> t.CPtr:
|
||||
# Original implementation:
|
||||
# d: BYTEPTR = BYTEPTR(dest)
|
||||
# s: BYTEPTR = BYTEPTR(src)
|
||||
|
||||
Reference in new issue
Block a user