-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathnewtypes.po
More file actions
2034 lines (1827 loc) · 112 KB
/
newtypes.po
File metadata and controls
2034 lines (1827 loc) · 112 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 1990-2021, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
# 秘湯 <xwhhsprings@gmail.com>, 2015
msgid ""
msgstr ""
"Project-Id-Version: Python 2.7\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-01 01:01+0900\n"
"PO-Revision-Date: 2019-09-01 05:18+0000\n"
"Last-Translator: tomo\n"
"Language-Team: Japanese (http://www.transifex.com/python-doc/python-27/"
"language/ja/)\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../extending/newtypes.rst:8
msgid "Defining New Types"
msgstr "新しい型を定義する"
#: ../../extending/newtypes.rst:15
msgid ""
"As mentioned in the last chapter, Python allows the writer of an extension "
"module to define new types that can be manipulated from Python code, much "
"like strings and lists in core Python."
msgstr ""
"前の章でふれたように、Python では拡張モジュールを書くプログラマが Python の"
"コードから操作できる、新しい型を定義できるようになっています。ちょうど "
"Python の中核にある文字列やリストをつくれるようなものです。"
#: ../../extending/newtypes.rst:19
msgid ""
"This is not hard; the code for all extension types follows a pattern, but "
"there are some details that you need to understand before you can get "
"started."
msgstr ""
"これはそんなにむずかしくはありません。拡張型のためのコードにはすべて、一定の"
"パターンが存在しています。しかし始める前に、いくつか細かいことを理解しておく"
"必要があるでしょう。"
#: ../../extending/newtypes.rst:24
msgid ""
"The way new types are defined changed dramatically (and for the better) in "
"Python 2.2. This document documents how to define new types for Python 2.2 "
"and later. If you need to support older versions of Python, you will need "
"to refer to `older versions of this documentation <https://www.python.org/"
"doc/versions/>`_."
msgstr ""
"Python 2.2 から、新しい型を定義する方法がかなり変わって (良くなって) います。"
"この文書は Python 2.2 およびそれ以降で新しい型をどうやって定義するかについて"
"述べています。古いバージョンの Python をサポートする必要がある場合は、 `この"
"文書の古い版 <https://www.python.org/doc/versions/>`_ を参照してください。"
#: ../../extending/newtypes.rst:34
msgid "The Basics"
msgstr "基本的なこと"
#: ../../extending/newtypes.rst:36
msgid ""
"The Python runtime sees all Python objects as variables of type :c:type:"
"`PyObject\\*`. A :c:type:`PyObject` is not a very magnificent object - it "
"just contains the refcount and a pointer to the object's \"type object\". "
"This is where the action is; the type object determines which (C) functions "
"get called when, for instance, an attribute gets looked up on an object or "
"it is multiplied by another object. These C functions are called \"type "
"methods\"."
msgstr ""
"Python ランタイムでは、すべての Python オブジェクトは :c:type:`PyObject\\*` "
"型の変数として扱います。 :c:type:`PyObject` はさほど大仰なオブジェクトではな"
"く、単にオブジェクトに対する参照回数と、そのオブジェクトの「タイプオブジェク"
"ト (type object)」へのポインタを格納しているだけです。重要な役割を果たしてい"
"るのはこのタイプオブジェクトです。つまりタイプオブジェクトは、例えばあるオブ"
"ジェクトのある属性が参照されるとか、あるいは別のオブジェクトとの間で乗算を行"
"うといったときに、どの (C の) 関数を呼び出すかを決定しているのです。これらの "
"C 関数は「タイプメソッド (type method)」と呼ばれ、 ``[].append`` のようなも"
"の (いわゆる「オブジェクトメソッド (object method)」) とは区別しています。"
#: ../../extending/newtypes.rst:43
msgid ""
"So, if you want to define a new object type, you need to create a new type "
"object."
msgstr ""
"なので、新しいオブジェクトの型を定義したいときは、新しいタイプオブジェクトを"
"作成すればよいわけです。"
#: ../../extending/newtypes.rst:46
msgid ""
"This sort of thing can only be explained by example, so here's a minimal, "
"but complete, module that defines a new type:"
msgstr ""
"この手のことは例を見たほうが早いでしょうから、ここに最小限の、しかし完全な、"
"新しい型を定義するモジュールをあげておきます:"
#: ../../extending/newtypes.rst:52
msgid ""
"Now that's quite a bit to take in at once, but hopefully bits will seem "
"familiar from the last chapter."
msgstr ""
"さしあたって覚えておくことは以上ですが、これで前の章からすこしは説明がわかり"
"やすくなっていることと思います。"
#: ../../extending/newtypes.rst:55
msgid "The first bit that will be new is::"
msgstr "最初に習うのは、つぎのようなものです::"
#: ../../extending/newtypes.rst:61
msgid ""
"This is what a Noddy object will contain---in this case, nothing more than "
"every Python object contains, namely a refcount and a pointer to a type "
"object. These are the fields the ``PyObject_HEAD`` macro brings in. The "
"reason for the macro is to standardize the layout and to enable special "
"debugging fields in debug builds. Note that there is no semicolon after the "
"``PyObject_HEAD`` macro; one is included in the macro definition. Be wary "
"of adding one by accident; it's easy to do from habit, and your compiler "
"might not complain, but someone else's probably will! (On Windows, MSVC is "
"known to call this an error and refuse to compile the code.)"
msgstr ""
"これが Noddy オブジェクトの内容です --- このケースでは、ほかの Python オブ"
"ジェクトが持っているものと何ら変わりはありません。つまり参照カウントと型オブ"
"ジェクトへのポインタですね。これらは ``PyObject_HEAD`` マクロによって展開され"
"るメンバです。マクロを使う理由は、レイアウトを標準化するためと、デバッグ用ビ"
"ルド時に特別なデバッグ用のメンバを定義できるようにするためです。この "
"``PyObject_HEAD`` マクロの後にはセミコロンがないことに注意してください。セミ"
"コロンはすでにマクロ内に含まれています。うっかり後にセミコロンをつけてしまわ"
"ないように気をつけて。これはお使いの機種では何の問題も起こらないかもしれませ"
"んが、機種によっては、おそらく問題になるのです! (Windows 上では、MS Visual C "
"がこの手のエラーを出し、コンパイルできないことが知られています)"
#: ../../extending/newtypes.rst:71
msgid ""
"For contrast, let's take a look at the corresponding definition for standard "
"Python integers::"
msgstr "比較のため、以下に標準的な Python の整数型の定義を見てみましょう::"
#: ../../extending/newtypes.rst:79
msgid "Moving on, we come to the crunch --- the type object. ::"
msgstr "では次にいってみます。かなめの部分、タイプオブジェクトです。 ::"
#: ../../extending/newtypes.rst:105
msgid ""
"Now if you go and look up the definition of :c:type:`PyTypeObject` in :file:"
"`object.h` you'll see that it has many more fields that the definition "
"above. The remaining fields will be filled with zeros by the C compiler, "
"and it's common practice to not specify them explicitly unless you need them."
msgstr ""
":file:`object.h` の中にある :c:type:`PyTypeObject` の定義を見ると、実際にはこ"
"こに挙げた以上の数のメンバがあるとわかるでしょう。これ以外のメンバは C コンパ"
"イラによってゼロに初期化されるので、必要な時を除いてふつうはそれらの値を明示"
"的には指定せずにおきます。"
#: ../../extending/newtypes.rst:110
msgid ""
"This is so important that we're going to pick the top of it apart still "
"further::"
msgstr "次のものは非常に重要なので、とくに最初の最初に見ておきましょう::"
#: ../../extending/newtypes.rst:115
msgid "This line is a bit of a wart; what we'd like to write is::"
msgstr "これはちょっとぶっきらぼうですね。実際に書きたかったのはこうです::"
#: ../../extending/newtypes.rst:119
msgid ""
"as the type of a type object is \"type\", but this isn't strictly conforming "
"C and some compilers complain. Fortunately, this member will be filled in "
"for us by :c:func:`PyType_Ready`. ::"
msgstr ""
"この場合、タイプオブジェクトの型は「type」という名前になりますが、これは厳密"
"には C の基準に従っておらず、コンパイラによっては文句を言われます。幸いにも、"
"このメンバは :c:func:`PyType_Ready` が埋めてくれます。 ::"
#: ../../extending/newtypes.rst:125
msgid ""
"The name of our type. This will appear in the default textual "
"representation of our objects and in some error messages, for example::"
msgstr ""
"これは型の名前です。この名前はオブジェクトのデフォルトの表現形式と、いくつか"
"のエラーメッセージ中で使われます。たとえば::"
#: ../../extending/newtypes.rst:133
msgid ""
"Note that the name is a dotted name that includes both the module name and "
"the name of the type within the module. The module in this case is :mod:"
"`noddy` and the type is :class:`Noddy`, so we set the type name to :class:"
"`noddy.Noddy`. One side effect of using an undotted name is that the pydoc "
"documentation tool will not list the new type in the module documentation. ::"
msgstr ""
"注意: この名前はドットで区切られた名前で、モジュール名とそのモジュール内での"
"型名の両方を含んでいます。\n"
"この場合のモジュールは :mod:`noddy` で型は :class:`Noddy` ですから、ここでの"
"型名としては :class:`noddy.Noddy` を指定するわけです。\n"
"ドットで区切られていない名前を使うと、文書ツールの pydoc がその新しい型をモ"
"ジュールの文書に載せなくなるという副作用があります。 ::"
#: ../../extending/newtypes.rst:141
msgid ""
"This is so that Python knows how much memory to allocate when you call :c:"
"func:`PyObject_New`."
msgstr ""
"これによって Python は :c:func:`PyObject_New` が呼ばれたときにどれくらいの量"
"のメモリを割り当てればよいのか知ることができます。"
#: ../../extending/newtypes.rst:146
msgid ""
"If you want your type to be subclassable from Python, and your type has the "
"same :c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have "
"problems with multiple inheritance. A Python subclass of your type will "
"have to list your type first in its :attr:`~class.__bases__`, or else it "
"will not be able to call your type's :meth:`__new__` method without getting "
"an error. You can avoid this problem by ensuring that your type has a "
"larger value for :c:member:`~PyTypeObject.tp_basicsize` than its base type "
"does. Most of the time, this will be true anyway, because either your base "
"type will be :class:`object`, or else you will be adding data members to "
"your base type, and therefore increasing its size."
msgstr ""
"あなたのタイプを Python でサブクラス化可能にしたい場合、そのタイプが基底タイ"
"プと同じ :c:member:`~PyTypeObject.tp_basicsize` をもっていると多重継承のとき"
"に問題が生じることがあります。そのタイプを Python のサブクラスにしたとき、そ"
"の :attr:`~class.__bases__` リストにはあなたのタイプが最初にくるようにしなけ"
"ればなりません。さもないとエラーの発生なしにあなたのタイプの :meth:`__new__` "
"メソッドを呼び出すことはできなくなります。この問題を回避するには、つねにあな"
"たのタイプの :c:member:`~PyTypeObject.tp_basicsize` をその基底タイプよりも大"
"きくしておくことです。ほとんどの場合、あなたのタイプは :class:`object` か、そ"
"うでなければ基底タイプにデータ用のメンバを追加したものでしょうから、したがっ"
"て大きさはつねに増加するためこの条件は満たされています。"
#: ../../extending/newtypes.rst:160
msgid ""
"This has to do with variable length objects like lists and strings. Ignore "
"this for now."
msgstr ""
"これはリストや文字列などの可変長オブジェクトのためのものです。今のところ無視"
"しましょう。"
#: ../../extending/newtypes.rst:163
msgid ""
"Skipping a number of type methods that we don't provide, we set the class "
"flags to :const:`Py_TPFLAGS_DEFAULT`. ::"
msgstr ""
"このあとのいくつかのタイプメソッドは使わないのでとばして、クラスのフラグ "
"(flags) には :const:`Py_TPFLAGS_DEFAULT` を入れます。 ::"
#: ../../extending/newtypes.rst:168
msgid ""
"All types should include this constant in their flags. It enables all of "
"the members defined by the current version of Python."
msgstr ""
"すべての型はフラグにこの定数を含めておく必要があります。これは現在のバージョ"
"ンの Python で定義されているすべてのメンバを許可します。"
#: ../../extending/newtypes.rst:171
msgid ""
"We provide a doc string for the type in :c:member:`~PyTypeObject.tp_doc`. ::"
msgstr "この型の docstring は :c:member:`~PyTypeObject.tp_doc` に入れます。 ::"
#: ../../extending/newtypes.rst:175
msgid ""
"Now we get into the type methods, the things that make your objects "
"different from the others. We aren't going to implement any of these in "
"this version of the module. We'll expand this example later to have more "
"interesting behavior."
msgstr ""
"ここからタイプメソッドに入るわけですが。ここがあなたのオブジェクトが他と違う"
"ところです。でも今回のバージョンでは、これらはどれも実装しないでおき、あとで"
"この例をより面白いものに改造することにしましょう。"
#: ../../extending/newtypes.rst:179
msgid ""
"For now, all we want to be able to do is to create new :class:`Noddy` "
"objects. To enable object creation, we have to provide a :c:member:"
"`~PyTypeObject.tp_new` implementation. In this case, we can just use the "
"default implementation provided by the API function :c:func:"
"`PyType_GenericNew`. We'd like to just assign this to the :c:member:"
"`~PyTypeObject.tp_new` slot, but we can't, for portability sake, On some "
"platforms or compilers, we can't statically initialize a structure member "
"with a function defined in another C module, so, instead, we'll assign the :"
"c:member:`~PyTypeObject.tp_new` slot in the module initialization function "
"just before calling :c:func:`PyType_Ready`::"
msgstr ""
"とりあえずやりたいのは、この :class:`Noddy` オブジェクトを新しく作れるように"
"することです。オブジェクトの作成を許可するには、 :c:member:`~PyTypeObject."
"tp_new` の実装を提供する必要があります。今回は、 API 関数によって提供されるデ"
"フォルトの実装 :c:func:`PyType_GenericNew` を使うだけにしましょう。これを単"
"に :c:member:`~PyTypeObject.tp_new` スロットに代入すればよいのですが、これは"
"互換上の理由からできません。プラットフォームやコンパイラによっては、構造体メ"
"ンバの初期化に別の場所で定義されている C の関数を代入することはできないので"
"す。なので、この :c:member:`~PyTypeObject.tp_new` の値はモジュール初期化用の"
"関数で代入します。 :c:func:`PyType_Ready` を呼ぶ直前です::"
#: ../../extending/newtypes.rst:193
msgid ""
"All the other type methods are *NULL*, so we'll go over them later --- "
"that's for a later section!"
msgstr ""
"これ以外のタイプメソッドはすべて *NULL* です。これらについては後ほどふれます!"
#: ../../extending/newtypes.rst:196
msgid ""
"Everything else in the file should be familiar, except for some code in :c:"
"func:`initnoddy`::"
msgstr ""
"このファイル中にある他のものは、どれもおなじみでしょう。 :c:func:`initnoddy` "
"のこれを除いて::"
#: ../../extending/newtypes.rst:202
msgid ""
"This initializes the :class:`Noddy` type, filing in a number of members, "
"including :attr:`ob_type` that we initially set to *NULL*. ::"
msgstr ""
"この関数は、上で *NULL* に指定していた :attr:`ob_type` などのいくつものメンバ"
"を埋めて、 :class:`Noddy` 型を初期化します。 ::"
#: ../../extending/newtypes.rst:207
msgid ""
"This adds the type to the module dictionary. This allows us to create :"
"class:`Noddy` instances by calling the :class:`Noddy` class::"
msgstr ""
"これはこの型をモジュール中の辞書に埋め込みます。これで、 :class:`Noddy` クラ"
"スを呼べば :class:`Noddy` インスタンスを作れるようになりました::"
#: ../../extending/newtypes.rst:213
msgid ""
"That's it! All that remains is to build it; put the above code in a file "
"called :file:`noddy.c` and ::"
msgstr ""
"これだけです! 残るはこれをどうやってビルドするかということです。上のコード"
"を :file:`noddy.c` というファイルに入れて、以下のものを :file:`setup.py` とい"
"うファイルに入れましょう ::"
#: ../../extending/newtypes.rst:220
msgid "in a file called :file:`setup.py`; then typing"
msgstr "そして、シェルから以下のように入力します"
#: ../../extending/newtypes.rst:226
msgid ""
"at a shell should produce a file :file:`noddy.so` in a subdirectory; move to "
"that directory and fire up Python --- you should be able to ``import noddy`` "
"and play around with Noddy objects."
msgstr ""
"これでサブディレクトリの下にファイル :file:`noddy.so` が作成されます。この"
"ディレクトリに移動して Python を起動しましょう。 ``import noddy`` して Noddy "
"オブジェクトで遊べるようになっているはずです。"
#: ../../extending/newtypes.rst:230
msgid "That wasn't so hard, was it?"
msgstr "そんなにむずかしくありません、よね?"
#: ../../extending/newtypes.rst:232
msgid ""
"Of course, the current Noddy type is pretty uninteresting. It has no data "
"and doesn't do anything. It can't even be subclassed."
msgstr ""
"もちろん、現在の Noddy 型はまだおもしろみに欠けています。何もデータを持ってな"
"いし、何もしてはくれません。継承してサブクラスを作ることさえできないのです。"
#: ../../extending/newtypes.rst:237
msgid "Adding data and methods to the Basic example"
msgstr "基本のサンプルにデータとメソッドを追加する"
#: ../../extending/newtypes.rst:239
msgid ""
"Let's extend the basic example to add some data and methods. Let's also "
"make the type usable as a base class. We'll create a new module, :mod:"
"`noddy2` that adds these capabilities:"
msgstr ""
"この基本のサンプルにデータとメソッドを追加してみましょう。ついでに、この型を"
"基底クラスとしても利用できるようにします。ここでは新しいモジュール :mod:"
"`noddy2` をつくり、以下の機能を追加します:"
#: ../../extending/newtypes.rst:246
msgid "This version of the module has a number of changes."
msgstr "このバージョンでは、いくつもの変更をおこないます。"
#: ../../extending/newtypes.rst:248
msgid "We've added an extra include::"
msgstr "以下の include を追加します::"
#: ../../extending/newtypes.rst:252
msgid ""
"This include provides declarations that we use to handle attributes, as "
"described a bit later."
msgstr ""
"すこしあとでふれますが、この include には属性を扱うための宣言が入っています。"
#: ../../extending/newtypes.rst:255
msgid ""
"The name of the :class:`Noddy` object structure has been shortened to :class:"
"`Noddy`. The type object name has been shortened to :class:`NoddyType`."
msgstr ""
":class:`Noddy` オブジェクトの構造体の名前は :class:`Noddy` に縮めることにしま"
"す。タイプオブジェクト名は :class:`NoddyType` に縮めます。"
#: ../../extending/newtypes.rst:258
msgid ""
"The :class:`Noddy` type now has three data attributes, *first*, *last*, and "
"*number*. The *first* and *last* variables are Python strings containing "
"first and last names. The *number* attribute is an integer."
msgstr ""
"これから :class:`Noddy` 型は 3つのデータ属性をもつようになります。 "
"*first* 、 *last* 、および *number* です。 *first* と *last* 属性はファースト"
"ネームとラストネームを格納した Python 文字列で、 *number* 属性は整数の値で"
"す。"
#: ../../extending/newtypes.rst:262
msgid "The object structure is updated accordingly::"
msgstr "これにしたがうと、オブジェクトの構造体は次のようになります::"
#: ../../extending/newtypes.rst:271
msgid ""
"Because we now have data to manage, we have to be more careful about object "
"allocation and deallocation. At a minimum, we need a deallocation method::"
msgstr ""
"いまや管理すべきデータができたので、オブジェクトの割り当てと解放に際してはよ"
"り慎重になる必要があります。最低限、オブジェクトの解放メソッドが必要です::"
#: ../../extending/newtypes.rst:282
msgid "which is assigned to the :c:member:`~PyTypeObject.tp_dealloc` member::"
msgstr ""
"この関数は :c:member:`~PyTypeObject.tp_dealloc` メンバに代入されます。 ::"
#: ../../extending/newtypes.rst:286
msgid ""
"This method decrements the reference counts of the two Python attributes. We "
"use :c:func:`Py_XDECREF` here because the :attr:`first` and :attr:`last` "
"members could be *NULL*. It then calls the :c:member:`~PyTypeObject."
"tp_free` member of the object's type to free the object's memory. Note that "
"the object's type might not be :class:`NoddyType`, because the object may be "
"an instance of a subclass."
msgstr ""
"このメソッドでやっているのは、ふたつの Python 属性の参照カウントを減らすこと"
"です。 :attr:`first` メンバと :attr:`last` メンバが *NULL* かもしれないため、"
"ここでは :c:func:`Py_XDECREF` を使いました。このあとそのオブジェクトのタイプ"
"メソッドである :c:member:`~PyTypeObject.tp_free` メンバを呼び出しています。こ"
"こではオブジェクトの型が :class:`NoddyType` とは限らないことに注意してくださ"
"い。なぜなら、このオブジェクトはサブクラス化したインスタンスかもしれないから"
"です。"
#: ../../extending/newtypes.rst:292
msgid ""
"We want to make sure that the first and last names are initialized to empty "
"strings, so we provide a new method::"
msgstr ""
"ファーストネームとラストネームを空文字列に初期化しておきたいので、新しいメ"
"ソッドを追加することにしましょう::"
#: ../../extending/newtypes.rst:322
msgid "and install it in the :c:member:`~PyTypeObject.tp_new` member::"
msgstr ""
"そしてこれを :c:member:`~PyTypeObject.tp_new` メンバとしてインストールしま"
"す::"
#: ../../extending/newtypes.rst:326
msgid ""
"The new member is responsible for creating (as opposed to initializing) "
"objects of the type. It is exposed in Python as the :meth:`__new__` "
"method. See the paper titled \"Unifying types and classes in Python\" for a "
"detailed discussion of the :meth:`__new__` method. One reason to implement "
"a new method is to assure the initial values of instance variables. In this "
"case, we use the new method to make sure that the initial values of the "
"members :attr:`first` and :attr:`last` are not *NULL*. If we didn't care "
"whether the initial values were *NULL*, we could have used :c:func:"
"`PyType_GenericNew` as our new method, as we did before. :c:func:"
"`PyType_GenericNew` initializes all of the instance variable members to "
"*NULL*."
msgstr ""
"この新しいメンバはその型のオブジェクトを (初期化するのではなく) 作成する責任"
"を負っています。Python ではこのメンバは :meth:`__new__` メソッドとして見えて"
"います。 :meth:`__new__` メソッドについての詳しい議論は \"Unifying types and "
"classes in Python\" という題名の論文を見てください。 new メソッドを実装する理"
"由のひとつは、インスタンス変数の初期値を保証するためです。この例でやりたいの"
"は new メソッドが :attr:`first` メンバと :attr:`last` メンバの値を *NULL* で"
"ないようにするということです。もしこれらの初期値が *NULL* でもよいのであれ"
"ば、先の例でやったように、new メソッドとして :c:func:`PyType_GenericNew` を使"
"うこともできたでしょう。 :c:func:`PyType_GenericNew` はすべてのインスタンス変"
"数のメンバを *NULL* にします。"
#: ../../extending/newtypes.rst:337
msgid ""
"The new method is a static method that is passed the type being instantiated "
"and any arguments passed when the type was called, and that returns the new "
"object created. New methods always accept positional and keyword arguments, "
"but they often ignore the arguments, leaving the argument handling to "
"initializer methods. Note that if the type supports subclassing, the type "
"passed may not be the type being defined. The new method calls the tp_alloc "
"slot to allocate memory. We don't fill the :c:member:`~PyTypeObject."
"tp_alloc` slot ourselves. Rather :c:func:`PyType_Ready` fills it for us by "
"inheriting it from our base class, which is :class:`object` by default. "
"Most types use the default allocation."
msgstr ""
"この new メソッドは静的なメソッドで、インスタンスを生成するときにその型と、型"
"が呼び出されたときの引数が渡され、新しいオブジェクトを作成して返します。new "
"メソッドはつねに、あらかじめ固定引数 (positional argument) とキーワード引数を"
"取りますが、これらのメソッドはしばしばそれらの引数は無視して初期化メソッドに"
"そのまま渡します。new メソッドはメモリ割り当てのために :c:member:"
"`~PyTypeObject.tp_alloc` メンバを呼び出します。 :c:member:`~PyTypeObject."
"tp_alloc` をこちらで初期化する必要はありません。これは :c:func:"
"`PyType_Ready` が基底クラス (デフォルトでは :class:`object`) をもとに埋めるも"
"のです。ほとんどの型ではデフォルトのメモリ割り当てを使っています。"
#: ../../extending/newtypes.rst:349
msgid ""
"If you are creating a co-operative :c:member:`~PyTypeObject.tp_new` (one "
"that calls a base type's :c:member:`~PyTypeObject.tp_new` or :meth:"
"`__new__`), you must *not* try to determine what method to call using method "
"resolution order at runtime. Always statically determine what type you are "
"going to call, and call its :c:member:`~PyTypeObject.tp_new` directly, or "
"via ``type->tp_base->tp_new``. If you do not do this, Python subclasses of "
"your type that also inherit from other Python-defined classes may not work "
"correctly. (Specifically, you may not be able to create instances of such "
"subclasses without getting a :exc:`TypeError`.)"
msgstr ""
"もし協力的な :c:member:`~PyTypeObject.tp_new` (基底タイプの :c:member:"
"`~PyTypeObject.tp_new` または :meth:`__new__` を呼んでいるもの) を作りたいの"
"ならば、実行時のメソッド解決順序をつかってどのメソッドを呼びだすかを決定しよ"
"うとしては *いけません* 。つねに呼び出す型を静的に決めておき、直接その :c:"
"member:`~PyTypeObject.tp_new` を呼び出すか、あるいは ``type->tp_base-"
">tp_new`` を経由してください。こうしないと、あなたが作成したタイプの Python "
"サブクラスが他の Python で定義されたクラスも継承している場合にうまく動かない"
"場合があります。 (とりわけ、そのようなサブクラスのインスタンスを :exc:"
"`TypeError` を出さずに作ることが不可能になります。)"
#: ../../extending/newtypes.rst:358
msgid "We provide an initialization function::"
msgstr "つぎに初期化用の関数を見てみましょう::"
#: ../../extending/newtypes.rst:389
msgid "by filling the :c:member:`~PyTypeObject.tp_init` slot. ::"
msgstr "これは :c:member:`~PyTypeObject.tp_init` メンバに代入されます。 ::"
#: ../../extending/newtypes.rst:393
msgid ""
"The :c:member:`~PyTypeObject.tp_init` slot is exposed in Python as the :meth:"
"`__init__` method. It is used to initialize an object after it's created. "
"Unlike the new method, we can't guarantee that the initializer is called. "
"The initializer isn't called when unpickling objects and it can be "
"overridden. Our initializer accepts arguments to provide initial values for "
"our instance. Initializers always accept positional and keyword arguments."
msgstr ""
"Python では、 :c:member:`~PyTypeObject.tp_init` メンバは :meth:`__init__` メ"
"ソッドとして見えています。このメソッドは、オブジェクトが作成されたあとに、そ"
"れを初期化する目的で使われます。 new メソッドとはちがって、初期化用のメソッド"
"は必ず呼ばれるとは限りません。初期化用のメソッドは、インスタンスの初期値を提"
"供するのに必要な引数を受けとります。このメソッドはつねに固定引数とキーワード"
"引数を受けとります。"
#: ../../extending/newtypes.rst:400
msgid ""
"Initializers can be called multiple times. Anyone can call the :meth:"
"`__init__` method on our objects. For this reason, we have to be extra "
"careful when assigning the new values. We might be tempted, for example to "
"assign the :attr:`first` member like this::"
msgstr ""
"初期化メソッドは複数回呼び出される可能性があります。あなたのオブジェクトの :"
"meth:`__init__` メソッドは、誰にでも呼び出すことができるからです。このため、"
"新しい値を代入するさいには特別な注意を払う必要があります。たとえば、 :attr:"
"`first` メンバには以下のように代入したくなるかもしれません::"
#: ../../extending/newtypes.rst:411
msgid ""
"But this would be risky. Our type doesn't restrict the type of the :attr:"
"`first` member, so it could be any kind of object. It could have a "
"destructor that causes code to be executed that tries to access the :attr:"
"`first` member. To be paranoid and protect ourselves against this "
"possibility, we almost always reassign members before decrementing their "
"reference counts. When don't we have to do this?"
msgstr ""
"しかしこのやり方は危険です。このタイプでは :attr:`first` メンバに入るオブジェ"
"クトをなにも限定していないので、どんなオブジェクトでもとり得てしまうからで"
"す。それはこのコードが :attr:`first` メンバにアクセスしようとする前に、そのデ"
"ストラクタが呼び出されてしまうかもしれないのです。このような可能性からパラノ"
"イア的に身をまもるため、ほとんどの場合メンバへの代入は,その参照カウントを減ら"
"す前におこなってください。こうする必要がないのはどんな場合でしょうか?"
#: ../../extending/newtypes.rst:418
msgid "when we absolutely know that the reference count is greater than 1"
msgstr "その参照カウントが 1 より大きいと確信できる場合。"
#: ../../extending/newtypes.rst:420
msgid ""
"when we know that deallocation of the object [#]_ will not cause any calls "
"back into our type's code"
msgstr ""
"そのオブジェクトの解放があなたのタイプのコードにコールバックするようなことが"
"決してない場合 [#]_ 。"
#: ../../extending/newtypes.rst:423
msgid ""
"when decrementing a reference count in a :c:member:`~PyTypeObject."
"tp_dealloc` handler when garbage-collections is not supported [#]_"
msgstr ""
"ガベージコレクションがサポートされていない場合に :c:member:`~PyTypeObject."
"tp_dealloc` ハンドラで参照カウントを減らすとき [#]_ 。"
#: ../../extending/newtypes.rst:426
msgid ""
"We want to expose our instance variables as attributes. There are a number "
"of ways to do that. The simplest way is to define member definitions::"
msgstr ""
"ここではインスタンス変数を属性として見えるようにしたいのですが、これにはいく"
"つもの方法があります。もっとも簡単な方法は、メンバの定義を与えることです::"
#: ../../extending/newtypes.rst:439
msgid ""
"and put the definitions in the :c:member:`~PyTypeObject.tp_members` slot::"
msgstr ""
"そして、この定義を :c:member:`~PyTypeObject.tp_members` スロットに入れましょ"
"う::"
#: ../../extending/newtypes.rst:443
msgid ""
"Each member definition has a member name, type, offset, access flags and "
"documentation string. See the :ref:`Generic-Attribute-Management` section "
"below for details."
msgstr ""
"各メンバの定義はそれぞれ、メンバの名前、型、オフセット、アクセスフラグおよび "
"docstring です。詳しくは後の \"総称的な属性を管理する\" (:ref:`Generic-"
"Attribute-Management`) の節をご覧ください。"
#: ../../extending/newtypes.rst:447
msgid ""
"A disadvantage of this approach is that it doesn't provide a way to restrict "
"the types of objects that can be assigned to the Python attributes. We "
"expect the first and last names to be strings, but any Python objects can be "
"assigned. Further, the attributes can be deleted, setting the C pointers to "
"*NULL*. Even though we can make sure the members are initialized to non-"
"*NULL* values, the members can be set to *NULL* if the attributes are "
"deleted."
msgstr ""
"この方法の欠点は、Python 属性に代入できるオブジェクトの型を制限する方法がない"
"ことです。ここではファーストネーム first とラストネーム last に、ともに文字列"
"が入るよう期待していますが、今のやり方ではどんな Python オブジェクトも代入で"
"きてしまいます。加えてこの属性は削除 (del) できてしまい、その場合、 C のポイ"
"ンタには *NULL* が設定されます。たとえもしメンバが *NULL* 以外の値に初期化さ"
"れるようにしてあったとしても、属性が削除されればメンバは *NULL* になってしま"
"います。"
#: ../../extending/newtypes.rst:454
msgid ""
"We define a single method, :meth:`name`, that outputs the objects name as "
"the concatenation of the first and last names. ::"
msgstr ""
"ここでは :meth:`name` と呼ばれるメソッドを定義しましょう。これはファースト"
"ネーム first とラストネーム last を連結した文字列をそのオブジェクトの名前とし"
"て返します。 ::"
#: ../../extending/newtypes.rst:489
msgid ""
"The method is implemented as a C function that takes a :class:`Noddy` (or :"
"class:`Noddy` subclass) instance as the first argument. Methods always take "
"an instance as the first argument. Methods often take positional and keyword "
"arguments as well, but in this case we don't take any and don't need to "
"accept a positional argument tuple or keyword argument dictionary. This "
"method is equivalent to the Python method::"
msgstr ""
"このメソッドは C 関数として実装され、 :class:`Noddy` (あるいは :class:"
"`Noddy` のサブクラス) のインスタンスを第一引数として受けとります。メソッドは"
"つねにそのインスタンスを最初の引数として受けとらなければなりません。しばしば"
"固定引数とキーワード引数も受けとりますが、今回はなにも必要ないので、固定引数"
"のタプルもキーワード引数の辞書も取らないことにします。このメソッドは Python "
"の以下のメソッドと等価です::"
#: ../../extending/newtypes.rst:499
msgid ""
"Note that we have to check for the possibility that our :attr:`first` and :"
"attr:`last` members are *NULL*. This is because they can be deleted, in "
"which case they are set to *NULL*. It would be better to prevent deletion "
"of these attributes and to restrict the attribute values to be strings. "
"We'll see how to do that in the next section."
msgstr ""
":attr:`first` メンバと :attr:`last` メンバがそれぞれ *NULL* かどうかチェック"
"しなければならないことに注意してください。これらは削除される可能性があり、そ"
"の場合値は *NULL* にセットされます。この属性の削除を禁止して、そこに入れられ"
"る値を文字列に限定できればなおいいでしょう。次の節ではこれについて扱います。"
#: ../../extending/newtypes.rst:505
msgid ""
"Now that we've defined the method, we need to create an array of method "
"definitions::"
msgstr ""
"さて、メソッドを定義したので、ここでメソッド定義用の配列を作成する必要があり"
"ます::"
#: ../../extending/newtypes.rst:515
msgid "and assign them to the :c:member:`~PyTypeObject.tp_methods` slot::"
msgstr "これを :c:member:`~PyTypeObject.tp_methods` スロットに入れましょう::"
#: ../../extending/newtypes.rst:519
msgid ""
"Note that we used the :const:`METH_NOARGS` flag to indicate that the method "
"is passed no arguments."
msgstr ""
"ここでの :const:`METH_NOARGS` フラグは、そのメソッドが引数を取らないことを宣"
"言するのに使われています。"
#: ../../extending/newtypes.rst:522
msgid ""
"Finally, we'll make our type usable as a base class. We've written our "
"methods carefully so far so that they don't make any assumptions about the "
"type of the object being created or used, so all we need to do is to add "
"the :const:`Py_TPFLAGS_BASETYPE` to our class flag definition::"
msgstr ""
"最後に、この型を基底クラスとして利用可能にしましょう。上のメソッドは注意ぶか"
"く書かれているので、これはそのオブジェクトの型が作成されたり利用される場合に"
"ついてどんな仮定も置いていません。なので、ここですべきことは :const:"
"`Py_TPFLAGS_BASETYPE` をクラス定義のフラグに加えるだけです::"
#: ../../extending/newtypes.rst:529
msgid ""
"We rename :c:func:`initnoddy` to :c:func:`initnoddy2` and update the module "
"name passed to :c:func:`Py_InitModule3`."
msgstr ""
":c:func:`initnoddy` の名前を :c:func:`initnoddy2` に変更し、 :c:func:"
"`Py_InitModule3` に渡されるモジュール名を更新します。"
#: ../../extending/newtypes.rst:532
msgid "Finally, we update our :file:`setup.py` file to build the new module::"
msgstr ""
"さいごに :file:`setup.py` ファイルを更新して新しいモジュールをビルドします::"
#: ../../extending/newtypes.rst:543
msgid "Providing finer control over data attributes"
msgstr "データ属性をこまかく制御する"
#: ../../extending/newtypes.rst:545
msgid ""
"In this section, we'll provide finer control over how the :attr:`first` and :"
"attr:`last` attributes are set in the :class:`Noddy` example. In the "
"previous version of our module, the instance variables :attr:`first` and :"
"attr:`last` could be set to non-string values or even deleted. We want to "
"make sure that these attributes always contain strings."
msgstr ""
"この節では、 :class:`Noddy` クラスの例にあった :attr:`first` と :attr:`last` "
"の各属性にたいして、より精密な制御を提供します。以前のバージョンのモジュール"
"では、インスタンス変数の :attr:`first` と :attr:`last` には文字列以外のものも"
"代入できてしまい、あまつさえ削除まで可能でした。ここではこれらの属性が必ず文"
"字列を保持しているようにしましょう。"
#: ../../extending/newtypes.rst:554
msgid ""
"To provide greater control, over the :attr:`first` and :attr:`last` "
"attributes, we'll use custom getter and setter functions. Here are the "
"functions for getting and setting the :attr:`first` attribute::"
msgstr ""
":attr:`first` 属性と :attr:`last` 属性をよりこまかく制御するためには、カスタ"
"ムメイドの getter 関数と setter 関数を使います。以下は :attr:`first` 属性から"
"値を取得する関数 (getter) と、この属性に値を格納する関数 (setter) です::"
#: ../../extending/newtypes.rst:585
msgid ""
"The getter function is passed a :class:`Noddy` object and a \"closure\", "
"which is void pointer. In this case, the closure is ignored. (The closure "
"supports an advanced usage in which definition data is passed to the getter "
"and setter. This could, for example, be used to allow a single set of getter "
"and setter functions that decide the attribute to get or set based on data "
"in the closure.)"
msgstr ""
"getter 関数には :class:`Noddy` オブジェクトと「閉包 (closure)」 (これは void"
"型のポインタです) が渡されます。今回のケースでは閉包は無視します。 (閉包とは"
"定義データが渡される setter や getter の高度な利用をサポートするためのもの"
"で、これを使うとたとえば getter と setter をひとまとめにした関数に、閉包の"
"データにもとづいて属性を get するか set するか決めさせる、といったことができ"
"ます。)"
#: ../../extending/newtypes.rst:591
msgid ""
"The setter function is passed the :class:`Noddy` object, the new value, and "
"the closure. The new value may be *NULL*, in which case the attribute is "
"being deleted. In our setter, we raise an error if the attribute is deleted "
"or if the attribute value is not a string."
msgstr ""
"setter 関数には :class:`Noddy` オブジェクトと新しい値、そして閉包が渡されま"
"す。新しい値は *NULL* かもしれず、その場合はこの属性が削除されます。ここでは"
"属性が削除されたり、その値が文字列でないときにはエラーを発生させるようにしま"
"す。"
#: ../../extending/newtypes.rst:596
msgid "We create an array of :c:type:`PyGetSetDef` structures::"
msgstr "ここでは :c:type:`PyGetSetDef` 構造体の配列をつくります::"
#: ../../extending/newtypes.rst:610
msgid "and register it in the :c:member:`~PyTypeObject.tp_getset` slot::"
msgstr ""
"そしてこれを :c:member:`~PyTypeObject.tp_getset` スロットに登録します::"
#: ../../extending/newtypes.rst:614
msgid "to register our attribute getters and setters."
msgstr "これで属性の getter と setter が登録できました。"
#: ../../extending/newtypes.rst:616
msgid ""
"The last item in a :c:type:`PyGetSetDef` structure is the closure mentioned "
"above. In this case, we aren't using the closure, so we just pass *NULL*."
msgstr ""
":c:type:`PyGetSetDef` 構造体の最後の要素が上で説明した閉包です。今回は閉包は"
"使わないので *NULL* を渡しています。"
#: ../../extending/newtypes.rst:619
msgid "We also remove the member definitions for these attributes::"
msgstr "また、メンバ定義からはこれらの属性を除いておきましょう::"
#: ../../extending/newtypes.rst:627
msgid ""
"We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only "
"allow strings [#]_ to be passed::"
msgstr ""
"また、ここでは :c:member:`~PyTypeObject.tp_init` ハンドラも渡されるものとして"
"文字列のみを許可するように修正する必要があります [#]_::"
#: ../../extending/newtypes.rst:659
msgid ""
"With these changes, we can assure that the :attr:`first` and :attr:`last` "
"members are never *NULL* so we can remove checks for *NULL* values in almost "
"all cases. This means that most of the :c:func:`Py_XDECREF` calls can be "
"converted to :c:func:`Py_DECREF` calls. The only place we can't change these "
"calls is in the deallocator, where there is the possibility that the "
"initialization of these members failed in the constructor."
msgstr ""
"これらの変更によって、 :attr:`first` メンバと :attr:`last` メンバが決して "
"*NULL* にならないと保証できました。これでほとんどすべてのケースから *NULL* 値"
"のチェックを除けます。これは :c:func:`Py_XDECREF` 呼び出しを :c:func:"
"`Py_DECREF` 呼び出しに変えられることを意味します。唯一これを変えられないのは"
"オブジェクト解放メソッド (deallocator) で、なぜならここではコンストラクタによ"
"るメンバ初期化が失敗している可能性があるからです。"
#: ../../extending/newtypes.rst:666
msgid ""
"We also rename the module initialization function and module name in the "
"initialization function, as we did before, and we add an extra definition to "
"the :file:`setup.py` file."
msgstr ""
"さて、先ほどもしたように、このモジュール初期化関数と初期化関数内にあるモ"
"ジュール名を変更しましょう。そして :file:`setup.py` ファイルに追加の定義をく"
"わえます。"
#: ../../extending/newtypes.rst:672
msgid "Supporting cyclic garbage collection"
msgstr "循環ガベージコレクションをサポートする"
#: ../../extending/newtypes.rst:674
msgid ""
"Python has a cyclic-garbage collector that can identify unneeded objects "
"even when their reference counts are not zero. This can happen when objects "
"are involved in cycles. For example, consider::"
msgstr ""
"Python は循環ガベージコレクション機能をもっており、これは不要なオブジェクト"
"を、たとえ参照カウントがゼロでなくても、発見することができます。これはオブ"
"ジェクトの参照が循環しているときに起こりえます。たとえば以下の例を考えてくだ"
"さい::"
#: ../../extending/newtypes.rst:682
msgid ""
"In this example, we create a list that contains itself. When we delete it, "
"it still has a reference from itself. Its reference count doesn't drop to "
"zero. Fortunately, Python's cyclic-garbage collector will eventually figure "
"out that the list is garbage and free it."
msgstr ""
"この例では、自分自身をふくむリストをつくりました。たとえこのリストを del して"
"も、それは自分自身への参照をまだ持ちつづけますから、参照カウントはゼロにはな"
"りません。嬉しいことに Python には循環ガベージコレクション機能がありますか"
"ら、最終的にはこのリストが不要であることを検出し、解放できます。"
#: ../../extending/newtypes.rst:687
msgid ""
"In the second version of the :class:`Noddy` example, we allowed any kind of "
"object to be stored in the :attr:`first` or :attr:`last` attributes [#]_. "
"This means that :class:`Noddy` objects can participate in cycles::"
msgstr ""
#: ../../extending/newtypes.rst:696
msgid ""
"This is pretty silly, but it gives us an excuse to add support for the "
"cyclic-garbage collector to the :class:`Noddy` example. To support cyclic "
"garbage collection, types need to fill two slots and set a class flag that "
"enables these slots:"
msgstr ""
"これは実にばかげた例ですが、すくなくとも :class:`Noddy` クラスに循環ガベージ"
"コレクション機能のサポートを加える口実を与えてくれます。循環ガベージコレク"
"ションをサポートするには 2つのタイプスロットを埋め、これらのスロットを許可す"
"るようにクラス定義のフラグを設定する必要があります:"
#: ../../extending/newtypes.rst:704
msgid ""
"The traversal method provides access to subobjects that could participate in "
"cycles::"
msgstr ""
"traversal メソッドは循環した参照に含まれる可能性のある内部オブジェクトへのア"
"クセスを提供します::"
#: ../../extending/newtypes.rst:726
msgid ""
"For each subobject that can participate in cycles, we need to call the :c:"
"func:`visit` function, which is passed to the traversal method. The :c:func:"
"`visit` function takes as arguments the subobject and the extra argument "
"*arg* passed to the traversal method. It returns an integer value that must "
"be returned if it is non-zero."
msgstr ""
"循環した参照に含まれるかもしれない各内部オブジェクトに対して、 traversal メ"
"ソッドに渡された :c:func:`visit` 関数を呼びます。 :c:func:`visit` 関数は内部"
"オブジェクトと、traversal メソッドに渡された追加の引数 *arg* を引数としてとり"
"ます。この関数はこの値が非負の場合に返される整数の値を返します。"
#: ../../extending/newtypes.rst:732
msgid ""
"Python 2.4 and higher provide a :c:func:`Py_VISIT` macro that automates "
"calling visit functions. With :c:func:`Py_VISIT`, :c:func:`Noddy_traverse` "
"can be simplified::"
msgstr ""
"Python 2.4 以降では、visit 関数の呼び出しを自動化する :c:func:`Py_VISIT` マク"
"ロが用意されています。 :c:func:`Py_VISIT` を使えば、 :c:func:"
"`Noddy_traverse` は次のように簡略化できます::"
#: ../../extending/newtypes.rst:746
msgid ""
"Note that the :c:member:`~PyTypeObject.tp_traverse` implementation must name "
"its arguments exactly *visit* and *arg* in order to use :c:func:`Py_VISIT`. "
"This is to encourage uniformity across these boring implementations."
msgstr ""
"注意: :c:member:`~PyTypeObject.tp_traverse` の実装で :c:func:`Py_VISIT` を使"
"うには、その引数に正確に *visit* および *arg* という名前をつける必要がありま"
"す。これは、この退屈な実装に統一性を導入することを促進します。"
#: ../../extending/newtypes.rst:750
msgid ""
"We also need to provide a method for clearing any subobjects that can "
"participate in cycles."
msgstr ""
#: ../../extending/newtypes.rst:771
msgid ""
"Notice the use of a temporary variable in :c:func:`Noddy_clear`. We use the "
"temporary variable so that we can set each member to *NULL* before "
"decrementing its reference count. We do this because, as was discussed "
"earlier, if the reference count drops to zero, we might cause code to run "
"that calls back into the object. In addition, because we now support "
"garbage collection, we also have to worry about code being run that triggers "
"garbage collection. If garbage collection is run, our :c:member:"
"`~PyTypeObject.tp_traverse` handler could get called. We can't take a chance "
"of having :c:func:`Noddy_traverse` called when a member's reference count "
"has dropped to zero and its value hasn't been set to *NULL*."
msgstr ""
":c:func:`Noddy_clear` 中での一時変数の使い方に注目してください。ここでは、一"
"時変数をつかって各メンバの参照カウントを減らす前にそれらに *NULL* を代入して"
"います。これは次のような理由によります。すでにお話ししたように、もし参照カウ"
"ントがゼロになると、このオブジェクトがコールバックされるようになってしまいま"
"す。さらに、いまやガベージコレクションをサポートしているため、ガベージコレク"
"ション時に実行されるコードについても心配しなくてはなりません。もしガベージコ"
"レクションが走っていると、あなたの :c:member:`~PyTypeObject.tp_traverse` ハン"
"ドラが呼び出される可能性があります。メンバの参照カウントがゼロになった場合"
"に、その値が *NULL* に設定されていないと :c:func:`Noddy_traverse` が呼ばれる"
"機会はありません。"
#: ../../extending/newtypes.rst:781
msgid ""
"Python 2.4 and higher provide a :c:func:`Py_CLEAR` that automates the "
"careful decrementing of reference counts. With :c:func:`Py_CLEAR`, the :c:"
"func:`Noddy_clear` function can be simplified::"
msgstr ""
"Python 2.4 以降では、注意ぶかく参照カウントを減らすためのマクロ :c:func:"
"`Py_CLEAR` が用意されています。 :c:func:`Py_CLEAR` を使えば、 :c:func:"
"`Noddy_clear` は次のように簡略化できます::"
#: ../../extending/newtypes.rst:793
msgid ""
"Note that :c:func:`Noddy_dealloc` may call arbitrary functions through "
"``__del__`` method or weakref callback. It means circular GC can be "
"triggered inside the function. Since GC assumes reference count is not "
"zero, we need to untrack the object from GC by calling :c:func:"
"`PyObject_GC_UnTrack` before clearing members. Here is reimplemented "
"deallocator which uses :c:func:`PyObject_GC_UnTrack` and :c:func:"
"`Noddy_clear`."
msgstr ""
#: ../../extending/newtypes.rst:810
msgid ""
"Finally, we add the :const:`Py_TPFLAGS_HAVE_GC` flag to the class flags::"
msgstr ""
"最後に、 :const:`Py_TPFLAGS_HAVE_GC` フラグをクラス定義のフラグに加えます::"
#: ../../extending/newtypes.rst:814
msgid ""
"That's pretty much it. If we had written custom :c:member:`~PyTypeObject."
"tp_alloc` or :c:member:`~PyTypeObject.tp_free` slots, we'd need to modify "
"them for cyclic-garbage collection. Most extensions will use the versions "
"automatically provided."
msgstr ""
"これで完了です。 :c:member:`~PyTypeObject.tp_alloc` スロットまたは :c:member:"
"`~PyTypeObject.tp_free` スロットが書かれていれば、それらを循環ガベージコレク"
"ションに使えるよう修正すればよいのです。ほとんどの拡張機能は自動的に提供され"
"るバージョンを使うでしょう。"
#: ../../extending/newtypes.rst:820
msgid "Subclassing other types"
msgstr "他の型のサブクラスを作る"
#: ../../extending/newtypes.rst:822
msgid ""