修复了关于 snprintf 的错误(不支持长度推导)
This commit is contained in:
@@ -1,86 +0,0 @@
|
|||||||
"""
|
|
||||||
Auto-generated Python stub file from w32.winsock2.vp
|
|
||||||
Module: w32.winsock2
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
import t, c
|
|
||||||
from stdint import *
|
|
||||||
from w32.win32base import *
|
|
||||||
|
|
||||||
WINSOCK_VERSION: t.CDefine = 0x0202 # 2.2
|
|
||||||
AF_INET: t.CDefine = 2
|
|
||||||
AF_INET6: t.CDefine = 23
|
|
||||||
SOCK_STREAM: t.CDefine = 1 # TCP
|
|
||||||
SOCK_DGRAM: t.CDefine = 2 # UDP
|
|
||||||
SOCK_RAW: t.CDefine = 3 # 原始套接字
|
|
||||||
IPPROTO_TCP: t.CDefine = 6
|
|
||||||
IPPROTO_UDP: t.CDefine = 17
|
|
||||||
SOL_SOCKET: t.CDefine = 0xFFFF # WinSock2 值
|
|
||||||
SO_RCVTIMEO: t.CDefine = 0x1006 # WinSock2 值
|
|
||||||
SO_SNDTIMEO: t.CDefine = 0x1005 # WinSock2 值
|
|
||||||
SO_REUSEADDR: t.CDefine = 0x0004 # WinSock2 值
|
|
||||||
INADDR_ANY: t.CDefine = 0
|
|
||||||
SOCKET_ERROR: t.CDefine = -1
|
|
||||||
INVALID_SOCKET: t.CDefine = 0xFFFFFFFF # WinSock2: ~0
|
|
||||||
MSG_NOSIGNAL: t.CDefine = 0 # Windows 不支持,设为 0
|
|
||||||
SD_SEND: t.CDefine = 1
|
|
||||||
SD_RECV: t.CDefine = 0
|
|
||||||
SD_BOTH: t.CDefine = 2
|
|
||||||
|
|
||||||
class WSASocketAddr:
|
|
||||||
family: u16
|
|
||||||
port: u16
|
|
||||||
addr: u32
|
|
||||||
zero: u64
|
|
||||||
class WSAData:
|
|
||||||
wVersion: WORD
|
|
||||||
wHighVersion: WORD
|
|
||||||
szDescription: BYTE
|
|
||||||
szSystemStatus: BYTE
|
|
||||||
iMaxSockets: u16
|
|
||||||
iMaxUdpDg: u16
|
|
||||||
lpVendorInfo: CHARPTR
|
|
||||||
class WSAHostEnt:
|
|
||||||
h_name: CHARPTR
|
|
||||||
h_aliases: CHARPTR
|
|
||||||
h_addrtype: SHORT
|
|
||||||
h_length: SHORT
|
|
||||||
h_addr_list: CHARPTR
|
|
||||||
class WinTimeVal:
|
|
||||||
tv_sec: LONG
|
|
||||||
tv_usec: LONG
|
|
||||||
|
|
||||||
def WSAStartup(wVersionRequested: WORD, lpWSAData: WSAData | t.CPtr) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def WSACleanup() -> INT | t.State: pass
|
|
||||||
|
|
||||||
def WSAGetLastError() -> INT | t.State: pass
|
|
||||||
|
|
||||||
def socket(family: INT, type: INT, protocol: INT) -> u64 | t.State: pass
|
|
||||||
|
|
||||||
def closesocket(s: u64) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def connect(s: u64, name: WSASocketAddr | t.CPtr, namelen: INT) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def send(s: u64, buf: t.CVoid | t.CPtr, len: INT, flags: INT) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def recv(s: u64, buf: t.CVoid | t.CPtr, len: INT, flags: INT) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def bind(s: u64, name: WSASocketAddr | t.CPtr, namelen: INT) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def listen(s: u64, backlog: INT) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def accept(s: u64, addr: WSASocketAddr | t.CPtr, addrlen: INT | t.CPtr) -> u64 | t.State: pass
|
|
||||||
|
|
||||||
def setsockopt(s: u64, level: INT, optname: INT, optval: t.CVoid | t.CPtr, optlen: INT) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def shutdown(s: u64, how: INT) -> INT | t.State: pass
|
|
||||||
|
|
||||||
def gethostbyname(name: t.CChar | t.CConst | t.CPtr) -> WSAHostEnt | t.CPtr | t.State: pass
|
|
||||||
|
|
||||||
def ntohs(netshort: u16) -> u16 | t.State: pass
|
|
||||||
|
|
||||||
def htons(hostshort: u16) -> u16 | t.State: pass
|
|
||||||
|
|
||||||
def inet_addr(cp: t.CChar | t.CConst | t.CPtr) -> u32 | t.State: pass
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
"""
|
|
||||||
Auto-generated Python stub file from w32.win32memory.vp
|
|
||||||
Module: w32.win32memory
|
|
||||||
"""
|
|
||||||
|
|
||||||
import c
|
|
||||||
|
|
||||||
|
|
||||||
import t
|
|
||||||
from stdint import *
|
|
||||||
from w32.win32base import *
|
|
||||||
|
|
||||||
MEM_COMMIT: t.CDefine = 0x00001000
|
|
||||||
MEM_RESERVE: t.CDefine = 0x00002000
|
|
||||||
MEM_DECOMMIT: t.CDefine = 0x00004000
|
|
||||||
MEM_RELEASE: t.CDefine = 0x00008000
|
|
||||||
MEM_FREE: t.CDefine = 0x00010000
|
|
||||||
MEM_RESET: t.CDefine = 0x00080000
|
|
||||||
MEM_TOP_DOWN: t.CDefine = 0x00100000
|
|
||||||
MEM_WRITE_WATCH: t.CDefine = 0x00200000
|
|
||||||
MEM_PHYSICAL: t.CDefine = 0x00400000
|
|
||||||
MEM_LARGE_PAGES: t.CDefine = 0x20000000
|
|
||||||
PAGE_NOACCESS: t.CDefine = 0x01
|
|
||||||
PAGE_READONLY: t.CDefine = 0x02
|
|
||||||
PAGE_READWRITE: t.CDefine = 0x04
|
|
||||||
PAGE_WRITECOPY: t.CDefine = 0x08
|
|
||||||
PAGE_EXECUTE: t.CDefine = 0x10
|
|
||||||
PAGE_EXECUTE_READ: t.CDefine = 0x20
|
|
||||||
PAGE_EXECUTE_READWRITE: t.CDefine = 0x40
|
|
||||||
PAGE_EXECUTE_WRITECOPY: t.CDefine = 0x80
|
|
||||||
PAGE_GUARD: t.CDefine = 0x100
|
|
||||||
PAGE_NOCACHE: t.CDefine = 0x200
|
|
||||||
PAGE_WRITECOMBINE: t.CDefine = 0x400
|
|
||||||
HEAP_NO_SERIALIZE: t.CDefine = 0x00000001
|
|
||||||
HEAP_GROWABLE: t.CDefine = 0x00000002
|
|
||||||
HEAP_GENERATE_EXCEPTIONS: t.CDefine = 0x00000004
|
|
||||||
HEAP_ZERO_MEMORY: t.CDefine = 0x00000008
|
|
||||||
HEAP_REALLOC_IN_PLACE_ONLY: t.CDefine = 0x00000010
|
|
||||||
|
|
||||||
class MEMORY_BASIC_INFORMATION:
|
|
||||||
BaseAddress: VOIDPTR
|
|
||||||
AllocationBase: VOIDPTR
|
|
||||||
AllocationProtect: ULONG
|
|
||||||
RegionSize: t.CSizeT
|
|
||||||
State: ULONG
|
|
||||||
Protect: ULONG
|
|
||||||
Type: ULONG
|
|
||||||
|
|
||||||
def VirtualAlloc(lpAddress: VOIDPTR, dwSize: t.CSizeT, flAllocationType: ULONG, flProtect: ULONG) -> VOIDPTR | t.State: pass
|
|
||||||
|
|
||||||
def VirtualFree(lpAddress: VOIDPTR, dwSize: t.CSizeT, dwFreeType: ULONG) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def VirtualProtect(lpAddress: VOIDPTR, dwSize: t.CSizeT, flNewProtect: ULONG, lpflOldProtect: ULONG | t.CPtr) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def VirtualQuery(lpAddress: t.CConst | VOIDPTR, lpBuffer: MEMORY_BASIC_INFORMATION | t.CPtr, dwLength: t.CSizeT) -> t.CSizeT | t.State: pass
|
|
||||||
|
|
||||||
def VirtualLock(lpAddress: VOIDPTR, dwSize: t.CSizeT) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def VirtualUnlock(lpAddress: VOIDPTR, dwSize: t.CSizeT) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def GetProcessHeap() -> HANDLE | t.State: pass
|
|
||||||
|
|
||||||
def HeapCreate(flOptions: ULONG, dwInitialSize: t.CSizeT, dwMaximumSize: t.CSizeT) -> HANDLE | t.State: pass
|
|
||||||
|
|
||||||
def HeapDestroy(hHeap: HANDLE) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def HeapAlloc(hHeap: HANDLE, dwFlags: ULONG, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
|
||||||
|
|
||||||
def HeapReAlloc(hHeap: HANDLE, dwFlags: ULONG, lpMem: VOIDPTR, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
|
||||||
|
|
||||||
def HeapFree(hHeap: HANDLE, dwFlags: ULONG, lpMem: VOIDPTR) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def HeapSize(hHeap: HANDLE, dwFlags: ULONG, lpMem: t.CConst | VOIDPTR) -> t.CSizeT | t.State: pass
|
|
||||||
|
|
||||||
def HeapValidate(hHeap: HANDLE, dwFlags: ULONG, lpMem: t.CConst | VOIDPTR) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def HeapCompact(hHeap: HANDLE, dwFlags: ULONG) -> t.CSizeT | t.State: pass
|
|
||||||
|
|
||||||
def GlobalAlloc(uFlags: UINT, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
|
||||||
|
|
||||||
def GlobalFree(hMem: VOIDPTR) -> VOIDPTR | t.State: pass
|
|
||||||
|
|
||||||
def GlobalLock(hMem: VOIDPTR) -> VOIDPTR | t.State: pass
|
|
||||||
|
|
||||||
def GlobalUnlock(hMem: VOIDPTR) -> BOOL | t.State: pass
|
|
||||||
|
|
||||||
def GlobalSize(hMem: VOIDPTR) -> t.CSizeT | t.State: pass
|
|
||||||
|
|
||||||
def LocalAlloc(uFlags: UINT, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
|
||||||
|
|
||||||
def LocalFree(hMem: VOIDPTR) -> VOIDPTR | t.State: pass
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
|||||||
067c78e9f121dce3:includes/w32\win32process.vp
|
067c78e9f121dce3:includes/w32\win32process.vp
|
||||||
06f53cc594b4ac6c:includes/w32\win32sync.vp
|
06f53cc594b4ac6c:includes/w32\win32sync.vp
|
||||||
0c67644125bea0fd:includes/sys.vp
|
0c67644125bea0fd:includes/sys.vp
|
||||||
0ccfde54972334b1:lib/core/Handles/HandlesImports.vp
|
0cc3dc5a1bb0c805:lib/core/Handles/HandlesAnnAssign.vp
|
||||||
0df65b8ed15664b0:includes/hashlib\__sha1.vp
|
0df65b8ed15664b0:includes/hashlib\__sha1.vp
|
||||||
19f8024d10c828e8:includes/hashlib\__md5.vp
|
19f8024d10c828e8:includes/hashlib\__md5.vp
|
||||||
1d74d1d3a174c684:includes/llvmlite\__init__.vp
|
1d74d1d3a174c684:includes/llvmlite\__init__.vp
|
||||||
@@ -10,24 +10,20 @@
|
|||||||
240a9a4157959a9f:includes/json\__parser.vp
|
240a9a4157959a9f:includes/json\__parser.vp
|
||||||
285b6aa29a34754d:includes/stdio.vp
|
285b6aa29a34754d:includes/stdio.vp
|
||||||
28de517e3820658a:includes/posix.vp
|
28de517e3820658a:includes/posix.vp
|
||||||
2b30cc2ce96fa464:lib/core/Handles/HandlesType.vp
|
|
||||||
2b59175b77f1304e:lib/core/Handles/HandlesAssign.vp
|
|
||||||
2b77d783c41d21d1:includes/hashtable.vp
|
2b77d783c41d21d1:includes/hashtable.vp
|
||||||
2d8debefda779c40:includes/llvmlite\__types.vp
|
2d8debefda779c40:includes/llvmlite\__types.vp
|
||||||
31e49accebfc8aac:lib/core/Handles/HandlesAugAssign.vp
|
343b406cabc82fe9:lib/core/BuildPipeline.vp
|
||||||
371fa89e15d8c015:lib/core/Handles/HandlesStruct.vp
|
|
||||||
3aa6057398be5673:includes/stdlib.vp
|
3aa6057398be5673:includes/stdlib.vp
|
||||||
|
3ed8c578036234a7:includes/viperlib.vp
|
||||||
4337fb260448bbe2:includes/ast\astaux.vp
|
4337fb260448bbe2:includes/ast\astaux.vp
|
||||||
456fb516ba3c5002:lib/core/Handles/HandlesFor.vp
|
456fb516ba3c5002:lib/core/Handles/HandlesFor.vp
|
||||||
4650533467115342:lib/Projectrans/Utils.vp
|
4650533467115342:lib/Projectrans/Utils.vp
|
||||||
4a7b57e6bd18f65e:lib/core/Handles/HandlesMain.vp
|
4a7b57e6bd18f65e:lib/core/Handles/HandlesMain.vp
|
||||||
4c644ade1f0d6d02:lib/core/Handles/HandlesReturn.vp
|
4c644ade1f0d6d02:lib/core/Handles/HandlesReturn.vp
|
||||||
4daf5ed3f8e421a1:includes/string.vp
|
|
||||||
4dd6b3f1427d1cc5:includes/ast\match.vp
|
4dd6b3f1427d1cc5:includes/ast\match.vp
|
||||||
4e052c29b4fe769c:lib/core/IncludesScanner.vp
|
55be14b41dd7ca15:lib/core/IncludesScanner.vp
|
||||||
53812752bc672fdb:lib/core/Handles/HandlesAnnAssign.vp
|
|
||||||
553972e4135f827e:lib/core/Phase1.vp
|
|
||||||
5a1d8c48f1243746:includes/llvmlite\__builder.vp
|
5a1d8c48f1243746:includes/llvmlite\__builder.vp
|
||||||
|
611a2ade7450d2ea:lib/core/Handles/HandlesAssign.vp
|
||||||
62805d8ad3e9b5ba:lib/core/Handles/HandlesTranslator.vp
|
62805d8ad3e9b5ba:lib/core/Handles/HandlesTranslator.vp
|
||||||
63a3d17e96a083ac:lib/core/Handles/HandlesBase.vp
|
63a3d17e96a083ac:lib/core/Handles/HandlesBase.vp
|
||||||
657e182b27c2a022:includes/ast\stmts.vp
|
657e182b27c2a022:includes/ast\stmts.vp
|
||||||
@@ -37,20 +33,19 @@
|
|||||||
6ff26590374ae6fc:includes/hashlib\__sha512.vp
|
6ff26590374ae6fc:includes/hashlib\__sha512.vp
|
||||||
71e0a3ffcb3ebfad:includes/stdarg.vp
|
71e0a3ffcb3ebfad:includes/stdarg.vp
|
||||||
72dbbb563aa943b0:includes/w32\fileio.vp
|
72dbbb563aa943b0:includes/w32\fileio.vp
|
||||||
787e3cfd2e1cf583:lib/core/Handles/HandlesExpr.vp
|
|
||||||
7cadfe07e983fd90:includes/_list.vp
|
7cadfe07e983fd90:includes/_list.vp
|
||||||
|
7cb3f5b12941ce89:lib/core/Handles/HandlesClassDef.vp
|
||||||
|
7feaa478b74c4e3e:lib/core/Phase1.vp
|
||||||
81eb28ba912467a6:lib/core/Handles/HandlesBody.vp
|
81eb28ba912467a6:lib/core/Handles/HandlesBody.vp
|
||||||
82ee4327adfe0c18:lib/core/Handles/HandlesExprCall.vp
|
|
||||||
874bac141c97bae9:includes/llvmlite\__function.vp
|
874bac141c97bae9:includes/llvmlite\__function.vp
|
||||||
8dc65d4c71e2936a:lib/core/Handles/HandlesWhile.vp
|
8dc65d4c71e2936a:lib/core/Handles/HandlesWhile.vp
|
||||||
|
8de6943bee5d0f32:lib/core/Phase2.vp
|
||||||
96837bcc64032444:includes/hashlib\__init__.vp
|
96837bcc64032444:includes/hashlib\__init__.vp
|
||||||
a26c73d7332b54b4:lib/core/StubMerger.vp
|
9b1f7f05ff99d863:lib/core/Handles/HandlesExpr.vp
|
||||||
a335eb99f2e34479:includes/subprocess.vp
|
a335eb99f2e34479:includes/subprocess.vp
|
||||||
a38b726f4a82545f:lib/core/BuildPipeline.vp
|
|
||||||
a5e9a83e9db303ad:includes/linkedlist.vp
|
a5e9a83e9db303ad:includes/linkedlist.vp
|
||||||
|
a6e43e1ab6aa79b7:lib/core/Handles/HandlesType.vp
|
||||||
aa246c6e6aa30484:includes/atom.vp
|
aa246c6e6aa30484:includes/atom.vp
|
||||||
aa34a7a33a3afab0:lib/core/Phase2.vp
|
|
||||||
aa45364399b86a03:lib/core/Handles/HandlesClassDef.vp
|
|
||||||
af9484a65085bf4b:lib/core/Handles/HandlesNonlocal.vp
|
af9484a65085bf4b:lib/core/Handles/HandlesNonlocal.vp
|
||||||
b370d93b74bf55cc:includes/argparse.vp
|
b370d93b74bf55cc:includes/argparse.vp
|
||||||
b543bc1dfb592119:includes/ast\exprs.vp
|
b543bc1dfb592119:includes/ast\exprs.vp
|
||||||
@@ -62,14 +57,18 @@ bdf5730851fb95f2:lib/core/VLogger.vp
|
|||||||
be8c2d7b882881c8:lib/core/Handles/HandlesExprOps.vp
|
be8c2d7b882881c8:lib/core/Handles/HandlesExprOps.vp
|
||||||
c0042adc0b7ec5df:lib/Projectrans/Config.vp
|
c0042adc0b7ec5df:lib/Projectrans/Config.vp
|
||||||
c2a4277744568003:lib/__init__.vp
|
c2a4277744568003:lib/__init__.vp
|
||||||
|
c34e22cc668c6a6e:lib/core/Handles/HandlesImports.vp
|
||||||
c9d54a4158f7f5a8:includes/hashlib\__sha256.vp
|
c9d54a4158f7f5a8:includes/hashlib\__sha256.vp
|
||||||
c9f4be41ca1cc2b4:includes/viperio.vp
|
c9f4be41ca1cc2b4:includes/viperio.vp
|
||||||
ca40915f11b8b6ad:includes/memhub.vp
|
ca40915f11b8b6ad:includes/memhub.vp
|
||||||
cb1aa3a78af6f362:lib/core/Handles/HandlesVar.vp
|
cb1aa3a78af6f362:lib/core/Handles/HandlesVar.vp
|
||||||
cba5876ccb277f42:lib/StubGen/Converter.vp
|
cba5876ccb277f42:lib/StubGen/Converter.vp
|
||||||
|
cf3556225b0a3c8c:lib/core/Handles/HandlesExprCall.vp
|
||||||
|
d9dd5fce03a20af1:lib/core/Handles/HandlesAugAssign.vp
|
||||||
e217def267d3d4a8:includes/ast\lexer.vp
|
e217def267d3d4a8:includes/ast\lexer.vp
|
||||||
e307a2d809cef071:includes/viperlib.vp
|
ead693cb29a9c343:lib/core/StubMerger.vp
|
||||||
f05b14a2ad5767a7:lib/core/Handles/HandlesEnum.vp
|
f05b14a2ad5767a7:lib/core/Handles/HandlesEnum.vp
|
||||||
|
f09b2f4a0f9d053e:lib/core/Handles/HandlesStruct.vp
|
||||||
f30a3b2d5f6bf092:main.vp
|
f30a3b2d5f6bf092:main.vp
|
||||||
f3444ec56937284f:includes/ast\__init__.vp
|
f3444ec56937284f:includes/ast\__init__.vp
|
||||||
f4cdbca2f8802c12:lib/core/Handles/HandlesIf.vp
|
f4cdbca2f8802c12:lib/core/Handles/HandlesIf.vp
|
||||||
@@ -78,3 +77,4 @@ f6b51804a0ba8ff0:includes/w32\win32file.vp
|
|||||||
f9e36e2cd6fa659f:includes/llvmlite\__values.vp
|
f9e36e2cd6fa659f:includes/llvmlite\__values.vp
|
||||||
fc980acec33d69a7:includes/w32\win32base.vp
|
fc980acec33d69a7:includes/w32\win32base.vp
|
||||||
fde6db0747bdd959:includes/ast\parser.vp
|
fde6db0747bdd959:includes/ast\parser.vp
|
||||||
|
ffaf70367668b227:includes/string.vp
|
||||||
|
|||||||
Binary file not shown.
@@ -21,7 +21,9 @@ def vsprintf(buf: t.CChar | t.CPtr, rule: str, *args) -> t.CInt:
|
|||||||
return vsnprintf(buf, 0x7FFFFFFF, rule, args)
|
return vsnprintf(buf, 0x7FFFFFFF, rule, args)
|
||||||
|
|
||||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, *args) -> t.CInt | t.CExport:
|
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, *args) -> t.CInt | t.CExport:
|
||||||
if buf is None or fmt is None or size == 0: return 0
|
if fmt is None: return 0
|
||||||
|
if buf is None or size == 0:
|
||||||
|
return vsnprintf(None, 0, fmt, args)
|
||||||
return vsnprintf(buf, size, fmt, args)
|
return vsnprintf(buf, size, fmt, args)
|
||||||
|
|
||||||
# Check floating-point special values (IEEE 754)
|
# Check floating-point special values (IEEE 754)
|
||||||
@@ -39,7 +41,17 @@ def _check_special_float(fv: t.CDouble) -> t.CInt:
|
|||||||
return 3
|
return 3
|
||||||
|
|
||||||
def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.CPtr) -> t.CInt | t.CExport:
|
def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.CPtr) -> t.CInt | t.CExport:
|
||||||
if buf is None or fmt is None or size == 0: return 0
|
if fmt is None: return 0
|
||||||
|
# 长度探测模式:buf is None 时只计算格式化后长度,不实际写入
|
||||||
|
# _step=0 使 ptr 不前进,反复写入同一个 dummy 字节(无害),write_count 正确累加
|
||||||
|
count_mode: t.CInt = 0
|
||||||
|
_step: t.CInt = 1
|
||||||
|
_dummy: t.CChar = '\0'
|
||||||
|
if buf is None or size == 0:
|
||||||
|
count_mode = 1
|
||||||
|
_step = 0
|
||||||
|
buf = c.Addr(_dummy)
|
||||||
|
size = 0x7FFFFFFF
|
||||||
ptr: t.CChar | t.CPtr = buf
|
ptr: t.CChar | t.CPtr = buf
|
||||||
write_count: t.CInt = 0
|
write_count: t.CInt = 0
|
||||||
temp: t.CArray[t.CChar, 68]
|
temp: t.CArray[t.CChar, 68]
|
||||||
@@ -48,7 +60,7 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
if c.Deref(fmt) != 37:
|
if c.Deref(fmt) != 37:
|
||||||
ptr[0] = c.Deref(fmt)
|
ptr[0] = c.Deref(fmt)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fmt += 1
|
fmt += 1
|
||||||
else:
|
else:
|
||||||
fmt += 1
|
fmt += 1
|
||||||
@@ -121,7 +133,7 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
ptr_i: t.CInt = va_arg(ap)
|
ptr_i: t.CInt = va_arg(ap)
|
||||||
ptr[0] = t.CChar(ptr_i)
|
ptr[0] = t.CChar(ptr_i)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
else:
|
else:
|
||||||
ptr_i: t.CInt = va_arg(ap)
|
ptr_i: t.CInt = va_arg(ap)
|
||||||
elif c.Deref(fmt) == 115:
|
elif c.Deref(fmt) == 115:
|
||||||
@@ -137,19 +149,19 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while c.Deref(s) != 0 and write_count < size - 1:
|
while c.Deref(s) != 0 and write_count < size - 1:
|
||||||
ptr[0] = c.Deref(s)
|
ptr[0] = c.Deref(s)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
s += 1
|
s += 1
|
||||||
if left_align and width > slen:
|
if left_align and width > slen:
|
||||||
pad_count = width - slen
|
pad_count = width - slen
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 100 or c.Deref(fmt) == 105:
|
elif c.Deref(fmt) == 100 or c.Deref(fmt) == 105:
|
||||||
if is_long_long or is_size or is_long:
|
if is_long_long or is_size or is_long:
|
||||||
@@ -192,26 +204,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > i:
|
if pad_zero and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while i > 0 and write_count < size - 1:
|
while i > 0 and write_count < size - 1:
|
||||||
i -= 1
|
i -= 1
|
||||||
ptr[0] = temp[i]
|
ptr[0] = temp[i]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > i:
|
if left_align and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 117:
|
elif c.Deref(fmt) == 117:
|
||||||
if is_long or is_long_long or is_size:
|
if is_long or is_long_long or is_size:
|
||||||
@@ -230,26 +242,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > i:
|
if pad_zero and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while i > 0 and write_count < size - 1:
|
while i > 0 and write_count < size - 1:
|
||||||
i -= 1
|
i -= 1
|
||||||
ptr[0] = temp[i]
|
ptr[0] = temp[i]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > i:
|
if left_align and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 120:
|
elif c.Deref(fmt) == 120:
|
||||||
if is_long or is_long_long or is_size:
|
if is_long or is_long_long or is_size:
|
||||||
@@ -280,35 +292,35 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if prefix_len > 0:
|
if prefix_len > 0:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 120
|
ptr[0] = 120
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if pad_zero and width > effective_len:
|
if pad_zero and width > effective_len:
|
||||||
pad_count = width - effective_len
|
pad_count = width - effective_len
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while i > 0 and write_count < size - 1:
|
while i > 0 and write_count < size - 1:
|
||||||
i -= 1
|
i -= 1
|
||||||
ptr[0] = temp[i]
|
ptr[0] = temp[i]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > effective_len:
|
if left_align and width > effective_len:
|
||||||
pad_count = width - effective_len
|
pad_count = width - effective_len
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 88:
|
elif c.Deref(fmt) == 88:
|
||||||
if is_long or is_long_long or is_size:
|
if is_long or is_long_long or is_size:
|
||||||
@@ -339,35 +351,35 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if prefix_len > 0:
|
if prefix_len > 0:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 88
|
ptr[0] = 88
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if pad_zero and width > effective_len:
|
if pad_zero and width > effective_len:
|
||||||
pad_count = width - effective_len
|
pad_count = width - effective_len
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while i > 0 and write_count < size - 1:
|
while i > 0 and write_count < size - 1:
|
||||||
i -= 1
|
i -= 1
|
||||||
ptr[0] = temp[i]
|
ptr[0] = temp[i]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > effective_len:
|
if left_align and width > effective_len:
|
||||||
pad_count = width - effective_len
|
pad_count = width - effective_len
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 111:
|
elif c.Deref(fmt) == 111:
|
||||||
if is_long or is_long_long or is_size:
|
if is_long or is_long_long or is_size:
|
||||||
@@ -397,26 +409,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > i:
|
if pad_zero and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while i > 0 and write_count < size - 1:
|
while i > 0 and write_count < size - 1:
|
||||||
i -= 1
|
i -= 1
|
||||||
ptr[0] = temp[i]
|
ptr[0] = temp[i]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > i:
|
if left_align and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 98:
|
elif c.Deref(fmt) == 98:
|
||||||
if is_long or is_long_long or is_size:
|
if is_long or is_long_long or is_size:
|
||||||
@@ -446,26 +458,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > i:
|
if pad_zero and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while i > 0 and write_count < size - 1:
|
while i > 0 and write_count < size - 1:
|
||||||
i -= 1
|
i -= 1
|
||||||
ptr[0] = temp[i]
|
ptr[0] = temp[i]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > i:
|
if left_align and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 112:
|
elif c.Deref(fmt) == 112:
|
||||||
ptr_val: t.CUInt64T = t.CUInt64T(va_arg(ap, t.CPtr))
|
ptr_val: t.CUInt64T = t.CUInt64T(va_arg(ap, t.CPtr))
|
||||||
@@ -500,26 +512,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > i:
|
if pad_zero and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while i > 0 and write_count < size - 1:
|
while i > 0 and write_count < size - 1:
|
||||||
i -= 1
|
i -= 1
|
||||||
ptr[0] = temp[i]
|
ptr[0] = temp[i]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > i:
|
if left_align and width > i:
|
||||||
pad_count = width - i
|
pad_count = width - i
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 102 or c.Deref(fmt) == 70:
|
elif c.Deref(fmt) == 102 or c.Deref(fmt) == 70:
|
||||||
f_upper: t.CInt = 1 if c.Deref(fmt) == 70 else 0
|
f_upper: t.CInt = 1 if c.Deref(fmt) == 70 else 0
|
||||||
@@ -540,23 +552,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while f_pad > 0 and write_count < size - 1:
|
while f_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
f_pad -= 1
|
f_pad -= 1
|
||||||
if f_sp == 2:
|
if f_sp == 2:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif f_sp == 1 and show_sign:
|
elif f_sp == 1 and show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif f_sp == 1 and space_sign:
|
elif f_sp == 1 and space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fi_c: t.CInt = 0
|
fi_c: t.CInt = 0
|
||||||
while fi_c < 3 and write_count < size - 1:
|
while fi_c < 3 and write_count < size - 1:
|
||||||
fc: t.CInt = 0
|
fc: t.CInt = 0
|
||||||
@@ -580,14 +592,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
fc -= 32
|
fc -= 32
|
||||||
ptr[0] = t.CChar(fc)
|
ptr[0] = t.CChar(fc)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fi_c += 1
|
fi_c += 1
|
||||||
if left_align and width > f_total_len:
|
if left_align and width > f_total_len:
|
||||||
f_pad = width - f_total_len
|
f_pad = width - f_total_len
|
||||||
while f_pad > 0 and write_count < size - 1:
|
while f_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
f_pad -= 1
|
f_pad -= 1
|
||||||
fmt += 1
|
fmt += 1
|
||||||
continue
|
continue
|
||||||
@@ -595,18 +607,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fv = 0.0 - fv
|
fv = 0.0 - fv
|
||||||
elif show_sign:
|
elif show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif space_sign:
|
elif space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
di: t.CInt = 0
|
di: t.CInt = 0
|
||||||
work: t.CDouble = fv
|
work: t.CDouble = fv
|
||||||
if work < 1.0:
|
if work < 1.0:
|
||||||
@@ -635,25 +647,25 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > f_total:
|
if pad_zero and width > f_total:
|
||||||
pad_count = width - f_total
|
pad_count = width - f_total
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
while di > 0 and write_count < size - 1:
|
while di > 0 and write_count < size - 1:
|
||||||
di -= 1
|
di -= 1
|
||||||
ptr[0] = temp[di]
|
ptr[0] = temp[di]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if precision > 0:
|
if precision > 0:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 46
|
ptr[0] = 46
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fi: t.CInt = 0
|
fi: t.CInt = 0
|
||||||
while fi < precision and fi < TEMP_BUF_SIZE - 1:
|
while fi < precision and fi < TEMP_BUF_SIZE - 1:
|
||||||
temp[fi] = t.CChar(frac_part % 10 + 48)
|
temp[fi] = t.CChar(frac_part % 10 + 48)
|
||||||
@@ -666,18 +678,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
fi -= 1
|
fi -= 1
|
||||||
ptr[0] = temp[fi]
|
ptr[0] = temp[fi]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif alt_form:
|
elif alt_form:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 46
|
ptr[0] = 46
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > f_total:
|
if left_align and width > f_total:
|
||||||
pad_count = width - f_total
|
pad_count = width - f_total
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 101 or c.Deref(fmt) == 69:
|
elif c.Deref(fmt) == 101 or c.Deref(fmt) == 69:
|
||||||
if precision < 0: precision = 6
|
if precision < 0: precision = 6
|
||||||
@@ -698,23 +710,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while e_pad > 0 and write_count < size - 1:
|
while e_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
e_pad -= 1
|
e_pad -= 1
|
||||||
if e_sp == 2:
|
if e_sp == 2:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif e_sp == 1 and show_sign:
|
elif e_sp == 1 and show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif e_sp == 1 and space_sign:
|
elif e_sp == 1 and space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
ei_c: t.CInt = 0
|
ei_c: t.CInt = 0
|
||||||
while ei_c < 3 and write_count < size - 1:
|
while ei_c < 3 and write_count < size - 1:
|
||||||
ec: t.CInt = 0
|
ec: t.CInt = 0
|
||||||
@@ -738,14 +750,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
ec -= 32
|
ec -= 32
|
||||||
ptr[0] = t.CChar(ec)
|
ptr[0] = t.CChar(ec)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
ei_c += 1
|
ei_c += 1
|
||||||
if left_align and width > e_total_len:
|
if left_align and width > e_total_len:
|
||||||
e_pad = width - e_total_len
|
e_pad = width - e_total_len
|
||||||
while e_pad > 0 and write_count < size - 1:
|
while e_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
e_pad -= 1
|
e_pad -= 1
|
||||||
fmt += 1
|
fmt += 1
|
||||||
continue
|
continue
|
||||||
@@ -753,18 +765,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fv = 0.0 - fv
|
fv = 0.0 - fv
|
||||||
elif show_sign:
|
elif show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif space_sign:
|
elif space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
exp10: t.CInt = 0
|
exp10: t.CInt = 0
|
||||||
if fv != 0.0:
|
if fv != 0.0:
|
||||||
while fv >= 10.0:
|
while fv >= 10.0:
|
||||||
@@ -799,24 +811,24 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > e_total:
|
if pad_zero and width > e_total:
|
||||||
pad_count = width - e_total
|
pad_count = width - e_total
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = t.CChar(int_digit + 48)
|
ptr[0] = t.CChar(int_digit + 48)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if precision > 0:
|
if precision > 0:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 46
|
ptr[0] = 46
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fi: t.CInt = 0
|
fi: t.CInt = 0
|
||||||
while fi < precision and fi < TEMP_BUF_SIZE - 1:
|
while fi < precision and fi < TEMP_BUF_SIZE - 1:
|
||||||
temp[fi] = t.CChar(frac_p % 10 + 48)
|
temp[fi] = t.CChar(frac_p % 10 + 48)
|
||||||
@@ -829,20 +841,20 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
fi -= 1
|
fi -= 1
|
||||||
ptr[0] = temp[fi]
|
ptr[0] = temp[fi]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif alt_form:
|
elif alt_form:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 46
|
ptr[0] = 46
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 101 if e_upper == 0 else 69
|
ptr[0] = 101 if e_upper == 0 else 69
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45 if exp10 < 0 else 43
|
ptr[0] = 45 if exp10 < 0 else 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
exp_abs: t.CUInt64T = t.CUInt64T(exp10) if exp10 >= 0 else t.CUInt64T(0 - exp10)
|
exp_abs: t.CUInt64T = t.CUInt64T(exp10) if exp10 >= 0 else t.CUInt64T(0 - exp10)
|
||||||
ei: t.CInt = 0
|
ei: t.CInt = 0
|
||||||
if exp_abs == 0:
|
if exp_abs == 0:
|
||||||
@@ -861,13 +873,13 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
ei -= 1
|
ei -= 1
|
||||||
ptr[0] = temp[ei]
|
ptr[0] = temp[ei]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > e_total:
|
if left_align and width > e_total:
|
||||||
pad_count = width - e_total
|
pad_count = width - e_total
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 103 or c.Deref(fmt) == 71:
|
elif c.Deref(fmt) == 103 or c.Deref(fmt) == 71:
|
||||||
if precision < 0: precision = 6
|
if precision < 0: precision = 6
|
||||||
@@ -889,23 +901,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while g_pad > 0 and write_count < size - 1:
|
while g_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
g_pad -= 1
|
g_pad -= 1
|
||||||
if g_sp == 2:
|
if g_sp == 2:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif g_sp == 1 and show_sign:
|
elif g_sp == 1 and show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif g_sp == 1 and space_sign:
|
elif g_sp == 1 and space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
gi_c: t.CInt = 0
|
gi_c: t.CInt = 0
|
||||||
while gi_c < 3 and write_count < size - 1:
|
while gi_c < 3 and write_count < size - 1:
|
||||||
gc: t.CInt = 0
|
gc: t.CInt = 0
|
||||||
@@ -929,14 +941,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
gc -= 32
|
gc -= 32
|
||||||
ptr[0] = t.CChar(gc)
|
ptr[0] = t.CChar(gc)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
gi_c += 1
|
gi_c += 1
|
||||||
if left_align and width > g_total_len:
|
if left_align and width > g_total_len:
|
||||||
g_pad = width - g_total_len
|
g_pad = width - g_total_len
|
||||||
while g_pad > 0 and write_count < size - 1:
|
while g_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
g_pad -= 1
|
g_pad -= 1
|
||||||
fmt += 1
|
fmt += 1
|
||||||
continue
|
continue
|
||||||
@@ -944,18 +956,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fv = 0.0 - fv
|
fv = 0.0 - fv
|
||||||
elif show_sign:
|
elif show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif space_sign:
|
elif space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fv_orig: t.CDouble = fv
|
fv_orig: t.CDouble = fv
|
||||||
exp10: t.CInt = 0
|
exp10: t.CInt = 0
|
||||||
if fv != 0.0:
|
if fv != 0.0:
|
||||||
@@ -1064,30 +1076,30 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
if pad_zero and width > g_total:
|
if pad_zero and width > g_total:
|
||||||
pad_count = width - g_total
|
pad_count = width - g_total
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
gi: t.CInt = 0
|
gi: t.CInt = 0
|
||||||
while gi < g_len and write_count < size - 1:
|
while gi < g_len and write_count < size - 1:
|
||||||
ptr[0] = temp[gi]
|
ptr[0] = temp[gi]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
gi += 1
|
gi += 1
|
||||||
if g_use_e:
|
if g_use_e:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 101 if g_upper == 0 else 69
|
ptr[0] = 101 if g_upper == 0 else 69
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45 if exp10 < 0 else 43
|
ptr[0] = 45 if exp10 < 0 else 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
exp_abs: t.CUInt64T = t.CUInt64T(exp10) if exp10 >= 0 else t.CUInt64T(0 - exp10)
|
exp_abs: t.CUInt64T = t.CUInt64T(exp10) if exp10 >= 0 else t.CUInt64T(0 - exp10)
|
||||||
ei: t.CInt = 0
|
ei: t.CInt = 0
|
||||||
if exp_abs == 0:
|
if exp_abs == 0:
|
||||||
@@ -1106,13 +1118,13 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
ei -= 1
|
ei -= 1
|
||||||
ptr[0] = temp[ei]
|
ptr[0] = temp[ei]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > g_total:
|
if left_align and width > g_total:
|
||||||
pad_count = width - g_total
|
pad_count = width - g_total
|
||||||
while pad_count > 0 and write_count < size - 1:
|
while pad_count > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
pad_count -= 1
|
pad_count -= 1
|
||||||
elif c.Deref(fmt) == 97 or c.Deref(fmt) == 65:
|
elif c.Deref(fmt) == 97 or c.Deref(fmt) == 65:
|
||||||
a_upper: t.CInt = 1 if c.Deref(fmt) == 65 else 0
|
a_upper: t.CInt = 1 if c.Deref(fmt) == 65 else 0
|
||||||
@@ -1132,23 +1144,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while a_pad > 0 and write_count < size - 1:
|
while a_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_pad -= 1
|
a_pad -= 1
|
||||||
if a_sp == 2:
|
if a_sp == 2:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif a_sp == 1 and show_sign:
|
elif a_sp == 1 and show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif a_sp == 1 and space_sign:
|
elif a_sp == 1 and space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
ai_c: t.CInt = 0
|
ai_c: t.CInt = 0
|
||||||
while ai_c < 3 and write_count < size - 1:
|
while ai_c < 3 and write_count < size - 1:
|
||||||
ac: t.CInt = 0
|
ac: t.CInt = 0
|
||||||
@@ -1172,14 +1184,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
ac -= 32
|
ac -= 32
|
||||||
ptr[0] = t.CChar(ac)
|
ptr[0] = t.CChar(ac)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
ai_c += 1
|
ai_c += 1
|
||||||
if left_align and width > a_total_len:
|
if left_align and width > a_total_len:
|
||||||
a_pad = width - a_total_len
|
a_pad = width - a_total_len
|
||||||
while a_pad > 0 and write_count < size - 1:
|
while a_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_pad -= 1
|
a_pad -= 1
|
||||||
fmt += 1
|
fmt += 1
|
||||||
continue
|
continue
|
||||||
@@ -1255,55 +1267,55 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
while a_pad > 0 and write_count < size - 1:
|
while a_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_pad -= 1
|
a_pad -= 1
|
||||||
if a_neg:
|
if a_neg:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif show_sign:
|
elif show_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
elif space_sign:
|
elif space_sign:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if pad_zero and width > a_content_len:
|
if pad_zero and width > a_content_len:
|
||||||
a_pad = width - a_content_len
|
a_pad = width - a_content_len
|
||||||
while a_pad > 0 and write_count < size - 1:
|
while a_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_pad -= 1
|
a_pad -= 1
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 48
|
ptr[0] = 48
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
if a_upper:
|
if a_upper:
|
||||||
ptr[0] = 88
|
ptr[0] = 88
|
||||||
else:
|
else:
|
||||||
ptr[0] = 120
|
ptr[0] = 120
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = t.CChar(a_leading + 48)
|
ptr[0] = t.CChar(a_leading + 48)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if a_has_dot:
|
if a_has_dot:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 46
|
ptr[0] = 46
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_hj: t.CInt = 0
|
a_hj: t.CInt = 0
|
||||||
while a_hj < a_hd_count and write_count < size - 1:
|
while a_hj < a_hd_count and write_count < size - 1:
|
||||||
ptr[0] = temp[a_hj]
|
ptr[0] = temp[a_hj]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_hj += 1
|
a_hj += 1
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
if a_upper:
|
if a_upper:
|
||||||
@@ -1311,26 +1323,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
else:
|
else:
|
||||||
ptr[0] = 112
|
ptr[0] = 112
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
if a_esign:
|
if a_esign:
|
||||||
ptr[0] = 45
|
ptr[0] = 45
|
||||||
else:
|
else:
|
||||||
ptr[0] = 43
|
ptr[0] = 43
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_ek: t.CInt = a_ecount
|
a_ek: t.CInt = a_ecount
|
||||||
while a_ek > 0 and write_count < size - 1:
|
while a_ek > 0 and write_count < size - 1:
|
||||||
a_ek -= 1
|
a_ek -= 1
|
||||||
ptr[0] = temp[60 + a_ek]
|
ptr[0] = temp[60 + a_ek]
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
if left_align and width > a_content_len:
|
if left_align and width > a_content_len:
|
||||||
a_pad = width - a_content_len
|
a_pad = width - a_content_len
|
||||||
while a_pad > 0 and write_count < size - 1:
|
while a_pad > 0 and write_count < size - 1:
|
||||||
ptr[0] = 32
|
ptr[0] = 32
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
a_pad -= 1
|
a_pad -= 1
|
||||||
elif c.Deref(fmt) == 110:
|
elif c.Deref(fmt) == 110:
|
||||||
if is_long_long or is_long:
|
if is_long_long or is_long:
|
||||||
@@ -1353,12 +1365,12 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
|||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = 37
|
ptr[0] = 37
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
else:
|
else:
|
||||||
if write_count < size - 1:
|
if write_count < size - 1:
|
||||||
ptr[0] = c.Deref(fmt)
|
ptr[0] = c.Deref(fmt)
|
||||||
write_count += 1
|
write_count += 1
|
||||||
ptr += 1
|
ptr += _step
|
||||||
fmt += 1
|
fmt += 1
|
||||||
ptr[0] = 0
|
ptr[0] = 0
|
||||||
return write_count
|
return write_count
|
||||||
|
|||||||
@@ -1195,6 +1195,11 @@ class ClassHandle(BaseHandle):
|
|||||||
MemberNode.Lineno = lineno
|
MemberNode.Lineno = lineno
|
||||||
MemberNode.IsEnumMember = True
|
MemberNode.IsEnumMember = True
|
||||||
self.Trans.SymbolTable.insert(VariantName, MemberNode)
|
self.Trans.SymbolTable.insert(VariantName, MemberNode)
|
||||||
|
# 同模块 REnum 变体也注册限定名和下划线名,
|
||||||
|
# 对齐跨模块导入(HandlesImports.py)的注册逻辑。
|
||||||
|
# 避免裸名被同名的工厂函数覆盖后,路径 2 的限定名查找失败。
|
||||||
|
self.Trans.SymbolTable.insert(f"{ClassName}.{VariantName}", MemberNode)
|
||||||
|
self.Trans.SymbolTable.insert(f"{ClassName}_{VariantName}", MemberNode)
|
||||||
# 更新预注册的 REnum 类型信息(填充变体列表)
|
# 更新预注册的 REnum 类型信息(填充变体列表)
|
||||||
PreTypeInfo.RenumVariants = variant_names
|
PreTypeInfo.RenumVariants = variant_names
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,34 @@ class MatchHandle(BaseHandle):
|
|||||||
elif isinstance(pattern, ast.MatchSequence):
|
elif isinstance(pattern, ast.MatchSequence):
|
||||||
HasDefault = True
|
HasDefault = True
|
||||||
CaseBBs.append(DefaultBB)
|
CaseBBs.append(DefaultBB)
|
||||||
|
elif isinstance(pattern, ast.MatchClass):
|
||||||
|
# 兜底处理:REnum 检测失败但 case 是 MatchClass(REnum 变体模式)
|
||||||
|
# 尝试从变体名查找 tag 值,按整数值处理
|
||||||
|
cls_node_mc: ast.expr = pattern.cls
|
||||||
|
VariantName_mc: str | None = None
|
||||||
|
QualifiedName_mc: str | None = None
|
||||||
|
if isinstance(cls_node_mc, ast.Name):
|
||||||
|
VariantName_mc = cls_node_mc.id
|
||||||
|
elif isinstance(cls_node_mc, ast.Attribute):
|
||||||
|
VariantName_mc = cls_node_mc.attr
|
||||||
|
if isinstance(cls_node_mc.value, ast.Attribute):
|
||||||
|
QualifiedName_mc = f"{cls_node_mc.value.attr}.{VariantName_mc}"
|
||||||
|
elif isinstance(cls_node_mc.value, ast.Name):
|
||||||
|
QualifiedName_mc = f"{cls_node_mc.value.id}.{VariantName_mc}"
|
||||||
|
TagValue_mc: int | None = None
|
||||||
|
SymInfo_mc: "SymbolTable.SymbolInfo" = None
|
||||||
|
if QualifiedName_mc:
|
||||||
|
SymInfo_mc = self.Trans.SymbolTable.lookup(QualifiedName_mc)
|
||||||
|
if not (SymInfo_mc and SymInfo_mc.IsEnumMember):
|
||||||
|
SymInfo_mc = self.Trans.SymbolTable.lookup(VariantName_mc)
|
||||||
|
if SymInfo_mc and SymInfo_mc.IsEnumMember:
|
||||||
|
TagValue_mc = SymInfo_mc.value
|
||||||
|
if TagValue_mc is not None:
|
||||||
|
CaseValues.append(ir.Constant(SwitchIntType, TagValue_mc))
|
||||||
|
CaseBBs.append(Gen.func.append_basic_block(name=f"match.case_{VariantName_mc}"))
|
||||||
|
else:
|
||||||
|
# 变体名未找到,跳过此 case(fast-fail 已在外层处理)
|
||||||
|
pass
|
||||||
def _HasNoBreak(stmts: list[ast.stmt]) -> bool:
|
def _HasNoBreak(stmts: list[ast.stmt]) -> bool:
|
||||||
for stmt in stmts:
|
for stmt in stmts:
|
||||||
if isinstance(stmt, ast.Expr) and isinstance(stmt.value, ast.Call):
|
if isinstance(stmt, ast.Expr) and isinstance(stmt.value, ast.Call):
|
||||||
@@ -187,6 +215,16 @@ class MatchHandle(BaseHandle):
|
|||||||
if not HasNoBreak[i]:
|
if not HasNoBreak[i]:
|
||||||
Gen.builder.branch(AfterBB)
|
Gen.builder.branch(AfterBB)
|
||||||
CaseIdx += 1
|
CaseIdx += 1
|
||||||
|
elif isinstance(pattern, ast.MatchClass):
|
||||||
|
# 兜底处理:MatchClass 在非 REnum 路径的 case body 生成
|
||||||
|
# case 收集阶段已创建 CaseBB,此处生成 body
|
||||||
|
if CaseIdx < len(CaseBBs) and CaseBBs[CaseIdx] != DefaultBB:
|
||||||
|
Gen.builder.position_at_start(CaseBBs[CaseIdx])
|
||||||
|
self.HandleBodyLlvm(case.body)
|
||||||
|
if not Gen.builder.block.is_terminated:
|
||||||
|
if not HasNoBreak[i]:
|
||||||
|
Gen.builder.branch(AfterBB)
|
||||||
|
CaseIdx += 1
|
||||||
if not HasDefault:
|
if not HasDefault:
|
||||||
Gen.builder.position_at_start(DefaultBB)
|
Gen.builder.position_at_start(DefaultBB)
|
||||||
Gen.builder.branch(AfterBB)
|
Gen.builder.branch(AfterBB)
|
||||||
|
|||||||
Reference in New Issue
Block a user