20
20
# Kevin Deng <kevindeng55+transifex@gmail.com>, 2024
21
21
# Wulian233 <xiguawulian@gmail.com>, 2024
22
22
# Rafael Fontenelle <rffontenelle@gmail.com>, 2025
23
+ # 汇民 王 <whuim@qq.com>, 2025
23
24
# Freesand Leo <yuqinju@163.com>, 2025
24
25
#
25
26
#, fuzzy
26
27
msgid ""
27
28
msgstr ""
28
29
"Project-Id-Version : Python 3.14\n "
29
30
"Report-Msgid-Bugs-To : \n "
30
- "POT-Creation-Date : 2025-06-27 14:20+0000\n "
31
+ "POT-Creation-Date : 2025-07-04 14:20+0000\n "
31
32
"PO-Revision-Date : 2021-06-28 00:50+0000\n "
32
33
"Last-Translator : Freesand Leo <yuqinju@163.com>, 2025\n "
33
34
"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -1796,6 +1797,8 @@ msgid ""
1796
1797
"instance, and call the type's :c:member:`~PyTypeObject.tp_free` function to "
1797
1798
"free the object itself."
1798
1799
msgstr ""
1800
+ "析构函数应移除该实例所拥有的所有引用(例如,调用 :c:func:`Py_CLEAR`),释放该实例所拥有的所有内存缓冲区,并调用该类型的 "
1801
+ ":c:member:`~PyTypeObject.tp_free` 函数来释放对象本身。"
1799
1802
1800
1803
#: ../../c-api/typeobj.rst:689
1801
1804
msgid ""
@@ -1804,6 +1807,8 @@ msgid ""
1804
1807
" ensure you don't clobber a preexisting error indicator (the deallocation "
1805
1808
"could have occurred while processing a different error):"
1806
1809
msgstr ""
1810
+ "如果您可能会调用那些可能设置错误指示器的函数,则必须使用 :c:func:`PyErr_GetRaisedException` 和 "
1811
+ ":c:func:`PyErr_SetRaisedException`,以确保不会破坏已存在的错误指示器(在处理另一个错误的过程中,可能已发生了内存释放):"
1807
1812
1808
1813
#: ../../c-api/typeobj.rst:694
1809
1814
msgid ""
@@ -1816,52 +1821,68 @@ msgid ""
1816
1821
" PyErr_SetRaisedException(exc);\n"
1817
1822
"}"
1818
1823
msgstr ""
1824
+ "static void\n"
1825
+ "foo_dealloc(foo_object *self)\n"
1826
+ "{\n"
1827
+ " PyObject *et, *ev, *etb;\n"
1828
+ " PyObject *exc = PyErr_GetRaisedException();\n"
1829
+ " ...\n"
1830
+ " PyErr_SetRaisedException(exc);\n"
1831
+ "}"
1819
1832
1820
1833
#: ../../c-api/typeobj.rst:705
1821
1834
msgid ""
1822
1835
"The dealloc handler itself must not raise an exception; if it hits an error "
1823
1836
"case it should call :c:func:`PyErr_FormatUnraisable` to log (and clear) an "
1824
1837
"unraisable exception."
1825
1838
msgstr ""
1839
+ "释放处理程序本身不应引发异常;若遇到错误情况,应调用 :c:func:`PyErr_FormatUnraisable` 记录(并清除)不可抛出的异常。"
1826
1840
1827
1841
#: ../../c-api/typeobj.rst:709
1828
1842
msgid "No guarantees are made about when an object is destroyed, except:"
1829
- msgstr ""
1843
+ msgstr "关于对象何时被销毁,不做任何保证,除非: "
1830
1844
1831
1845
#: ../../c-api/typeobj.rst:711
1832
1846
msgid ""
1833
1847
"Python will destroy an object immediately or some time after the final "
1834
1848
"reference to the object is deleted, unless its finalizer "
1835
1849
"(:c:member:`~PyTypeObject.tp_finalize`) subsequently resurrects the object."
1836
1850
msgstr ""
1851
+ "Python "
1852
+ "会在对象的最后一个引用被删除后立即销毁该对象,或者在一段时间后再销毁,除非其终结器(:c:member:`~PyTypeObject.tp_finalize`)在此期间重新激活了该对象。"
1837
1853
1838
1854
#: ../../c-api/typeobj.rst:715
1839
1855
msgid ""
1840
1856
"An object will not be destroyed while it is being automatically finalized "
1841
1857
"(:c:member:`~PyTypeObject.tp_finalize`) or automatically cleared "
1842
1858
"(:c:member:`~PyTypeObject.tp_clear`)."
1843
1859
msgstr ""
1860
+ "在对象被自动终结(:c:member:`~PyTypeObject.tp_finalize`)或自动清理(:c:member:`~PyTypeObject.tp_clear`)的过程中,不会销毁该对象。"
1844
1861
1845
1862
#: ../../c-api/typeobj.rst:719
1846
1863
msgid ""
1847
1864
"CPython currently destroys an object immediately from :c:func:`Py_DECREF` "
1848
1865
"when the new reference count is zero, but this may change in a future "
1849
1866
"version."
1850
- msgstr ""
1867
+ msgstr "当前 CPython 在引用计数归零时,会立即通过 :c:func:`Py_DECREF` 销毁对象,但这一行为在未来版本中可能会改变。 "
1851
1868
1852
1869
#: ../../c-api/typeobj.rst:723
1853
1870
msgid ""
1854
1871
"It is recommended to call :c:func:`PyObject_CallFinalizerFromDealloc` at the"
1855
1872
" beginning of :c:member:`!tp_dealloc` to guarantee that the object is always"
1856
1873
" finalized before destruction."
1857
1874
msgstr ""
1875
+ "建议在 :c:member:`!tp_dealloc` 的开头调用 "
1876
+ ":c:func:`PyObject_CallFinalizerFromDealloc` 以确保对象在销毁前始终被终结。"
1858
1877
1859
1878
#: ../../c-api/typeobj.rst:727
1860
1879
msgid ""
1861
1880
"If the type supports garbage collection (the :c:macro:`Py_TPFLAGS_HAVE_GC` "
1862
1881
"flag is set), the destructor should call :c:func:`PyObject_GC_UnTrack` "
1863
1882
"before clearing any member fields."
1864
1883
msgstr ""
1884
+ "若该类型支持垃圾回收(即设置了 :c:macro:`Py_TPFLAGS_HAVE_GC` 标志),则析构函数应在清理任何成员字段之前调用 "
1885
+ ":c:func:`PyObject_GC_UnTrack`。"
1865
1886
1866
1887
#: ../../c-api/typeobj.rst:731
1867
1888
msgid ""
@@ -1870,6 +1891,9 @@ msgid ""
1870
1891
" object is always cleared before destruction. Beware that "
1871
1892
":c:member:`!tp_clear` might have already been called."
1872
1893
msgstr ""
1894
+ "允许从 :c:member:`!tp_dealloc` 方法中调用 "
1895
+ ":c:member:`~PyTypeObject.tp_clear`,以减少代码重复并确保对象在销毁前始终被清理。但需注意,:c:member:`!tp_clear`"
1896
+ " 可能已被提前调用。"
1873
1897
1874
1898
#: ../../c-api/typeobj.rst:736
1875
1899
msgid ""
@@ -1878,6 +1902,8 @@ msgid ""
1878
1902
":c:func:`Py_DECREF`) after calling the type deallocator. See the example "
1879
1903
"code below.::"
1880
1904
msgstr ""
1905
+ "如果该类型是堆分配的(:c:macro:`Py_TPFLAGS_HEAPTYPE`),则释放器应在调用类型释放器之后,释放对其类型对象的自有引用(通过 "
1906
+ ":c:func:`Py_DECREF`)。参见下面的示例代码。::"
1881
1907
1882
1908
#: ../../c-api/typeobj.rst:741
1883
1909
msgid ""
@@ -1890,6 +1916,14 @@ msgid ""
1890
1916
" Py_TYPE(self)->tp_free(self);\n"
1891
1917
"}"
1892
1918
msgstr ""
1919
+ "static void\n"
1920
+ "foo_dealloc(PyObject *op)\n"
1921
+ "{\n"
1922
+ " foo_object *self = (foo_object *) op;\n"
1923
+ " PyObject_GC_UnTrack(self);\n"
1924
+ " Py_CLEAR(self->ref);\n"
1925
+ " Py_TYPE(self)->tp_free(self);\n"
1926
+ "}"
1893
1927
1894
1928
#: ../../c-api/typeobj.rst:750
1895
1929
msgid ""
@@ -1898,6 +1932,8 @@ msgid ""
1898
1932
"must be backed up first and restored later (after logging any exceptions "
1899
1933
"with :c:func:`PyErr_WriteUnraisable`)."
1900
1934
msgstr ""
1935
+ ":c:member:`!tp_dealloc` 必须保持异常状态不变。如果它需要调用可能引发异常的函数,必须先备份异常状态,之后(在用 "
1936
+ ":c:func:`PyErr_WriteUnraisable` 记录任何异常后)再恢复该状态。"
1901
1937
1902
1938
#: ../../c-api/typeobj.rst:755
1903
1939
msgid "Example::"
@@ -1944,6 +1980,44 @@ msgid ""
1944
1980
" PyErr_SetRaisedException(exc);\n"
1945
1981
"}"
1946
1982
msgstr ""
1983
+ "static void\n"
1984
+ "foo_dealloc(PyObject *self)\n"
1985
+ "{\n"
1986
+ " PyObject *exc = PyErr_GetRaisedException();\n"
1987
+ "\n"
1988
+ " if (PyObject_CallFinalizerFromDealloc(self) < 0) {\n"
1989
+ " // 自我复活了。\n"
1990
+ " goto done;\n"
1991
+ " }\n"
1992
+ "\n"
1993
+ " PyTypeObject *tp = Py_TYPE(self);\n"
1994
+ "\n"
1995
+ " if (tp->tp_flags & Py_TPFLAGS_HAVE_GC) {\n"
1996
+ " PyObject_GC_UnTrack(self);\n"
1997
+ " }\n"
1998
+ "\n"
1999
+ " // 可选,但可以避免代码重复,较为方便。\n"
2000
+ " if (tp->tp_clear && tp->tp_clear(self) < 0) {\n"
2001
+ " PyErr_WriteUnraisable(self);\n"
2002
+ " }\n"
2003
+ "\n"
2004
+ " // 此处可执行任何额外的销毁操作。\n"
2005
+ "\n"
2006
+ " tp->tp_free(self);\n"
2007
+ " self = NULL; // 若后续调用了 PyErr_WriteUnraisable() 函数。\n"
2008
+ "\n"
2009
+ " if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE) {\n"
2010
+ " Py_CLEAR(tp);\n"
2011
+ " }\n"
2012
+ "\n"
2013
+ "done:\n"
2014
+ " // 可选操作:若之前调用的操作可能引发了异常。\n"
2015
+ " // \n"
2016
+ " if (PyErr_Occurred()) {\n"
2017
+ " PyErr_WriteUnraisable(self);\n"
2018
+ " }\n"
2019
+ " PyErr_SetRaisedException(exc);\n"
2020
+ "}"
1947
2021
1948
2022
#: ../../c-api/typeobj.rst:796
1949
2023
msgid ""
@@ -1957,12 +2031,17 @@ msgid ""
1957
2031
"objects on the thread which called :c:member:`!tp_dealloc` will not violate "
1958
2032
"any assumptions of the library."
1959
2033
msgstr ""
2034
+ ":c:member:`!tp_dealloc` 可能从任意 Python "
2035
+ "线程调用,而不仅限于创建该对象的线程(如果对象成为引用循环的一部分,该循环可能由任意线程的垃圾回收操作回收)。 这对 Python API "
2036
+ "调用不是问题,因为调用 :c:member:`!tp_dealloc` 的线程会带有 :term:`attached thread "
2037
+ "state`。然而,如果被销毁的对象反过来会销毁其他 C 库中的对象,则需要确保在调用 :c:member:`!tp_dealloc` "
2038
+ "的线程上销毁这些对象不会违反该库的任何假设条件。"
1960
2039
1961
2040
#: ../../c-api/typeobj.rst:814 ../../c-api/typeobj.rst:1714
1962
2041
#: ../../c-api/typeobj.rst:2447
1963
2042
msgid ""
1964
2043
":ref:`life-cycle` for details about how this slot relates to other slots."
1965
- msgstr ""
2044
+ msgstr "有关此槽位如何与其他槽位关联的详细信息,请参阅 :ref:`life-cycle`。 "
1966
2045
1967
2046
#: ../../c-api/typeobj.rst:819
1968
2047
msgid ""
0 commit comments