From 4e279d806f9236c649075000eaf7b9aab7f3c9e4 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Tue, 13 Oct 2026 10:08:25 +0800 Subject: [PATCH] =?UTF-8?q?test(cpythontest):=20PyUnicode=5FGetLength(Py?= =?UTF-8?q?=5Fssize=5Ft=3D64=E4=BD=8D)=20=E6=94=B9=E7=94=A8=20t.CPtrDiffT?= =?UTF-8?q?=20=E6=8E=A5=E6=94=B6=EF=BC=8C=E5=B9=B6=E6=A0=A1=E6=AD=A3=20cpy?= =?UTF-8?q?thon.vp=20=E4=B8=89=E5=A4=84=E5=BA=94=E4=B8=BA=2064=20=E4=BD=8D?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPythonTest/App/cpython.vp | 6 +++--- CPythonTest/App/main.vp | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CPythonTest/App/cpython.vp b/CPythonTest/App/cpython.vp index 1321105..fd55172 100644 --- a/CPythonTest/App/cpython.vp +++ b/CPythonTest/App/cpython.vp @@ -109,8 +109,8 @@ extern def PyLong_FromSize_t(v: sizet) -> PyObject* extern def PyLong_FromDouble(v: double) -> PyObject* extern def PyLong_AsLong(obj: PyObject*) -> int extern def PyLong_AsUnsignedLong(obj: PyObject*) -> t.CUnsignedLong -extern def PyLong_AsLongLong(obj: PyObject*) -> t.CLong -extern def PyLong_AsUnsignedLongLong(obj: PyObject*) -> t.CUnsignedLong +extern def PyLong_AsLongLong(obj: PyObject*) -> t.CLongLong +extern def PyLong_AsUnsignedLongLong(obj: PyObject*) -> t.CUnsignedLongLong extern def PyLong_AsDouble(obj: PyObject*) -> double extern def PyLong_AsSsize_t(obj: PyObject*) -> t.CPtrDiffT extern def PyLong_AsSize_t(obj: PyObject*) -> sizet @@ -220,7 +220,7 @@ extern def PyObject_IsTrue(obj: PyObject*) -> int extern def PyObject_Not(obj: PyObject*) -> int extern def PyObject_RichCompare(o1: PyObject*, o2: PyObject*, opid: int) -> PyObject* extern def PyObject_RichCompareBool(o1: PyObject*, o2: PyObject*, opid: int) -> int -extern def PyObject_Hash(obj: PyObject*) -> t.CLong +extern def PyObject_Hash(obj: PyObject*) -> t.CPtrDiffT extern def PyObject_Length(obj: PyObject*) -> sizet extern def PyObject_GetItem(obj: PyObject*, key: PyObject*) -> PyObject* extern def PyObject_SetItem(obj: PyObject*, key: PyObject*, val: PyObject*) -> int diff --git a/CPythonTest/App/main.vp b/CPythonTest/App/main.vp index 93f9cfe..d595b10 100644 --- a/CPythonTest/App/main.vp +++ b/CPythonTest/App/main.vp @@ -68,7 +68,9 @@ def test_string_operations(): printf(" PyUnicode_FromString -> %s\n", utf8) # String length - length: CLong = cpython.PyUnicode_GetLength(py_s1) + # PyUnicode_GetLength 返回 CPython 的 Py_ssize_t(= ptrdiff_t,64 位);CLong 在本目标 + # (x86_64-pc-windows-gnu / LLP64) 只有 32 位,用 CLong 接收会触发「隐式窄化禁止」。 + length: t.CPtrDiffT = cpython.PyUnicode_GetLength(py_s1) testcheck.check(length == 13, "GetLength == 13", "GetLength == 13") # String concat