refactor: 全量迁移 includes 到新规范语法

按根目录 新规范 迁移 R1/R2/R3/R4/R6/R7/R8/R9:指针 T* 后缀、内建类型短别名、c.Addr/c.Deref 单目化、c.Asm 改 __asm__、t.CDefine 改 define 软关键字、t.CEnum 改 enum。R4 对内建 cast 多参实参保留 c.Deref 原写法(单目化会致 TPC 类型退化)。验证:includes 52/52 编译通过,TransPyV 自举产物顺序回归 77/77 全通过。
This commit is contained in:
TermiNexus committed 2026-10-05 09:04:46 +08:00
1 parent aecdf27132
commit e80284a6d5
88 files changed
+4474 -4474

No files matched your search

+16 -16
View File
@@ -29,7 +29,7 @@ import memhub
# - 握手成功后可用 last_tls_info() 查看 TLS 版本 / 加密套件 / 对端证书主题。
# ============================================================
HTTPS_PORT: t.CDefine = 443
define HTTPS_PORT = 443
# 模块内部状态
_ossl_ready: bool = False
@@ -47,7 +47,7 @@ _last_verify_flag: INT = -1 # 最近一次请求 verify 标志(1=
# _st_state: 0=运行中 1=完成(2xx) 2=失败
# _st_status: HTTP 状态码(失败网络路径为负错误码)
# ============================================================
STREAM_CAP: t.CDefine = 262144
define STREAM_CAP = 262144
_st_buf: t.CArray[char, 262144]
_st_len: sizet = 0
_st_consumed: sizet = 0
@@ -154,7 +154,7 @@ def _EnsureReady() -> INT:
return 0
def _ParseHttpsUrl(url: str, host_buf: str, host_size: INT, path_buf: str, path_size: INT, port: INT | t.CPtr) -> INT:
def _ParseHttpsUrl(url: str, host_buf: str, host_size: INT, path_buf: str, path_size: INT, port: INT*) -> INT:
"""解析 https://host[:port][/path],端口缺省 443。"""
if url is None: return -1
if host_buf is None or path_buf is None or port is None: return -1
@@ -212,7 +212,7 @@ def _ScratchBuf() -> str:
def _TlsErrText():
"""把最近一次 openssl 错误队列文本写入静态 scratch 缓冲。"""
e: t.CUInt32T = openssl.ERR_get_error()
e: uint32 = openssl.ERR_get_error()
if e == 0:
_scratch_store[0] = 0
string.strncpy(_scratch_store, "openssl error (no detail)", 26)
@@ -255,7 +255,7 @@ def _HttpsRequest(method: str, url: str, verify: bool, ca_file: str, data: str,
path_buf: t.CArray[char, 1024]
port: INT = 0
if _ParseHttpsUrl(url, host_buf, 256, path_buf, 1024, c.Addr(port)) != 0:
if _ParseHttpsUrl(url, host_buf, 256, path_buf, 1024, &port) != 0:
stdio.snprintf(errmsg, 512, "bad https url: %s", url)
_RecordErrorText(errmsg)
requests._mbuddy.free(errmsg)
@@ -343,7 +343,7 @@ def _HttpsRequest(method: str, url: str, verify: bool, ca_file: str, data: str,
# ---- 证书链校验结果复核 ----
if verify:
vres: t.CInt32T = openssl.SSL_get_verify_result(ssl)
vres: int32 = openssl.SSL_get_verify_result(ssl)
if vres != 0:
reason: str = openssl.X509_verify_cert_error_string(vres)
if reason is None:
@@ -461,7 +461,7 @@ def _HttpsRequest(method: str, url: str, verify: bool, ca_file: str, data: str,
requests._mbuddy.free(errmsg)
requests.release(resp)
return None
resp_buf = char(t.CUInt64T(nb), t.CPtr)
resp_buf = char(uint64(nb), t.CPtr)
room = resp_cap - 1 - total
n: INT = openssl.SSL_read(ssl, resp_buf + total, room)
if n <= 0:
@@ -669,7 +669,7 @@ def post_stream(url: str, data: str, content_type: str = "application/json",
host_buf: t.CArray[char, 256]
path_buf: t.CArray[char, 1024]
port: INT = 0
if _ParseHttpsUrl(url, host_buf, 256, path_buf, 1024, c.Addr(port)) != 0:
if _ParseHttpsUrl(url, host_buf, 256, path_buf, 1024, &port) != 0:
stdio.snprintf(errmsg, 512, "bad https url: %s", url)
_RecordErrorText(errmsg)
_SetStreamFail(-1)
@@ -743,7 +743,7 @@ def post_stream(url: str, data: str, content_type: str = "application/json",
return -1
if verify:
vres: t.CInt32T = openssl.SSL_get_verify_result(ssl)
vres: int32 = openssl.SSL_get_verify_result(ssl)
if vres != 0:
reason: str = openssl.X509_verify_cert_error_string(vres)
if reason is None:
@@ -930,7 +930,7 @@ def post_stream(url: str, data: str, content_type: str = "application/json",
# ============================================================
def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
dst: str, dst_cap: INT, out_status: INT | t.CPtr,
dst: str, dst_cap: INT, out_status: INT*,
out_loc: str, out_loccap: INT,
out_total: sizet*) -> INT:
"""HTTPS 单次 Range 拉取(线程安全,见模块注释)。"""
@@ -938,8 +938,8 @@ def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
if url is None or dst is None or dst_cap <= 0 \
or out_status is None or out_total is None:
return -1
c.Set(c.Deref(out_status), 0)
c.Set(c.Deref(out_total), 0)
c.Set(*out_status, 0)
c.Set(*out_total, 0)
if out_loc is not None and out_loccap > 0:
out_loc[0] = 0
_last_verify_flag = 1 if verify else 0
@@ -950,7 +950,7 @@ def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
host_buf: t.CArray[char, 256]
path_buf: t.CArray[char, 1024]
port: INT = 0
if _ParseHttpsUrl(url, host_buf, 256, path_buf, 1024, c.Addr(port)) != 0:
if _ParseHttpsUrl(url, host_buf, 256, path_buf, 1024, &port) != 0:
_RecordErrorText("bad https url")
return -3
@@ -1064,7 +1064,7 @@ def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
dst[total] = 0
st: INT = requests._StatusRaw(dst)
c.Set(c.Deref(out_status), st)
c.Set(*out_status, st)
if st == 0:
_RecordErrorText("empty response")
return -3
@@ -1078,11 +1078,11 @@ def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
return -3
if st == 206:
c.Set(c.Deref(out_total), requests._CRTotalOf(dst, total))
c.Set(*out_total, requests._CRTotalOf(dst, total))
else:
cl2: INT = requests._CLenOf(dst, total)
if cl2 > 0:
c.Set(c.Deref(out_total), sizet(cl2))
c.Set(*out_total, sizet(cl2))
bo: INT = requests._FindBodyStart(dst, total)
if bo < 0 or bo >= total:
return 0