55#
66# Translators:
77# Rafael Fontenelle <rffontenelle@gmail.com>, 2025
8+ # Freesand Leo <yuqinju@163.com>, 2025
89#
910#, fuzzy
1011msgid ""
@@ -13,7 +14,7 @@ msgstr ""
1314"Report-Msgid-Bugs-To : \n "
1415"POT-Creation-Date : 2025-05-30 14:58+0000\n "
1516"PO-Revision-Date : 2025-05-08 05:09+0000\n "
16- "Last-Translator : Rafael Fontenelle <rffontenelle@gmail .com>, 2025\n "
17+ "Last-Translator : Freesand Leo <yuqinju@163 .com>, 2025\n "
1718"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
1819"MIME-Version : 1.0\n "
1920"Content-Type : text/plain; charset=UTF-8\n "
@@ -136,6 +137,58 @@ msgid ""
136137" return PyModuleDef_Init(&custom_module);\n"
137138"}\n"
138139msgstr ""
140+ "#define PY_SSIZE_T_CLEAN\n"
141+ "#include <Python.h>\n"
142+ "\n"
143+ "typedef struct {\n"
144+ " PyObject_HEAD\n"
145+ " /* 这里添加类型专属的字段。 */\n"
146+ "} CustomObject;\n"
147+ "\n"
148+ "static PyTypeObject CustomType = {\n"
149+ " .ob_base = PyVarObject_HEAD_INIT(NULL, 0)\n"
150+ " .tp_name = \" custom.Custom\" ,\n"
151+ " .tp_doc = PyDoc_STR(\" Custom objects\" ),\n"
152+ " .tp_basicsize = sizeof(CustomObject),\n"
153+ " .tp_itemsize = 0,\n"
154+ " .tp_flags = Py_TPFLAGS_DEFAULT,\n"
155+ " .tp_new = PyType_GenericNew,\n"
156+ "};\n"
157+ "\n"
158+ "static int\n"
159+ "custom_module_exec(PyObject *m)\n"
160+ "{\n"
161+ " if (PyType_Ready(&CustomType) < 0) {\n"
162+ " return -1;\n"
163+ " }\n"
164+ "\n"
165+ " if (PyModule_AddObjectRef(m, \" Custom\" , (PyObject *) &CustomType) < 0) {\n"
166+ " return -1;\n"
167+ " }\n"
168+ "\n"
169+ " return 0;\n"
170+ "}\n"
171+ "\n"
172+ "static PyModuleDef_Slot custom_module_slots[] = {\n"
173+ " {Py_mod_exec, custom_module_exec},\n"
174+ " // 使用静态类型时就使用这个\n"
175+ " {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},\n"
176+ " {0, NULL}\n"
177+ "};\n"
178+ "\n"
179+ "static PyModuleDef custom_module = {\n"
180+ " .m_base = PyModuleDef_HEAD_INIT,\n"
181+ " .m_name = \" custom\" ,\n"
182+ " .m_doc = \" Example module that creates an extension type.\" ,\n"
183+ " .m_size = 0,\n"
184+ " .m_slots = custom_module_slots,\n"
185+ "};\n"
186+ "\n"
187+ "PyMODINIT_FUNC\n"
188+ "PyInit_custom(void)\n"
189+ "{\n"
190+ " return PyModuleDef_Init(&custom_module);\n"
191+ "}\n"
139192
140193#: ../../extending/newtypes_tutorial.rst:50
141194msgid ""
0 commit comments