@@ -1237,19 +1237,24 @@ msgid ""
12371237"this was the last reference to that object, it would free the memory "
12381238"associated with it, thereby invalidating ``item``."
12391239msgstr ""
1240+ "既然是Python写的, :meth:`__del__` 方法可以执行任意Python代码。是否可能在 :c:func:`bug` 的 ``item``"
1241+ " 废止引用呢,是的。假设列表传递到 :c:func:`bug` 会被 :meth:`__del__` 方法所访问,就可以执行一个语句来实现 ``del "
1242+ "list[0]`` ,然后假设这是最后一个对对象的引用,就需要释放内存,从而使得 ``item`` 无效化。"
12401243
12411244#: ../../extending/extending.rst:1037
12421245msgid ""
12431246"The solution, once you know the source of the problem, is easy: temporarily "
12441247"increment the reference count. The correct version of the function reads::"
1245- msgstr ""
1248+ msgstr "解决方法是,当你知道了问题的根源,就容易了:临时增加引用计数。正确版本的函数代码如下: "
12461249
12471250#: ../../extending/extending.rst:1051
12481251msgid ""
12491252"This is a true story. An older version of Python contained variants of this"
12501253" bug and someone spent a considerable amount of time in a C debugger to "
12511254"figure out why his :meth:`__del__` methods would fail..."
12521255msgstr ""
1256+ "这是个真实的故事。一个旧版本的Python包含了这个bug的变种,而一些人花费了大量时间在C调试器上去寻找为什么 :meth:`__del__` "
1257+ "方法会失败。"
12531258
12541259#: ../../extending/extending.rst:1055
12551260msgid ""
@@ -1263,6 +1268,10 @@ msgid ""
12631268"complete. Obviously, the following function has the same problem as the "
12641269"previous one::"
12651270msgstr ""
1271+ "这个问题的第二种情况是借用的引用涉及线程的变种。通常,Python解释器里多个线程无法进入对方的路径,因为有个全局锁保护着Python整个对象空间。但可以使用宏"
1272+ " :c:macro:`Py_BEGIN_ALLOW_THREADS` 来临时释放这个锁,重新获取锁用 "
1273+ ":c:macro:`Py_END_ALLOW_THREADS` "
1274+ "。这通常围绕在阻塞I/O调用外,使得其他线程可以在等待I/O期间使用处理器。显然,如下函数会跟之前那个有一样的问题:"
12661275
12671276#: ../../extending/extending.rst:1078
12681277msgid "NULL Pointers"
@@ -1279,20 +1288,27 @@ msgid ""
12791288"*NULL*, there would be a lot of redundant tests and the code would run more "
12801289"slowly."
12811290msgstr ""
1291+ "通常,函数接受对象引用作为参数,而非期待你传入 *NULL* 指针,你非这么干会导致dump core (或者之后导致core dumps) "
1292+ "。函数返回对象引用时,返回的 *NULL* 用以指示发生了异常。 *NULL* 参数的理由在从其他函数接收时并未测试,如果每个函数都测试 *NULL* "
1293+ ",就会导致大量的冗余测试,并使得代码运行更慢。"
12821294
12831295#: ../../extending/extending.rst:1088
12841296msgid ""
12851297"It is better to test for *NULL* only at the \" source:\" when a pointer that "
12861298"may be *NULL* is received, for example, from :c:func:`malloc` or from a "
12871299"function that may raise an exception."
12881300msgstr ""
1301+ "好的方法是仅在 \" 源头\" 测试 *NULL* ,当一个指针可能是 *NULL* 时,例如 :c:func:`malloc` "
1302+ "或者从一个可能抛出异常的函数。"
12891303
12901304#: ../../extending/extending.rst:1092
12911305msgid ""
12921306"The macros :c:func:`Py_INCREF` and :c:func:`Py_DECREF` do not check for "
12931307"*NULL* pointers --- however, their variants :c:func:`Py_XINCREF` and "
12941308":c:func:`Py_XDECREF` do."
12951309msgstr ""
1310+ "宏 :c:func:`Py_INCREF` 和 :c:func:`Py_DECREF` 不会检查 *NULL* 指针。但他们的变种 "
1311+ ":c:func:`Py_XINCREF` 和 :c:func:`Py_XDECREF` 会检查。"
12961312
12971313#: ../../extending/extending.rst:1096
12981314msgid ""
@@ -1302,19 +1318,21 @@ msgid ""
13021318"expected types, and this would generate redundant tests. There are no "
13031319"variants with *NULL* checking."
13041320msgstr ""
1321+ "用以检查对象类型的宏( ``Pytype_Check()`` )不会检查 *NULL* "
1322+ "指针,有很多代码会多次测试一个对象是否是预期的类型,这可能产生冗余的测试。而 *NULL* 检查没有冗余。"
13051323
13061324#: ../../extending/extending.rst:1102
13071325msgid ""
13081326"The C function calling mechanism guarantees that the argument list passed to"
13091327" C functions (``args`` in the examples) is never *NULL* --- in fact it "
13101328"guarantees that it is always a tuple [#]_."
1311- msgstr ""
1329+ msgstr "C函数调用机制会确保传递到C函数的参数列表 (例如 ``args`` )不会是 *NULL* ,实际上会确保总是元组 [#]_ 。 "
13121330
13131331#: ../../extending/extending.rst:1106
13141332msgid ""
13151333"It is a severe error to ever let a *NULL* pointer \" escape\" to the Python "
13161334"user."
1317- msgstr ""
1335+ msgstr "把 *NULL* 指针转义给Python用户是个严重的错误。 "
13181336
13191337#: ../../extending/extending.rst:1117
13201338msgid "Writing Extensions in C++"
0 commit comments