@@ -29,15 +29,17 @@ msgstr ""
2929
3030#: ../../extending/extending.rst:8
3131msgid "Extending Python with C or C++"
32- msgstr "使用C/C++扩展Python "
32+ msgstr "使用 C 或 C++ 扩展 Python "
3333
3434#: ../../extending/extending.rst:10
3535msgid ""
3636"It is quite easy to add new built-in modules to Python, if you know how to "
3737"program in C. Such :dfn:`extension modules` can do two things that can't be"
3838" done directly in Python: they can implement new built-in object types, and "
3939"they can call C library functions and system calls."
40- msgstr "如果你会用C,实现Python嵌入模块很简单。利用扩展模块可做很多Python不方便做的事情,他们可以直接调用C库和系统调用。"
40+ msgstr ""
41+ "如果你会用 C,添加新的 Python 内置模块会很简单。以下两件不能用 Python 直接做的事,可以通过 :dfn:`extension "
42+ "modules` 来实现:实现新的内置对象类型;调用 C 的库函数和系统调用。"
4143
4244#: ../../extending/extending.rst:15
4345msgid ""
@@ -46,14 +48,14 @@ msgid ""
4648" aspects of the Python run-time system. The Python API is incorporated in a"
4749" C source file by including the header ``\" Python.h\" ``."
4850msgstr ""
49- "为了支持扩展,Python API定义了一系列函数 、宏和变量,提供了对Python运行时系统的访问支持。Python的C API由C源码组成,并包含 "
50- "` \" Python.h\" ` 头文件 。"
51+ "为了支持扩展,Python API(应用程序编程接口)定义了一系列函数 、宏和变量,可以访问 Python 运行时系统的大部分内容。Python 的 "
52+ "API 可以通过在一个 C 源文件中引用 `` \" Python.h\" `` 头文件来使用 。"
5153
5254#: ../../extending/extending.rst:20
5355msgid ""
5456"The compilation of an extension module depends on its intended use as well "
5557"as on your system setup; details are given in later chapters."
56- msgstr "编写扩展模块与你的系统相关,下面会详解 。"
58+ msgstr "扩展模块的编写方式取决与你的目的以及系统设置;下面章节会详细介绍 。"
5759
5860#: ../../extending/extending.rst:25
5961msgid ""
@@ -87,17 +89,20 @@ msgid ""
8789"is called ``spam``, the C file containing its implementation is called "
8890":file:`spammodule.c`; if the module name is very long, like ``spammify``, "
8991"the module name can be just :file:`spammify.c`.)"
90- msgstr "一个C扩展模块的文件名可以直接是 模块名.c 或者是 模块名module.c 。第一行应该导入头文件:"
92+ msgstr ""
93+ "首先创建一个 :file:`spammodule.c` 文件。(传统上,如果一个模块叫 ``spam``,则对应实现它的 C 文件叫 "
94+ ":file:`spammodule.c`;如果这个模块名字非常长,比如 ``spammify``,则这个模块的文件可以直接叫 "
95+ ":file:`spammify.c`。)"
9196
9297#: ../../extending/extending.rst:58
9398msgid "The first line of our file can be::"
94- msgstr "文件的第一行应该是 :"
99+ msgstr "文件的第一行可以是: :"
95100
96101#: ../../extending/extending.rst:62
97102msgid ""
98103"which pulls in the Python API (you can add a comment describing the purpose "
99104"of the module and a copyright notice if you like)."
100- msgstr "这会导入Python API (你可以添加注释来描述模块的目标和版权提示 )。"
105+ msgstr "这会导入 Python API(如果你喜欢,你可以在这里添加描述模块目标和版权信息的注释 )。"
101106
102107#: ../../extending/extending.rst:67
103108msgid ""
@@ -570,7 +575,9 @@ msgid ""
570575"on Windows (chapter :ref:`building-on-windows`) for more information about "
571576"this."
572577msgstr ""
573- "如果使用动态载入,细节依赖于系统,查看关于( :ref:`构建` )扩展模块部分,和关于在( :ref:`Windows下构建扩展`) 的细节。"
578+ "在你能使用你的新写的扩展之前,你还需要做两件事情:使用 Python "
579+ "系统来编译和链接。如果你使用动态加载,这取决于你使用的操作系统的动态加载机制;更多信息请参考编译扩展模块的章节( :ref:`building` "
580+ "章节),以及在 Windows 上编译需要的额外信息( :ref:`building-on-windows` 章节)。"
574581
575582#: ../../extending/extending.rst:439
576583msgid ""
@@ -695,10 +702,9 @@ msgid ""
695702"should somehow :c:func:`Py_DECREF` the result, even (especially!) if you are"
696703" not interested in its value."
697704msgstr ""
698- ":c:func:`PyEval_CallObject` 的返回值总是新的,新建对象或者是对已有对象增加引用计数。所以你必须获取这个对象指针,在使用后用 "
699- ":c:func:Py_DECREF` (特别的) "
700- "减少其引用计数,即便是对返回值没有兴趣也要这么做。但是在减少这个引用计数之前,你必须先检查返回的指针是否为NULL。如果是NULL,则表示出现了异常并中止了。如果没有处理则会向上传递并最终显示调用栈,当然,你最好还是处理好异常。如果你对异常没有兴趣,可以用"
701- " PyErr_Clear() 清除异常,例如:"
705+ ":c:func:`PyEval_CallObject` "
706+ "的返回值总是“新”的:要么是一个新建的对象;要么是已有对象,但增加了引用计数。所以除非你想把结果保存在全局变量中,你需要对这个值使用 "
707+ ":c:func:`Py_DECREF`,即使你对里面的内容(特别!)不感兴趣。"
702708
703709#: ../../extending/extending.rst:558
704710msgid ""
@@ -766,8 +772,8 @@ msgid ""
766772"Reference Manual. The remaining arguments must be addresses of variables "
767773"whose type is determined by the format string."
768774msgstr ""
769- "参数 *arg* 必须是一个tuple对象,包含传递过来的参数, *format* 参数必须是格式化字符串,语法解释见 \" Python C/API \" "
770- " 的5.5节 。剩余参数是各个变量的地址,类型要与格式化字符串对应 。"
775+ "参数 *arg* 必须是一个元组对象,包含从 Python 传递给 C 函数的参数列表。 *format* 参数必须是一个格式字符串,语法请参考 "
776+ "Python C/API 手册中的 :ref:`arg-parsing` 。剩余参数是各个变量的地址,类型要与格式字符串对应 。"
771777
772778#: ../../extending/extending.rst:626
773779msgid ""
0 commit comments