@@ -735,6 +735,8 @@ msgid ""
735735"complete: :c:func:`Py_BuildValue` may run out of memory, and this should be "
736736"checked."
737737msgstr ""
738+ "注意 ``Py_DECREF(arglist)`` 所在处会立即调用,在错误检查之前。当然还要注意一些常规的错误,比如 "
739+ ":c:func:`Py_BuildValue` 可能会遭遇内存不足等等。"
738740
739741#: ../../extending/extending.rst:594
740742msgid ""
@@ -743,14 +745,16 @@ msgid ""
743745" in the above example, we use :c:func:`Py_BuildValue` to construct the "
744746"dictionary. ::"
745747msgstr ""
748+ "你还需要注意,用关键字参数调用 :c:func:`PyObject_Call` ,需要支持普通参数和关键字参数。有如如上例子中,我们使用 "
749+ ":c:func:`Py_BuildValue` 来构造字典。"
746750
747751#: ../../extending/extending.rst:612
748752msgid "Extracting Parameters in Extension Functions"
749- msgstr ""
753+ msgstr "提取扩展函数的参数 "
750754
751755#: ../../extending/extending.rst:616
752756msgid "The :c:func:`PyArg_ParseTuple` function is declared as follows::"
753- msgstr ""
757+ msgstr "函数 :c:func:`PyArg_ParseTuple` 的声明如下: "
754758
755759#: ../../extending/extending.rst:620
756760msgid ""
@@ -760,6 +764,8 @@ msgid ""
760764"Reference Manual. The remaining arguments must be addresses of variables "
761765"whose type is determined by the format string."
762766msgstr ""
767+ "参数 *arg* 必须是一个tuple对象,包含传递过来的参数, *format* 参数必须是格式化字符串,语法解释见 \" Python C/API\" "
768+ " 的5.5节。剩余参数是各个变量的地址,类型要与格式化字符串对应。"
763769
764770#: ../../extending/extending.rst:626
765771msgid ""
@@ -768,6 +774,8 @@ msgid ""
768774"variables passed to the call: if you make mistakes there, your code will "
769775"probably crash or at least overwrite random bits in memory. So be careful!"
770776msgstr ""
777+ "注意 :c:func:`PyArg_ParseTuple` "
778+ "会检测他需要的Python参数类型,却无法检测传递给他的C变量地址,如果这里出错了,可能会在内存中随机写入东西,小心。"
771779
772780#: ../../extending/extending.rst:631
773781msgid ""
@@ -777,16 +785,16 @@ msgstr "注意任何由调用者提供的Python对象引用是 *借来的* 引
777785
778786#: ../../extending/extending.rst:634
779787msgid "Some example calls::"
780- msgstr ""
788+ msgstr "一些调用的例子: "
781789
782790#: ../../extending/extending.rst:704
783791msgid "Keyword Parameters for Extension Functions"
784- msgstr ""
792+ msgstr "给扩展函数的关键字参数 "
785793
786794#: ../../extending/extending.rst:708
787795msgid ""
788796"The :c:func:`PyArg_ParseTupleAndKeywords` function is declared as follows::"
789- msgstr ""
797+ msgstr "函数 :c:func:`PyArg_ParseTupleAndKeywords` 声明如下: "
790798
791799#: ../../extending/extending.rst:713
792800msgid ""
@@ -799,29 +807,33 @@ msgid ""
799807":c:func:`PyArg_ParseTupleAndKeywords` returns true, otherwise it returns "
800808"false and raises an appropriate exception."
801809msgstr ""
810+ "参数 *arg* 和 *format* 定义同 :c:func:`PyArg_ParseTuple` 。参数 *kwdict* "
811+ "是关键字字典,用于接受运行时传来的关键字参数。参数 *kwlist* 是一个 *NULL* 结尾的字符串,定义了可以接受的参数名,并从左到右与 "
812+ "*format* 中各个变量对应。如果执行成功 :c:func:`PyArg_ParseTupleAndKeywords` "
813+ "会返回true,否则返回false并抛出异常。"
802814
803815#: ../../extending/extending.rst:723
804816msgid ""
805817"Nested tuples cannot be parsed when using keyword arguments! Keyword "
806818"parameters passed in which are not present in the *kwlist* will cause "
807819":exc:`TypeError` to be raised."
808- msgstr ""
820+ msgstr "嵌套的元组在使用关键字参数时无法生效,不在 *kwlist* 中的关键字参数会导致 :exc:`TypeError` 异常。 "
809821
810822#: ../../extending/extending.rst:729
811823msgid ""
812824"Here is an example module which uses keywords, based on an example by Geoff "
813825814- msgstr ""
826+ msgstr "如下是使用关键字参数的例子模块,作者是 Geoff Philbrick ([email protected] ): " 815827
816828#: ../../extending/extending.rst:783
817829msgid "Building Arbitrary Values"
818- msgstr ""
830+ msgstr "构造任意值 "
819831
820832#: ../../extending/extending.rst:785
821833msgid ""
822834"This function is the counterpart to :c:func:`PyArg_ParseTuple`. It is "
823835"declared as follows::"
824- msgstr ""
836+ msgstr "这个函数与 :c:func:`PyArg_ParseTuple` 很相似,声明如下: "
825837
826838#: ../../extending/extending.rst:790
827839msgid ""
@@ -830,6 +842,8 @@ msgid ""
830842"function, not output) must not be pointers, just values. It returns a new "
831843"Python object, suitable for returning from a C function called from Python."
832844msgstr ""
845+ "接受一个格式字符串,与 :c:func:`PyArg_ParseTuple` "
846+ "相同,但是参数必须是原变量的地址指针(输入给函数,而非输出)。最终返回一个Python对象适合于返回C函数调用给Python代码。"
833847
834848#: ../../extending/extending.rst:795
835849msgid ""
@@ -842,11 +856,15 @@ msgid ""
842856"by that format unit. To force it to return a tuple of size 0 or one, "
843857"parenthesize the format string."
844858msgstr ""
859+ "一个与 :c:func:`PyArg_ParseTuple` "
860+ "的不同是,后面可能需要的要求返回一个元组(Python参数里诶包总是在内部描述为元组),比如用于传递给其他Python函数以参数。 "
861+ ":c:func:`Py_BuildValue` 并不总是生成元组,在多于1个参数时会生成元组,而如果没有参数则返回 ``None`` "
862+ ",一个参数则直接返回该参数的对象。如果要求强制生成一个长度为空的元组,或包含一个元素的元组,需要在格式字符串中加上括号。"
845863
846864#: ../../extending/extending.rst:803
847865msgid ""
848866"Examples (to the left the call, to the right the resulting Python value):"
849- msgstr ""
867+ msgstr "例子(左侧是调用,右侧是Python值结果): "
850868
851869#: ../../extending/extending.rst:829
852870msgid "Reference Counts"
@@ -860,6 +878,8 @@ msgid ""
860878"``new`` and ``delete`` are used with essentially the same meaning and we'll "
861879"restrict the following discussion to the C case."
862880msgstr ""
881+ "在C/C++语言中,程序员负责动态分配和回收堆(heap)当中的内存。在C里,通过函数 :c:func:`malloc` 和 "
882+ ":c:func:`free` 来完成。在C++里是操作 ``new`` 和 ``delete`` 来实现相同的功能。"
863883
864884#: ../../extending/extending.rst:837
865885msgid ""
0 commit comments