@@ -46,7 +46,7 @@ msgid ""
4646" C source file by including the header ``\" Python.h\" ``."
4747msgstr ""
4848"为了支持扩展,Python API定义了一系列函数、宏和变量,提供了对Python运行时系统的访问支持。Python的C API由C源码组成,并包含 "
49- "\" Python.h\" 头文件。"
49+ "` \" Python.h\" ` 头文件。"
5050
5151#: ../../extending/extending.rst:20
5252msgid ""
@@ -117,18 +117,20 @@ msgid ""
117117"file does not exist on your system, it declares the functions "
118118":c:func:`malloc`, :c:func:`free` and :c:func:`realloc` directly."
119119msgstr ""
120- "所有用户可见的符号都定义自爱 :file:`Python.h` 中,并拥有前缀 ``Py`` 或 ``PY`` "
121- ",除了那些已经定义在i包准头文件的。 为了方便,以及为了让Python解释器应用广泛, `` Python.h`` 也包含了少量标准头文件: "
122- "``<stdio.h>`` , ``<string.h>`` , ``<errno.h>`` , 和 ``<stdlib.h>`` "
123- "。 如果后面的头文件在你的系统上不存在,还会直接声明函数 :c:func:`malloc` , :c:func:`free` 和 "
120+ "所有用户可见的符号都定义自 :file:`Python.h` 中,并拥有前缀 ``Py`` 或 ``PY`` ,除了那些已经定义在标准头文件的。 "
121+ "为了方便,以及由于其在 Python 解释器中广泛应用,`` \" Python.h\" `` 也包含了少量标准头文件: "
122+ "``<stdio.h>``, ``<string.h>``, ``<errno.h>`` 和 ``<stdlib.h>``。 "
123+ "如果后面的头文件在你的系统上不存在,还会直接声明函数 :c:func:`malloc`, :c:func:`free` 和 "
124124":c:func:`realloc` 。"
125125
126126#: ../../extending/extending.rst:79
127127msgid ""
128128"The next thing we add to our module file is the C function that will be "
129129"called when the Python expression ``spam.system(string)`` is evaluated "
130130"(we'll see shortly how it ends up being called)::"
131- msgstr "下面添加C代码到扩展模块,当调用 \" spam.system(string)\" 时会做出响应:"
131+ msgstr ""
132+ "下面要做的事是将 C 函数添加到我们的扩展模块,当 Python 表达式 ``spam.system(string)`` "
133+ "被求值时函数将被调用(我们很快就会看到它最终是如何被调用的)::"
132134
133135#: ../../extending/extending.rst:95
134136msgid ""
@@ -157,9 +159,10 @@ msgid ""
157159"determine the required types of the arguments as well as the types of the C "
158160"variables into which to store the converted values. More about this later."
159161msgstr ""
160- "args "
161- "参数是一个指向Python的tuple对象的指针,包含参数。每个tuple子项对应一个调用参数。这些参数也全都是Python对象,所以需要先转换成C值。函数"
162- " :c:func:`PyArg_ParseTuple()` 检查参数类型并转换成C值。它使用模板字符串检测需要的参数类型。细节在后面讲。"
162+ "*args* 参数是指向一个 Python 的 tuple 对象的指针,其中包含参数。 每个 tuple 项对应一个调用参数。 这些参数也全都是 "
163+ "Python 对象 --- 要在我们的 C 函数中使用它们就需要先将其转换为 C 值。 Python API 中的函数 "
164+ ":c:func:`PyArg_ParseTuple` 会检查参数类型并将其转换为 C 值。 它使用模板字符串确定需要的参数类型以及存储被转换的值的 C "
165+ "变量类型。 细节将稍后说明。"
163166
164167#: ../../extending/extending.rst:112
165168msgid ""
@@ -317,11 +320,11 @@ msgid ""
317320" particular range or must satisfy other conditions, "
318321":c:data:`PyExc_ValueError` is appropriate."
319322msgstr ""
320- "选择抛出哪个异常完全是你的个人爱好了。有一系列的C对象代表了内置Python异常 ,例如 "
321- ":c:data:`PyExc_ZeroDivisionError` ,你可以直接使用。 当然,你可能选择更合适的异常,不过别使用 "
322- ":c:data:`PyExc_TypeError` 告知文件打开失败(有个更合适的 :c:data:`PyExc_IOError` "
323- ")。如果参数列表有误, :c:func:`PyArg_ParseTuple` 通常会抛出 :c:data:`PyExc_TypeError` "
324- "。如果参数值域有误, PyExc_ValueError 更合适一些 。"
323+ "选择引发哪个异常完全取决于你的喜好。 所有内置的 Python 异常都有对应的预声明 C 对象 ,例如 "
324+ ":c:data:`PyExc_ZeroDivisionError`,你可以直接使用它们。 当然,你应当明智地选择异常 --- 不要使用 "
325+ ":c:data:`PyExc_TypeError` 来表示一个文件无法被打开 (那大概应该用 :c:data:`PyExc_IOError`)。 "
326+ "如果参数列表有问题, :c:func:`PyArg_ParseTuple` 函数通常会引发 :c:data:`PyExc_TypeError`。 "
327+ "如果你想要一个参数的值必须处于特定范围之内或必须满足其他条件,则适宜使用 :c:data:` PyExc_ValueError` 。"
325328
326329#: ../../extending/extending.rst:202
327330msgid ""
@@ -393,9 +396,9 @@ msgid ""
393396"which it points (so in Standard C, the variable :c:data:`command` should "
394397"properly be declared as ``const char *command``)."
395398msgstr ""
396- "就是为了报告解释器一个异常而返回 *NULL* "
397- "(表示函数返回错误)。如果执行正常则变量会拷贝到本地,后面的变量都应该以指针的方式提供,以方便设置变量。本例中的command会被声明为( "
398- "\" const char* command\" 。) "
399+ "如果在参数列表中检测到错误,将会返回 *NULL* (返回对象指针的函数的错误指示器) , 依据 :c:func:`PyArg_ParseTuple` "
400+ "所设置的异常。 在其他情况下参数的字符串值会被拷贝到局部变量 :c:data:`command`。 这是一个指针赋值,你不应该修改它所指向的字符串 "
401+ "(所以在标准 C 中,变量 :c:data:`command` 应当被正确地声明为 `` const char * command``)。 "
399402
400403#: ../../extending/extending.rst:279
401404msgid ""
0 commit comments