diff --git a/App/lib/StubGen/Converter.vp b/App/lib/StubGen/Converter.vp index 4cd8506..928e5cf 100644 --- a/App/lib/StubGen/Converter.vp +++ b/App/lib/StubGen/Converter.vp @@ -205,7 +205,7 @@ def _PyiTypeStr(buf: bytes, buf_size: t.CSizeT, pos: t.CSizeT, pos = _PyiTypeStr(buf, buf_size, pos, bop.right) return pos - # Constant: 字符串前向引用 (如 'MyClass') 或 None + # Constant: 字符串前向引用 (如 'MyClass')、None 或数字常量(CArray count) if k == ast.ASTKind.Constant: cn: ast.Constant | t.CPtr = (ast.Constant | t.CPtr)(annot) if cn.const_kind == ast.CONST_STR: @@ -216,6 +216,17 @@ def _PyiTypeStr(buf: bytes, buf_size: t.CSizeT, pos: t.CSizeT, return pos if cn.const_kind == ast.CONST_NONE: return _PyiEmit(buf, buf_size, pos, "None") + # 数字常量(t.CArray[t.CUInt32T, 64] 的 count 等):输出数值本身, + # 而不是回退 t.CInt——否则 vpi 生成 "t.CArray[..., t.CInt]" 在加载 + # stub 时触发 TypeError(count 必须是整数常量、None、CDefine 常量名 + # 或常量表达式)。 + if cn.const_kind == ast.CONST_INT or cn.const_kind == ast.CONST_CHAR: + num_buf_ct: str = stdlib.malloc(24) + if num_buf_ct is not None: + viperlib.snprintf(num_buf_ct, 24, "%d", cn.int_val) + pos = _PyiEmit(buf, buf_size, pos, num_buf_ct) + stdlib.free(num_buf_ct) + return pos return _PyiEmit(buf, buf_size, pos, "t.CInt") # Tuple: 多参数下标 (如 Dict[str, int])