-
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathctypes.po
More file actions
3025 lines (2596 loc) · 144 KB
/
ctypes.po
File metadata and controls
3025 lines (2596 loc) · 144 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) 2001-2025, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# python-doc bot, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.9\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-03 16:35+0000\n"
"PO-Revision-Date: 2025-09-22 17:54+0000\n"
"Last-Translator: python-doc bot, 2025\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../library/ctypes.rst:2
msgid ":mod:`ctypes` --- A foreign function library for Python"
msgstr ":mod:`ctypes` --- Python 的外部函数库"
#: ../../library/ctypes.rst:11
msgid ""
":mod:`ctypes` is a foreign function library for Python. It provides C "
"compatible data types, and allows calling functions in DLLs or shared "
"libraries. It can be used to wrap these libraries in pure Python."
msgstr ""
":mod:`ctypes` 是 Python 的外部函数库。它提供了与 C 兼容的数据类型,并允许调用 DLL 或共享库中的函数。可使用该模块以纯 "
"Python 形式对这些库进行封装。"
#: ../../library/ctypes.rst:19
msgid "ctypes tutorial"
msgstr "ctypes 教程"
#: ../../library/ctypes.rst:21
msgid ""
"Note: The code samples in this tutorial use :mod:`doctest` to make sure that"
" they actually work. Since some code samples behave differently under "
"Linux, Windows, or macOS, they contain doctest directives in comments."
msgstr ""
"注:本教程中的示例代码使用 :mod:`doctest` 来保证它们能正确运行。 由于有些代码示例在 Linux, Windows 或 macOS "
"上的行为有所不同,它们在注释中包含了一些 doctest 指令。"
#: ../../library/ctypes.rst:25
msgid ""
"Note: Some code samples reference the ctypes :class:`c_int` type. On "
"platforms where ``sizeof(long) == sizeof(int)`` it is an alias to "
":class:`c_long`. So, you should not be confused if :class:`c_long` is "
"printed if you would expect :class:`c_int` --- they are actually the same "
"type."
msgstr ""
"注意:部分示例代码引用了 ctypes :class:`c_int` 类型。在 ``sizeof(long) == sizeof(int)`` "
"的平台上此类型是 :class:`c_long` 的一个别名。所以,在程序输出 :class:`c_long` 而不是你期望的 "
":class:`c_int` 时不必感到迷惑 --- 它们实际上是同一种类型。"
#: ../../library/ctypes.rst:33
msgid "Loading dynamic link libraries"
msgstr "载入动态连接库"
#: ../../library/ctypes.rst:35
msgid ""
":mod:`ctypes` exports the *cdll*, and on Windows *windll* and *oledll* "
"objects, for loading dynamic link libraries."
msgstr ""
":mod:`ctypes` 导出了 *cdll* 对象,在 Windows 系统中还导出了 *windll* 和 *oledll* "
"对象用于载入动态连接库。"
#: ../../library/ctypes.rst:38
msgid ""
"You load libraries by accessing them as attributes of these objects. *cdll* "
"loads libraries which export functions using the standard ``cdecl`` calling "
"convention, while *windll* libraries call functions using the ``stdcall`` "
"calling convention. *oledll* also uses the ``stdcall`` calling convention, "
"and assumes the functions return a Windows :c:type:`HRESULT` error code. The"
" error code is used to automatically raise an :class:`OSError` exception "
"when the function call fails."
msgstr ""
"通过操作这些对象的属性,你可以载入外部的动态链接库。*cdll* 载入按标准的 ``cdecl`` 调用协议导出的函数,而 *windll* 导入的库按"
" ``stdcall`` 调用协议调用其中的函数。 *oledll* 也按 ``stdcall`` 调用协议调用其中的函数,并假定该函数返回的是 "
"Windows :c:type:`HRESULT` 错误代码,并当函数调用失败时,自动根据该代码甩出一个 :class:`OSError` 异常。"
#: ../../library/ctypes.rst:46
msgid ""
"Windows errors used to raise :exc:`WindowsError`, which is now an alias of "
":exc:`OSError`."
msgstr "原来在 Windows 下抛出的异常类型 :exc:`WindowsError` 现在是 :exc:`OSError` 的一个别名。"
#: ../../library/ctypes.rst:51
msgid ""
"Here are some examples for Windows. Note that ``msvcrt`` is the MS standard "
"C library containing most standard C functions, and uses the cdecl calling "
"convention::"
msgstr ""
"这是一些 Windows 下的例子。注意:``msvcrt`` 是微软 C 标准库,包含了大部分 C 标准函数,这些函数都是以 cdecl "
"调用协议进行调用的。"
#: ../../library/ctypes.rst:63
msgid "Windows appends the usual ``.dll`` file suffix automatically."
msgstr "Windows 会自动添加通常的 ``.dll`` 文件扩展名。"
#: ../../library/ctypes.rst:66
msgid ""
"Accessing the standard C library through ``cdll.msvcrt`` will use an "
"outdated version of the library that may be incompatible with the one being "
"used by Python. Where possible, use native Python functionality, or else "
"import and use the ``msvcrt`` module."
msgstr ""
"通过 ``cdll.msvcrt`` 调用的标准 C 函数,可能会导致调用一个过时的,与当前 Python 所不兼容的函数。因此,请尽量使用标准的 "
"Python 函数,而不要使用 ``msvcrt`` 模块。"
#: ../../library/ctypes.rst:71
msgid ""
"On Linux, it is required to specify the filename *including* the extension "
"to load a library, so attribute access can not be used to load libraries. "
"Either the :meth:`LoadLibrary` method of the dll loaders should be used, or "
"you should load the library by creating an instance of CDLL by calling the "
"constructor::"
msgstr ""
"在 Linux 下,必须使用 *包含* 文件扩展名的文件名来导入共享库。因此不能简单使用对象属性的方式来导入库。因此,你可以使用方法 "
":meth:`LoadLibrary`,或构造 CDLL 对象来导入库。"
#: ../../library/ctypes.rst:89
msgid "Accessing functions from loaded dlls"
msgstr "操作导入的动态链接库中的函数"
#: ../../library/ctypes.rst:91
msgid "Functions are accessed as attributes of dll objects::"
msgstr "通过操作dll对象的属性来操作这些函数。"
#: ../../library/ctypes.rst:106
msgid ""
"Note that win32 system dlls like ``kernel32`` and ``user32`` often export "
"ANSI as well as UNICODE versions of a function. The UNICODE version is "
"exported with an ``W`` appended to the name, while the ANSI version is "
"exported with an ``A`` appended to the name. The win32 ``GetModuleHandle`` "
"function, which returns a *module handle* for a given module name, has the "
"following C prototype, and a macro is used to expose one of them as "
"``GetModuleHandle`` depending on whether UNICODE is defined or not::"
msgstr ""
"注意:Win32 系统的动态库,比如 ``kernel32`` 和 ``user32``,通常会同时导出同一个函数的 ANSI 版本和 UNICODE "
"版本。UNICODE 版本通常会在名字最后以 ``W`` 结尾,而 ANSI 版本的则以 ``A`` 结尾。 win32的 "
"``GetModuleHandle`` 函数会根据一个模块名返回一个 *模块句柄*,该函数暨同时包含这样的两个版本的原型函数,并通过宏 UNICODE "
"是否定义,来决定宏 ``GetModuleHandle`` 导出的是哪个具体函数。"
#: ../../library/ctypes.rst:119
msgid ""
"*windll* does not try to select one of them by magic, you must access the "
"version you need by specifying ``GetModuleHandleA`` or ``GetModuleHandleW`` "
"explicitly, and then call it with bytes or string objects respectively."
msgstr ""
"*windll* 不会通过这样的魔法手段来帮你决定选择哪一种函数,你必须显式的调用 ``GetModuleHandleA`` 或 "
"``GetModuleHandleW``,并分别使用字节对象或字符串对象作参数。"
#: ../../library/ctypes.rst:123
msgid ""
"Sometimes, dlls export functions with names which aren't valid Python "
"identifiers, like ``\"??2@YAPAXI@Z\"``. In this case you have to use "
":func:`getattr` to retrieve the function::"
msgstr ""
"有时候,dlls的导出的函数名不符合 Python 的标识符规范,比如 ``\"??2@YAPAXI@Z\"``。此时,你必须使用 "
":func:`getattr` 方法来获得该函数。"
#: ../../library/ctypes.rst:131
msgid ""
"On Windows, some dlls export functions not by name but by ordinal. These "
"functions can be accessed by indexing the dll object with the ordinal "
"number::"
msgstr ""
"Windows 下,有些 dll 导出的函数没有函数名,而是通过其顺序号调用。对此类函数,你也可以通过 dll 对象的数值索引来操作这些函数。"
#: ../../library/ctypes.rst:148
msgid "Calling functions"
msgstr "调用函数"
#: ../../library/ctypes.rst:150
msgid ""
"You can call these functions like any other Python callable. This example "
"uses the ``time()`` function, which returns system time in seconds since the"
" Unix epoch, and the ``GetModuleHandleA()`` function, which returns a win32 "
"module handle."
msgstr ""
"你可以貌似是调用其它 Python 函数那样直接调用这些函数。在这个例子中,我们调用了 ``time()`` 函数,该函数返回一个系统时间戳(从 "
"Unix 时间起点到现在的秒数),而``GetModuleHandleA()`` 函数返回一个 win32 模块句柄。"
#: ../../library/ctypes.rst:155
msgid ""
"This example calls both functions with a ``NULL`` pointer (``None`` should "
"be used as the ``NULL`` pointer)::"
msgstr "此函数中调用的两个函数都使用了空指针(用 ``None`` 作为空指针)::"
#: ../../library/ctypes.rst:164
msgid ""
":exc:`ValueError` is raised when you call an ``stdcall`` function with the "
"``cdecl`` calling convention, or vice versa::"
msgstr ""
"如果你用 ``cdecl`` 调用方式调用 ``stdcall`` 约定的函数,则会甩出一个异常 :exc:`ValueError`。反之亦然。"
#: ../../library/ctypes.rst:179
msgid ""
"To find out the correct calling convention you have to look into the C "
"header file or the documentation for the function you want to call."
msgstr "你必须阅读这些库的头文件或说明文档来确定它们的正确的调用协议。"
#: ../../library/ctypes.rst:182
msgid ""
"On Windows, :mod:`ctypes` uses win32 structured exception handling to "
"prevent crashes from general protection faults when functions are called "
"with invalid argument values::"
msgstr "在 Windows 中,:mod:`ctypes` 使用 win32 结构化异常处理来防止由于在调用函数时使用非法参数导致的程序崩溃。"
#: ../../library/ctypes.rst:192
msgid ""
"There are, however, enough ways to crash Python with :mod:`ctypes`, so you "
"should be careful anyway. The :mod:`faulthandler` module can be helpful in "
"debugging crashes (e.g. from segmentation faults produced by erroneous C "
"library calls)."
msgstr ""
"然而,总有许多办法,通过调用 :mod:`ctypes` 使得 Python 程序崩溃。因此,你必须小心使用。 :mod:`faulthandler` "
"模块可以用于帮助诊断程序崩溃的原因。(比如由于错误的C库函数调用导致的段错误)。"
#: ../../library/ctypes.rst:197
msgid ""
"``None``, integers, bytes objects and (unicode) strings are the only native "
"Python objects that can directly be used as parameters in these function "
"calls. ``None`` is passed as a C ``NULL`` pointer, bytes objects and strings"
" are passed as pointer to the memory block that contains their data "
"(:c:type:`char *` or :c:type:`wchar_t *`). Python integers are passed as "
"the platforms default C :c:type:`int` type, their value is masked to fit "
"into the C type."
msgstr ""
"``None``,整型,字节对象和(UNICODE)字符串是仅有的可以直接作为函数参数使用的四种Python本地数据类型。`None`` 作为C的空指针"
" (``NULL``),字节和字符串类型作为一个指向其保存数据的内存块指针 (:c:type:`char *` 或 :c:type:`wchar_t "
"*`)。Python 的整型则作为平台默认的C的 :c:type:`int` 类型,他们的数值被截断以适应C类型的整型长度。"
#: ../../library/ctypes.rst:204
msgid ""
"Before we move on calling functions with other parameter types, we have to "
"learn more about :mod:`ctypes` data types."
msgstr "在我们开始调用函数前,我们必须先了解作为函数参数的 :mod:`ctypes` 数据类型。"
#: ../../library/ctypes.rst:211 ../../library/ctypes.rst:2138
msgid "Fundamental data types"
msgstr "基础数据类型"
#: ../../library/ctypes.rst:213
msgid ":mod:`ctypes` defines a number of primitive C compatible data types:"
msgstr ":mod:`ctypes` 定义了一些和C兼容的基本数据类型:"
#: ../../library/ctypes.rst:216
msgid "ctypes type"
msgstr "ctypes 类型"
#: ../../library/ctypes.rst:216
msgid "C type"
msgstr "C 类型"
#: ../../library/ctypes.rst:216
msgid "Python type"
msgstr "Python 类型"
#: ../../library/ctypes.rst:218
msgid ":class:`c_bool`"
msgstr ":class:`c_bool`"
#: ../../library/ctypes.rst:218
msgid ":c:type:`_Bool`"
msgstr ":c:type:`_Bool`"
#: ../../library/ctypes.rst:218
msgid "bool (1)"
msgstr "bool (1)"
#: ../../library/ctypes.rst:220
msgid ":class:`c_char`"
msgstr ":class:`c_char`"
#: ../../library/ctypes.rst:220 ../../library/ctypes.rst:224
msgid ":c:type:`char`"
msgstr ":c:type:`char`"
#: ../../library/ctypes.rst:220
msgid "1-character bytes object"
msgstr "单字符字节串对象"
#: ../../library/ctypes.rst:222
msgid ":class:`c_wchar`"
msgstr ":class:`c_wchar`"
#: ../../library/ctypes.rst:222
msgid ":c:type:`wchar_t`"
msgstr ":c:type:`wchar_t`"
#: ../../library/ctypes.rst:222
msgid "1-character string"
msgstr "单字符字符串"
#: ../../library/ctypes.rst:224
msgid ":class:`c_byte`"
msgstr ":class:`c_byte`"
#: ../../library/ctypes.rst:224 ../../library/ctypes.rst:226
#: ../../library/ctypes.rst:228 ../../library/ctypes.rst:230
#: ../../library/ctypes.rst:232 ../../library/ctypes.rst:234
#: ../../library/ctypes.rst:236 ../../library/ctypes.rst:238
#: ../../library/ctypes.rst:240 ../../library/ctypes.rst:242
#: ../../library/ctypes.rst:245 ../../library/ctypes.rst:247
msgid "int"
msgstr "int"
#: ../../library/ctypes.rst:226
msgid ":class:`c_ubyte`"
msgstr ":class:`c_ubyte`"
#: ../../library/ctypes.rst:226
msgid ":c:type:`unsigned char`"
msgstr ":c:type:`unsigned char`"
#: ../../library/ctypes.rst:228
msgid ":class:`c_short`"
msgstr ":class:`c_short`"
#: ../../library/ctypes.rst:228
msgid ":c:type:`short`"
msgstr ":c:type:`short`"
#: ../../library/ctypes.rst:230
msgid ":class:`c_ushort`"
msgstr ":class:`c_ushort`"
#: ../../library/ctypes.rst:230
msgid ":c:type:`unsigned short`"
msgstr ":c:type:`unsigned short`"
#: ../../library/ctypes.rst:232
msgid ":class:`c_int`"
msgstr ":class:`c_int`"
#: ../../library/ctypes.rst:232
msgid ":c:type:`int`"
msgstr ":c:type:`int`"
#: ../../library/ctypes.rst:234
msgid ":class:`c_uint`"
msgstr ":class:`c_uint`"
#: ../../library/ctypes.rst:234
msgid ":c:type:`unsigned int`"
msgstr ":c:type:`unsigned int`"
#: ../../library/ctypes.rst:236
msgid ":class:`c_long`"
msgstr ":class:`c_long`"
#: ../../library/ctypes.rst:236
msgid ":c:type:`long`"
msgstr ":c:type:`long`"
#: ../../library/ctypes.rst:238
msgid ":class:`c_ulong`"
msgstr ":class:`c_ulong`"
#: ../../library/ctypes.rst:238
msgid ":c:type:`unsigned long`"
msgstr ":c:type:`unsigned long`"
#: ../../library/ctypes.rst:240
msgid ":class:`c_longlong`"
msgstr ":class:`c_longlong`"
#: ../../library/ctypes.rst:240
msgid ":c:type:`__int64` or :c:type:`long long`"
msgstr ":c:type:`__int64` 或 :c:type:`long long`"
#: ../../library/ctypes.rst:242
msgid ":class:`c_ulonglong`"
msgstr ":class:`c_ulonglong`"
#: ../../library/ctypes.rst:242
msgid ":c:type:`unsigned __int64` or :c:type:`unsigned long long`"
msgstr ":c:type:`unsigned __int64` 或 :c:type:`unsigned long long`"
#: ../../library/ctypes.rst:245
msgid ":class:`c_size_t`"
msgstr ":class:`c_size_t`"
#: ../../library/ctypes.rst:245
msgid ":c:type:`size_t`"
msgstr ":c:type:`size_t`"
#: ../../library/ctypes.rst:247
msgid ":class:`c_ssize_t`"
msgstr ":class:`c_ssize_t`"
#: ../../library/ctypes.rst:247
msgid ":c:type:`ssize_t` or :c:type:`Py_ssize_t`"
msgstr ":c:type:`ssize_t` 或 :c:type:`Py_ssize_t`"
#: ../../library/ctypes.rst:250
msgid ":class:`c_float`"
msgstr ":class:`c_float`"
#: ../../library/ctypes.rst:250
msgid ":c:type:`float`"
msgstr ":c:type:`float`"
#: ../../library/ctypes.rst:250 ../../library/ctypes.rst:252
#: ../../library/ctypes.rst:254
msgid "float"
msgstr "float"
#: ../../library/ctypes.rst:252
msgid ":class:`c_double`"
msgstr ":class:`c_double`"
#: ../../library/ctypes.rst:252
msgid ":c:type:`double`"
msgstr ":c:type:`double`"
#: ../../library/ctypes.rst:254
msgid ":class:`c_longdouble`"
msgstr ":class:`c_longdouble`"
#: ../../library/ctypes.rst:254
msgid ":c:type:`long double`"
msgstr ":c:type:`long double`"
#: ../../library/ctypes.rst:256
msgid ":class:`c_char_p`"
msgstr ":class:`c_char_p`"
#: ../../library/ctypes.rst:256
msgid ":c:type:`char *` (NUL terminated)"
msgstr ":c:type:`char *` (NUL terminated)"
#: ../../library/ctypes.rst:256
msgid "bytes object or ``None``"
msgstr "字节串对象或 ``None``"
#: ../../library/ctypes.rst:258
msgid ":class:`c_wchar_p`"
msgstr ":class:`c_wchar_p`"
#: ../../library/ctypes.rst:258
msgid ":c:type:`wchar_t *` (NUL terminated)"
msgstr ":c:type:`wchar_t *` (NUL terminated)"
#: ../../library/ctypes.rst:258
msgid "string or ``None``"
msgstr "字符串或 ``None``"
#: ../../library/ctypes.rst:260
msgid ":class:`c_void_p`"
msgstr ":class:`c_void_p`"
#: ../../library/ctypes.rst:260
msgid ":c:type:`void *`"
msgstr ":c:type:`void *`"
#: ../../library/ctypes.rst:260
msgid "int or ``None``"
msgstr "int 或 ``None``"
#: ../../library/ctypes.rst:264
msgid "The constructor accepts any object with a truth value."
msgstr "构造函数接受任何具有真值的对象。"
#: ../../library/ctypes.rst:266
msgid ""
"All these types can be created by calling them with an optional initializer "
"of the correct type and value::"
msgstr "所有这些类型都可以通过使用正确类型和值的可选初始值调用它们来创建::"
#: ../../library/ctypes.rst:277
msgid ""
"Since these types are mutable, their value can also be changed afterwards::"
msgstr "由于这些类型是可变的,它们的值也可以在以后更改::"
#: ../../library/ctypes.rst:289
msgid ""
"Assigning a new value to instances of the pointer types :class:`c_char_p`, "
":class:`c_wchar_p`, and :class:`c_void_p` changes the *memory location* they"
" point to, *not the contents* of the memory block (of course not, because "
"Python bytes objects are immutable)::"
msgstr ""
"当给指针类型的对象 :class:`c_char_p`, :class:`c_wchar_p` 和 :class:`c_void_p` "
"等赋值时,将改变它们所指向的 *内存地址*,而 *不是* 它们所指向的内存区域的 *内容* (这是理所当然的,因为 Python 的 bytes "
"对象是不可变的)::"
#: ../../library/ctypes.rst:309
msgid ""
"You should be careful, however, not to pass them to functions expecting "
"pointers to mutable memory. If you need mutable memory blocks, ctypes has a "
":func:`create_string_buffer` function which creates these in various ways. "
"The current memory block contents can be accessed (or changed) with the "
"``raw`` property; if you want to access it as NUL terminated string, use the"
" ``value`` property::"
msgstr ""
"但你要注意不能将它们传递给会改变指针所指内存的函数。如果你需要可改变的内存块,ctypes 提供了 "
":func:`create_string_buffer` 函数,它提供多种方式创建这种内存块。当前的内存块内容可以通过 ``raw`` "
"属性存取,如果你希望将它作为NUL结束的字符串,请使用 ``value`` 属性::"
#: ../../library/ctypes.rst:333
msgid ""
"The :func:`create_string_buffer` function replaces the :func:`c_buffer` "
"function (which is still available as an alias), as well as the "
":func:`c_string` function from earlier ctypes releases. To create a mutable"
" memory block containing unicode characters of the C type :c:type:`wchar_t` "
"use the :func:`create_unicode_buffer` function."
msgstr ""
":func:`create_string_buffer` 函数替代以前的ctypes版本中的 :func:`c_buffer` 函数 "
"(仍然可当作别名使用)和 :func:`c_string` 函数。:func:`create_unicode_buffer` 函数创建包含 "
"unicode 字符的可变内存块,与之对应的C语言类型是 :c:type:`wchar_t`。"
#: ../../library/ctypes.rst:343
msgid "Calling functions, continued"
msgstr "调用函数,继续"
#: ../../library/ctypes.rst:345
msgid ""
"Note that printf prints to the real standard output channel, *not* to "
":data:`sys.stdout`, so these examples will only work at the console prompt, "
"not from within *IDLE* or *PythonWin*::"
msgstr ""
"注意 printf 将打印到真正标准输出设备,而*不是* :data:`sys.stdout`,因此这些实例只能在控制台提示符下工作,而不能在 "
"*IDLE* 或 *PythonWin* 中运行。"
#: ../../library/ctypes.rst:365
msgid ""
"As has been mentioned before, all Python types except integers, strings, and"
" bytes objects have to be wrapped in their corresponding :mod:`ctypes` type,"
" so that they can be converted to the required C data type::"
msgstr ""
"正如前面所提到过的,除了整数、字符串以及字节串之外,所有的 Python 类型都必须使用它们对应的 :mod:`ctypes` "
"类型包装,才能够被正确地转换为所需的C语言类型。"
#: ../../library/ctypes.rst:378
msgid "Calling functions with your own custom data types"
msgstr "使用自定义的数据类型调用函数"
#: ../../library/ctypes.rst:380
msgid ""
"You can also customize :mod:`ctypes` argument conversion to allow instances "
"of your own classes be used as function arguments. :mod:`ctypes` looks for "
"an :attr:`_as_parameter_` attribute and uses this as the function argument."
" Of course, it must be one of integer, string, or bytes::"
msgstr ""
"你也可以通过自定义 :mod:`ctypes` 参数转换方式来允许自定义类型作为参数。 :mod:`ctypes` 会寻找 "
":attr:`_as_parameter_` 属性并使用它作为函数参数。当然,它必须是数字、字符串或者二进制字符串::"
#: ../../library/ctypes.rst:395
msgid ""
"If you don't want to store the instance's data in the :attr:`_as_parameter_`"
" instance variable, you could define a :class:`property` which makes the "
"attribute available on request."
msgstr ""
"如果你不想把实例的数据存储到 :attr:`_as_parameter_` 属性。可以通过定义 :class:`property` 函数计算出这个属性。"
#: ../../library/ctypes.rst:403
msgid "Specifying the required argument types (function prototypes)"
msgstr "指定必选参数的类型(函数原型)"
#: ../../library/ctypes.rst:405
msgid ""
"It is possible to specify the required argument types of functions exported "
"from DLLs by setting the :attr:`argtypes` attribute."
msgstr "可以通过设置 :attr:`argtypes` 属性的方法指定从 DLL 中导出函数的必选参数类型。"
#: ../../library/ctypes.rst:408
msgid ""
":attr:`argtypes` must be a sequence of C data types (the ``printf`` function"
" is probably not a good example here, because it takes a variable number and"
" different types of parameters depending on the format string, on the other "
"hand this is quite handy to experiment with this feature)::"
msgstr ""
":attr:`argtypes` 必须是一个 C 数据类型的序列 (这里的 ``printf`` "
"可能不是个好例子,因为它是变长参数,而且每个参数的类型依赖于格式化字符串,不过尝试这个功能也很方便)::"
#: ../../library/ctypes.rst:419
msgid ""
"Specifying a format protects against incompatible argument types (just as a "
"prototype for a C function), and tries to convert the arguments to valid "
"types::"
msgstr "指定数据类型可以防止不合理的参数传递(就像 C 函数的原型),并且会自动尝试将参数转换为需要的类型::"
#: ../../library/ctypes.rst:431
msgid ""
"If you have defined your own classes which you pass to function calls, you "
"have to implement a :meth:`from_param` class method for them to be able to "
"use them in the :attr:`argtypes` sequence. The :meth:`from_param` class "
"method receives the Python object passed to the function call, it should do "
"a typecheck or whatever is needed to make sure this object is acceptable, "
"and then return the object itself, its :attr:`_as_parameter_` attribute, or "
"whatever you want to pass as the C function argument in this case. Again, "
"the result should be an integer, string, bytes, a :mod:`ctypes` instance, or"
" an object with an :attr:`_as_parameter_` attribute."
msgstr ""
"如果你想通过自定义类型传递参数给函数,必须实现 :meth:`from_param` 类方法,才能够将此自定义类型用于 :attr:`argtypes`"
" 序列。:meth:`from_param` 类方法接受一个 Python "
"对象作为函数输入,它应该进行类型检查或者其他必要的操作以保证接收到的对象是合法的,然后返回这个对象,或者它的 "
":attr:`_as_parameter_` 属性,或者其他你想要传递给 C 函数的参数。这里也一样,返回的结果必须是整型、字符串、二进制字符串、 "
":mod:`ctypes` 类型,或者一个具有 :attr:`_as_parameter_` 属性的对象。"
#: ../../library/ctypes.rst:445
msgid "Return types"
msgstr "返回类型"
#: ../../library/ctypes.rst:447
msgid ""
"By default functions are assumed to return the C :c:type:`int` type. Other "
"return types can be specified by setting the :attr:`restype` attribute of "
"the function object."
msgstr ""
"默认情况下都会假定函数返回 C :c:type:`int` 类型。 其他返回类型可以通过设置函数对象的 :attr:`restype` 属性来指定。"
#: ../../library/ctypes.rst:451
msgid ""
"Here is a more advanced example, it uses the ``strchr`` function, which "
"expects a string pointer and a char, and returns a pointer to a string::"
msgstr "这是个更高级的例子,它调用了 ``strchr`` 函数,这个函数接收一个字符串指针以及一个字符作为参数,返回另一个字符串指针。"
#: ../../library/ctypes.rst:464
msgid ""
"If you want to avoid the ``ord(\"x\")`` calls above, you can set the "
":attr:`argtypes` attribute, and the second argument will be converted from a"
" single character Python bytes object into a C char::"
msgstr ""
"如果希望避免上述的 ``ord(\"x\")`` 调用,可以设置 :attr:`argtypes` 属性,第二个参数就会将单字符的 Python "
"二进制字符对象转换为 C 字符::"
#: ../../library/ctypes.rst:482
msgid ""
"You can also use a callable Python object (a function or a class for "
"example) as the :attr:`restype` attribute, if the foreign function returns "
"an integer. The callable will be called with the *integer* the C function "
"returns, and the result of this call will be used as the result of your "
"function call. This is useful to check for error return values and "
"automatically raise an exception::"
msgstr ""
"如果外部函数返回了一个整数,你也可以使用要给可调用的 Python 对象(比如函数或者类)作为 :attr:`restype` 属性的值。将会以 C "
"函数返回的 *整数* 对象作为参数调用这个可调用对象,执行后的结果作为最终函数返回值。这在错误返回值校验和自动抛出异常等方面比较有用。"
#: ../../library/ctypes.rst:505
msgid ""
"``WinError`` is a function which will call Windows ``FormatMessage()`` api "
"to get the string representation of an error code, and *returns* an "
"exception. ``WinError`` takes an optional error code parameter, if no one is"
" used, it calls :func:`GetLastError` to retrieve it."
msgstr ""
"``WinError`` 函数可以调用 Windows 的 ``FormatMessage()`` API 获取错误码的字符串说明,然后 *返回* "
"一个异常。 ``WinError`` 接收一个可选的错误码作为参数,如果没有的话,它将调用 :func:`GetLastError` 获取错误码。"
#: ../../library/ctypes.rst:510
msgid ""
"Please note that a much more powerful error checking mechanism is available "
"through the :attr:`errcheck` attribute; see the reference manual for "
"details."
msgstr "请注意,使用 :attr:`errcheck` 属性可以实现更强大的错误检查手段;详情请见参考手册。"
#: ../../library/ctypes.rst:517
msgid "Passing pointers (or: passing parameters by reference)"
msgstr "传递指针(或以引用方式传递形参)"
#: ../../library/ctypes.rst:519
msgid ""
"Sometimes a C api function expects a *pointer* to a data type as parameter, "
"probably to write into the corresponding location, or if the data is too "
"large to be passed by value. This is also known as *passing parameters by "
"reference*."
msgstr ""
"有时候 C 函数接口可能由于要往某个地址写入值,或者数据太大不适合作为值传递,从而希望接收一个 *指针* 作为数据参数类型。这和 *传递参数引用* "
"类似。"
#: ../../library/ctypes.rst:523
msgid ""
":mod:`ctypes` exports the :func:`byref` function which is used to pass "
"parameters by reference. The same effect can be achieved with the "
":func:`pointer` function, although :func:`pointer` does a lot more work "
"since it constructs a real pointer object, so it is faster to use "
":func:`byref` if you don't need the pointer object in Python itself::"
msgstr ""
":mod:`ctypes` 暴露了 :func:`byref` 函数用于通过引用传递参数,使用 :func:`pointer` "
"函数也能达到同样的效果,只不过 :func:`pointer` 需要更多步骤,因为它要先构造一个真实指针对象。所以在 Python "
"代码本身不需要使用这个指针对象的情况下,使用 :func:`byref` 效率更高。"
#: ../../library/ctypes.rst:545
msgid "Structures and unions"
msgstr "结构体和联合"
#: ../../library/ctypes.rst:547
msgid ""
"Structures and unions must derive from the :class:`Structure` and "
":class:`Union` base classes which are defined in the :mod:`ctypes` module. "
"Each subclass must define a :attr:`_fields_` attribute. :attr:`_fields_` "
"must be a list of *2-tuples*, containing a *field name* and a *field type*."
msgstr ""
"结构体和联合必须继承自 :mod:`ctypes` 模块中的 :class:`Structure` 和 :class:`Union` 。子类必须定义 "
":attr:`_fields_` 属性。 :attr:`_fields_` 是一个二元组列表,二元组中包含 *field name* 和 *field "
"type* 。"
#: ../../library/ctypes.rst:552
msgid ""
"The field type must be a :mod:`ctypes` type like :class:`c_int`, or any "
"other derived :mod:`ctypes` type: structure, union, array, pointer."
msgstr ""
"type 字段必须是一个 :mod:`ctypes` 类型,比如 :class:`c_int`,或者其他 :mod:`ctypes` 类型: "
"结构体、联合、数组、指针。"
#: ../../library/ctypes.rst:555
msgid ""
"Here is a simple example of a POINT structure, which contains two integers "
"named *x* and *y*, and also shows how to initialize a structure in the "
"constructor::"
msgstr "这是一个简单的 POINT 结构体,它包含名称为 *x* 和 *y* 的两个变量,还展示了如何通过构造函数初始化结构体。"
#: ../../library/ctypes.rst:575
msgid ""
"You can, however, build much more complicated structures. A structure can "
"itself contain other structures by using a structure as a field type."
msgstr "当然,你可以构造更复杂的结构体。一个结构体可以通过设置 type 字段包含其他结构体或者自身。"
#: ../../library/ctypes.rst:578
msgid ""
"Here is a RECT structure which contains two POINTs named *upperleft* and "
"*lowerright*::"
msgstr "这是以一个 RECT 结构体,他包含了两个 POINT ,分别叫 *upperleft* 和 *lowerright*::"
#: ../../library/ctypes.rst:592
msgid ""
"Nested structures can also be initialized in the constructor in several "
"ways::"
msgstr "嵌套结构体可以通过几种方式构造初始化::"
#: ../../library/ctypes.rst:597
msgid ""
"Field :term:`descriptor`\\s can be retrieved from the *class*, they are "
"useful for debugging because they can provide useful information::"
msgstr "可以通过 *类* 获取字段 :term:`descriptor` ,它能提供很多有用的调试信息。"
#: ../../library/ctypes.rst:611
msgid ""
":mod:`ctypes` does not support passing unions or structures with bit-fields "
"to functions by value. While this may work on 32-bit x86, it's not "
"guaranteed by the library to work in the general case. Unions and "
"structures with bit-fields should always be passed to functions by pointer."
msgstr ""
":mod:`ctypes` 不支持带位域的结构体、联合以值的方式传给函数。这可能在 32 位 x86 "
"平台上可以正常工作,但是对于一般情况,这种行为是未定义的。带位域的结构体、联合应该总是通过指针传递给函数。"
#: ../../library/ctypes.rst:617
msgid "Structure/union alignment and byte order"
msgstr "结构体/联合字段对齐及字节顺序"
#: ../../library/ctypes.rst:619
msgid ""
"By default, Structure and Union fields are aligned in the same way the C "
"compiler does it. It is possible to override this behavior by specifying a "
":attr:`_pack_` class attribute in the subclass definition. This must be set "
"to a positive integer and specifies the maximum alignment for the fields. "
"This is what ``#pragma pack(n)`` also does in MSVC."
msgstr ""
"默认情况下,结构体和联合的字段与 C 的字节对齐是一样的。也可以在定义子类的时候指定类的 :attr:`_pack_` 属性来覆盖这种行为。 "
"它必须设置为一个正整数,表示字段的最大对齐字节。这和 MSVC 中的 ``#pragma pack(n)`` 功能一样。"
#: ../../library/ctypes.rst:625
msgid ""
":mod:`ctypes` uses the native byte order for Structures and Unions. To "
"build structures with non-native byte order, you can use one of the "
":class:`BigEndianStructure`, :class:`LittleEndianStructure`, "
":class:`BigEndianUnion`, and :class:`LittleEndianUnion` base classes. These"
" classes cannot contain pointer fields."
msgstr ""
":mod:`ctypes` 中的结构体和联合使用的是本地字节序。要使用非本地字节序,可以使用 :class:`BigEndianStructure`, "
":class:`LittleEndianStructure`, :class:`BigEndianUnion`, and "
":class:`LittleEndianUnion` 作为基类。这些类不能包含指针字段。"
#: ../../library/ctypes.rst:635
msgid "Bit fields in structures and unions"
msgstr "结构体和联合中的位域"
#: ../../library/ctypes.rst:637
msgid ""
"It is possible to create structures and unions containing bit fields. Bit "
"fields are only possible for integer fields, the bit width is specified as "
"the third item in the :attr:`_fields_` tuples::"
msgstr "结构体和联合中是可以包含位域字段的。位域只能用于整型字段,位长度通过 :attr:`_fields_` 中的第三个参数指定::"
#: ../../library/ctypes.rst:655
msgid "Arrays"
msgstr "数组"
#: ../../library/ctypes.rst:657
msgid ""
"Arrays are sequences, containing a fixed number of instances of the same "
"type."
msgstr "数组是一个序列,包含指定个数元素,且必须类型相同。"
#: ../../library/ctypes.rst:659
msgid ""
"The recommended way to create array types is by multiplying a data type with"
" a positive integer::"
msgstr "创建数组类型的推荐方式是使用一个类型乘以一个正数::"
#: ../../library/ctypes.rst:664
msgid ""
"Here is an example of a somewhat artificial data type, a structure "
"containing 4 POINTs among other stuff::"
msgstr "下面是一个构造的数据案例,结构体中包含了4个 POINT 和一些其他东西。"
#: ../../library/ctypes.rst:680
msgid "Instances are created in the usual way, by calling the class::"
msgstr "和平常一样,通过调用它创建实例::"
#: ../../library/ctypes.rst:686
msgid ""
"The above code print a series of ``0 0`` lines, because the array contents "
"is initialized to zeros."
msgstr "以上代码会打印几行 ``0 0`` ,因为数组内容被初始化为 0."
#: ../../library/ctypes.rst:689
msgid "Initializers of the correct type can also be specified::"
msgstr "也能通过指定正确类型的数据来初始化::"
#: ../../library/ctypes.rst:705
msgid "Pointers"
msgstr "指针"
#: ../../library/ctypes.rst:707
msgid ""
"Pointer instances are created by calling the :func:`pointer` function on a "
":mod:`ctypes` type::"
msgstr "可以将 :mod:`ctypes` 类型数据传入 :func:`pointer` 函数创建指针::"
#: ../../library/ctypes.rst:715
msgid ""
"Pointer instances have a :attr:`~_Pointer.contents` attribute which returns "
"the object to which the pointer points, the ``i`` object above::"
msgstr "指针实例拥有 :attr:`~_Pointer.contents` 属性,它返回指针指向的真实对象,如上面的 ``i`` 对象::"
#: ../../library/ctypes.rst:722
msgid ""
"Note that :mod:`ctypes` does not have OOR (original object return), it "
"constructs a new, equivalent object each time you retrieve an attribute::"
msgstr "注意 :mod:`ctypes` 并没有 OOR (返回原始对象), 每次访问这个属性时都会构造返回一个新的相同对象::"
#: ../../library/ctypes.rst:731
msgid ""
"Assigning another :class:`c_int` instance to the pointer's contents "
"attribute would cause the pointer to point to the memory location where this"
" is stored::"
msgstr "将这个指针的 contents 属性赋值为另一个 :class:`c_int` 实例将会导致该指针指向该实例的内存地址::"
#: ../../library/ctypes.rst:743
msgid "Pointer instances can also be indexed with integers::"
msgstr "指针对象也可以通过整数下标进行访问::"
#: ../../library/ctypes.rst:749
msgid "Assigning to an integer index changes the pointed to value::"
msgstr "通过整数下标赋值可以改变指针所指向的真实内容::"
#: ../../library/ctypes.rst:758
msgid ""
"It is also possible to use indexes different from 0, but you must know what "
"you're doing, just as in C: You can access or change arbitrary memory "
"locations. Generally you only use this feature if you receive a pointer from"
" a C function, and you *know* that the pointer actually points to an array "
"instead of a single item."
msgstr ""
"使用 0 以外的索引也是合法的,但是你必须确保知道自己为什么这么做,就像 C 语言中: 你可以访问或者修改任意内存内容。 "
"通常只会在函数接收指针是才会使用这种特性,而且你 *知道* 这个指针指向的是一个数组而不是单个值。"
#: ../../library/ctypes.rst:764
msgid ""
"Behind the scenes, the :func:`pointer` function does more than simply create"
" pointer instances, it has to create pointer *types* first. This is done "
"with the :func:`POINTER` function, which accepts any :mod:`ctypes` type, and"
" returns a new type::"
msgstr ""
"内部细节, :func:`pointer` 函数不只是创建了一个指针实例,它首先创建了一个指针 *类型* 。这是通过调用 "
":func:`POINTER` 函数实现的,它接收 :mod:`ctypes` 类型为参数,返回一个新的类型::"
#: ../../library/ctypes.rst:780
msgid ""
"Calling the pointer type without an argument creates a ``NULL`` pointer. "
"``NULL`` pointers have a ``False`` boolean value::"
msgstr "无参调用指针类型可以创建一个 ``NULL`` 指针。 ``NULL`` 指针的布尔值是 ``False`` ::"
#: ../../library/ctypes.rst:788
msgid ""
":mod:`ctypes` checks for ``NULL`` when dereferencing pointers (but "
"dereferencing invalid non-\\ ``NULL`` pointers would crash Python)::"
msgstr ""
"解引用指针的时候, :mod:`ctypes` 会帮你检测是否指针为 ``NULL`` (但是解引用无效的 非 ``NULL`` 指针仍会导致 "
"Python 崩溃)::"
#: ../../library/ctypes.rst:807
msgid "Type conversions"
msgstr "类型转换"
#: ../../library/ctypes.rst:809
msgid ""
"Usually, ctypes does strict type checking. This means, if you have "
"``POINTER(c_int)`` in the :attr:`argtypes` list of a function or as the type"
" of a member field in a structure definition, only instances of exactly the "
"same type are accepted. There are some exceptions to this rule, where "
"ctypes accepts other objects. For example, you can pass compatible array "
"instances instead of pointer types. So, for ``POINTER(c_int)``, ctypes "
"accepts an array of c_int::"
msgstr ""
"通常情况下, ctypes 具有严格的类型检查。这代表着, 如果在函数 :attr:`argtypes` 中或者结构体定义成员中有 "
"``POINTER(c_int)`` 类型,只有相同类型的实例才会被接受。 也有一些例外。比如,你可以传递兼容的数组实例给指针类型。所以,对于 "
"``POINTER(c_int)`` ,ctypes 也可以接受 c_int 类型的数组::"
#: ../../library/ctypes.rst:830
msgid ""
"In addition, if a function argument is explicitly declared to be a pointer "
"type (such as ``POINTER(c_int)``) in :attr:`argtypes`, an object of the "
"pointed type (``c_int`` in this case) can be passed to the function. ctypes"
" will apply the required :func:`byref` conversion in this case "
"automatically."
msgstr ""
"另外,如果一个函数 :attr:`argtypes` 列表中的参数显式的定义为指针类型(如 ``POINTER(c_int)`` ),指针所指向的 类型"
" (这个例子中是 ``c_int`` )也可以传递给函数。ctypes 会自动调用对应的 :func:`byref` 转换。"
#: ../../library/ctypes.rst:835
msgid "To set a POINTER type field to ``NULL``, you can assign ``None``::"
msgstr "可以给指针内容赋值为 None 将其设置为 ``Null`` ::"
#: ../../library/ctypes.rst:842
msgid ""
"Sometimes you have instances of incompatible types. In C, you can cast one "
"type into another type. :mod:`ctypes` provides a :func:`cast` function "
"which can be used in the same way. The ``Bar`` structure defined above "
"accepts ``POINTER(c_int)`` pointers or :class:`c_int` arrays for its "
"``values`` field, but not instances of other types::"
msgstr ""
"有时候你拥有一个不兼容的类型。 在 C 中,你可以将一个类型强制转换为另一个。 :mod:`ctypes` 中的 a :func:`cast` "
"函数提供了相同的功能。 上面的结构体 ``Bar`` 的 ``value`` 字段接收 ``POINTER(c_int)`` 指针或者 "
":class:`c_int` 数组,但是不能接受其他类型的实例::"
#: ../../library/ctypes.rst:854
msgid "For these cases, the :func:`cast` function is handy."
msgstr "这种情况下, 需要手动使用 :func:`cast` 函数。"
#: ../../library/ctypes.rst:856
msgid ""
"The :func:`cast` function can be used to cast a ctypes instance into a "
"pointer to a different ctypes data type. :func:`cast` takes two parameters,"
" a ctypes object that is or can be converted to a pointer of some kind, and "
"a ctypes pointer type. It returns an instance of the second argument, which"
" references the same memory block as the first argument::"
msgstr ""
":func:`cast` 函数可以将一个指针实例强制转换为另一种 ctypes 类型。 :func:`cast` 接收两个参数,一个 ctypes "
"指针对象或者可以被转换为指针的其他类型对象,和一个 ctypes 指针类型。 返回第二个类型的一个实例,该返回实例和第一个参数指向同一片内存空间::"
#: ../../library/ctypes.rst:867
msgid ""
"So, :func:`cast` can be used to assign to the ``values`` field of ``Bar`` "
"the structure::"
msgstr "所以 :func:`cast` 可以用来给结构体 ``Bar`` 的 ``values`` 字段赋值::"
#: ../../library/ctypes.rst:880
msgid "Incomplete Types"
msgstr "不完整类型"
#: ../../library/ctypes.rst:882
msgid ""
"*Incomplete Types* are structures, unions or arrays whose members are not "
"yet specified. In C, they are specified by forward declarations, which are "
"defined later::"
msgstr "*不完整类型* 即还没有定义成员的结构体、联合或者数组。在 C 中,它们通常用于前置声明,然后在后面定义::"
#: ../../library/ctypes.rst:893
msgid ""
"The straightforward translation into ctypes code would be this, but it does "
"not work::"
msgstr "直接翻译成 ctypes 的代码如下,但是这行不通::"
#: ../../library/ctypes.rst:906
msgid ""
"because the new ``class cell`` is not available in the class statement "
"itself. In :mod:`ctypes`, we can define the ``cell`` class and set the "
":attr:`_fields_` attribute later, after the class statement::"
msgstr ""
"因为新的 ``cell 类`` 在 class 语句结束之前还没有完成定义。在 :mod:`ctypes` 中,我们可以先定义 ``cell`` "
"类,在 class 语句结束之后再设置 :attr:`_fields_` 属性::"
#: ../../library/ctypes.rst:918
msgid ""
"Let's try it. We create two instances of ``cell``, and let them point to "
"each other, and finally follow the pointer chain a few times::"
msgstr "让我们试试。我们定义两个 ``cell`` 实例,让它们互相指向对方,然后通过指针链式访问几次::"
#: ../../library/ctypes.rst:939
msgid "Callback functions"