|
| 1 | +# SOME DESCRIPTIVE TITLE. |
| 2 | +# Copyright (C) 2001 Python Software Foundation |
| 3 | +# This file is distributed under the same license as the Python package. |
| 4 | +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
| 5 | +# |
| 6 | +# Translators: |
| 7 | +# tomo, 2025 |
| 8 | +# |
| 9 | +#, fuzzy |
| 10 | +msgid "" |
| 11 | +msgstr "" |
| 12 | +"Project-Id-Version: Python 3.14\n" |
| 13 | +"Report-Msgid-Bugs-To: \n" |
| 14 | +"POT-Creation-Date: 2025-06-20 14:21+0000\n" |
| 15 | +"PO-Revision-Date: 2025-06-20 14:22+0000\n" |
| 16 | +"Last-Translator: tomo, 2025\n" |
| 17 | +"Language-Team: Japanese (https://app.transifex.com/python-doc/teams/5390/" |
| 18 | +"ja/)\n" |
| 19 | +"MIME-Version: 1.0\n" |
| 20 | +"Content-Type: text/plain; charset=UTF-8\n" |
| 21 | +"Content-Transfer-Encoding: 8bit\n" |
| 22 | +"Language: ja\n" |
| 23 | +"Plural-Forms: nplurals=1; plural=0;\n" |
| 24 | + |
| 25 | +#: ../../c-api/extension-modules.rst:6 |
| 26 | +msgid "Defining extension modules" |
| 27 | +msgstr "" |
| 28 | + |
| 29 | +#: ../../c-api/extension-modules.rst:8 |
| 30 | +msgid "" |
| 31 | +"A C extension for CPython is a shared library (for example, a ``.so`` file " |
| 32 | +"on Linux, ``.pyd`` DLL on Windows), which is loadable into the Python " |
| 33 | +"process (for example, it is compiled with compatible compiler settings), and " |
| 34 | +"which exports an :ref:`initialization function <extension-export-hook>`." |
| 35 | +msgstr "" |
| 36 | + |
| 37 | +#: ../../c-api/extension-modules.rst:13 |
| 38 | +msgid "" |
| 39 | +"To be importable by default (that is, by :py:class:`importlib.machinery." |
| 40 | +"ExtensionFileLoader`), the shared library must be available on :py:attr:`sys." |
| 41 | +"path`, and must be named after the module name plus an extension listed in :" |
| 42 | +"py:attr:`importlib.machinery.EXTENSION_SUFFIXES`." |
| 43 | +msgstr "" |
| 44 | + |
| 45 | +#: ../../c-api/extension-modules.rst:21 |
| 46 | +msgid "" |
| 47 | +"Building, packaging and distributing extension modules is best done with " |
| 48 | +"third-party tools, and is out of scope of this document. One suitable tool " |
| 49 | +"is Setuptools, whose documentation can be found at https://setuptools.pypa." |
| 50 | +"io/en/latest/setuptools.html." |
| 51 | +msgstr "" |
| 52 | + |
| 53 | +#: ../../c-api/extension-modules.rst:26 |
| 54 | +msgid "" |
| 55 | +"Normally, the initialization function returns a module definition " |
| 56 | +"initialized using :c:func:`PyModuleDef_Init`. This allows splitting the " |
| 57 | +"creation process into several phases:" |
| 58 | +msgstr "" |
| 59 | + |
| 60 | +#: ../../c-api/extension-modules.rst:30 |
| 61 | +msgid "" |
| 62 | +"Before any substantial code is executed, Python can determine which " |
| 63 | +"capabilities the module supports, and it can adjust the environment or " |
| 64 | +"refuse loading an incompatible extension." |
| 65 | +msgstr "" |
| 66 | + |
| 67 | +#: ../../c-api/extension-modules.rst:33 |
| 68 | +msgid "" |
| 69 | +"By default, Python itself creates the module object -- that is, it does the " |
| 70 | +"equivalent of :py:meth:`object.__new__` for classes. It also sets initial " |
| 71 | +"attributes like :attr:`~module.__package__` and :attr:`~module.__loader__`." |
| 72 | +msgstr "" |
| 73 | + |
| 74 | +#: ../../c-api/extension-modules.rst:37 |
| 75 | +msgid "" |
| 76 | +"Afterwards, the module object is initialized using extension-specific code " |
| 77 | +"-- the equivalent of :py:meth:`~object.__init__` on classes." |
| 78 | +msgstr "" |
| 79 | + |
| 80 | +#: ../../c-api/extension-modules.rst:40 |
| 81 | +msgid "" |
| 82 | +"This is called *multi-phase initialization* to distinguish it from the " |
| 83 | +"legacy (but still supported) *single-phase initialization* scheme, where the " |
| 84 | +"initialization function returns a fully constructed module. See the :ref:" |
| 85 | +"`single-phase-initialization section below <single-phase-initialization>` " |
| 86 | +"for details." |
| 87 | +msgstr "" |
| 88 | + |
| 89 | +#: ../../c-api/extension-modules.rst:48 |
| 90 | +msgid "Added support for multi-phase initialization (:pep:`489`)." |
| 91 | +msgstr "" |
| 92 | + |
| 93 | +#: ../../c-api/extension-modules.rst:52 |
| 94 | +msgid "Multiple module instances" |
| 95 | +msgstr "" |
| 96 | + |
| 97 | +#: ../../c-api/extension-modules.rst:54 |
| 98 | +msgid "" |
| 99 | +"By default, extension modules are not singletons. For example, if the :py:" |
| 100 | +"attr:`sys.modules` entry is removed and the module is re-imported, a new " |
| 101 | +"module object is created, and typically populated with fresh method and type " |
| 102 | +"objects. The old module is subject to normal garbage collection. This " |
| 103 | +"mirrors the behavior of pure-Python modules." |
| 104 | +msgstr "" |
| 105 | + |
| 106 | +#: ../../c-api/extension-modules.rst:61 |
| 107 | +msgid "" |
| 108 | +"Additional module instances may be created in :ref:`sub-interpreters <sub-" |
| 109 | +"interpreter-support>` or after Python runtime reinitialization (:c:func:" |
| 110 | +"`Py_Finalize` and :c:func:`Py_Initialize`). In these cases, sharing Python " |
| 111 | +"objects between module instances would likely cause crashes or undefined " |
| 112 | +"behavior." |
| 113 | +msgstr "" |
| 114 | + |
| 115 | +#: ../../c-api/extension-modules.rst:68 |
| 116 | +msgid "" |
| 117 | +"To avoid such issues, each instance of an extension module should be " |
| 118 | +"*isolated*: changes to one instance should not implicitly affect the others, " |
| 119 | +"and all state owned by the module, including references to Python objects, " |
| 120 | +"should be specific to a particular module instance. See :ref:`isolating-" |
| 121 | +"extensions-howto` for more details and a practical guide." |
| 122 | +msgstr "" |
| 123 | + |
| 124 | +#: ../../c-api/extension-modules.rst:74 |
| 125 | +msgid "" |
| 126 | +"A simpler way to avoid these issues is :ref:`raising an error on repeated " |
| 127 | +"initialization <isolating-extensions-optout>`." |
| 128 | +msgstr "" |
| 129 | + |
| 130 | +#: ../../c-api/extension-modules.rst:77 |
| 131 | +msgid "" |
| 132 | +"All modules are expected to support :ref:`sub-interpreters <sub-interpreter-" |
| 133 | +"support>`, or otherwise explicitly signal a lack of support. This is usually " |
| 134 | +"achieved by isolation or blocking repeated initialization, as above. A " |
| 135 | +"module may also be limited to the main interpreter using the :c:data:" |
| 136 | +"`Py_mod_multiple_interpreters` slot." |
| 137 | +msgstr "" |
| 138 | + |
| 139 | +#: ../../c-api/extension-modules.rst:89 |
| 140 | +msgid "Initialization function" |
| 141 | +msgstr "" |
| 142 | + |
| 143 | +#: ../../c-api/extension-modules.rst:91 |
| 144 | +msgid "" |
| 145 | +"The initialization function defined by an extension module has the following " |
| 146 | +"signature:" |
| 147 | +msgstr "" |
| 148 | + |
| 149 | +#: ../../c-api/extension-modules.rst:96 |
| 150 | +msgid "" |
| 151 | +"Its name should be :samp:`PyInit_{<name>}`, with ``<name>`` replaced by the " |
| 152 | +"name of the module." |
| 153 | +msgstr "" |
| 154 | + |
| 155 | +#: ../../c-api/extension-modules.rst:99 |
| 156 | +msgid "" |
| 157 | +"For modules with ASCII-only names, the function must instead be named :samp:" |
| 158 | +"`PyInit_{<name>}`, with ``<name>`` replaced by the name of the module. When " |
| 159 | +"using :ref:`multi-phase-initialization`, non-ASCII module names are allowed. " |
| 160 | +"In this case, the initialization function name is :samp:`PyInitU_{<name>}`, " |
| 161 | +"with ``<name>`` encoded using Python's *punycode* encoding with hyphens " |
| 162 | +"replaced by underscores. In Python:" |
| 163 | +msgstr "" |
| 164 | + |
| 165 | +#: ../../c-api/extension-modules.rst:106 |
| 166 | +msgid "" |
| 167 | +"def initfunc_name(name):\n" |
| 168 | +" try:\n" |
| 169 | +" suffix = b'_' + name.encode('ascii')\n" |
| 170 | +" except UnicodeEncodeError:\n" |
| 171 | +" suffix = b'U_' + name.encode('punycode').replace(b'-', b'_')\n" |
| 172 | +" return b'PyInit' + suffix" |
| 173 | +msgstr "" |
| 174 | + |
| 175 | +#: ../../c-api/extension-modules.rst:115 |
| 176 | +msgid "" |
| 177 | +"It is recommended to define the initialization function using a helper macro:" |
| 178 | +msgstr "" |
| 179 | + |
| 180 | +#: ../../c-api/extension-modules.rst:119 |
| 181 | +msgid "Declare an extension module initialization function. This macro:" |
| 182 | +msgstr "" |
| 183 | + |
| 184 | +#: ../../c-api/extension-modules.rst:122 |
| 185 | +msgid "specifies the :c:expr:`PyObject*` return type," |
| 186 | +msgstr "" |
| 187 | + |
| 188 | +#: ../../c-api/extension-modules.rst:123 |
| 189 | +msgid "adds any special linkage declarations required by the platform, and" |
| 190 | +msgstr "" |
| 191 | + |
| 192 | +#: ../../c-api/extension-modules.rst:124 |
| 193 | +msgid "for C++, declares the function as ``extern \"C\"``." |
| 194 | +msgstr "" |
| 195 | + |
| 196 | +#: ../../c-api/extension-modules.rst:126 |
| 197 | +msgid "For example, a module called ``spam`` would be defined like this::" |
| 198 | +msgstr "" |
| 199 | + |
| 200 | +#: ../../c-api/extension-modules.rst:128 |
| 201 | +msgid "" |
| 202 | +"static struct PyModuleDef spam_module = {\n" |
| 203 | +" .m_base = PyModuleDef_HEAD_INIT,\n" |
| 204 | +" .m_name = \"spam\",\n" |
| 205 | +" ...\n" |
| 206 | +"};\n" |
| 207 | +"\n" |
| 208 | +"PyMODINIT_FUNC\n" |
| 209 | +"PyInit_spam(void)\n" |
| 210 | +"{\n" |
| 211 | +" return PyModuleDef_Init(&spam_module);\n" |
| 212 | +"}" |
| 213 | +msgstr "" |
| 214 | + |
| 215 | +#: ../../c-api/extension-modules.rst:140 |
| 216 | +msgid "" |
| 217 | +"It is possible to export multiple modules from a single shared library by " |
| 218 | +"defining multiple initialization functions. However, importing them requires " |
| 219 | +"using symbolic links or a custom importer, because by default only the " |
| 220 | +"function corresponding to the filename is found. See the `Multiple modules " |
| 221 | +"in one library <https://peps.python.org/pep-0489/#multiple-modules-in-one-" |
| 222 | +"library>`__ section in :pep:`489` for details." |
| 223 | +msgstr "" |
| 224 | + |
| 225 | +#: ../../c-api/extension-modules.rst:147 |
| 226 | +msgid "" |
| 227 | +"The initialization function is typically the only non-\\ ``static`` item " |
| 228 | +"defined in the module's C source." |
| 229 | +msgstr "" |
| 230 | + |
| 231 | +#: ../../c-api/extension-modules.rst:154 |
| 232 | +msgid "Multi-phase initialization" |
| 233 | +msgstr "多段階初期化" |
| 234 | + |
| 235 | +#: ../../c-api/extension-modules.rst:156 |
| 236 | +msgid "" |
| 237 | +"Normally, the :ref:`initialization function <extension-export-hook>` " |
| 238 | +"(``PyInit_modulename``) returns a :c:type:`PyModuleDef` instance with non-" |
| 239 | +"``NULL`` :c:member:`~PyModuleDef.m_slots`. Before it is returned, the " |
| 240 | +"``PyModuleDef`` instance must be initialized using the following function:" |
| 241 | +msgstr "" |
| 242 | + |
| 243 | +#: ../../c-api/extension-modules.rst:165 |
| 244 | +msgid "" |
| 245 | +"Ensure a module definition is a properly initialized Python object that " |
| 246 | +"correctly reports its type and a reference count." |
| 247 | +msgstr "" |
| 248 | + |
| 249 | +#: ../../c-api/extension-modules.rst:168 |
| 250 | +msgid "Return *def* cast to ``PyObject*``, or ``NULL`` if an error occurred." |
| 251 | +msgstr "" |
| 252 | + |
| 253 | +#: ../../c-api/extension-modules.rst:170 |
| 254 | +msgid "" |
| 255 | +"Calling this function is required for :ref:`multi-phase-initialization`. It " |
| 256 | +"should not be used in other contexts." |
| 257 | +msgstr "" |
| 258 | + |
| 259 | +#: ../../c-api/extension-modules.rst:173 |
| 260 | +msgid "" |
| 261 | +"Note that Python assumes that ``PyModuleDef`` structures are statically " |
| 262 | +"allocated. This function may return either a new reference or a borrowed " |
| 263 | +"one; this reference must not be released." |
| 264 | +msgstr "" |
| 265 | + |
| 266 | +#: ../../c-api/extension-modules.rst:184 |
| 267 | +msgid "Legacy single-phase initialization" |
| 268 | +msgstr "" |
| 269 | + |
| 270 | +#: ../../c-api/extension-modules.rst:187 |
| 271 | +msgid "" |
| 272 | +"Single-phase initialization is a legacy mechanism to initialize extension " |
| 273 | +"modules, with known drawbacks and design flaws. Extension module authors are " |
| 274 | +"encouraged to use multi-phase initialization instead." |
| 275 | +msgstr "" |
| 276 | + |
| 277 | +#: ../../c-api/extension-modules.rst:191 |
| 278 | +msgid "" |
| 279 | +"In single-phase initialization, the :ref:`initialization function <extension-" |
| 280 | +"export-hook>` (``PyInit_modulename``) should create, populate and return a " |
| 281 | +"module object. This is typically done using :c:func:`PyModule_Create` and " |
| 282 | +"functions like :c:func:`PyModule_AddObjectRef`." |
| 283 | +msgstr "" |
| 284 | + |
| 285 | +#: ../../c-api/extension-modules.rst:197 |
| 286 | +msgid "" |
| 287 | +"Single-phase initialization differs from the :ref:`default <multi-phase-" |
| 288 | +"initialization>` in the following ways:" |
| 289 | +msgstr "" |
| 290 | + |
| 291 | +#: ../../c-api/extension-modules.rst:200 |
| 292 | +msgid "Single-phase modules are, or rather *contain*, “singletons”." |
| 293 | +msgstr "" |
| 294 | + |
| 295 | +#: ../../c-api/extension-modules.rst:202 |
| 296 | +msgid "" |
| 297 | +"When the module is first initialized, Python saves the contents of the " |
| 298 | +"module's ``__dict__`` (that is, typically, the module's functions and types)." |
| 299 | +msgstr "" |
| 300 | + |
| 301 | +#: ../../c-api/extension-modules.rst:206 |
| 302 | +msgid "" |
| 303 | +"For subsequent imports, Python does not call the initialization function " |
| 304 | +"again. Instead, it creates a new module object with a new ``__dict__``, and " |
| 305 | +"copies the saved contents to it. For example, given a single-phase module " |
| 306 | +"``_testsinglephase`` [#testsinglephase]_ that defines a function ``sum`` and " |
| 307 | +"an exception class ``error``:" |
| 308 | +msgstr "" |
| 309 | + |
| 310 | +#: ../../c-api/extension-modules.rst:214 |
| 311 | +msgid "" |
| 312 | +">>> import sys\n" |
| 313 | +">>> import _testsinglephase as one\n" |
| 314 | +">>> del sys.modules['_testsinglephase']\n" |
| 315 | +">>> import _testsinglephase as two\n" |
| 316 | +">>> one is two\n" |
| 317 | +"False\n" |
| 318 | +">>> one.__dict__ is two.__dict__\n" |
| 319 | +"False\n" |
| 320 | +">>> one.sum is two.sum\n" |
| 321 | +"True\n" |
| 322 | +">>> one.error is two.error\n" |
| 323 | +"True" |
| 324 | +msgstr "" |
| 325 | + |
| 326 | +#: ../../c-api/extension-modules.rst:229 |
| 327 | +msgid "" |
| 328 | +"The exact behavior should be considered a CPython implementation detail." |
| 329 | +msgstr "" |
| 330 | + |
| 331 | +#: ../../c-api/extension-modules.rst:231 |
| 332 | +msgid "" |
| 333 | +"To work around the fact that ``PyInit_modulename`` does not take a *spec* " |
| 334 | +"argument, some state of the import machinery is saved and applied to the " |
| 335 | +"first suitable module created during the ``PyInit_modulename`` call. " |
| 336 | +"Specifically, when a sub-module is imported, this mechanism prepends the " |
| 337 | +"parent package name to the name of the module." |
| 338 | +msgstr "" |
| 339 | + |
| 340 | +#: ../../c-api/extension-modules.rst:237 |
| 341 | +msgid "" |
| 342 | +"A single-phase ``PyInit_modulename`` function should create “its” module " |
| 343 | +"object as soon as possible, before any other module objects can be created." |
| 344 | +msgstr "" |
| 345 | + |
| 346 | +#: ../../c-api/extension-modules.rst:240 |
| 347 | +msgid "Non-ASCII module names (``PyInitU_modulename``) are not supported." |
| 348 | +msgstr "" |
| 349 | + |
| 350 | +#: ../../c-api/extension-modules.rst:242 |
| 351 | +msgid "" |
| 352 | +"Single-phase modules support module lookup functions like :c:func:" |
| 353 | +"`PyState_FindModule`." |
| 354 | +msgstr "" |
| 355 | + |
| 356 | +#: ../../c-api/extension-modules.rst:245 |
| 357 | +msgid "" |
| 358 | +"``_testsinglephase`` is an internal module used \\ in CPython's self-test " |
| 359 | +"suite; your installation may or may not \\ include it." |
| 360 | +msgstr "" |
0 commit comments