1. ariovistus
  2. pyd

Source

pyd / infrastructure / python / python.d

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
/* DSR:2005.10.26.16.28:
// Ellery Newcomer is going to make this THE python header for 2.4 thru 2.7.
// yuck.

XXX:

- In a build process controlled by Python distutils, need to detect whether the
  Python interpreter was built in debug build mode, and if so, make the
  appropriate adjustments to the header mixins.

*/

/**
Contains all relevant definitions from python/Include

When issue 7758 is resolved, we will have this module split into
separate files to match python/Include (and all defs will show up in ddoc)
*/
module python;

// here's what we like
version(Python_2_7_Or_Later){
}else version(Python_2_6_Or_Later){
}else version(Python_2_5_Or_Later){
}else version(Python_2_4_Or_Later){
}else{
    static assert(false,"Python version not specified!");
}
/+
version (build) {
    version (DigitalMars) {
        version (Windows) {
            pragma(link, "python25_digitalmars");
        }
    } else {
        pragma(link, "python2.5");
    }
}

version (Tango) {
    import tango.stdc.stdio;
    import tango.stdc.time;
    import tango.stdc.string;
} else {+/
    import std.c.stdio;
    import std.c.time;
    import std.c.string;
    import std.string: toStringz;
//}


/* D long is always 64 bits, but when the Python/C API mentions long, it is of
 * course referring to the C type long, the size of which is 32 bits on both
 * X86 and X86_64 under Windows, but 32 bits on X86 and 64 bits on X86_64 under
 * most other operating systems. */

alias long C_longlong;
alias ulong C_ulonglong;

version(Windows) {
  alias int C_long;
  alias uint C_ulong;
} else {
  version (X86) {
    alias int C_long;
    alias uint C_ulong;
  } else {
    alias long C_long;
    alias ulong C_ulong;
  }
}


/*
 * Py_ssize_t is defined as a signed type which is 8 bytes on X86_64 and 4
 * bytes on X86.
 */
version(Python_2_5_Or_Later){
    version (X86_64) {
        alias long Py_ssize_t;
    } else {
        alias int Py_ssize_t;
    }
}else {
    /*
     * Seems Py_ssize_t didn't exist in 2.4, and int was everywhere it is now.
     */
    alias int Py_ssize_t;
}

extern (C) {
///////////////////////////////////////////////////////////////////////////////
// PYTHON DATA STRUCTURES AND ALIASES
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/Python.h:
  enum int Py_single_input = 256;
  enum int Py_file_input = 257;
  enum int Py_eval_input = 258;

  // Python-header-file: Include/object.h:

  // XXX:Conditionalize in if running debug build of Python interpreter:
  /*
  version (Python_Debug_Build) {
    template _PyObject_HEAD_EXTRA() {
      PyObject *_ob_next;
      PyObject *_ob_prev;
    }
  } else {
  */
    template _PyObject_HEAD_EXTRA() {}
  /*}*/

  template PyObject_HEAD() {
    mixin _PyObject_HEAD_EXTRA;
    Py_ssize_t ob_refcnt;
    PyTypeObject *ob_type;
  }

  struct PyObject {
    mixin PyObject_HEAD;
  }

  /+-++ Not part of Python api!!! ++++/
  /**
    Denotes a borrowed reference.

    Intended use: An api function Foo returning a borrowed reference will
    have return type Borrowed!PyObject* instead of PyObject*. Py_INCREF can
    be used to get the original type back.

    Params:
    T = Python object type (PyObject, PyTypeObject, etc)

    Example:
    ---
    Borrowed!PyObject* borrowed = PyTuple_GetItem(tuple, 0);
    PyObject* item = Py_XINCREF(borrowed);
    ---
    */
  struct Borrowed(T) {
  }

  /**
  Convert a python reference to borrowed reference.
  */
  Borrowed!T* borrowed(T)(T* obj) {
    return cast(Borrowed!T*) obj;
  }
  alias Borrowed!PyObject PyObject_BorrowedRef;

  /+-++ End Not part of Python api!!! ++++/

  template PyObject_VAR_HEAD() {
    mixin PyObject_HEAD;
    Py_ssize_t ob_size; /* Number of items in variable part */
  }

  struct PyVarObject {
    mixin PyObject_VAR_HEAD;
  }

  version(Python_2_6_Or_Later){
      auto Py_REFCNT()(PyObject* ob){ return ob.ob_refcnt; }
      auto Py_TYPE()(PyObject* ob){ return ob.ob_type; }
      auto Py_SIZE()(PyVarObject* ob){ return ob.ob_size; }
  }

  alias PyObject* function(PyObject *) unaryfunc;
  alias PyObject* function(PyObject *, PyObject *) binaryfunc;
  alias PyObject* function(PyObject *, PyObject *, PyObject *) ternaryfunc;
  alias Py_ssize_t function(PyObject *) lenfunc;
  alias lenfunc inquiry;
  alias int function(PyObject **, PyObject **) coercion;
  alias PyObject* function(PyObject *, Py_ssize_t) ssizeargfunc;
  alias PyObject* function(PyObject *, Py_ssize_t, Py_ssize_t) ssizessizeargfunc;
  version(Python_2_5_Or_Later){
  }else{
      alias ssizeargfunc intargfunc;
      alias ssizessizeargfunc intintargfunc;
  }
  alias int function(PyObject *, Py_ssize_t, PyObject *) ssizeobjargproc;
  alias int function(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *) ssizessizeobjargproc;
  version(Python_2_5_Or_Later){
  }else{
      alias ssizeobjargproc intobjargproc;
      alias ssizessizeobjargproc intintobjargproc;
  }
  alias int function(PyObject *, PyObject *, PyObject *) objobjargproc;

  // ssize_t-based buffer interface
  alias Py_ssize_t function(PyObject *, Py_ssize_t, void **) readbufferproc;
  alias Py_ssize_t function(PyObject *, Py_ssize_t, void **) writebufferproc;
  alias Py_ssize_t function(PyObject *, Py_ssize_t *) segcountproc;
  alias Py_ssize_t function(PyObject *, Py_ssize_t, char **) charbufferproc;
  version(Python_2_5_Or_Later){
  }else{
      // int-based buffer interface
      alias readbufferproc getreadbufferproc;
      alias writebufferproc getwritebufferproc;
      alias segcountproc getsegcountproc;
      alias charbufferproc getcharbufferproc;
  }

  version(Python_2_6_Or_Later){
      /* Py3k buffer interface */

      struct Py_buffer{
          void *buf;
          Borrowed!PyObject *obj;        /* borrowed reference */
          Py_ssize_t len;
          Py_ssize_t itemsize;  /* This is Py_ssize_t so it can be
                                   pointed to by strides in simple case.*/
          int readonly;
          int ndim;
          char *format;
          Py_ssize_t *shape;
          Py_ssize_t *strides;
          Py_ssize_t *suboffsets;
          version(Python_2_7_Or_Later) {
              Py_ssize_t[2] smalltable;
          }
          void *internal;
      };

      alias int function(PyObject *, Py_buffer *, int) getbufferproc;
      alias void function(PyObject *, Py_buffer *) releasebufferproc;

      /* Flags for getting buffers */
      enum PyBUF_SIMPLE = 0;
      enum PyBUF_WRITABLE = 0x0001;
      /*  we used to include an E, backwards compatible alias  */
      enum PyBUF_WRITEABLE = PyBUF_WRITABLE;
      enum PyBUF_FORMAT = 0x0004;
      enum PyBUF_ND = 0x0008;
      enum PyBUF_STRIDES = (0x0010 | PyBUF_ND);
      enum PyBUF_C_CONTIGUOUS = (0x0020 | PyBUF_STRIDES);
      enum PyBUF_F_CONTIGUOUS = (0x0040 | PyBUF_STRIDES);
      enum PyBUF_ANY_CONTIGUOUS = (0x0080 | PyBUF_STRIDES);
      enum PyBUF_INDIRECT = (0x0100 | PyBUF_STRIDES);

      enum PyBUF_CONTIG = (PyBUF_ND | PyBUF_WRITABLE);
      enum PyBUF_CONTIG_RO = (PyBUF_ND);

      enum PyBUF_STRIDED = (PyBUF_STRIDES | PyBUF_WRITABLE);
      enum PyBUF_STRIDED_RO = (PyBUF_STRIDES);

      enum PyBUF_RECORDS = (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT);
      enum PyBUF_RECORDS_RO = (PyBUF_STRIDES | PyBUF_FORMAT);

      enum PyBUF_FULL = (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT);
      enum PyBUF_FULL_RO = (PyBUF_INDIRECT | PyBUF_FORMAT);


      enum PyBUF_READ  = 0x100;
      enum PyBUF_WRITE = 0x200;
      enum PyBUF_SHADOW = 0x400;
      /* end Py3k buffer interface */
  }

  alias int function(PyObject *, PyObject *) objobjproc;
  alias int function(PyObject *, void *) visitproc;
  alias int function(PyObject *, visitproc, void *) traverseproc;

  // Python-header-file: Include/object.h:
  struct PyNumberMethods {
    binaryfunc nb_add;
    binaryfunc nb_subtract;
    binaryfunc nb_multiply;
    binaryfunc nb_divide;
    binaryfunc nb_remainder;
    binaryfunc nb_divmod;
    ternaryfunc nb_power;
    unaryfunc nb_negative;
    unaryfunc nb_positive;
    unaryfunc nb_absolute;
    inquiry nb_nonzero;
    unaryfunc nb_invert;
    binaryfunc nb_lshift;
    binaryfunc nb_rshift;
    binaryfunc nb_and;
    binaryfunc nb_xor;
    binaryfunc nb_or;
    coercion nb_coerce;
    unaryfunc nb_int;
    unaryfunc nb_long;
    unaryfunc nb_float;
    unaryfunc nb_oct;
    unaryfunc nb_hex;

    binaryfunc nb_inplace_add;
    binaryfunc nb_inplace_subtract;
    binaryfunc nb_inplace_multiply;
    binaryfunc nb_inplace_divide;
    binaryfunc nb_inplace_remainder;
    ternaryfunc nb_inplace_power;
    binaryfunc nb_inplace_lshift;
    binaryfunc nb_inplace_rshift;
    binaryfunc nb_inplace_and;
    binaryfunc nb_inplace_xor;
    binaryfunc nb_inplace_or;

    binaryfunc nb_floor_divide;
    binaryfunc nb_true_divide;
    binaryfunc nb_inplace_floor_divide;
    binaryfunc nb_inplace_true_divide;

    version(Python_2_5_Or_Later){
        /* Added in release 2.5 */
        unaryfunc nb_index;
    }
  }

  struct PySequenceMethods {
    lenfunc sq_length;
    binaryfunc sq_concat;
    ssizeargfunc sq_repeat;
    ssizeargfunc sq_item;
    ssizessizeargfunc sq_slice;
    ssizeobjargproc sq_ass_item;
    ssizessizeobjargproc sq_ass_slice;
    objobjproc sq_contains;
    binaryfunc sq_inplace_concat;
    ssizeargfunc sq_inplace_repeat;
  }

  struct PyMappingMethods {
    lenfunc mp_length;
    binaryfunc mp_subscript;
    objobjargproc mp_ass_subscript;
  }

  struct PyBufferProcs {
    readbufferproc bf_getreadbuffer;
    writebufferproc bf_getwritebuffer;
    segcountproc bf_getsegcount;
    charbufferproc bf_getcharbuffer;
    version(Python_2_6_Or_Later){
        getbufferproc bf_getbuffer;
        releasebufferproc bf_releasebuffer;
    }
  }


  alias void function(void *) freefunc;
  alias void function(PyObject *) destructor;
  alias int function(PyObject *, FILE *, int) printfunc;
  alias PyObject* function(PyObject *, char *) getattrfunc;
  alias PyObject* function(PyObject *, PyObject *) getattrofunc;
  alias int function(PyObject *, char *, PyObject *) setattrfunc;
  alias int function(PyObject *, PyObject *, PyObject *) setattrofunc;
  alias int function(PyObject *, PyObject *) cmpfunc;
  alias PyObject* function(PyObject *) reprfunc;
  alias C_long function(PyObject *) hashfunc;
  alias PyObject* function(PyObject *, PyObject *, int) richcmpfunc;
  alias PyObject* function(PyObject *) getiterfunc;
  alias PyObject* function(PyObject *) iternextfunc;
  alias PyObject* function(PyObject *, PyObject *, PyObject *) descrgetfunc;
  alias int function(PyObject *, PyObject *, PyObject *) descrsetfunc;
  alias int function(PyObject *, PyObject *, PyObject *) initproc;
  alias PyObject* function(PyTypeObject *, PyObject *, PyObject *) newfunc;
  alias PyObject* function(PyTypeObject *, Py_ssize_t) allocfunc;

  struct PyTypeObject {
    mixin PyObject_VAR_HEAD;

    Char1 *tp_name;
    Py_ssize_t tp_basicsize, tp_itemsize;

    destructor tp_dealloc;
    printfunc tp_print;
    getattrfunc tp_getattr;
    setattrfunc tp_setattr;
    cmpfunc tp_compare;
    reprfunc tp_repr;

    PyNumberMethods *tp_as_number;
    PySequenceMethods *tp_as_sequence;
    PyMappingMethods *tp_as_mapping;

    hashfunc tp_hash;
    ternaryfunc tp_call;
    reprfunc tp_str;
    getattrofunc tp_getattro;
    setattrofunc tp_setattro;

    PyBufferProcs *tp_as_buffer;

    C_long tp_flags;

    Char1 *tp_doc;

    traverseproc tp_traverse;

    inquiry tp_clear;

    richcmpfunc tp_richcompare;

    version(Python_2_5_Or_Later){
        Py_ssize_t tp_weaklistoffset;
    }else{
        C_long tp_weaklistoffset;
    }

    getiterfunc tp_iter;
    iternextfunc tp_iternext;

    PyMethodDef *tp_methods;
    PyMemberDef *tp_members;
    PyGetSetDef *tp_getset;
    PyTypeObject *tp_base;
    PyObject *tp_dict;
    descrgetfunc tp_descr_get;
    descrsetfunc tp_descr_set;
    version(Python_2_5_Or_Later){
        Py_ssize_t tp_dictoffset;
    }else{
        C_long tp_dictoffset;
    }
    initproc tp_init;
    allocfunc tp_alloc;
    newfunc tp_new;
    freefunc tp_free;
    inquiry tp_is_gc;
    PyObject *tp_bases;
    PyObject *tp_mro;
    PyObject *tp_cache;
    PyObject *tp_subclasses;
    PyObject *tp_weaklist;
    destructor tp_del;
    version(Python_2_6_Or_Later){
        /* Type attribute cache version tag. Added in version 2.6 */
        uint tp_version_tag;
    }
  }

  //alias _typeobject PyTypeObject;

  struct _heaptypeobject {
      version(Python_2_5_Or_Later){
          PyTypeObject ht_type;
      }else{
          PyTypeObject type;
      }
    PyNumberMethods as_number;
    PyMappingMethods as_mapping;
    PySequenceMethods as_sequence;
    PyBufferProcs as_buffer;
      version(Python_2_5_Or_Later){
          PyObject *ht_name;
          PyObject *ht_slots;
      }else{
          PyObject *name;
          PyObject *slots;
      }
  }
  alias _heaptypeobject PyHeapTypeObject;


  // Python-header-file: Include/pymem.h:
  void * PyMem_Malloc(size_t);
  void * PyMem_Realloc(void *, size_t);
  void PyMem_Free(void *);


///////////////////////////////////////////////////////////////////////////////
// GENERIC TYPE CHECKING
///////////////////////////////////////////////////////////////////////////////

  int PyType_IsSubtype(PyTypeObject *, PyTypeObject *);

  // D translation of C macro:
  int PyObject_TypeCheck()(PyObject *ob, PyTypeObject *tp) {
    return (ob.ob_type == tp || PyType_IsSubtype(ob.ob_type, tp));
  }

  /* Note that this Python support module makes pointers to PyType_Type and
   * other global variables exposed by the Python API available to D
   * programmers indirectly (see this module's static initializer). */

  // D translation of C macro:
  int PyType_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyType_Type_p);
  }
  // D translation of C macro:
  int PyType_CheckExact()(PyObject *op) {
    return op.ob_type == PyType_Type_p;
  }

  int PyType_Ready(PyTypeObject *);
  PyObject * PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
  PyObject * PyType_GenericNew(PyTypeObject *, PyObject *, PyObject *);
  version(Python_2_6_Or_Later){
      uint PyType_ClearCache();
      void PyType_Modified(PyTypeObject *);
  }


  int PyObject_Print(PyObject *, FILE *, int);
  PyObject * PyObject_Repr(PyObject *);
  PyObject * PyObject_Str(PyObject *);

  version(Python_2_6_Or_Later){
      alias PyObject_Str PyObject_Bytes;
  }

  PyObject * PyObject_Unicode(PyObject *);

  int PyObject_Compare(PyObject *, PyObject *);
  PyObject * PyObject_RichCompare(PyObject *, PyObject *, int);
  int PyObject_RichCompareBool(PyObject *, PyObject *, int);
  PyObject * PyObject_GetAttrString(PyObject *, Char1 *);
  int PyObject_SetAttrString(PyObject *, Char1 *, PyObject *);
  int PyObject_HasAttrString(PyObject *, Char1 *);
  PyObject * PyObject_GetAttr(PyObject *, PyObject *);
  int PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
  int PyObject_HasAttr(PyObject *, PyObject *);
  PyObject * PyObject_SelfIter(PyObject *);
  PyObject * PyObject_GenericGetAttr(PyObject *, PyObject *);
  int PyObject_GenericSetAttr(PyObject *,
                PyObject *, PyObject *);
  C_long PyObject_Hash(PyObject *);
  version(Python_2_6_Or_Later){
      C_long PyObject_HashNotImplemented(PyObject *);
  }
  int PyObject_IsTrue(PyObject *);
  int PyObject_Not(PyObject *);
  //int PyCallable_Check(PyObject *);
  int PyNumber_Coerce(PyObject **, PyObject **);
  int PyNumber_CoerceEx(PyObject **, PyObject **);

  void PyObject_ClearWeakRefs(PyObject *);

  PyObject * PyObject_Dir(PyObject *);

  int Py_ReprEnter(PyObject *);
  void Py_ReprLeave(PyObject *);

  enum int Py_PRINT_RAW = 1;


  enum int Py_TPFLAGS_HAVE_GETCHARBUFFER       = 1L<<0;
  enum int Py_TPFLAGS_HAVE_SEQUENCE_IN         = 1L<<1;
  enum int Py_TPFLAGS_GC                       = 0;
  enum int Py_TPFLAGS_HAVE_INPLACEOPS          = 1L<<3;
  enum int Py_TPFLAGS_CHECKTYPES               = 1L<<4;
  enum int Py_TPFLAGS_HAVE_RICHCOMPARE         = 1L<<5;
  enum int Py_TPFLAGS_HAVE_WEAKREFS            = 1L<<6;
  enum int Py_TPFLAGS_HAVE_ITER                = 1L<<7;
  enum int Py_TPFLAGS_HAVE_CLASS               = 1L<<8;
  enum int Py_TPFLAGS_HEAPTYPE                 = 1L<<9;
  enum int Py_TPFLAGS_BASETYPE                 = 1L<<10;
  enum int Py_TPFLAGS_READY                    = 1L<<12;
  enum int Py_TPFLAGS_READYING                 = 1L<<13;
  enum int Py_TPFLAGS_HAVE_GC                  = 1L<<14;

  // YYY: Should conditionalize for stackless:
  //#ifdef STACKLESS
  //#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15)
  //#else
  enum int Py_TPFLAGS_HAVE_STACKLESS_EXTENSION = 0;
  //#endif
  version(Python_2_5_Or_Later){
      enum Py_TPFLAGS_HAVE_INDEX               = 1L<<17;
  }
  version(Python_2_6_Or_Later){
      /* Objects support type attribute cache */
      enum Py_TPFLAGS_HAVE_VERSION_TAG =  (1L<<18);
      enum Py_TPFLAGS_VALID_VERSION_TAG =  (1L<<19);

      /* Type is abstract and cannot be instantiated */
      enum Py_TPFLAGS_IS_ABSTRACT = (1L<<20);

      /* Has the new buffer protocol */
      enum Py_TPFLAGS_HAVE_NEWBUFFER = (1L<<21);

      /* These flags are used to determine if a type is a subclass. */
      enum Py_TPFLAGS_INT_SUBCLASS         =(1L<<23);
      enum Py_TPFLAGS_LONG_SUBCLASS        =(1L<<24);
      enum Py_TPFLAGS_LIST_SUBCLASS        =(1L<<25);
      enum Py_TPFLAGS_TUPLE_SUBCLASS       =(1L<<26);
      enum Py_TPFLAGS_STRING_SUBCLASS      =(1L<<27);
      enum Py_TPFLAGS_UNICODE_SUBCLASS     =(1L<<28);
      enum Py_TPFLAGS_DICT_SUBCLASS        =(1L<<29);
      enum Py_TPFLAGS_BASE_EXC_SUBCLASS    =(1L<<30);
      enum Py_TPFLAGS_TYPE_SUBCLASS        =(1L<<31);
  }

  version(Python_2_5_Or_Later){
      enum int Py_TPFLAGS_DEFAULT =
          Py_TPFLAGS_HAVE_GETCHARBUFFER |
          Py_TPFLAGS_HAVE_SEQUENCE_IN |
          Py_TPFLAGS_HAVE_INPLACEOPS |
          Py_TPFLAGS_HAVE_RICHCOMPARE |
          Py_TPFLAGS_HAVE_WEAKREFS |
          Py_TPFLAGS_HAVE_ITER |
          Py_TPFLAGS_HAVE_CLASS |
          Py_TPFLAGS_HAVE_STACKLESS_EXTENSION |
          Py_TPFLAGS_HAVE_INDEX |
          0
          ;
      version(Python_2_6_Or_Later){
          // meh
          enum Py_TPFLAGS_DEFAULT_EXTERNAL = Py_TPFLAGS_DEFAULT;
      }
  }else{
      enum int Py_TPFLAGS_DEFAULT =
          Py_TPFLAGS_HAVE_GETCHARBUFFER |
          Py_TPFLAGS_HAVE_SEQUENCE_IN |
          Py_TPFLAGS_HAVE_INPLACEOPS |
          Py_TPFLAGS_HAVE_RICHCOMPARE |
          Py_TPFLAGS_HAVE_WEAKREFS |
          Py_TPFLAGS_HAVE_ITER |
          Py_TPFLAGS_HAVE_CLASS |
          Py_TPFLAGS_HAVE_STACKLESS_EXTENSION |
          0
          ;
  }

  // D translation of C macro:
  int PyType_HasFeature()(PyTypeObject *t, int f) {
    return (t.tp_flags & f) != 0;
  }

  version(Python_2_6_Or_Later){
      alias PyType_HasFeature PyType_FastSubclass;
  }


///////////////////////////////////////////////////////////////////////////////
// REFERENCE COUNTING
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/object.h:

  auto Py_INCREF(T)(T op) 
  if(is(T == PyObject*) || is(T _unused : Borrowed!P*, P))
  {
      static if(is(T _unused : Borrowed!P*, P)) {
          PyObject* pop = cast(PyObject*) op;
          ++pop.ob_refcnt;
          return cast(P*) pop;
      }else {
          ++op.ob_refcnt;
      }
  }

  auto Py_XINCREF(T)(T op) {
    if (op == null) {
        static if(is(typeof(Py_INCREF!T(op)) == void))
            return;
        else {
            import std.exception;
            enforce(0, "INCREF on null");
        }
    }
    return Py_INCREF(op);
  }

  void Py_DECREF()(PyObject *op) {
      // version(PY_REF_DEBUG) _Py_RefTotal++
      --op.ob_refcnt;
    
      // EMN: this is a horrible idea because it takes forever to figure out 
      //      what's going on if this is being called from within the garbage 
      //      collector.
      assert (op.ob_refcnt >= 0);
      if(op.ob_refcnt != 0) {
          // version(PY_REF_DEBUG) _Py_NegativeRefcount(__FILE__, __LINE__, cast(PyObject*)op);
      }else {
        op.ob_type.tp_dealloc(op);
      }
  }

  void Py_XDECREF()(PyObject* op)
  {
    if(op == null) {
      return;
    }

    Py_DECREF(op);
  }

  void Py_IncRef(PyObject *);
  void Py_DecRef(PyObject *);

  /* Rich comparison opcodes */
  enum int Py_LT = 0;
  enum int Py_LE = 1;
  enum int Py_EQ = 2;
  enum int Py_NE = 3;
  enum int Py_GT = 4;
  enum int Py_GE = 5;


///////////////////////////////////////////////////////////////////////////////////////////////
// UNICODE
///////////////////////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/unicodeobject.h:
      import std.c.stdarg: va_list;
  /* The Python header explains:
   *   Unicode API names are mangled to assure that UCS-2 and UCS-4 builds
   *   produce different external names and thus cause import errors in
   *   case Python interpreters and extensions with mixed compiled in
   *   Unicode width assumptions are combined. */


  version (Python_Unicode_UCS2) {
    version (Windows) {
      alias wchar Py_UNICODE;
    } else {
      alias ushort Py_UNICODE;
    }
  } else {
    alias uint Py_UNICODE;
  }

  struct PyUnicodeObject {
    mixin PyObject_HEAD;

    Py_ssize_t length;
    Py_UNICODE *str;
    C_long hash;
    PyObject *defenc;
  }

  // &PyUnicode_Type is accessible via PyUnicode_Type_p.
  // D translations of C macros:
  int PyUnicode_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyUnicode_Type_p);
  }
  int PyUnicode_CheckExact()(PyObject *op) {
    return op.ob_type == PyUnicode_Type_p;
  }

  size_t PyUnicode_GET_SIZE()(PyUnicodeObject *op) {
    return op.length;
  }
  size_t PyUnicode_GET_DATA_SIZE()(PyUnicodeObject *op) {
    return op.length * Py_UNICODE.sizeof;
  }
  Py_UNICODE *PyUnicode_AS_UNICODE()(PyUnicodeObject *op) {
    return op.str;
  }
  const(char) *PyUnicode_AS_DATA()(PyUnicodeObject *op) {
    return cast(const(char)*) op.str;
  }

  Py_UNICODE Py_UNICODE_REPLACEMENT_CHARACTER = 0xFFFD;

  // EMN: waddawedohere? TODO: figure it out
  version(Python_2_6_Or_Later){
      /* Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */
      PyObject* PyUnicode_FromStringAndSize(
              const(char)*u,        /* char buffer */
              Py_ssize_t size       /* size of buffer */
              );

      /* Similar to PyUnicode_FromUnicode(), but u points to null-terminated
         Latin-1 encoded bytes */
      PyObject* PyUnicode_FromString(
              const(char)*u        /* string */
              );
      PyObject * PyUnicode_FromFormatV(const(char)*, va_list);
      PyObject * PyUnicode_FromFormat(const(char)*, ...);

      /* Format the object based on the format_spec, as defined in PEP 3101
         (Advanced String Formatting). */
      PyObject * _PyUnicode_FormatAdvanced(PyObject *obj,
              Py_UNICODE *format_spec,
              Py_ssize_t format_spec_len);
      int PyUnicode_ClearFreeList();
      PyObject* PyUnicode_DecodeUTF7Stateful(
              const(char)*string,         /* UTF-7 encoded string */
              Py_ssize_t length,          /* size of string */
              const(char)*errors,         /* error handling */
              Py_ssize_t *consumed        /* bytes consumed */
              );
      PyObject* PyUnicode_DecodeUTF32(
              const(char)*string,         /* UTF-32 encoded string */
              Py_ssize_t length,          /* size of string */
              const(char)*errors,         /* error handling */
              int *byteorder              /* pointer to byteorder to use
                                             0=native;-1=LE,1=BE; updated on
                                             exit */
              );

      PyObject* PyUnicode_DecodeUTF32Stateful(
              const(char)*string,         /* UTF-32 encoded string */
              Py_ssize_t length,          /* size of string */
              const(char)*errors,         /* error handling */
              int *byteorder,             /* pointer to byteorder to use
                                             0=native;-1=LE,1=BE; updated on
                                             exit */
              Py_ssize_t *consumed        /* bytes consumed */
              );
      /* Returns a Python string using the UTF-32 encoding in native byte
         order. The string always starts with a BOM mark.  */

      PyObject* PyUnicode_AsUTF32String(
              PyObject *unicode           /* Unicode object */
              );

      /* Returns a Python string object holding the UTF-32 encoded value of
         the Unicode data.

         If byteorder is not 0, output is written according to the following
         byte order:

         byteorder == -1: little endian
         byteorder == 0:  native byte order (writes a BOM mark)
         byteorder == 1:  big endian

         If byteorder is 0, the output string will always start with the
         Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is
         prepended.

       */

      PyObject* PyUnicode_EncodeUTF32(
              const Py_UNICODE *data,     /* Unicode char buffer */
              Py_ssize_t length,          /* number of Py_UNICODE chars to encode */
              const(char)*errors,         /* error handling */
              int byteorder               /* byteorder to use 0=BOM+native;-1=LE,1=BE */
              );
  }

  // YYY: Unfortunately, we have to do it the tedious way since there's no
  // preprocessor in D:
  version (Python_Unicode_UCS2) {
    PyObject *PyUnicodeUCS2_FromUnicode(Py_UNICODE *u, Py_ssize_t size);
    Py_UNICODE *PyUnicodeUCS2_AsUnicode(PyObject *unicode);
    Py_ssize_t PyUnicodeUCS2_GetSize(PyObject *unicode);
    Py_UNICODE PyUnicodeUCS2_GetMax();

    int PyUnicodeUCS2_Resize(PyObject **unicode, Py_ssize_t length);
    PyObject *PyUnicodeUCS2_FromEncodedObject(PyObject *obj, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS2_FromObject(PyObject *obj);

    PyObject *PyUnicodeUCS2_FromWideChar(const(wchar) *w, Py_ssize_t size);
    Py_ssize_t PyUnicodeUCS2_AsWideChar(PyUnicodeObject *unicode, const(wchar) *w, Py_ssize_t size);

    PyObject *PyUnicodeUCS2_FromOrdinal(int ordinal);

    PyObject *_PyUnicodeUCS2_AsDefaultEncodedString(PyObject *, const(char)*);

    const(char)*PyUnicodeUCS2_GetDefaultEncoding();
    int PyUnicodeUCS2_SetDefaultEncoding(const(char)*encoding);

    PyObject *PyUnicodeUCS2_Decode(const(char) *s, Py_ssize_t size, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS2_Encode(Py_UNICODE *s, Py_ssize_t size, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS2_AsEncodedObject(PyObject *unicode, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS2_AsEncodedString(PyObject *unicode, const(char) *encoding, const(char) *errors);

    PyObject *PyUnicodeUCS2_DecodeUTF7(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS2_EncodeUTF7(Py_UNICODE *data, Py_ssize_t length,
        int encodeSetO, int encodeWhiteSpace, const(char) *errors
      );

    PyObject *PyUnicodeUCS2_DecodeUTF8(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS2_DecodeUTF8Stateful(const(char) *string, Py_ssize_t length,
        const(char) *errors, Py_ssize_t *consumed
      );
    PyObject *PyUnicodeUCS2_AsUTF8String(PyObject *unicode);
    PyObject *PyUnicodeUCS2_EncodeUTF8(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS2_DecodeUTF16(const(char) *string, Py_ssize_t length, const(char) *errors, int *byteorder);
    PyObject *PyUnicodeUCS2_DecodeUTF16Stateful(const(char) *string, Py_ssize_t length,
        const(char) *errors, int *byteorder, Py_ssize_t *consumed
      );
    PyObject *PyUnicodeUCS2_AsUTF16String(PyObject *unicode);
    PyObject *PyUnicodeUCS2_EncodeUTF16(Py_UNICODE *data, Py_ssize_t length,
        const(char) *errors, int byteorder
      );

    PyObject *PyUnicodeUCS2_DecodeUnicodeEscape(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS2_AsUnicodeEscapeString(PyObject *unicode);
    PyObject *PyUnicodeUCS2_EncodeUnicodeEscape(Py_UNICODE *data, Py_ssize_t length);
    PyObject *PyUnicodeUCS2_DecodeRawUnicodeEscape(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS2_AsRawUnicodeEscapeString(PyObject *unicode);
    PyObject *PyUnicodeUCS2_EncodeRawUnicodeEscape(Py_UNICODE *data, Py_ssize_t length);

    PyObject *_PyUnicodeUCS2_DecodeUnicodeInternal(const(char) *string, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS2_DecodeLatin1(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS2_AsLatin1String(PyObject *unicode);
    PyObject *PyUnicodeUCS2_EncodeLatin1(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS2_DecodeASCII(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS2_AsASCIIString(PyObject *unicode);
    PyObject *PyUnicodeUCS2_EncodeASCII(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS2_DecodeCharmap(const(char) *string, Py_ssize_t length,
        PyObject *mapping, const(char) *errors
      );
    PyObject *PyUnicodeUCS2_AsCharmapString(PyObject *unicode, PyObject *mapping);
    PyObject *PyUnicodeUCS2_EncodeCharmap(Py_UNICODE *data, Py_ssize_t length,
        PyObject *mapping, const(char) *errors
      );
    PyObject *PyUnicodeUCS2_TranslateCharmap(Py_UNICODE *data, Py_ssize_t length,
        PyObject *table, const(char) *errors
      );

    version (Windows) {
      PyObject *PyUnicodeUCS2_DecodeMBCS(const(char) *string, Py_ssize_t length, const(char) *errors);
      PyObject *PyUnicodeUCS2_AsMBCSString(PyObject *unicode);
      PyObject *PyUnicodeUCS2_EncodeMBCS(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);
    }

    int PyUnicodeUCS2_EncodeDecimal(Py_UNICODE *s, Py_ssize_t length, char *output, const(char) *errors);

    PyObject *PyUnicodeUCS2_Concat(PyObject *left, PyObject *right);
    PyObject *PyUnicodeUCS2_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit);
    PyObject *PyUnicodeUCS2_Splitlines(PyObject *s, int keepends);
    version(Python_2_5_Or_Later){
        PyObject *PyUnicodeUCS2_Partition(PyObject* s, PyObject* sep);
        PyObject *PyUnicodeUCS2_RPartition(PyObject* s, PyObject* sep);
    }
    PyObject *PyUnicodeUCS2_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit);
    PyObject *PyUnicodeUCS2_Translate(PyObject *str, PyObject *table, const(char) *errors);
    PyObject *PyUnicodeUCS2_Join(PyObject *separator, PyObject *seq);
    Py_ssize_t PyUnicodeUCS2_Tailmatch(PyObject *str, PyObject *substr,
        Py_ssize_t start, Py_ssize_t end, int direction
      );
    Py_ssize_t PyUnicodeUCS2_Find(PyObject *str, PyObject *substr,
        Py_ssize_t start, Py_ssize_t end, int direction
      );
    Py_ssize_t PyUnicodeUCS2_Count(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end);
    PyObject *PyUnicodeUCS2_Replace(PyObject *str, PyObject *substr,
        PyObject *replstr, Py_ssize_t maxcount
      );
    int PyUnicodeUCS2_Compare(PyObject *left, PyObject *right);
    PyObject *PyUnicodeUCS2_Format(PyObject *format, PyObject *args);
    int PyUnicodeUCS2_Contains(PyObject *container, PyObject *element);
    PyObject *_PyUnicodeUCS2_XStrip(PyUnicodeObject *self, int striptype,
        PyObject *sepobj
      );

    int _PyUnicodeUCS2_IsLowercase(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsUppercase(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsTitlecase(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsWhitespace(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsLinebreak(Py_UNICODE ch);
    Py_UNICODE _PyUnicodeUCS2_ToLowercase(Py_UNICODE ch);
    Py_UNICODE _PyUnicodeUCS2_ToUppercase(Py_UNICODE ch);
    Py_UNICODE _PyUnicodeUCS2_ToTitlecase(Py_UNICODE ch);
    int _PyUnicodeUCS2_ToDecimalDigit(Py_UNICODE ch);
    int _PyUnicodeUCS2_ToDigit(Py_UNICODE ch);
    double _PyUnicodeUCS2_ToNumeric(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsDecimalDigit(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsDigit(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsNumeric(Py_UNICODE ch);
    int _PyUnicodeUCS2_IsAlpha(Py_UNICODE ch);

  } else { /* not Python_Unicode_UCS2: */

    PyObject *PyUnicodeUCS4_FromUnicode(Py_UNICODE *u, Py_ssize_t size);
    Py_UNICODE *PyUnicodeUCS4_AsUnicode(PyObject *unicode);
    Py_ssize_t PyUnicodeUCS4_GetSize(PyObject *unicode);
    Py_UNICODE PyUnicodeUCS4_GetMax();

    int PyUnicodeUCS4_Resize(PyObject **unicode, Py_ssize_t length);
    PyObject *PyUnicodeUCS4_FromEncodedObject(PyObject *obj, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS4_FromObject(PyObject *obj);

    PyObject *PyUnicodeUCS4_FromWideChar(const(wchar) *w, Py_ssize_t size);
    Py_ssize_t PyUnicodeUCS4_AsWideChar(PyUnicodeObject *unicode, const(wchar) *w, Py_ssize_t size);

    PyObject *PyUnicodeUCS4_FromOrdinal(int ordinal);

    PyObject *_PyUnicodeUCS4_AsDefaultEncodedString(PyObject *, const(char) *);

    const(char) *PyUnicodeUCS4_GetDefaultEncoding();
    int PyUnicodeUCS4_SetDefaultEncoding(const(char) *encoding);

    PyObject *PyUnicodeUCS4_Decode(const(char) *s, Py_ssize_t size, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS4_Encode(Py_UNICODE *s, Py_ssize_t size, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS4_AsEncodedObject(PyObject *unicode, const(char) *encoding, const(char) *errors);
    PyObject *PyUnicodeUCS4_AsEncodedString(PyObject *unicode, const(char) *encoding, const(char) *errors);

    PyObject *PyUnicodeUCS4_DecodeUTF7(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS4_EncodeUTF7(Py_UNICODE *data, Py_ssize_t length,
        int encodeSetO, int encodeWhiteSpace, const(char) *errors
      );

    PyObject *PyUnicodeUCS4_DecodeUTF8(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS4_DecodeUTF8Stateful(const(char) *string, Py_ssize_t length,
        const(char) *errors, Py_ssize_t *consumed
      );
    PyObject *PyUnicodeUCS4_AsUTF8String(PyObject *unicode);
    PyObject *PyUnicodeUCS4_EncodeUTF8(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS4_DecodeUTF16(const(char) *string, Py_ssize_t length, const(char) *errors, int *byteorder);
    PyObject *PyUnicodeUCS4_DecodeUTF16Stateful(const(char) *string, Py_ssize_t length,
        const(char) *errors, int *byteorder, Py_ssize_t *consumed
      );
    PyObject *PyUnicodeUCS4_AsUTF16String(PyObject *unicode);
    PyObject *PyUnicodeUCS4_EncodeUTF16(Py_UNICODE *data, Py_ssize_t length,
        const(char) *errors, int byteorder
      );

    PyObject *PyUnicodeUCS4_DecodeUnicodeEscape(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS4_AsUnicodeEscapeString(PyObject *unicode);
    PyObject *PyUnicodeUCS4_EncodeUnicodeEscape(Py_UNICODE *data, Py_ssize_t length);
    PyObject *PyUnicodeUCS4_DecodeRawUnicodeEscape(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS4_AsRawUnicodeEscapeString(PyObject *unicode);
    PyObject *PyUnicodeUCS4_EncodeRawUnicodeEscape(Py_UNICODE *data, Py_ssize_t length);

    PyObject *_PyUnicodeUCS4_DecodeUnicodeInternal(const(char) *string, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS4_DecodeLatin1(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS4_AsLatin1String(PyObject *unicode);
    PyObject *PyUnicodeUCS4_EncodeLatin1(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS4_DecodeASCII(const(char) *string, Py_ssize_t length, const(char) *errors);
    PyObject *PyUnicodeUCS4_AsASCIIString(PyObject *unicode);
    PyObject *PyUnicodeUCS4_EncodeASCII(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);

    PyObject *PyUnicodeUCS4_DecodeCharmap(const(char) *string, Py_ssize_t length,
        PyObject *mapping, const(char) *errors
      );
    PyObject *PyUnicodeUCS4_AsCharmapString(PyObject *unicode, PyObject *mapping);
    PyObject *PyUnicodeUCS4_EncodeCharmap(Py_UNICODE *data, Py_ssize_t length,
        PyObject *mapping, const(char) *errors
      );
    PyObject *PyUnicodeUCS4_TranslateCharmap(Py_UNICODE *data, Py_ssize_t length,
        PyObject *table, const(char) *errors
      );

    version (Windows) {
      PyObject *PyUnicodeUCS4_DecodeMBCS(const(char) *string, Py_ssize_t length, const(char) *errors);
      PyObject *PyUnicodeUCS4_AsMBCSString(PyObject *unicode);
      PyObject *PyUnicodeUCS4_EncodeMBCS(Py_UNICODE *data, Py_ssize_t length, const(char) *errors);
    }

    int PyUnicodeUCS4_EncodeDecimal(Py_UNICODE *s, Py_ssize_t length, char *output, const(char) *errors);

    PyObject *PyUnicodeUCS4_Concat(PyObject *left, PyObject *right);
    PyObject *PyUnicodeUCS4_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit);
    PyObject *PyUnicodeUCS4_Splitlines(PyObject *s, int keepends);
    version(Python_2_5_Or_Later){
        PyObject *PyUnicodeUCS4_Partition(PyObject* s, PyObject* sep);
        PyObject *PyUnicodeUCS4_RPartition(PyObject* s, PyObject* sep);
    }
    PyObject *PyUnicodeUCS4_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit);
    PyObject *PyUnicodeUCS4_Translate(PyObject *str, PyObject *table, const(char) *errors);
    PyObject *PyUnicodeUCS4_Join(PyObject *separator, PyObject *seq);
    Py_ssize_t PyUnicodeUCS4_Tailmatch(PyObject *str, PyObject *substr,
        Py_ssize_t start, Py_ssize_t end, int direction
      );
    Py_ssize_t PyUnicodeUCS4_Find(PyObject *str, PyObject *substr,
        Py_ssize_t start, Py_ssize_t end, int direction
      );
    Py_ssize_t PyUnicodeUCS4_Count(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end);
    PyObject *PyUnicodeUCS4_Replace(PyObject *str, PyObject *substr,
        PyObject *replstr, Py_ssize_t maxcount
      );
    int PyUnicodeUCS4_Compare(PyObject *left, PyObject *right);
    PyObject *PyUnicodeUCS4_Format(PyObject *format, PyObject *args);
    int PyUnicodeUCS4_Contains(PyObject *container, PyObject *element);
    PyObject *_PyUnicodeUCS4_XStrip(PyUnicodeObject *self, int striptype,
        PyObject *sepobj
      );

    int _PyUnicodeUCS4_IsLowercase(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsUppercase(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsTitlecase(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsWhitespace(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsLinebreak(Py_UNICODE ch);
    Py_UNICODE _PyUnicodeUCS4_ToLowercase(Py_UNICODE ch);
    Py_UNICODE _PyUnicodeUCS4_ToUppercase(Py_UNICODE ch);
    Py_UNICODE _PyUnicodeUCS4_ToTitlecase(Py_UNICODE ch);
    int _PyUnicodeUCS4_ToDecimalDigit(Py_UNICODE ch);
    int _PyUnicodeUCS4_ToDigit(Py_UNICODE ch);
    double _PyUnicodeUCS4_ToNumeric(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsDecimalDigit(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsDigit(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsNumeric(Py_UNICODE ch);
    int _PyUnicodeUCS4_IsAlpha(Py_UNICODE ch);
  }


  /* The client programmer should call PyUnicode_XYZ, but linkage should be
   * done via either PyUnicodeUCS2_XYZ or PyUnicodeUCS4_XYZ. */
  version (Python_Unicode_UCS2) {
    alias PyUnicodeUCS2_AsASCIIString PyUnicode_AsASCIIString;
    alias PyUnicodeUCS2_AsCharmapString PyUnicode_AsCharmapString;
    alias PyUnicodeUCS2_AsEncodedObject PyUnicode_AsEncodedObject;
    alias PyUnicodeUCS2_AsEncodedString PyUnicode_AsEncodedString;
    alias PyUnicodeUCS2_AsLatin1String PyUnicode_AsLatin1String;
    alias PyUnicodeUCS2_AsRawUnicodeEscapeString PyUnicode_AsRawUnicodeEscapeString;
    alias PyUnicodeUCS2_AsUTF16String PyUnicode_AsUTF16String;
    alias PyUnicodeUCS2_AsUTF8String PyUnicode_AsUTF8String;
    alias PyUnicodeUCS2_AsUnicode PyUnicode_AsUnicode;
    alias PyUnicodeUCS2_AsUnicodeEscapeString PyUnicode_AsUnicodeEscapeString;
    alias PyUnicodeUCS2_AsWideChar PyUnicode_AsWideChar;
    alias PyUnicodeUCS2_Compare PyUnicode_Compare;
    alias PyUnicodeUCS2_Concat PyUnicode_Concat;
    alias PyUnicodeUCS2_Contains PyUnicode_Contains;
    alias PyUnicodeUCS2_Count PyUnicode_Count;
    alias PyUnicodeUCS2_Decode PyUnicode_Decode;
    alias PyUnicodeUCS2_DecodeASCII PyUnicode_DecodeASCII;
    alias PyUnicodeUCS2_DecodeCharmap PyUnicode_DecodeCharmap;
    alias PyUnicodeUCS2_DecodeLatin1 PyUnicode_DecodeLatin1;
    alias PyUnicodeUCS2_DecodeRawUnicodeEscape PyUnicode_DecodeRawUnicodeEscape;
    alias PyUnicodeUCS2_DecodeUTF16 PyUnicode_DecodeUTF16;
    alias PyUnicodeUCS2_DecodeUTF16Stateful PyUnicode_DecodeUTF16Stateful;
    alias PyUnicodeUCS2_DecodeUTF8 PyUnicode_DecodeUTF8;
    alias PyUnicodeUCS2_DecodeUTF8Stateful PyUnicode_DecodeUTF8Stateful;
    alias PyUnicodeUCS2_DecodeUnicodeEscape PyUnicode_DecodeUnicodeEscape;
    alias PyUnicodeUCS2_Encode PyUnicode_Encode;
    alias PyUnicodeUCS2_EncodeASCII PyUnicode_EncodeASCII;
    alias PyUnicodeUCS2_EncodeCharmap PyUnicode_EncodeCharmap;
    alias PyUnicodeUCS2_EncodeDecimal PyUnicode_EncodeDecimal;
    alias PyUnicodeUCS2_EncodeLatin1 PyUnicode_EncodeLatin1;
    alias PyUnicodeUCS2_EncodeRawUnicodeEscape PyUnicode_EncodeRawUnicodeEscape;
    alias PyUnicodeUCS2_EncodeUTF16 PyUnicode_EncodeUTF16;
    alias PyUnicodeUCS2_EncodeUTF8 PyUnicode_EncodeUTF8;
    alias PyUnicodeUCS2_EncodeUnicodeEscape PyUnicode_EncodeUnicodeEscape;
    alias PyUnicodeUCS2_Find PyUnicode_Find;
    alias PyUnicodeUCS2_Format PyUnicode_Format;
    alias PyUnicodeUCS2_FromEncodedObject PyUnicode_FromEncodedObject;
    alias PyUnicodeUCS2_FromObject PyUnicode_FromObject;
    alias PyUnicodeUCS2_FromOrdinal PyUnicode_FromOrdinal;
    alias PyUnicodeUCS2_FromUnicode PyUnicode_FromUnicode;
    alias PyUnicodeUCS2_FromWideChar PyUnicode_FromWideChar;
    alias PyUnicodeUCS2_GetDefaultEncoding PyUnicode_GetDefaultEncoding;
    alias PyUnicodeUCS2_GetMax PyUnicode_GetMax;
    alias PyUnicodeUCS2_GetSize PyUnicode_GetSize;
    alias PyUnicodeUCS2_Join PyUnicode_Join;
    version(Python_2_5_Or_Later){
        alias PyUnicodeUCS2_Partition PyUnicode_Partition;
        alias PyUnicodeUCS2_Replace PyUnicode_Replace;
    }
    alias PyUnicodeUCS2_Resize PyUnicode_Resize;
    alias PyUnicodeUCS2_SetDefaultEncoding PyUnicode_SetDefaultEncoding;
    alias PyUnicodeUCS2_Split PyUnicode_Split;
    alias PyUnicodeUCS2_RPartition PyUnicode_RPartition;
    alias PyUnicodeUCS2_RSplit PyUnicode_RSplit;
    alias PyUnicodeUCS2_Splitlines PyUnicode_Splitlines;
    alias PyUnicodeUCS2_Tailmatch PyUnicode_Tailmatch;
    alias PyUnicodeUCS2_Translate PyUnicode_Translate;
    alias PyUnicodeUCS2_TranslateCharmap PyUnicode_TranslateCharmap;
    alias _PyUnicodeUCS2_AsDefaultEncodedString _PyUnicode_AsDefaultEncodedString;
    // omitted _PyUnicode_Fini
    // omitted _PyUnicode_Init
    alias _PyUnicodeUCS2_IsAlpha _PyUnicode_IsAlpha;
    alias _PyUnicodeUCS2_IsDecimalDigit _PyUnicode_IsDecimalDigit;
    alias _PyUnicodeUCS2_IsDigit _PyUnicode_IsDigit;
    alias _PyUnicodeUCS2_IsLinebreak _PyUnicode_IsLinebreak;
    alias _PyUnicodeUCS2_IsLowercase _PyUnicode_IsLowercase;
    alias _PyUnicodeUCS2_IsNumeric _PyUnicode_IsNumeric;
    alias _PyUnicodeUCS2_IsTitlecase _PyUnicode_IsTitlecase;
    alias _PyUnicodeUCS2_IsUppercase _PyUnicode_IsUppercase;
    alias _PyUnicodeUCS2_IsWhitespace _PyUnicode_IsWhitespace;
    alias _PyUnicodeUCS2_ToDecimalDigit _PyUnicode_ToDecimalDigit;
    alias _PyUnicodeUCS2_ToDigit _PyUnicode_ToDigit;
    alias _PyUnicodeUCS2_ToLowercase _PyUnicode_ToLowercase;
    alias _PyUnicodeUCS2_ToNumeric _PyUnicode_ToNumeric;
    alias _PyUnicodeUCS2_ToTitlecase _PyUnicode_ToTitlecase;
    alias _PyUnicodeUCS2_ToUppercase _PyUnicode_ToUppercase;
  } else {
    alias PyUnicodeUCS4_AsASCIIString PyUnicode_AsASCIIString;
    alias PyUnicodeUCS4_AsCharmapString PyUnicode_AsCharmapString;
    alias PyUnicodeUCS4_AsEncodedObject PyUnicode_AsEncodedObject;
    alias PyUnicodeUCS4_AsEncodedString PyUnicode_AsEncodedString;
    alias PyUnicodeUCS4_AsLatin1String PyUnicode_AsLatin1String;
    alias PyUnicodeUCS4_AsRawUnicodeEscapeString PyUnicode_AsRawUnicodeEscapeString;
    alias PyUnicodeUCS4_AsUTF16String PyUnicode_AsUTF16String;
    alias PyUnicodeUCS4_AsUTF8String PyUnicode_AsUTF8String;
    alias PyUnicodeUCS4_AsUnicode PyUnicode_AsUnicode;
    alias PyUnicodeUCS4_AsUnicodeEscapeString PyUnicode_AsUnicodeEscapeString;
    alias PyUnicodeUCS4_AsWideChar PyUnicode_AsWideChar;
    alias PyUnicodeUCS4_Compare PyUnicode_Compare;
    alias PyUnicodeUCS4_Concat PyUnicode_Concat;
    alias PyUnicodeUCS4_Contains PyUnicode_Contains;
    alias PyUnicodeUCS4_Count PyUnicode_Count;
    alias PyUnicodeUCS4_Decode PyUnicode_Decode;
    alias PyUnicodeUCS4_DecodeASCII PyUnicode_DecodeASCII;
    alias PyUnicodeUCS4_DecodeCharmap PyUnicode_DecodeCharmap;
    alias PyUnicodeUCS4_DecodeLatin1 PyUnicode_DecodeLatin1;
    alias PyUnicodeUCS4_DecodeRawUnicodeEscape PyUnicode_DecodeRawUnicodeEscape;
    alias PyUnicodeUCS4_DecodeUTF16 PyUnicode_DecodeUTF16;
    alias PyUnicodeUCS4_DecodeUTF16Stateful PyUnicode_DecodeUTF16Stateful;
    alias PyUnicodeUCS4_DecodeUTF8 PyUnicode_DecodeUTF8;
    alias PyUnicodeUCS4_DecodeUTF8Stateful PyUnicode_DecodeUTF8Stateful;
    alias PyUnicodeUCS4_DecodeUnicodeEscape PyUnicode_DecodeUnicodeEscape;
    alias PyUnicodeUCS4_Encode PyUnicode_Encode;
    alias PyUnicodeUCS4_EncodeASCII PyUnicode_EncodeASCII;
    alias PyUnicodeUCS4_EncodeCharmap PyUnicode_EncodeCharmap;
    alias PyUnicodeUCS4_EncodeDecimal PyUnicode_EncodeDecimal;
    alias PyUnicodeUCS4_EncodeLatin1 PyUnicode_EncodeLatin1;
    alias PyUnicodeUCS4_EncodeRawUnicodeEscape PyUnicode_EncodeRawUnicodeEscape;
    alias PyUnicodeUCS4_EncodeUTF16 PyUnicode_EncodeUTF16;
    alias PyUnicodeUCS4_EncodeUTF8 PyUnicode_EncodeUTF8;
    alias PyUnicodeUCS4_EncodeUnicodeEscape PyUnicode_EncodeUnicodeEscape;
    alias PyUnicodeUCS4_Find PyUnicode_Find;
    alias PyUnicodeUCS4_Format PyUnicode_Format;
    alias PyUnicodeUCS4_FromEncodedObject PyUnicode_FromEncodedObject;
    alias PyUnicodeUCS4_FromObject PyUnicode_FromObject;
    alias PyUnicodeUCS4_FromOrdinal PyUnicode_FromOrdinal;
    alias PyUnicodeUCS4_FromUnicode PyUnicode_FromUnicode;
    alias PyUnicodeUCS4_FromWideChar PyUnicode_FromWideChar;
    alias PyUnicodeUCS4_GetDefaultEncoding PyUnicode_GetDefaultEncoding;
    alias PyUnicodeUCS4_GetMax PyUnicode_GetMax;
    alias PyUnicodeUCS4_GetSize PyUnicode_GetSize;
    alias PyUnicodeUCS4_Join PyUnicode_Join;
    version(Python_2_5_Or_Later){
        alias PyUnicodeUCS4_Partition PyUnicode_Partition;
        alias PyUnicodeUCS4_RPartition PyUnicode_RPartition;
    }
    alias PyUnicodeUCS4_Replace PyUnicode_Replace;
    alias PyUnicodeUCS4_Resize PyUnicode_Resize;
    alias PyUnicodeUCS4_RSplit PyUnicode_RSplit;
    alias PyUnicodeUCS4_SetDefaultEncoding PyUnicode_SetDefaultEncoding;
    alias PyUnicodeUCS4_Split PyUnicode_Split;
    alias PyUnicodeUCS4_Splitlines PyUnicode_Splitlines;
    alias PyUnicodeUCS4_Tailmatch PyUnicode_Tailmatch;
    alias PyUnicodeUCS4_Translate PyUnicode_Translate;
    alias PyUnicodeUCS4_TranslateCharmap PyUnicode_TranslateCharmap;
    alias _PyUnicodeUCS4_AsDefaultEncodedString _PyUnicode_AsDefaultEncodedString;
    // omitted _PyUnicode_Fini
    // omitted _PyUnicode_Init
    alias _PyUnicodeUCS4_IsAlpha _PyUnicode_IsAlpha;
    alias _PyUnicodeUCS4_IsDecimalDigit _PyUnicode_IsDecimalDigit;
    alias _PyUnicodeUCS4_IsDigit _PyUnicode_IsDigit;
    alias _PyUnicodeUCS4_IsLinebreak _PyUnicode_IsLinebreak;
    alias _PyUnicodeUCS4_IsLowercase _PyUnicode_IsLowercase;
    alias _PyUnicodeUCS4_IsNumeric _PyUnicode_IsNumeric;
    alias _PyUnicodeUCS4_IsTitlecase _PyUnicode_IsTitlecase;
    alias _PyUnicodeUCS4_IsUppercase _PyUnicode_IsUppercase;
    alias _PyUnicodeUCS4_IsWhitespace _PyUnicode_IsWhitespace;
    alias _PyUnicodeUCS4_ToDecimalDigit _PyUnicode_ToDecimalDigit;
    alias _PyUnicodeUCS4_ToDigit _PyUnicode_ToDigit;
    alias _PyUnicodeUCS4_ToLowercase _PyUnicode_ToLowercase;
    alias _PyUnicodeUCS4_ToNumeric _PyUnicode_ToNumeric;
    alias _PyUnicodeUCS4_ToTitlecase _PyUnicode_ToTitlecase;
    alias _PyUnicodeUCS4_ToUppercase _PyUnicode_ToUppercase;
  }

  alias _PyUnicode_IsWhitespace Py_UNICODE_ISSPACE;
  alias _PyUnicode_IsLowercase Py_UNICODE_ISLOWER;
  alias _PyUnicode_IsUppercase Py_UNICODE_ISUPPER;
  alias _PyUnicode_IsTitlecase Py_UNICODE_ISTITLE;
  alias _PyUnicode_IsLinebreak Py_UNICODE_ISLINEBREAK;
  alias _PyUnicode_ToLowercase Py_UNICODE_TOLOWER;
  alias _PyUnicode_ToUppercase Py_UNICODE_TOUPPER;
  alias _PyUnicode_ToTitlecase Py_UNICODE_TOTITLE;
  alias _PyUnicode_IsDecimalDigit Py_UNICODE_ISDECIMAL;
  alias _PyUnicode_IsDigit Py_UNICODE_ISDIGIT;
  alias _PyUnicode_IsNumeric Py_UNICODE_ISNUMERIC;
  alias _PyUnicode_ToDecimalDigit Py_UNICODE_TODECIMAL;
  alias _PyUnicode_ToDigit Py_UNICODE_TODIGIT;
  alias _PyUnicode_ToNumeric Py_UNICODE_TONUMERIC;
  alias _PyUnicode_IsAlpha Py_UNICODE_ISALPHA;

  int Py_UNICODE_ISALNUM()(Py_UNICODE ch) {
    return (
           Py_UNICODE_ISALPHA(ch)
        || Py_UNICODE_ISDECIMAL(ch)
        || Py_UNICODE_ISDIGIT(ch)
        || Py_UNICODE_ISNUMERIC(ch)
      );
  }

  void Py_UNICODE_COPY()(void *target, void *source, size_t length) {
    memcpy(target, source, cast(uint)(length * Py_UNICODE.sizeof));
  }

  void Py_UNICODE_FILL()(Py_UNICODE *target, Py_UNICODE value, size_t length) {
    for (size_t i = 0; i < length; i++) {
      target[i] = value;
    }
  }

  int Py_UNICODE_MATCH()(PyUnicodeObject *string, size_t offset,
      PyUnicodeObject *substring
    )
  {
    return (
         (*(string.str + offset) == *(substring.str))
      && !memcmp(string.str + offset, substring.str,
             substring.length * Py_UNICODE.sizeof
          )
      );
  }


///////////////////////////////////////////////////////////////////////////////
// INT INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/intobject.h:

  struct PyIntObject {
    mixin PyObject_HEAD;

    C_long ob_ival;
  }

  // &PyInt_Type is accessible via PyInt_Type_p.

  // D translation of C macro:
  int PyInt_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyInt_Type_p);
  }
  // D translation of C macro:
  int PyInt_CheckExact()(PyObject *op) {
    return op.ob_type == PyInt_Type_p;
  }

  PyObject *PyInt_FromString(char *, char **, int);
  PyObject *PyInt_FromUnicode(Py_UNICODE *, Py_ssize_t, int);
  PyObject *PyInt_FromLong(C_long);
  version(Python_2_5_Or_Later){
      PyObject *PyInt_FromSize_t(size_t);
      PyObject *PyInt_FromSsize_t(Py_ssize_t);

      Py_ssize_t PyInt_AsSsize_t(PyObject*);
  }

  C_long PyInt_AsLong(PyObject *);
  C_ulong PyInt_AsUnsignedLongMask(PyObject *);
  C_ulonglong PyInt_AsUnsignedLongLongMask(PyObject *);

  C_long PyInt_GetMax(); /* Accessible at the Python level as sys.maxint */

  C_ulong PyOS_strtoul(char *, char **, int);
  C_long PyOS_strtol(char *, char **, int);
  version(Python_2_6_Or_Later){
      C_long PyOS_strtol(char *, char **, int);

      /* free list api */
      int PyInt_ClearFreeList();

      /* Convert an integer to the given base.  Returns a string.
         If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'.
         If newstyle is zero, then use the pre-2.6 behavior of octal having
         a leading "0" */
      PyObject* _PyInt_Format(PyIntObject* v, int base, int newstyle);

      /* Format the object based on the format_spec, as defined in PEP 3101
         (Advanced String Formatting). */
      PyObject * _PyInt_FormatAdvanced(PyObject *obj,
              char *format_spec,
              Py_ssize_t format_spec_len);
  }


///////////////////////////////////////////////////////////////////////////////
// BOOL INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/boolobject.h:

  alias PyIntObject PyBoolObject;

  // &PyBool_Type is accessible via PyBool_Type_p.

  // D translation of C macro:
  int PyBool_Check()(PyObject *x) {
    return x.ob_type == PyBool_Type_p;
  }

  // Py_False and Py_True are actually macros in the Python/C API, so they're
  // loaded as PyObject pointers in this module static initializer.

  PyObject * PyBool_FromLong(C_long);


///////////////////////////////////////////////////////////////////////////////
// LONG INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/longobject.h:

  // &PyLong_Type is accessible via PyLong_Type_p.

  version(Python_2_6_Or_Later){
      int PyLong_Check()(PyObject* op){
          return PyType_FastSubclass((op).ob_type, Py_TPFLAGS_LONG_SUBCLASS);
      }
  }else{
      // D translation of C macro:
      int PyLong_Check()(PyObject *op) {
          return PyObject_TypeCheck(op, PyLong_Type_p);
      }
  }
  // D translation of C macro:
  int PyLong_CheckExact()(PyObject *op) {
      return op.ob_type == PyLong_Type_p;
  }

  PyObject * PyLong_FromLong(C_long);
  PyObject * PyLong_FromUnsignedLong(C_ulong);

  PyObject * PyLong_FromLongLong(C_longlong);
  PyObject * PyLong_FromUnsignedLongLong(C_ulonglong);

  PyObject * PyLong_FromDouble(double);
  version(Python_2_6_Or_Later){
      PyObject * PyLong_FromSize_t(size_t);
      PyObject * PyLong_FromSsize_t(Py_ssize_t);
  }
  PyObject * PyLong_FromVoidPtr(void *);

  C_long PyLong_AsLong(PyObject *);
  C_ulong PyLong_AsUnsignedLong(PyObject *);
  C_ulong PyLong_AsUnsignedLongMask(PyObject *);
  version(Python_2_6_Or_Later){
      Py_ssize_t PyLong_AsSsize_t(PyObject *);
  }

  C_longlong PyLong_AsLongLong(PyObject *);
  C_ulonglong PyLong_AsUnsignedLongLong(PyObject *);
  C_ulonglong PyLong_AsUnsignedLongLongMask(PyObject *);
  version(Python_2_7_Or_Later) {
      C_long PyLong_AsLongAndOverflow(PyObject*, int*);
      C_longlong PyLong_AsLongLongAndOverflow(PyObject*, int*);
  }

  double PyLong_AsDouble(PyObject *);
  PyObject * PyLong_FromVoidPtr(void *);
  void * PyLong_AsVoidPtr(PyObject *);

  PyObject * PyLong_FromString(char *, char **, int);
  PyObject * PyLong_FromUnicode(Py_UNICODE *, int, int);
  int _PyLong_Sign(PyObject* v);
  size_t _PyLong_NumBits(PyObject* v);
  PyObject* _PyLong_FromByteArray(
	const(ubyte)* bytes, size_t n,
	int little_endian, int is_signed);
  int _PyLong_AsByteArray(PyLongObject* v,
	ubyte* bytes, size_t n,
	int little_endian, int is_signed);

  version(Python_2_6_Or_Later){
      /* _PyLong_Format: Convert the long to a string object with given base,
         appending a base prefix of 0[box] if base is 2, 8 or 16.
         Add a trailing "L" if addL is non-zero.
         If newstyle is zero, then use the pre-2.6 behavior of octal having
         a leading "0", instead of the prefix "0o" */
      PyObject * _PyLong_Format(PyObject *aa, int base, int addL, int newstyle);

      /* Format the object based on the format_spec, as defined in PEP 3101
         (Advanced String Formatting). */
      PyObject * _PyLong_FormatAdvanced(PyObject *obj,
					      char *format_spec,
					      Py_ssize_t format_spec_len);
  }

// Python-header-file: Include/longintrepr.h:

struct PyLongObject {
	mixin PyObject_VAR_HEAD;
	ushort ob_digit[1];
}

PyLongObject* _PyLong_New(int);

/* Return a copy of src. */
PyObject* _PyLong_Copy(PyLongObject* src);

///////////////////////////////////////////////////////////////////////////////
// FLOAT INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/floatobject.h:

  struct PyFloatObject {
    mixin PyObject_HEAD;

    double ob_fval;
  }

  // &PyFloat_Type is accessible via PyFloat_Type_p.

  // D translation of C macro:
  int PyFloat_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyFloat_Type_p);
  }
  // D translation of C macro:
  int PyFloat_CheckExact()(PyObject *op) {
    return op.ob_type == PyFloat_Type_p;
  }

  version(Python_2_6_Or_Later){
      double PyFloat_GetMax();
      double PyFloat_GetMin();
      PyObject * PyFloat_GetInfo();
  }

  PyObject * PyFloat_FromString(PyObject *, char** junk);
  PyObject * PyFloat_FromDouble(double);

  double PyFloat_AsDouble(PyObject *);
  void PyFloat_AsReprString(char *, PyFloatObject *v);
  void PyFloat_AsString(char *, PyFloatObject *v);

  version(Python_2_6_Or_Later){
      // _PyFloat_Digits ??
      // _PyFloat_DigitsInit ??
      /* free list api */
      int PyFloat_ClearFreeList();
      // _PyFloat_FormatAdvanced ??
  }


///////////////////////////////////////////////////////////////////////////////
// COMPLEX INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/complexobject.h:

  struct Py_complex {
    double real_; // real is the name of a D type, so must rename
    double imag;
  }

  struct PyComplexObject {
    mixin PyObject_HEAD;

    Py_complex cval;
  }

  Py_complex c_sum(Py_complex, Py_complex);
  Py_complex c_diff(Py_complex, Py_complex);
  Py_complex c_neg(Py_complex);
  Py_complex c_prod(Py_complex, Py_complex);
  Py_complex c_quot(Py_complex, Py_complex);
  Py_complex c_pow(Py_complex, Py_complex);
  version(Python_2_6_Or_Later){
      double c_abs(Py_complex);
  }

  // &PyComplex_Type is accessible via PyComplex_Type_p.

  // D translation of C macro:
  int PyComplex_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyComplex_Type_p);
  }
  // D translation of C macro:
  int PyComplex_CheckExact()(PyObject *op) {
    return op.ob_type == PyComplex_Type_p;
  }

  PyObject * PyComplex_FromCComplex(Py_complex);
  PyObject * PyComplex_FromDoubles(double real_, double imag);

  double PyComplex_RealAsDouble(PyObject *op);
  double PyComplex_ImagAsDouble(PyObject *op);
  Py_complex PyComplex_AsCComplex(PyObject *op);


///////////////////////////////////////////////////////////////////////////////
// RANGE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/rangeobject.h:

  // &PyRange_Type is accessible via PyRange_Type_p.

  // D translation of C macro:
  int PyRange_Check()(PyObject *op) {
    return op.ob_type == PyRange_Type_p;
  }

  version(Python_2_5_Or_Later){
      // Removed in 2.5
  }else{
      PyObject * PyRange_New(C_long, C_long, C_long, int);
  }


///////////////////////////////////////////////////////////////////////////////
// STRING INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/stringobject.h:

  struct PyStringObject {
    mixin PyObject_VAR_HEAD;

    C_long ob_shash;
    int ob_sstate;
    // DSR:XXX:LAYOUT:
    // Will the D layout for a 1-char array be the same as the C layout?  I
    // think the D array will be larger.
    char _ob_sval[1];
    char* ob_sval()() {
        return _ob_sval.ptr;
    }
  }

  // &PyBaseString_Type is accessible via PyBaseString_Type_p.
  // &PyString_Type is accessible via PyString_Type_p.

  // D translation of C macro:
  int PyString_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyString_Type_p);
  }
  // D translation of C macro:
  int PyString_CheckExact()(PyObject *op) {
    return op.ob_type == PyString_Type_p;
  }

  PyObject * PyString_FromStringAndSize(const(char) *, Py_ssize_t);
  PyObject * PyString_FromString(const(char) *);
  // PyString_FromFormatV omitted
  PyObject * PyString_FromFormat(const(char)*, ...);
  Py_ssize_t PyString_Size(PyObject *);
  char * PyString_AsString(PyObject *);
  /* Use only if you know it's a string */
  int PyString_CHECK_INTERNED()(PyObject* op) {
    return (cast(PyStringObject*)op).ob_sstate;
  }
  /* Macro, trading safety for speed */
  PyStringObject* PyString_AS_STRING()(PyObject* op) {
    return (cast(PyStringObject*)op).ob_sval;
  }
  Py_ssize_t PyString_GET_SIZE()(PyObject* op) {
    return (cast(PyStringObject*)op).ob_size;
  }
  PyObject * PyString_Repr(PyObject *, int);
  void PyString_Concat(PyObject **, PyObject *);
  void PyString_ConcatAndDel(PyObject **, PyObject *);
  PyObject * PyString_Format(PyObject *, PyObject *);
  PyObject * PyString_DecodeEscape(const(char) *, Py_ssize_t, const(char) *, Py_ssize_t, const(char) *);

  void PyString_InternInPlace(PyObject **);
  void PyString_InternImmortal(PyObject **);
  PyObject * PyString_InternFromString(const(char) *);

  PyObject * _PyString_Join(PyObject *sep, PyObject *x);


  PyObject* PyString_Decode(const(char) *s, Py_ssize_t size, const(char) *encoding, const(char) *errors);
  PyObject* PyString_Encode(const(char) *s, Py_ssize_t size, const(char) *encoding, const(char) *errors);

  PyObject* PyString_AsEncodedObject(PyObject *str, const(char) *encoding, const(char) *errors);
  PyObject* PyString_AsDecodedObject(PyObject *str, const(char) *encoding, const(char) *errors);

  // Since no one has legacy Python extensions written in D, the deprecated
  // functions PyString_AsDecodedString and PyString_AsEncodedString were
  // omitted.

  int PyString_AsStringAndSize(PyObject *obj, char **s, int *len);

  version(Python_2_6_Or_Later){
      /* Using the current locale, insert the thousands grouping
         into the string pointed to by buffer.  For the argument descriptions,
         see Objects/stringlib/localeutil.h */

      int _PyString_InsertThousandsGrouping(char *buffer,
              Py_ssize_t n_buffer,
              Py_ssize_t n_digits,
              Py_ssize_t buf_size,
              Py_ssize_t *count,
              int append_zero_char);

      /* Format the object based on the format_spec, as defined in PEP 3101
         (Advanced String Formatting). */
      PyObject * _PyBytes_FormatAdvanced(PyObject *obj,
              char *format_spec,
              Py_ssize_t format_spec_len);
  }


///////////////////////////////////////////////////////////////////////////////
// BUFFER INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/bufferobject.h:

  // &PyBuffer_Type is accessible via PyBuffer_Type_p.

  // D translation of C macro:
  int PyBuffer_Check()(PyObject *op) {
    return op.ob_type == PyBuffer_Type_p;
  }

  enum int Py_END_OF_BUFFER = -1;

  PyObject * PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size);
  PyObject * PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size);

  PyObject * PyBuffer_FromMemory(void *ptr, Py_ssize_t size);
  PyObject * PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);

  PyObject * PyBuffer_New(Py_ssize_t size);


///////////////////////////////////////////////////////////////////////////////
// TUPLE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/tupleobject.h:

  struct PyTupleObject {
    mixin PyObject_VAR_HEAD;

    // DSR:XXX:LAYOUT:
    // Will the D layout for a 1-PyObject* array be the same as the C layout?
    // I think the D array will be larger.
    PyObject *_ob_item[1];
    PyObject** ob_item()() {
      return _ob_item.ptr;
    }
  }

  // &PyTuple_Type is accessible via PyTuple_Type_p.

  // D translation of C macro:
  int PyTuple_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyTuple_Type_p);
  }
  // D translation of C macro:
  int PyTuple_CheckExact()(PyObject *op) {
    return op.ob_type == PyTuple_Type_p;
  }

  PyObject * PyTuple_New(Py_ssize_t size);
  Py_ssize_t PyTuple_Size(PyObject *);
  Borrowed!PyObject* PyTuple_GetItem(PyObject*, Py_ssize_t);
  int PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
  PyObject * PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
  int _PyTuple_Resize(PyObject **, Py_ssize_t);
  PyObject * PyTuple_Pack(Py_ssize_t, ...);

  // D translations of C macros:
  // XXX: These do not work.
  Borrowed!PyObject* PyTuple_GET_ITEM()(PyObject* op, Py_ssize_t i) {
    return (cast(PyTupleObject *) op).ob_item[i];
  }
  size_t PyTuple_GET_SIZE()(PyObject *op) {
    return (cast(PyTupleObject *) op).ob_size;
  }
  PyObject *PyTuple_SET_ITEM()(PyObject *op, Py_ssize_t i, PyObject *v) {
    PyTupleObject *opAsTuple = cast(PyTupleObject *) op;
    opAsTuple.ob_item[i] = v;
    return v;
  }

  version(Python_2_6_Or_Later){
      int PyTuple_ClearFreeList();
  }

///////////////////////////////////////////////////////////////////////////////
// LIST INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/listobject.h:

  struct PyListObject {
    mixin PyObject_VAR_HEAD;

    PyObject **ob_item;
    Py_ssize_t allocated;
  }

  // &PyList_Type is accessible via PyList_Type_p.

  // D translation of C macro:
  int PyList_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyList_Type_p);
  }
  // D translation of C macro:
  int PyList_CheckExact()(PyObject *op) {
    return op.ob_type == PyList_Type_p;
  }

  PyObject * PyList_New(Py_ssize_t size);
  Py_ssize_t PyList_Size(PyObject *);

  Borrowed!PyObject* PyList_GetItem(PyObject*, Py_ssize_t);
  int PyList_SetItem(PyObject*, Py_ssize_t, PyObject*);
  int PyList_Insert(PyObject*, Py_ssize_t, PyObject*);
  int PyList_Append(PyObject*, PyObject*);
  PyObject* PyList_GetSlice(PyObject*, Py_ssize_t, Py_ssize_t);
  int PyList_SetSlice(PyObject*, Py_ssize_t, Py_ssize_t, PyObject*);
  int PyList_Sort(PyObject*);
  int PyList_Reverse(PyObject*);
  PyObject* PyList_AsTuple(PyObject*);

  // D translations of C macros:
  Borrowed!PyObject* PyList_GET_ITEM()(PyObject* op, Py_ssize_t i) {
    return (cast(PyListObject*) op).ob_item[i];
  }
  void PyList_SET_ITEM()(PyObject *op, Py_ssize_t i, PyObject *v) {
    (cast(PyListObject*)op).ob_item[i] = v;
  }
  size_t PyList_GET_SIZE()(PyObject *op) {
    return (cast(PyListObject *) op).ob_size;
  }


///////////////////////////////////////////////////////////////////////////////
// DICTIONARY OBJECT TYPE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/dictobject.h:

  enum int PyDict_MINSIZE = 8;

  struct PyDictEntry {
      version(Python_2_5_Or_Later){
          Py_ssize_t me_hash;
      }else{
          C_long me_hash;
      }
    PyObject *me_key;
    PyObject *me_value;
  }

  struct _dictobject {
    mixin PyObject_HEAD;

    Py_ssize_t ma_fill;
    Py_ssize_t ma_used;
    Py_ssize_t ma_mask;
    PyDictEntry *ma_table;
    PyDictEntry* function(PyDictObject *mp, PyObject *key, C_long hash) ma_lookup;
    PyDictEntry ma_smalltable[PyDict_MINSIZE];
  }
  alias _dictobject PyDictObject;

  // &PyDict_Type is accessible via PyDict_Type_p.

  // D translation of C macro:
  int PyDict_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyDict_Type_p);
  }
  // D translation of C macro:
  int PyDict_CheckExact()(PyObject *op) {
    return op.ob_type == PyDict_Type_p;
  }

  PyObject* PyDict_New();
  Borrowed!PyObject* PyDict_GetItem(PyObject* mp, PyObject* key);
  int PyDict_SetItem(PyObject* mp, PyObject* key, PyObject* item);
  int PyDict_DelItem(PyObject *mp, PyObject *key);
  void PyDict_Clear(PyObject *mp);
  int PyDict_Next(PyObject *mp, Py_ssize_t *pos, Borrowed!PyObject** key, Borrowed!PyObject** value);
  PyObject * PyDict_Keys(PyObject *mp);
  PyObject * PyDict_Values(PyObject *mp);
  PyObject * PyDict_Items(PyObject *mp);
  Py_ssize_t PyDict_Size(PyObject *mp);
  PyObject * PyDict_Copy(PyObject *mp);
  int PyDict_Contains(PyObject *mp, PyObject *key);

  int PyDict_Update(PyObject *mp, PyObject *other);
  int PyDict_Merge(PyObject *mp, PyObject *other, int override_);
  int PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override_);

  Borrowed!PyObject* PyDict_GetItemString(PyObject* dp, const(char)* key);
  int PyDict_SetItemString(PyObject* dp, const(char)* key, PyObject* item);
  int PyDict_DelItemString(PyObject* dp, const(char)* key);


///////////////////////////////////////////////////////////////////////////////
// PYTHON EXTENSION FUNCTION INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/methodobject.h:

  // &PyCFunction_Type is accessible via PyCFunction_Type_p.

  // D translation of C macro:
  int PyCFunction_Check()(PyObject *op) {
    return op.ob_type == PyCFunction_Type_p;
  }

  alias PyObject* function(PyObject *, PyObject *) PyCFunction;
  alias PyObject* function(PyObject *, PyObject *,PyObject *) PyCFunctionWithKeywords;
  alias PyObject* function(PyObject *) PyNoArgsFunction;

  PyCFunction PyCFunction_GetFunction(PyObject *);
  PyObject * PyCFunction_GetSelf(PyObject *);
  int PyCFunction_GetFlags(PyObject *);

  PyObject * PyCFunction_Call(PyObject *, PyObject *, PyObject *);

      version(Python_2_5_Or_Later){
          alias const(char)	Char1;
      }else{
          alias char	Char1;
      }
  struct PyMethodDef {
      Char1	*ml_name;
      PyCFunction  ml_meth;
      int		 ml_flags;
      Char1	*ml_doc;
  }

  PyObject * Py_FindMethod(PyMethodDef[], PyObject *, Char1 *);
  PyObject * PyCFunction_NewEx(PyMethodDef *, PyObject *,PyObject *);
  PyObject * PyCFunction_New()(PyMethodDef* ml, PyObject* self) {
    return PyCFunction_NewEx(ml, self, null);
  }

  enum int METH_OLDARGS = 0x0000;
  enum int METH_VARARGS = 0x0001;
  enum int METH_KEYWORDS= 0x0002;
  enum int METH_NOARGS  = 0x0004;
  enum int METH_O       = 0x0008;
  enum int METH_CLASS   = 0x0010;
  enum int METH_STATIC  = 0x0020;
  enum int METH_COEXIST = 0x0040;

  struct PyMethodChain {
    PyMethodDef *methods;
    PyMethodChain *link;
  }

  PyObject * Py_FindMethodInChain(PyMethodChain *, PyObject *, Char1 *);

  struct PyCFunctionObject {
    mixin PyObject_HEAD;

    PyMethodDef *m_ml;
    PyObject    *m_self;
    PyObject    *m_module;
  }

  version(Python_2_6_Or_Later){
      int PyCFunction_ClearFreeList();
  }


///////////////////////////////////////////////////////////////////////////////
// MODULE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/moduleobject.h:

  // &PyModule_Type is accessible via PyModule_Type_p.

  // D translation of C macro:
  int PyModule_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyModule_Type_p);
  }
  // D translation of C macro:
  int PyModule_CheckExact()(PyObject *op) {
    return op.ob_type == PyModule_Type_p;
  }

  PyObject* PyModule_New(Char1*);
  Borrowed!PyObject* PyModule_GetDict(PyObject*);
  char* PyModule_GetName(PyObject*);
  char* PyModule_GetFilename(PyObject*);
  void _PyModule_Clear(PyObject *);

  // Python-header-file: Include/modsupport.h:

      version(Python_2_5_Or_Later){
          enum PYTHON_API_VERSION = 1013;
          enum PYTHON_API_STRING = "1013";
      }else version(Python_2_4_Or_Later){
          enum PYTHON_API_VERSION = 1012;
          enum PYTHON_API_STRING = "1012";
      }

  int PyArg_Parse(PyObject *, Char1 *, ...);
  int PyArg_ParseTuple(PyObject *, Char1 *, ...);
  int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
                            Char1 *, char **, ...);
  int PyArg_UnpackTuple(PyObject *, Char1 *, Py_ssize_t, Py_ssize_t, ...);
  PyObject * Py_BuildValue(Char1 *, ...);

  int PyModule_AddObject(PyObject *, Char1 *, PyObject *);
  int PyModule_AddIntConstant(PyObject *, Char1 *, C_long);
  int PyModule_AddStringConstant(PyObject *, Char1 *, Char1 *);

  version(Python_2_5_Or_Later){
      version(X86_64){
          enum Py_InitModuleSym = "Py_InitModule4_64";
      }else{
          enum Py_InitModuleSym = "Py_InitModule4";
      }
  }else{
      enum Py_InitModuleSym = "Py_InitModule4";
  }
  mixin("Borrowed!PyObject* "~Py_InitModuleSym~"(Char1 *name, PyMethodDef *methods, Char1 *doc,
                  PyObject *self, int apiver);

  Borrowed!PyObject* Py_InitModule()(string name, PyMethodDef *methods)
  {
    return "~Py_InitModuleSym~"(cast(Char1*) name.ptr, methods, cast(Char1 *)(null),
      cast(PyObject *)(null), PYTHON_API_VERSION);
  }

  Borrowed!PyObject* Py_InitModule3()(string name, PyMethodDef *methods, string doc) {
    return "~Py_InitModuleSym~"(cast(Char1*)name.ptr, methods, cast(Char1*) doc, cast(PyObject *)null,
      PYTHON_API_VERSION);
  }");


///////////////////////////////////////////////////////////////////////////////
// PYTHON FUNCTION INTERFACE (to functions created by the 'def' statement)
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/funcobject.h:

  struct PyFunctionObject {
    mixin PyObject_HEAD;

    PyObject *func_code;
    PyObject *func_globals;
    PyObject *func_defaults;
    PyObject *func_closure;
    PyObject *func_doc;
    PyObject *func_name;
    PyObject *func_dict;
    PyObject *func_weakreflist;
    PyObject *func_module;
  }

  // &PyFunction_Type is accessible via PyFunction_Type_p.

  // D translation of C macro:
  int PyFunction_Check()(PyObject *op) {
    return op.ob_type == PyFunction_Type_p;
  }

  PyObject * PyFunction_New(PyObject *, PyObject *);
  Borrowed!PyObject* PyFunction_GetCode(PyObject*);
  Borrowed!PyObject* PyFunction_GetGlobals(PyObject*);
  Borrowed!PyObject* PyFunction_GetModule(PyObject*);
  Borrowed!PyObject* PyFunction_GetDefaults(PyObject*);
  int PyFunction_SetDefaults(PyObject *, PyObject *);
  Borrowed!PyObject* PyFunction_GetClosure(PyObject *);
  int PyFunction_SetClosure(PyObject *, PyObject *);

  PyObject* PyFunction_GET_CODE()(PyObject* func) {
    return (cast(PyFunctionObject*)func).func_code;
  }
  PyObject* PyFunction_GET_GLOBALS()(PyObject* func) {
    return (cast(PyFunctionObject*)func).func_globals;
  }
  PyObject* PyFunction_GET_MODULE()(PyObject* func) {
    return (cast(PyFunctionObject*)func).func_module;
  }
  PyObject* PyFunction_GET_DEFAULTS()(PyObject* func) {
    return (cast(PyFunctionObject*)func).func_defaults;
  }
  PyObject* PyFunction_GET_CLOSURE()(PyObject* func) {
    return (cast(PyFunctionObject*)func).func_closure;
  }

  // &PyClassMethod_Type is accessible via PyClassMethod_Type_p.
  // &PyStaticMethod_Type is accessible via PyStaticMethod_Type_p.

  PyObject * PyClassMethod_New(PyObject *);
  PyObject * PyStaticMethod_New(PyObject *);


///////////////////////////////////////////////////////////////////////////////
// PYTHON CLASS INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/classobject.h:

  struct PyClassObject {
    mixin PyObject_HEAD;

    PyObject	*cl_bases;	/* A tuple of class objects */
    PyObject	*cl_dict;	/* A dictionary */
    PyObject	*cl_name;	/* A string */
    /* The following three are functions or null */
    PyObject	*cl_getattr;
    PyObject	*cl_setattr;
    PyObject	*cl_delattr;
  }

  struct PyInstanceObject {
    mixin PyObject_HEAD;

    PyClassObject *in_class;
    PyObject	  *in_dict;
    PyObject	  *in_weakreflist;
  }

  struct PyMethodObject {
    mixin PyObject_HEAD;

    PyObject *im_func;
    PyObject *im_self;
    PyObject *im_class;
    PyObject *im_weakreflist;
  }

  // &PyClass_Type is accessible via PyClass_Type_p.
  // D translation of C macro:
  int PyClass_Check()(PyObject *op) {
    return op.ob_type == PyClass_Type_p;
  }

  // &PyInstance_Type is accessible via PyInstance_Type_p.
  // D translation of C macro:
  int PyInstance_Check()(PyObject *op) {
    return op.ob_type == PyInstance_Type_p;
  }

  // &PyMethod_Type is accessible via PyMethod_Type_p.
  // D translation of C macro:
  int PyMethod_Check()(PyObject *op) {
    return op.ob_type == PyMethod_Type_p;
  }

  PyObject * PyClass_New(PyObject *, PyObject *, PyObject *);
  PyObject * PyInstance_New(PyObject *, PyObject *,
                        PyObject *);
  PyObject * PyInstance_NewRaw(PyObject *, PyObject *);
  PyObject * PyMethod_New(PyObject *, PyObject *, PyObject *);

  Borrowed!PyObject* PyMethod_Function(PyObject *);
  Borrowed!PyObject* PyMethod_Self(PyObject *);
  Borrowed!PyObject* PyMethod_Class(PyObject*);

  PyObject * _PyInstance_Lookup(PyObject *pinst, PyObject *name);

  Borrowed!PyObject* PyMethod_GET_FUNCTION()(PyObject* meth) {
    return (cast(PyMethodObject*)meth).im_func;
  }
  Borrowed!PyObject* PyMethod_GET_SELF()(PyObject* meth) {
    return (cast(PyMethodObject*)meth).im_self;
  }
  Borrowed!PyObject* PyMethod_GET_CLASS()(PyObject* meth) {
    return borrowed((cast(PyMethodObject*)meth).im_class);
  }

  int PyClass_IsSubclass(PyObject *, PyObject *);

  version(Python_2_6_Or_Later){
      int PyMethod_ClearFreeList();
  }


///////////////////////////////////////////////////////////////////////////////
// FILE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/fileobject.h:

  struct PyFileObject {
    mixin PyObject_HEAD;

    FILE *f_fp;
    PyObject *f_name;
    PyObject *f_mode;
    int function(FILE *) f_close;
    int f_softspace;
    int f_binary;
    char* f_buf;
    char* f_bufend;
    char* f_bufptr;
    char *f_setbuf;
    int f_univ_newline;
    int f_newlinetypes;
    int f_skipnextlf;
    PyObject *f_encoding;
    version(Python_2_6_Or_Later){
        PyObject *f_errors;
    }
    PyObject *weakreflist;
    version(Python_2_6_Or_Later){
        int unlocked_count;         /* Num. currently running sections of code
                                       using f_fp with the GIL released. */
        int readable;
        int writable;
    }
  }

  // &PyFile_Type is accessible via PyFile_Type_p.
  // D translation of C macro:
  int PyFile_Check()(PyObject *op) {
    return PyObject_TypeCheck(op, PyFile_Type_p);
  }
  // D translation of C macro:
  int PyFile_CheckExact()(PyObject *op) {
    return op.ob_type == PyFile_Type_p;
  }

  PyObject * PyFile_FromString(char *, char *);
  void PyFile_SetBufSize(PyObject *, int);
  int PyFile_SetEncoding(PyObject *, const(char) *);
  version(Python_2_6_Or_Later){
      int PyFile_SetEncodingAndErrors(PyObject *, const(char)*, const(char)*errors);
  }
  PyObject * PyFile_FromFile(FILE *, char *, char *,
                         int function(FILE *));
  FILE * PyFile_AsFile(PyObject *);
  version(Python_2_6_Or_Later){
      void PyFile_IncUseCount(PyFileObject *);
      void PyFile_DecUseCount(PyFileObject *);
  }
  Borrowed!PyObject* PyFile_Name(PyObject*);
  PyObject * PyFile_GetLine(PyObject *, int);
  int PyFile_WriteObject(PyObject *, PyObject *, int);
  int PyFile_SoftSpace(PyObject *, int);
  int PyFile_WriteString(const(char)*, PyObject *);
  int PyObject_AsFileDescriptor(PyObject *);

  // We deal with char *Py_FileSystemDefaultEncoding in the global variables
  // section toward the bottom of this file.

  enum PY_STDIOTEXTMODE = "b";

  char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
  size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);


///////////////////////////////////////////////////////////////////////////////
// COBJECT INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/cobject.h:

  // PyCObject_Type is a Python type for transporting an arbitrary C pointer
  // from the C level to Python and back (in essence, an opaque handle).

  // &PyCObject_Type is accessible via PyCObject_Type_p.
  // D translation of C macro:
  int PyCObject_Check()(PyObject *op) {
    return op.ob_type == PyCObject_Type_p;
  }

  PyObject * PyCObject_FromVoidPtr(void *cobj, void function(void*) destruct);
  PyObject * PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc,
    void function(void*,void*) destruct);
  void * PyCObject_AsVoidPtr(PyObject *);
  void * PyCObject_GetDesc(PyObject *);
  void * PyCObject_Import(char *module_name, char *cobject_name);
  int PyCObject_SetVoidPtr(PyObject *self, void *cobj);

  version(Python_2_6_Or_Later){
      struct PyCObject {
          mixin PyObject_HEAD;
          void *cobject;
          void *desc;
          void function(void *) destructor;
      };
  }


///////////////////////////////////////////////////////////////////////////////////////////////
// TRACEBACK INTERFACE
///////////////////////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/traceback.h:

  struct PyTracebackObject {
    mixin PyObject_HEAD;

    PyTracebackObject *tb_next;
    PyFrameObject *tb_frame;
    int tb_lasti;
    int tb_lineno;
  }

  int PyTraceBack_Here(PyFrameObject *);
  int PyTraceBack_Print(PyObject *, PyObject *);
  version(Python_2_6_Or_Later){
      int _Py_DisplaySourceLine(PyObject *, const(char)*, int, int);
  }

  // &PyTraceBack_Type is accessible via PyTraceBack_Type_p.
  // D translation of C macro:
  int PyTraceBack_Check()(PyObject *v) {
    return v.ob_type == PyTraceBack_Type_p;
  }


///////////////////////////////////////////////////////////////////////////////
// SLICE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/sliceobject.h:

  // We deal with Py_Ellipsis in the global variables section toward the bottom
  // of this file.

  struct PySliceObject {
    mixin PyObject_HEAD;

    PyObject *start;
    PyObject *stop;
    PyObject *step;
  }

  // &PySlice_Type is accessible via PySlice_Type_p.
  // D translation of C macro:
  int PySlice_Check()(PyObject *op) {
    return op.ob_type == PySlice_Type_p;
  }

  PyObject * PySlice_New(PyObject *start, PyObject *stop, PyObject *step);
  int PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
                Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
  int PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
                Py_ssize_t *start, Py_ssize_t *stop,
                Py_ssize_t *step, Py_ssize_t *slicelength);


///////////////////////////////////////////////////////////////////////////////
// CELL INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/cellobject.h:

  struct PyCellObject {
    mixin PyObject_HEAD;

    PyObject *ob_ref;
  }

  // &PyCell_Type is accessible via PyCell_Type_p.
  // D translation of C macro:
  int PyCell_Check()(PyObject *op) {
    return op.ob_type == PyCell_Type_p;
  }

  PyObject * PyCell_New(PyObject *);
  PyObject * PyCell_Get(PyObject *);
  int PyCell_Set(PyObject *, PyObject *);


///////////////////////////////////////////////////////////////////////////////
// ITERATOR INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/iterobject.h:

  // &PySeqIter_Type is accessible via PySeqIter_Type_p.
  // D translation of C macro:
  int PySeqIter_Check()(PyObject *op) {
    return op.ob_type == PySeqIter_Type_p;
  }

  PyObject * PySeqIter_New(PyObject *);

  // &PyCallIter_Type is accessible via PyCallIter_Type_p.
  // D translation of C macro:
  int PyCallIter_Check()(PyObject *op) {
    return op.ob_type == PyCallIter_Type_p;
  }

  PyObject * PyCallIter_New(PyObject *, PyObject *);


///////////////////////////////////////////////////////////////////////////////
// DESCRIPTOR INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/descrobject.h:

  alias PyObject* function(PyObject *, void *) getter;
  alias int function(PyObject *, PyObject *, void *) setter;

  struct PyGetSetDef {
    char *name;
    getter get;
    setter set;
    char *doc;
    void *closure;
  }

  alias PyObject* function(PyObject *, PyObject *, void *) wrapperfunc;
  alias PyObject* function(PyObject *, PyObject *, void *, PyObject *) wrapperfunc_kwds;

  struct wrapperbase {
    char *name;
    int offset;
    void *function_;
    wrapperfunc wrapper;
    char *doc;
    int flags;
    PyObject *name_strobj;
  }

  enum PyWrapperFlag_KEYWORDS = 1;

  template PyDescr_COMMON() {
    mixin PyObject_HEAD;
    PyTypeObject *d_type;
    PyObject *d_name;
  }

  struct PyDescrObject {
    mixin PyDescr_COMMON;
  }

  struct PyMethodDescrObject {
    mixin PyDescr_COMMON;
    PyMethodDef *d_method;
  }

  struct PyMemberDescrObject {
    mixin PyDescr_COMMON;
    PyMemberDef *d_member;
  }

  struct PyGetSetDescrObject {
    mixin PyDescr_COMMON;
    PyGetSetDef *d_getset;
  }

  struct PyWrapperDescrObject {
    mixin PyDescr_COMMON;
    wrapperbase *d_base;
    void *d_wrapped;
  }

  // PyWrapperDescr_Type is currently not accessible from D.
  version(Python_2_6_Or_Later){
    // nor PyDictProxy_Type;
    // norPyGetSetDescr_Type;
    // nor PyMemberDescr_Type;
  }

  PyObject * PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
  PyObject * PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
  PyObject * PyDescr_NewMember(PyTypeObject *, PyMemberDef *);
  PyObject * PyDescr_NewGetSet(PyTypeObject *, PyGetSetDef *);
  PyObject * PyDescr_NewWrapper(PyTypeObject *, wrapperbase *, void *);
  PyObject * PyDictProxy_New(PyObject *);
  PyObject * PyWrapper_New(PyObject *, PyObject *);

  // &PyProperty_Type is accessible via PyProperty_Type_p.


///////////////////////////////////////////////////////////////////////////////
// WEAK REFERENCE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/weakrefobject.h:

  struct PyWeakReference {
    mixin PyObject_HEAD;

    PyObject *wr_object;
    PyObject *wr_callback;
    C_long hash;
    PyWeakReference *wr_prev;
    PyWeakReference *wr_next;
  }

  // &_PyWeakref_RefType is accessible via _PyWeakref_RefType_p.
  // &_PyWeakref_ProxyType is accessible via _PyWeakref_ProxyType_p.
  // &_PyWeakref_CallableProxyType is accessible via _PyWeakref_CallableProxyType_p.

  // D translations of C macros:
  int PyWeakref_CheckRef()(PyObject *op) {
    return PyObject_TypeCheck(op, _PyWeakref_RefType_p);
  }
  int PyWeakref_CheckRefExact()(PyObject *op) {
    return op.ob_type == _PyWeakref_RefType_p;
  }
  int PyWeakref_CheckProxy()(PyObject *op) {
    return op.ob_type == _PyWeakref_ProxyType_p
        || op.ob_type == _PyWeakref_CallableProxyType_p;
  }
  int PyWeakref_Check()(PyObject *op) {
    return PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op);
  }

  PyObject* PyWeakref_NewRef(PyObject* ob, PyObject* callback);
  PyObject* PyWeakref_NewProxy(PyObject* ob, PyObject* callback);
  Borrowed!PyObject* PyWeakref_GetObject(PyObject* _ref);

  version(Python_2_5_Or_Later){
      Py_ssize_t _PyWeakref_GetWeakrefCount(PyWeakReference* head);
  }else{
      C_long _PyWeakref_GetWeakrefCount(PyWeakReference *head);
  }
  void _PyWeakref_ClearRef(PyWeakReference *self);

  Borrowed!PyObject* PyWeakref_GET_OBJECT()(PyObject* _ref) {
    return (cast(PyWeakReference *) _ref).wr_object;
  }


///////////////////////////////////////////////////////////////////////////////
// CODEC REGISTRY AND SUPPORT INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/codecs.h:

  int PyCodec_Register(PyObject *search_function);
  PyObject * _PyCodec_Lookup(const(char)*encoding);
  PyObject * PyCodec_Encode(PyObject *object, const(char)*encoding, const(char)*errors);
  PyObject * PyCodec_Decode(PyObject *object, const(char)*encoding, const(char)*errors);
  PyObject * PyCodec_Encoder(const(char)*encoding);
  PyObject * PyCodec_Decoder(const(char) *encoding);
  PyObject * PyCodec_StreamReader(const(char) *encoding, PyObject *stream, const(char) *errors);
  PyObject * PyCodec_StreamWriter(const(char) *encoding, PyObject *stream, const(char) *errors);

  /////////////////////////////////////////////////////////////////////////////
  // UNICODE ENCODING INTERFACE
  /////////////////////////////////////////////////////////////////////////////

  int PyCodec_RegisterError(const(char) *name, PyObject *error);
  PyObject * PyCodec_LookupError(const(char) *name);
  PyObject * PyCodec_StrictErrors(PyObject *exc);
  PyObject * PyCodec_IgnoreErrors(PyObject *exc);
  PyObject * PyCodec_ReplaceErrors(PyObject *exc);
  PyObject * PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
  PyObject * PyCodec_BackslashReplaceErrors(PyObject *exc);


///////////////////////////////////////////////////////////////////////////////
// ERROR HANDLING INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/pyerrors.h:

  version(Python_2_5_Or_Later){
  /* Error objects */

  struct PyBaseExceptionObject {
      mixin PyObject_HEAD;
      PyObject *dict;
      PyObject *args;
      PyObject *message;
  }

  struct PySyntaxErrorObject {
      mixin PyObject_HEAD;
      PyObject *dict;
      PyObject *args;
      PyObject *message;
      PyObject *msg;
      PyObject *filename;
      PyObject *lineno;
      PyObject *offset;
      PyObject *text;
      PyObject *print_file_and_line;
  }

  struct PyUnicodeErrorObject {
      mixin PyObject_HEAD;
      PyObject *dict;
      PyObject *args;
      PyObject *message;
      PyObject *encoding;
      PyObject *object;
      version(Python_2_6_Or_Later){
          Py_ssize_t start;
          Py_ssize_t end;
      }else{
          PyObject *start;
          PyObject *end;
      }
      PyObject *reason;
  }

  struct PySystemExitObject {
      mixin PyObject_HEAD;
      PyObject *dict;
      PyObject *args;
      PyObject *message;
      PyObject *code;
  }

  struct PyEnvironmentErrorObject {
      mixin PyObject_HEAD;
      PyObject *dict;
      PyObject *args;
      PyObject *message;
      PyObject *myerrno;
      PyObject *strerror;
      PyObject *filename;
  }

  version(Windows) {
    struct PyWindowsErrorObject {
        mixin PyObject_HEAD;
        PyObject *dict;
        PyObject *args;
        PyObject *message;
        PyObject *myerrno;
        PyObject *strerror;
        PyObject *filename;
        PyObject *winerror;
    }
  }
  }

  void PyErr_SetNone(PyObject *);
  void PyErr_SetObject(PyObject *, PyObject *);
  void PyErr_SetString(PyObject *, const(char) *);
  PyObject * PyErr_Occurred();
  void PyErr_Clear();
  void PyErr_Fetch(PyObject **, PyObject **, PyObject **);
  void PyErr_Restore(PyObject *, PyObject *, PyObject *);

  int PyErr_GivenExceptionMatches(PyObject *, PyObject *);
  int PyErr_ExceptionMatches(PyObject *);
  void PyErr_NormalizeException(PyObject **, PyObject **, PyObject **);

  // All predefined Python exception types are dealt with in the global
  // variables section toward the end of this file.

  int PyErr_BadArgument();
  PyObject * PyErr_NoMemory();
  PyObject * PyErr_SetFromErrno(PyObject *);
  PyObject * PyErr_SetFromErrnoWithFilenameObject(PyObject *, PyObject *);
  PyObject * PyErr_SetFromErrnoWithFilename(PyObject *, char *);
  PyObject * PyErr_SetFromErrnoWithUnicodeFilename(PyObject *, Py_UNICODE *);

  PyObject * PyErr_Format(PyObject *, const(char) *, ...);

  version (Windows) {
    PyObject * PyErr_SetFromWindowsErrWithFilenameObject(int,  const(char) *);
    PyObject * PyErr_SetFromWindowsErrWithFilename(int, const(char) *);
    PyObject * PyErr_SetFromWindowsErrWithUnicodeFilename(int, Py_UNICODE *);
    PyObject * PyErr_SetFromWindowsErr(int);
    PyObject * PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *, int, PyObject *);
    PyObject * PyErr_SetExcFromWindowsErrWithFilename(PyObject *, int,  const(char) *);
    PyObject * PyErr_SetExcFromWindowsErrWithUnicodeFilename(PyObject *, int, Py_UNICODE *);
    PyObject * PyErr_SetExcFromWindowsErr(PyObject *, int);
  }

  // PyErr_BadInternalCall and friends purposely omitted.

  PyObject * PyErr_NewException(char *name, PyObject *base, PyObject *dict);
  void PyErr_WriteUnraisable(PyObject *);

  version(Python_2_5_Or_Later){
      int PyErr_WarnEx(PyObject*, char*, Py_ssize_t);
  }else{
      int PyErr_Warn(PyObject *, char *);
  }
  int PyErr_WarnExplicit(PyObject *, const(char) *, const(char) *, int, const(char) *, PyObject *);

  int PyErr_CheckSignals();
  void PyErr_SetInterrupt();

  void PyErr_SyntaxLocation(const(char) *, int);
  PyObject * PyErr_ProgramText(const(char) *, int);

  /////////////////////////////////////////////////////////////////////////////
  // UNICODE ENCODING ERROR HANDLING INTERFACE
  /////////////////////////////////////////////////////////////////////////////
  PyObject *PyUnicodeDecodeError_Create(const(char) *, const(char) *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const(char) *);

  PyObject *PyUnicodeEncodeError_Create(const(char) *, Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const(char) *);

  PyObject *PyUnicodeTranslateError_Create(Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const(char) *);

  PyObject *PyUnicodeEncodeError_GetEncoding(PyObject *);
  PyObject *PyUnicodeDecodeError_GetEncoding(PyObject *);

  PyObject *PyUnicodeEncodeError_GetObject(PyObject *);
  PyObject *PyUnicodeDecodeError_GetObject(PyObject *);
  PyObject *PyUnicodeTranslateError_GetObject(PyObject *);

  int PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
  int PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
  int PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);

  int PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
  int PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
  int PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);

  int PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
  int PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
  int PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);

  int PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
  int PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
  int PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);

  PyObject *PyUnicodeEncodeError_GetReason(PyObject *);
  PyObject *PyUnicodeDecodeError_GetReason(PyObject *);
  PyObject *PyUnicodeTranslateError_GetReason(PyObject *);

  int PyUnicodeEncodeError_SetReason(PyObject *, const(char) *);
  int PyUnicodeDecodeError_SetReason(PyObject *, const(char) *);
  int PyUnicodeTranslateError_SetReason(PyObject *, const(char) *);

  int PyOS_snprintf(char *str, size_t size, const(char) *format, ...);
  int PyOS_vsnprintf(char *str, size_t size, const(char) *format, va_list va);


///////////////////////////////////////////////////////////////////////////////
// BYTECODE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/code.h:

  struct PyCodeObject { /* Bytecode object */
    mixin PyObject_HEAD;

    int co_argcount;
    int co_nlocals;
    int co_stacksize;
    int co_flags;
    PyObject *co_code;
    PyObject *co_consts;
    PyObject *co_names;
    PyObject *co_varnames;
    PyObject *co_freevars;
    PyObject *co_cellvars;

    PyObject *co_filename;
    PyObject *co_name;
    int co_firstlineno;
    PyObject *co_lnotab;
    version(Python_2_5_Or_Later){
        void *co_zombieframe;
    }

  }

  /* Masks for co_flags above */
  enum int CO_OPTIMIZED   = 0x0001;
  enum int CO_NEWLOCALS   = 0x0002;
  enum int CO_VARARGS     = 0x0004;
  enum int CO_VARKEYWORDS = 0x0008;
  enum int CO_NESTED      = 0x0010;
  enum int CO_GENERATOR   = 0x0020;
  enum int CO_NOFREE      = 0x0040;

  version(Python_2_5_Or_Later){
      // Removed in 2.5
  }else{
      enum int CO_GENERATOR_ALLOWED      = 0x1000;
  }
  enum int CO_FUTURE_DIVISION        = 0x2000;
  version(Python_2_5_Or_Later){
      enum int CO_FUTURE_ABSOLUTE_IMPORT = 0x4000;
      enum int CO_FUTURE_WITH_STATEMENT  = 0x8000;
      enum int CO_FUTURE_PRINT_FUNCTION  = 0x10000;
      enum int CO_FUTURE_UNICODE_LITERALS  = 0x20000;
  }

  enum int CO_MAXBLOCKS = 20;

  // &PyCode_Type is accessible via PyCode_Type_p.
  // D translations of C macros:
  int PyCode_Check()(PyObject *op) {
    return op.ob_type == PyCode_Type_p;
  }
  size_t PyCode_GetNumFree()(PyObject *op) {
    return PyObject_Length((cast(PyCodeObject *) op).co_freevars);
  }

  PyCodeObject *PyCode_New(
    int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,
    PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *);
  int PyCode_Addr2Line(PyCodeObject *, int);

  struct PyAddrPair {
    int ap_lower;
    int ap_upper;
  }

  int PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds);
  version(Python_2_6_Or_Later){
      PyObject* PyCode_Optimize(PyObject *code, PyObject* consts,
                                      PyObject *names, PyObject *lineno_obj);
  }

  // Python-header-file: Include/pyarena.h:
  struct PyArena;

  version(Python_2_5_Or_Later){
      PyArena* PyArena_New();
      void PyArena_Free(PyArena*);

      void* PyArena_Malloc(PyArena*, size_t);
      int PyArena_AddPyObject(PyArena*, PyObject*);
  }

///////////////////////////////////////////////////////////////////////////////
// COMPILATION INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/node.h
  struct node {
    short	n_type;
    char	*n_str;
    int		n_lineno;
    version(Python_2_5_Or_Later){
    int		n_col_offset;
    }
    int		n_nchildren;
    node	*n_child;
  }
  node * PyNode_New(int type);
  int PyNode_AddChild(node *n, int type,
        char *str, int lineno, int col_offset);
  void PyNode_Free(node *n);
  void PyNode_ListTree(node *);

  // Python-header-file: Include/compile.h:
  PyCodeObject *PyNode_Compile(node *, const(char) *);

  struct PyFutureFeatures {
      version(Python_2_5_Or_Later){
      }else{
          int ff_found_docstring;
          int ff_last_linno;
      }
    int ff_features;
    version(Python_2_5_Or_Later){
        int ff_lineno;
    }
  }

  version(Python_2_5_Or_Later){
  }else{
      PyFutureFeatures *PyNode_Future(node *, const(char) *);
      PyCodeObject *PyNode_CompileFlags(node *, const(char) *, PyCompilerFlags *);
  }

  enum FUTURE_NESTED_SCOPES = "nested_scopes";
  enum FUTURE_GENERATORS = "generators";
  enum FUTURE_DIVISION = "division";
  version(Python_2_5_Or_Later){
      enum FUTURE_ABSOLUTE_IMPORT = "absolute_import";
      enum FUTURE_WITH_STATEMENT = "with_statement";
      version(Python_2_6_Or_Later){
          enum FUTURE_PRINT_FUNCTION = "print_function";
          enum FUTURE_UNICODE_LITERALS = "unicode_literals";
      }

      struct _mod; /* Declare the existence of this type */
      PyCodeObject * PyAST_Compile(_mod *, const(char) *, PyCompilerFlags *, PyArena *);
      PyFutureFeatures * PyFuture_FromAST(_mod *, const(char) *);

      // Python-header-file: Include/ast.h
      _mod* PyAST_FromNode(node*, PyCompilerFlags*, const(char)*, PyArena*);
  }


///////////////////////////////////////////////////////////////////////////////
// CODE EXECUTION INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/pythonrun.h:

  struct PyCompilerFlags {
    int cf_flags;
  }

  void Py_SetProgramName(char *);
  char *Py_GetProgramName();

  void Py_SetPythonHome(char *);
  char *Py_GetPythonHome();

  void Py_Initialize();
  void Py_InitializeEx(int);
  void Py_Finalize();
  int Py_IsInitialized();
  PyThreadState *Py_NewInterpreter();
  void Py_EndInterpreter(PyThreadState *);

  version(Python_2_5_Or_Later){
      int PyRun_AnyFile()(FILE *fp, const(char) *name) {
          return PyRun_AnyFileExFlags(fp, name, 0, null);
      }
      int PyRun_AnyFileEx()(FILE *fp, const(char) *name, int closeit) {
          return PyRun_AnyFileExFlags(fp, name, closeit, null);
      }
      int PyRun_AnyFileFlags()(FILE *fp, const(char) *name, PyCompilerFlags *flags) {
          return PyRun_AnyFileExFlags(fp, name, 0, flags);
      }
      int PyRun_SimpleString()(const(char) *s) {
          return PyRun_SimpleStringFlags(s, null);
      }
      int PyRun_SimpleFile()(FILE *f, const(char) *p) {
          return PyRun_SimpleFileExFlags(f, p, 0, null);
      }
      int PyRun_SimpleFileEx()(FILE *f, const(char) *p, int c) {
          return PyRun_SimpleFileExFlags(f, p, c, null);
      }
      int PyRun_InteractiveOne()(FILE *f, const(char) *p) {
          return PyRun_InteractiveOneFlags(f, p, null);
      }
      int PyRun_InteractiveLoop()(FILE *f, const(char) *p) {
          return PyRun_InteractiveLoopFlags(f, p, null);
      }
  }else{
      int PyRun_AnyFile(FILE *, const(char) *);
      int PyRun_AnyFileEx(FILE *, const(char) *,int);

      int PyRun_AnyFileFlags(FILE *, const(char) *, PyCompilerFlags *);
      int PyRun_SimpleString(const(char) *);
      int PyRun_SimpleFile(FILE *, const(char) *);
      int PyRun_SimpleFileEx(FILE *, const(char) *, int);
      int PyRun_InteractiveOne(FILE *, const(char) *);
      int PyRun_InteractiveLoop(FILE *, const(char) *);
  }

  int PyRun_AnyFileExFlags(FILE *, const(char) *, int, PyCompilerFlags *);

  int PyRun_SimpleStringFlags(const(char) *, PyCompilerFlags *);

  int PyRun_SimpleFileExFlags(FILE *,  const(char) *, int, PyCompilerFlags *);

  int PyRun_InteractiveOneFlags(FILE *, const(char) *, PyCompilerFlags *);
  int PyRun_InteractiveLoopFlags(FILE *, const(char) *, PyCompilerFlags *);

  version(Python_2_5_Or_Later){
      _mod* PyParser_ASTFromString(const(char) *, const(char) *, 
              int, PyCompilerFlags *, PyArena *);
      _mod* PyParser_ASTFromFile(FILE *, const(char) *, int, 
              char *, char *, PyCompilerFlags *, int *, PyArena *);
      node *PyParser_SimpleParseString()(const(char) *s, int b) {
          return PyParser_SimpleParseStringFlags(s, b, 0);
      }
      node *PyParser_SimpleParseFile()(FILE *f, const(char) *s, int b) {
          return PyParser_SimpleParseFileFlags(f, s, b, 0);
      }
  }else{
      node *PyParser_SimpleParseString(const(char) *, int);
      node *PyParser_SimpleParseFile(FILE *, const(char) *, int);
      node *PyParser_SimpleParseStringFlagsFilename(const(char) *, const(char) *, int, int);
  }

  node *PyParser_SimpleParseStringFlags(const(char) *, int, int);
  node *PyParser_SimpleParseFileFlags(FILE *, const(char) *,int, int);

  PyObject *PyRun_StringFlags( const(char) *, int, PyObject *, PyObject *, PyCompilerFlags *);
  version(Python_2_5_Or_Later){
      PyObject *PyRun_String()(const(char) *str, int s, PyObject *g, PyObject *l) {
          return PyRun_StringFlags(str, s, g, l, null);
      }
      PyObject *PyRun_File()(FILE *fp, const(char) *p, int s, PyObject *g, PyObject *l) {
          return PyRun_FileExFlags(fp, p, s, g, l, 0, null);
      }
      PyObject *PyRun_FileEx()(FILE *fp, const(char) *p, int s, PyObject *g, PyObject *l, int c) {
          return PyRun_FileExFlags(fp, p, s, g, l, c, null);
      }
      PyObject *PyRun_FileFlags()(FILE *fp, const(char) *p, int s, PyObject *g, 
              PyObject *l, PyCompilerFlags *flags) {
          return PyRun_FileExFlags(fp, p, s, g, l, 0, flags);
      }
      PyObject *Py_CompileString()(const(char) *str, const(char) *p, int s) {
          return Py_CompileStringFlags(str, p, s, null);
      }
  }else{
      PyObject *PyRun_String(const(char) *, int, PyObject *, PyObject *);
      PyObject *PyRun_File(FILE *, const(char) *, int, PyObject *, PyObject *);
      PyObject *PyRun_FileEx(FILE *, const(char) *, int, PyObject *, PyObject *, int);
      PyObject *PyRun_FileFlags(FILE *, const(char) *, int, PyObject *, PyObject *, 
              PyCompilerFlags *);
      PyObject *Py_CompileString(const(char) *, const(char) *, int);
  }

  PyObject *PyRun_FileExFlags(FILE *, const(char) *, int, PyObject *, PyObject *, int, PyCompilerFlags *);

  PyObject *Py_CompileStringFlags(const(char) *, const(char) *, int, PyCompilerFlags *);
  // Py_SymtableString is undocumented, so it's omitted here.

  void PyErr_Print();
  void PyErr_PrintEx(int);
  void PyErr_Display(PyObject *, PyObject *, PyObject *);

  int Py_AtExit(void function() func);

  void Py_Exit(int);

  int Py_FdIsInteractive(FILE *, const(char) *);

///////////////////////////////////////////////////////////////////////////////
// BOOTSTRAPPING INTERFACE (for embedding Python in D)
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/pythonrun.h:

  int Py_Main(int argc, char **argv);

  char *Py_GetProgramFullPath();
  char *Py_GetPrefix();
  char *Py_GetExecPrefix();
  char *Py_GetPath();

  const(char) *Py_GetVersion();
  const(char) *Py_GetPlatform();
  const(char) *Py_GetCopyright();
  const(char) *Py_GetCompiler();
  const(char) *Py_GetBuildInfo();
  version(Python_2_5_Or_Later){
      const(char) * _Py_svnversion();
      const(char) * Py_SubversionRevision();
      const(char) * Py_SubversionShortBranch();
  }

  version(Python_2_6_Or_Later){
      int PyByteArray_Init();
  }

  /////////////////////////////////////////////////////////////////////////////
  // ONE-TIME INITIALIZERS
  /////////////////////////////////////////////////////////////////////////////

  PyObject *_PyBuiltin_Init();
  PyObject *_PySys_Init();
  void _PyImport_Init();
  void _PyExc_Init();
  void _PyImportHooks_Init();
  int _PyFrame_Init();
  int _PyInt_Init();

  /////////////////////////////////////////////////////////////////////////////
  // FINALIZERS
  /////////////////////////////////////////////////////////////////////////////

  void _PyExc_Fini();
  void _PyImport_Fini();
  void PyMethod_Fini();
  void PyFrame_Fini();
  void PyCFunction_Fini();
  version(Python_2_6_Or_Later){
      void PyDict_Fini();
  }
  void PyTuple_Fini();
  void PyString_Fini();
  void PyInt_Fini();
  void PyFloat_Fini();
  void PyOS_FiniInterrupts();
  version(Python_2_6_Or_Later){
      void PyByteArray_Fini();
  }

  /////////////////////////////////////////////////////////////////////////////
  // VARIOUS (API members documented as having "no proper home")
  /////////////////////////////////////////////////////////////////////////////
  char *PyOS_Readline(FILE *, FILE *, char *);
  __gshared int function() PyOS_InputHook;
  __gshared char* function(FILE *, FILE *, char *) PyOS_ReadlineFunctionPointer;
  // _PyOS_ReadlineTState omitted.
  enum PYOS_STACK_MARGIN = 2048;
  // PyOS_CheckStack omitted.

  /////////////////////////////////////////////////////////////////////////////
  // SIGNALS
  /////////////////////////////////////////////////////////////////////////////

  alias void function(int) PyOS_sighandler_t;
  PyOS_sighandler_t PyOS_getsig(int);
  PyOS_sighandler_t PyOS_setsig(int, PyOS_sighandler_t);


///////////////////////////////////////////////////////////////////////////////
// EVAL CALLS (documented as "Interface to random parts in ceval.c")
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/ceval.h:
  PyObject *PyEval_CallObjectWithKeywords(PyObject *, PyObject *, PyObject *);
  version(Python_2_5_Or_Later){
      PyObject *PyEval_CallObject()(PyObject *func, PyObject *arg) {
          return PyEval_CallObjectWithKeywords(func, arg, null);
      }
  }else{
      PyObject *PyEval_CallObject(PyObject *, PyObject *);
  }
  PyObject *PyEval_CallFunction(PyObject *obj, Char1 *format, ...);
  PyObject *PyEval_CallMethod(PyObject *obj, Char1 *methodname, Char1 *format, ...);

  void PyEval_SetProfile(Py_tracefunc, PyObject *);
  void PyEval_SetTrace(Py_tracefunc, PyObject *);

  Borrowed!PyObject* PyEval_GetBuiltins();
  Borrowed!PyObject* PyEval_GetGlobals();
  Borrowed!PyObject* PyEval_GetLocals();
  Borrowed!PyFrameObject* PyEval_GetFrame();
  int PyEval_GetRestricted();

  int PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
  int Py_FlushLine();
  int Py_AddPendingCall(int function(void *) func, void *arg);
  int Py_MakePendingCalls();

  void Py_SetRecursionLimit(int);
  int Py_GetRecursionLimit();

  // The following API members are undocumented, so they're omitted here:
    // Py_EnterRecursiveCall
    // Py_LeaveRecursiveCall
    // _Py_CheckRecursiveCall
    // _Py_CheckRecursionLimit
    // _Py_MakeRecCheck

  Char1 *PyEval_GetFuncName(PyObject *);
  Char1 *PyEval_GetFuncDesc(PyObject *);

  PyObject *PyEval_GetCallStats(PyObject *);
  PyObject *PyEval_EvalFrame(PyFrameObject *);
  version(Python_2_5_Or_Later){
      PyObject *PyEval_EvalFrameEx(PyFrameObject *, int);
  }


///////////////////////////////////////////////////////////////////////////////
// SYSTEM MODULE INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/sysmodule.h:

  PyObject *PySys_GetObject(char *);
  int PySys_SetObject(char *, PyObject *);
  FILE *PySys_GetFile(char *, FILE *);
  void PySys_SetArgv(int, char **);
  version(Python_2_6_Or_Later){
      void PySys_SetArgvEx(int, char **, int);
  }
  void PySys_SetPath(char *);

  void PySys_WriteStdout(const(char) *format, ...);
  void PySys_WriteStderr(const(char) *format, ...);

  void PySys_ResetWarnOptions();
  void PySys_AddWarnOption(char *);
  version(Python_2_6_Or_Later){
      int PySys_HasWarnOptions();
  }


///////////////////////////////////////////////////////////////////////////////
// INTERRUPT INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/intrcheck.h:

  int PyOS_InterruptOccurred();
  void PyOS_InitInterrupts();
  void PyOS_AfterFork();


///////////////////////////////////////////////////////////////////////////////
// FRAME INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/frameobject.h:

  struct PyTryBlock {
    int b_type;
    int b_handler;
    int b_level;
  }

  struct PyFrameObject {
    mixin PyObject_VAR_HEAD;

    PyFrameObject *f_back;
    PyCodeObject *f_code;
    PyObject *f_builtins;
    PyObject *f_globals;
    PyObject *f_locals;
    PyObject **f_valuestack;
    PyObject **f_stacktop;
    PyObject *f_trace;
    PyObject *f_exc_type;
    PyObject *f_exc_value;
    PyObject *f_exc_traceback;
    PyThreadState *f_tstate;
    int f_lasti;
    int f_lineno;
    version(Python_2_5_Or_Later){
    }else{
        int f_restricted;
    }
    int f_iblock;
    PyTryBlock f_blockstack[CO_MAXBLOCKS];
    version(Python_2_5_Or_Later){
    }else{
        int f_nlocals;
        int f_ncells;
        int f_nfreevars;
        int f_stacksize;
    }
    PyObject *_f_localsplus[1];
    PyObject** f_localsplus()() {
      return _f_localsplus.ptr;
    }
  }

  // &PyFrame_Type is accessible via PyFrame_Type_p.
  // D translation of C macro:
  int PyFrame_Check()(PyObject *op) {
    return op.ob_type == PyFrame_Type_p;
  }
  version(Python_2_5_Or_Later){
      int PyFrame_IsRestricted()(PyFrameObject* f) {
          return f.f_builtins != f.f_tstate.interp.builtins;
      }
  }

  PyFrameObject *PyFrame_New(PyThreadState *, PyCodeObject *,
                             PyObject *, PyObject *);

  void PyFrame_BlockSetup(PyFrameObject *, int, int, int);
  PyTryBlock *PyFrame_BlockPop(PyFrameObject *);
  PyObject **PyFrame_ExtendStack(PyFrameObject *, int, int);

  void PyFrame_LocalsToFast(PyFrameObject *, int);
  void PyFrame_FastToLocals(PyFrameObject *);
  version(Python_2_6_Or_Later){
      int PyFrame_ClearFreeList();
  }


///////////////////////////////////////////////////////////////////////////////
// INTERPRETER STATE AND THREAD STATE INTERFACES
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/pystate.h:

  struct PyInterpreterState {
    PyInterpreterState *next;
    PyThreadState *tstate_head;

    PyObject *modules;
    PyObject *sysdict;
    PyObject *builtins;

    PyObject *codec_search_path;
    PyObject *codec_search_cache;
    PyObject *codec_error_registry;

    int dlopenflags;

    // XXX: Not sure what WITH_TSC refers to, or how to conditionalize it in D:
    //#ifdef WITH_TSC
    //  int tscdump;
    //#endif
  }

  alias int function(PyObject *, PyFrameObject *, int, PyObject *) Py_tracefunc;

  enum PyTrace_CALL   	= 0;
  enum PyTrace_EXCEPTION = 1;
  enum PyTrace_LINE 		= 2;
  enum PyTrace_RETURN 	= 3;
  enum PyTrace_C_CALL = 4;
  enum PyTrace_C_EXCEPTION = 5;
  enum PyTrace_C_RETURN = 6;

  struct PyThreadState {
    PyThreadState *next;
    PyInterpreterState *interp;

    PyFrameObject *frame;
    int recursion_depth;
    int tracing;
    int use_tracing;

    Py_tracefunc c_profilefunc;
    Py_tracefunc c_tracefunc;
    PyObject *c_profileobj;
    PyObject *c_traceobj;

    PyObject *curexc_type;
    PyObject *curexc_value;
    PyObject *curexc_traceback;

    PyObject *exc_type;
    PyObject *exc_value;
    PyObject *exc_traceback;

    PyObject *dict;

    int tick_counter;
    int gilstate_counter;

    PyObject *async_exc;
    C_long thread_id;
  }

  PyInterpreterState *PyInterpreterState_New();
  void PyInterpreterState_Clear(PyInterpreterState *);
  void PyInterpreterState_Delete(PyInterpreterState *);

  PyThreadState *PyThreadState_New(PyInterpreterState *);
  version(Python_2_6_Or_Later){
      PyThreadState * _PyThreadState_Prealloc(PyInterpreterState *);
      void _PyThreadState_Init(PyThreadState *);
  }
  void PyThreadState_Clear(PyThreadState *);
  void PyThreadState_Delete(PyThreadState *);
  void PyThreadState_DeleteCurrent();

  PyThreadState* PyThreadState_Get();
  PyThreadState* PyThreadState_Swap(PyThreadState *);
  Borrowed!PyObject* PyThreadState_GetDict();
  int PyThreadState_SetAsyncExc(C_long, PyObject *);

  enum PyGILState_STATE {PyGILState_LOCKED, PyGILState_UNLOCKED};

  PyGILState_STATE PyGILState_Ensure();
  void PyGILState_Release(PyGILState_STATE);
  PyThreadState *PyGILState_GetThisThreadState();
  PyInterpreterState *PyInterpreterState_Head();
  PyInterpreterState *PyInterpreterState_Next(PyInterpreterState *);
  PyThreadState *PyInterpreterState_ThreadHead(PyInterpreterState *);
  PyThreadState *PyThreadState_Next(PyThreadState *);

  alias PyFrameObject* function(PyThreadState *self_) PyThreadFrameGetter;

  // Python-header-file: Include/ceval.h:
  PyThreadState *PyEval_SaveThread();
  void PyEval_RestoreThread(PyThreadState *);

  int PyEval_ThreadsInitialized();
  void PyEval_InitThreads();
  void PyEval_AcquireLock();
  void PyEval_ReleaseLock();
  void PyEval_AcquireThread(PyThreadState *tstate);
  void PyEval_ReleaseThread(PyThreadState *tstate);
  void PyEval_ReInitThreads();

  // YYY: The following macros need to be implemented somehow, but DSR doesn't
  // think D's mixin feature is up to the job.
  // Py_BEGIN_ALLOW_THREADS
  // Py_BLOCK_THREADS
  // Py_UNBLOCK_THREADS
  // Py_END_ALLOW_THREADS


///////////////////////////////////////////////////////////////////////////////
// MODULE IMPORT INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/import.h:

  C_long PyImport_GetMagicNumber();
  PyObject *PyImport_ExecCodeModule(char *name, PyObject *co);
  PyObject *PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname);
  PyObject *PyImport_GetModuleDict();
  PyObject *PyImport_AddModule(Char1 *name);
  PyObject *PyImport_ImportModule(Char1 *name);

  version(Python_2_5_Or_Later){
      PyObject *PyImport_ImportModuleLevel(char *name,
              PyObject *globals, PyObject *locals, PyObject *fromlist, 
              int level);
  }
  version(Python_2_6_Or_Later){
      PyObject * PyImport_ImportModuleNoBlock(const(char)*);
  }else version(Python_2_5_Or_Later){
      PyObject *PyImport_ImportModuleEx()(char *n, PyObject *g, PyObject *l, 
              PyObject *f) {
          return PyImport_ImportModuleLevel(n, g, l, f, -1);
      }
  }else{
      PyObject *PyImport_ImportModuleEx(char *, PyObject *, PyObject *, PyObject *);
  }

  version(Python_2_6_Or_Later){
      PyObject * PyImport_GetImporter(PyObject *path);
  }
  PyObject *PyImport_Import(PyObject *name);
  PyObject *PyImport_ReloadModule(PyObject *m);
  void PyImport_Cleanup();
  int PyImport_ImportFrozenModule(char *);

  // The following API members are undocumented, so they're omitted here:
    // _PyImport_FindModule
    // _PyImport_IsScript
    // _PyImport_ReInitLock

  PyObject *_PyImport_FindExtension(char *, char *);
  PyObject *_PyImport_FixupExtension(char *, char *);

  struct _inittab {
    char *name;
    void function() initfunc;
  }

  // PyNullImporter_Type not available in d
  // PyImport_Inittab not available in d

  version(Python_2_7_Or_Later){
      alias const(char) Char2;
  }else{
      alias char Char2;
  }

  int PyImport_AppendInittab(Char2 *name, void function() initfunc);
  int PyImport_ExtendInittab(_inittab *newtab);

  struct _frozen {
    char *name;
    ubyte *code;
    int size;
  }

  // Omitted:
    // PyImport_FrozenModules


///////////////////////////////////////////////////////////////////////////////
// ABSTRACT OBJECT INTERFACE
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/abstract.h:

  // D translations of C macros:
  int PyObject_DelAttrString()(PyObject *o, Char1 *a) {
    return PyObject_SetAttrString(o, a, null);
  }
  int PyObject_DelAttr()(PyObject *o, PyObject *a) {
    return PyObject_SetAttr(o, a, null);
  }

  int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);

  /////////////////////////////////////////////////////////////////////////////
  // CALLABLES
  /////////////////////////////////////////////////////////////////////////////
  int PyCallable_Check(PyObject *o);

  PyObject *PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw);
  PyObject *PyObject_CallObject(PyObject *callable_object, PyObject *args);
  version(Python_2_5_Or_Later){
  }else{
      PyObject *PyObject_CallFunction(PyObject *callable_object, char *format, ...);
      PyObject *PyObject_CallMethod(PyObject *o, char *m, char *format, ...);
  }
  PyObject *_PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...);
  PyObject *_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...);
  version(Python_2_5_Or_Later){
      alias _PyObject_CallFunction_SizeT PyObject_CallFunction;
      alias _PyObject_CallMethod_SizeT PyObject_CallMethod;
  }
  PyObject *PyObject_CallFunctionObjArgs(PyObject *callable, ...);
  PyObject *PyObject_CallMethodObjArgs(PyObject *o,PyObject *m, ...);

  /////////////////////////////////////////////////////////////////////////////
  // GENERIC
  /////////////////////////////////////////////////////////////////////////////
  PyObject *PyObject_Type(PyObject *o);

  /////////////////////////////////////////////////////////////////////////////
  // CONTAINERS
  /////////////////////////////////////////////////////////////////////////////

  Py_ssize_t PyObject_Size(PyObject *o);
  //int PyObject_Length(PyObject *o);
  alias PyObject_Size PyObject_Length;
  version(Python_2_6_Or_Later){
      Py_ssize_t _PyObject_LengthHint(PyObject*, Py_ssize_t);
  }else version(Python_2_5_Or_Later){
      Py_ssize_t _PyObject_LengthHint(PyObject*);
  }

  PyObject *PyObject_GetItem(PyObject *o, PyObject *key);
  int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
  int PyObject_DelItemString(PyObject *o, char *key);
  int PyObject_DelItem(PyObject *o, PyObject *key);

  int PyObject_AsCharBuffer(PyObject *obj, const(char) **buffer, Py_ssize_t *buffer_len);
  int PyObject_CheckReadBuffer(PyObject *obj);
  int PyObject_AsReadBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len);
  int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len);

  version(Python_2_6_Or_Later){
    /* new buffer API */

      int PyObject_CheckBuffer()(PyObject *obj){
          return (obj.ob_type.tp_as_buffer !is null) &&
              PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_NEWBUFFER) &&
              (obj.ob_type.tp_as_buffer.bf_getbuffer !is null);
      }

    /* Return 1 if the getbuffer function is available, otherwise
       return 0 */

     int PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
                                        int flags);

    /* This is a C-API version of the getbuffer function call.  It checks
       to make sure object has the required function pointer and issues the
       call.  Returns -1 and raises an error on failure and returns 0 on
       success
    */


     void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);

    /* Get the memory area pointed to by the indices for the buffer given.
       Note that view->ndim is the assumed size of indices
    */

     int PyBuffer_SizeFromFormat(const(char) *);

    /* Return the implied itemsize of the data-format area from a
       struct-style description */



     int PyBuffer_ToContiguous(void *buf, Py_buffer *view,
                                           Py_ssize_t len, char fort);

     int PyBuffer_FromContiguous(Py_buffer *view, void *buf,
                                             Py_ssize_t len, char fort);


    /* Copy len bytes of data from the contiguous chunk of memory
       pointed to by buf into the buffer exported by obj.  Return
       0 on success and return -1 and raise a PyBuffer_Error on
       error (i.e. the object does not have a buffer interface or
       it is not working).

       If fort is 'F' and the object is multi-dimensional,
       then the data will be copied into the array in
       Fortran-style (first dimension varies the fastest).  If
       fort is 'C', then the data will be copied into the array
       in C-style (last dimension varies the fastest).  If fort
       is 'A', then it does not matter and the copy will be made
       in whatever way is more efficient.

    */

     int PyObject_CopyData(PyObject *dest, PyObject *src);

    /* Copy the data from the src buffer to the buffer of destination
     */

     int PyBuffer_IsContiguous(Py_buffer *view, char fort);


     void PyBuffer_FillContiguousStrides(int ndims,
                                                    Py_ssize_t *shape,
                                                    Py_ssize_t *strides,
                                                    int itemsize,
                                                    char fort);

    /*  Fill the strides array with byte-strides of a contiguous
        (Fortran-style if fort is 'F' or C-style otherwise)
        array of the given shape with the given number of bytes
        per element.
    */

     int PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,
                                       Py_ssize_t len, int readonly,
                                       int flags);

    /* Fills in a buffer-info structure correctly for an exporter
       that can only share a contiguous chunk of memory of
       "unsigned bytes" of the given length. Returns 0 on success
       and -1 (with raising an error) on error.
     */

     void PyBuffer_Release(Py_buffer *view);

       /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.
    */

     PyObject* PyObject_Format(PyObject* obj,
                                            PyObject *format_spec);
       /*
     Takes an arbitrary object and returns the result of
     calling obj.__format__(format_spec).
       */

  }

  /////////////////////////////////////////////////////////////////////////////
  // ITERATORS
  /////////////////////////////////////////////////////////////////////////////
  PyObject *PyObject_GetIter(PyObject *);

  // D translation of C macro:
  int PyIter_Check()(PyObject *obj) {
    return PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_ITER)
        && obj.ob_type.tp_iternext != null;
  }

  PyObject *PyIter_Next(PyObject *);

  /////////////////////////////////////////////////////////////////////////////
  // NUMBERS
  /////////////////////////////////////////////////////////////////////////////

  int PyNumber_Check(PyObject *o);

  PyObject *PyNumber_Add(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Subtract(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Multiply(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Divide(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Remainder(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Divmod(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3);
  PyObject *PyNumber_Negative(PyObject *o);
  PyObject *PyNumber_Positive(PyObject *o);
  PyObject *PyNumber_Absolute(PyObject *o);
  PyObject *PyNumber_Invert(PyObject *o);
  PyObject *PyNumber_Lshift(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Rshift(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_And(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Xor(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_Or(PyObject *o1, PyObject *o2);

  version(Python_2_5_Or_Later){
      int PyIndex_Check()(PyObject* obj) {
          return obj.ob_type.tp_as_number !is null &&
              PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_INDEX) &&
              obj.ob_type.tp_as_number.nb_index !is null;
      }
      PyObject *PyNumber_Index(PyObject *o);
      Py_ssize_t PyNumber_AsSsize_t(PyObject* o, PyObject* exc);
  }
  version(Python_2_6_Or_Later){
       /*
     Returns the Integral instance converted to an int. The
     instance is expected to be int or long or have an __int__
     method. Steals integral's reference. error_format will be
     used to create the TypeError if integral isn't actually an
     Integral instance. error_format should be a format string
     that can accept a char* naming integral's type.
       */

     PyObject * _PyNumber_ConvertIntegralToInt(
         PyObject *integral,
         const(char)* error_format);
  }

  PyObject *PyNumber_Int(PyObject *o);
  PyObject *PyNumber_Long(PyObject *o);
  PyObject *PyNumber_Float(PyObject *o);

  PyObject *PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3);
  PyObject *PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
  PyObject *PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);

  version(Python_2_6_Or_Later){
     PyObject* PyNumber_ToBase(PyObject *n, int base);

       /*
     Returns the integer n converted to a string with a base, with a base
     marker of 0b, 0o or 0x prefixed if applicable.
     If n is not an int object, it is converted with PyNumber_Index first.
       */
  }

  /////////////////////////////////////////////////////////////////////////////
  // SEQUENCES
  /////////////////////////////////////////////////////////////////////////////

  int PySequence_Check(PyObject *o);
  Py_ssize_t PySequence_Size(PyObject *o);
  alias PySequence_Size PySequence_Length;

  PyObject *PySequence_Concat(PyObject *o1, PyObject *o2);
  PyObject *PySequence_Repeat(PyObject *o, Py_ssize_t count);
  PyObject *PySequence_GetItem(PyObject *o, Py_ssize_t i);
  PyObject *PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);

  int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
  int PySequence_DelItem(PyObject *o, Py_ssize_t i);
  int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v);
  int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);

  PyObject *PySequence_Tuple(PyObject *o);
  PyObject *PySequence_List(PyObject *o);

  PyObject *PySequence_Fast(PyObject *o,  const(char)* m);
  // D translations of C macros:
  Py_ssize_t PySequence_Fast_GET_SIZE()(PyObject *o) {
    return PyList_Check(o) ? cast(Py_ssize_t) PyList_GET_SIZE(o) :
        cast(Py_ssize_t) PyTuple_GET_SIZE(o);
  }
  PyObject *PySequence_Fast_GET_ITEM()(PyObject *o, Py_ssize_t i) {
    return PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i);
  }
  PyObject *PySequence_ITEM()(PyObject *o, Py_ssize_t i) {
    return o.ob_type.tp_as_sequence.sq_item(o, i);
  }
  PyObject **PySequence_Fast_ITEMS()(PyObject *sf) {
    return
        PyList_Check(sf) ?
            (cast(PyListObject *)sf).ob_item
          : (cast(PyTupleObject *)sf).ob_item
      ;
  }

  Py_ssize_t PySequence_Count(PyObject *o, PyObject *value);
  int PySequence_Contains(PyObject *seq, PyObject *ob);

  int PY_ITERSEARCH_COUNT    = 1;
  int PY_ITERSEARCH_INDEX    = 2;
  int PY_ITERSEARCH_CONTAINS = 3;

  Py_ssize_t _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation);
  //int PySequence_In(PyObject *o, PyObject *value);
  alias PySequence_Contains PySequence_In;
  Py_ssize_t PySequence_Index(PyObject *o, PyObject *value);

  PyObject * PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
  PyObject * PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);

  /////////////////////////////////////////////////////////////////////////////
  // MAPPINGS
  /////////////////////////////////////////////////////////////////////////////
  int PyMapping_Check(PyObject *o);
  Py_ssize_t PyMapping_Size(PyObject *o);
  //int PyMapping_Length(PyObject *o);
  alias PyMapping_Size PyMapping_Length;

  // D translations of C macros:
  int PyMapping_DelItemString()(PyObject *o, char *k) {
    return PyObject_DelItemString(o, k);
  }
  int PyMapping_DelItem()(PyObject *o, PyObject *k) {
    return PyObject_DelItem(o, k);
  }

  int PyMapping_HasKeyString(PyObject *o, char *key);
  int PyMapping_HasKey(PyObject *o, PyObject *key);

  // D translations of C macros:
  PyObject *PyMapping_Keys()(PyObject *o) {
    return PyObject_CallMethod(o, "keys".dup.ptr, null);
  }
  PyObject *PyMapping_Values()(PyObject *o) {
    return PyObject_CallMethod(o, "values".dup.ptr, null);
  }
  PyObject *PyMapping_Items()(PyObject *o) {
    return PyObject_CallMethod(o, "items".dup.ptr, null);
  }

  PyObject *PyMapping_GetItemString(PyObject *o, char *key);
  int PyMapping_SetItemString(PyObject *o, char *key, PyObject *value);

  /////////////////////////////////////////////////////////////////////////////
  // GENERIC
  /////////////////////////////////////////////////////////////////////////////
  int PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
  int PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);

  version(Python_2_6_Or_Later){
      int _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);

      int _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
  }


///////////////////////////////////////////////////////////////////////////////
// OBJECT CREATION AND GARBAGE COLLECTION
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/objimpl.h:

  void * PyObject_Malloc(size_t);
  void * PyObject_Realloc(void *, size_t);
  void PyObject_Free(void *);

  Borrowed!PyObject* PyObject_Init(PyObject*, PyTypeObject*);

  Borrowed!PyVarObject* PyObject_InitVar(PyVarObject*,
                           PyTypeObject *, Py_ssize_t);
  /* Without macros, DSR knows of no way to translate PyObject_New and
   * PyObject_NewVar to D; the lower-level _PyObject_New and _PyObject_NewVar
   * will have to suffice.
   * YYY: Perhaps D's mixins could be used?
   * KGM: Pfft, it's a simple template function. */
  PyObject * _PyObject_New(PyTypeObject *);
  PyVarObject * _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
  type* PyObject_New(type)(PyTypeObject* o) {
    return cast(type*)_PyObject_New(o);
  }
  type* PyObject_NewVar(type)(PyTypeObject* o, Py_ssize_t n) {
    return cast(type*)_PyObject_NewVar(o, n);
  }


  C_long PyGC_Collect();

  // D translations of C macros:
  int PyType_IS_GC()(PyTypeObject *t) {
    return PyType_HasFeature(t, Py_TPFLAGS_HAVE_GC);
  }
  int PyObject_IS_GC()(PyObject *o) {
    return PyType_IS_GC(o.ob_type)
        && (o.ob_type.tp_is_gc == null || o.ob_type.tp_is_gc(o));
  }
  PyVarObject *_PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
  // XXX: Can D mixins allows trans of PyObject_GC_Resize?
  // KGM: No, but template functions can.
  type* PyObject_GC_Resize(type) (PyVarObject *op, Py_ssize_t n) {
	return cast(type*)_PyObject_GC_Resize(op, n);
  }


  union PyGC_Head {
    struct gc {
      PyGC_Head *gc_next;
      PyGC_Head *gc_prev;
      Py_ssize_t gc_refs;
    }
    real dummy; // XXX: C type was long double; is this equiv?
  }

  // Numerous macro definitions that appear in objimpl.h at this point are not
  // document.  They appear to be for internal use, so they're omitted here.

  PyObject *_PyObject_GC_Malloc(size_t);
  PyObject *_PyObject_GC_New(PyTypeObject *);
  PyVarObject *_PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);
  void PyObject_GC_Track(void *);
  void PyObject_GC_UnTrack(void *);
  void PyObject_GC_Del(void *);

  // XXX: DSR currently knows of no way to translate the PyObject_GC_New and
  // PyObject_GC_NewVar macros to D.
  // KGM does, though.
  type* PyObject_GC_New(type) (PyTypeObject* o) {
    return cast(type*)_PyObject_GC_New(o);
  }
  type* PyObject_GC_NewVar(type) (PyTypeObject* o, Py_ssize_t n) {
    return cast(type*)_PyObject_GC_NewVar(o, n);
  }

  /////////////////////////////////////////////////////////////////////////////
  // MISCELANEOUS
  /////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/pydebug.h:
  void Py_FatalError(char *message);


///////////////////////////////////////////////////////////////////////////////
// cStringIO (Must be explicitly imported with PycString_IMPORT().)
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/cStringIO.h:

PycStringIO_CAPI *PycStringIO = null;

PycStringIO_CAPI *PycString_IMPORT()() {
  if (PycStringIO == null) {
    PycStringIO = cast(PycStringIO_CAPI *)
      PyCObject_Import("cStringIO".dup.ptr, "cStringIO_CAPI".dup.ptr);
  }
  return PycStringIO;
}

struct PycStringIO_CAPI {
  int function(PyObject *, char **, Py_ssize_t) cread;
  int function(PyObject *, char **) creadline;
  int function(PyObject *, Char1 *, Py_ssize_t) cwrite;
  PyObject* function(PyObject *) cgetvalue;
  PyObject* function(int) NewOutput;
  PyObject* function(PyObject *) NewInput;
  PyTypeObject *InputType;
  PyTypeObject *OutputType;
}

// D translations of C macros:
int PycStringIO_InputCheck()(PyObject *o) {
  return o.ob_type == PycStringIO.InputType;
}
int PycStringIO_OutputCheck()(PyObject *o) {
  return o.ob_type == PycStringIO.OutputType;
}


///////////////////////////////////////////////////////////////////////////////
// datetime (Must be explicitly imported with PycString_IMPORT().)
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/datetime.h:

enum _PyDateTime_DATE_DATASIZE = 4;
enum _PyDateTime_TIME_DATASIZE = 6;
enum _PyDateTime_DATETIME_DATASIZE = 10;

struct PyDateTime_Delta {
  mixin PyObject_HEAD;

  C_long hashcode;
  int days;
  int seconds;
  int microseconds;
}

struct PyDateTime_TZInfo {
  mixin PyObject_HEAD;
}

template _PyTZINFO_HEAD() {
  mixin PyObject_HEAD;
  C_long hashcode;
  ubyte hastzinfo;
}

struct _PyDateTime_BaseTZInfo {
  mixin _PyTZINFO_HEAD;
}

template _PyDateTime_TIMEHEAD() {
  mixin _PyTZINFO_HEAD;
  ubyte data[_PyDateTime_TIME_DATASIZE];
}

struct _PyDateTime_BaseTime {
  mixin _PyDateTime_TIMEHEAD;
}

struct PyDateTime_Time {
  mixin _PyDateTime_TIMEHEAD;
  PyObject *tzinfo;
}

struct PyDateTime_Date {
  mixin _PyTZINFO_HEAD;
  ubyte data[_PyDateTime_DATE_DATASIZE];
}

template _PyDateTime_DATETIMEHEAD() {
  mixin _PyTZINFO_HEAD;
  ubyte data[_PyDateTime_DATETIME_DATASIZE];
}

struct _PyDateTime_BaseDateTime {
  mixin _PyDateTime_DATETIMEHEAD;
}

struct PyDateTime_DateTime {
  mixin _PyDateTime_DATETIMEHEAD;
  PyObject *tzinfo;
}

// D translations of C macros:
int PyDateTime_GET_YEAR()(PyObject *o) {
  PyDateTime_Date *ot = cast(PyDateTime_Date *) o;
  return (ot.data[0] << 8) | ot.data[1];
}
int PyDateTime_GET_MONTH()(PyObject *o) {
  PyDateTime_Date *ot = cast(PyDateTime_Date *) o;
  return ot.data[2];
}
int PyDateTime_GET_DAY()(PyObject *o) {
  PyDateTime_Date *ot = cast(PyDateTime_Date *) o;
  return ot.data[3];
}

int PyDateTime_DATE_GET_HOUR()(PyObject *o) {
  PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
  return ot.data[4];
}
int PyDateTime_DATE_GET_MINUTE()(PyObject *o) {
  PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
  return ot.data[5];
}
int PyDateTime_DATE_GET_SECOND()(PyObject *o) {
  PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
  return ot.data[6];
}
int PyDateTime_DATE_GET_MICROSECOND()(PyObject *o) {
  PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
  return (ot.data[7] << 16) | (ot.data[8] << 8) | ot.data[9];
}

int PyDateTime_TIME_GET_HOUR()(PyObject *o) {
  PyDateTime_Time *ot = cast(PyDateTime_Time *) o;
  return ot.data[0];
}
int PyDateTime_TIME_GET_MINUTE()(PyObject *o) {
  PyDateTime_Time *ot = cast(PyDateTime_Time *) o;
  return ot.data[1];
}
int PyDateTime_TIME_GET_SECOND()(PyObject *o) {
  PyDateTime_Time *ot = cast(PyDateTime_Time *) o;
  return ot.data[2];
}
int PyDateTime_TIME_GET_MICROSECOND()(PyObject *o) {
  PyDateTime_Time *ot = cast(PyDateTime_Time *) o;
  return (ot.data[3] << 16) | (ot.data[4] << 8) | ot.data[5];
}

struct PyDateTime_CAPI {
  PyTypeObject *DateType;
  PyTypeObject *DateTimeType;
  PyTypeObject *TimeType;
  PyTypeObject *DeltaType;
  PyTypeObject *TZInfoType;

  PyObject* function(int, int, int, PyTypeObject*) Date_FromDate;
  PyObject* function(int, int, int, int, int, int, int,
          PyObject*, PyTypeObject*) DateTime_FromDateAndTime;
  PyObject* function(int, int, int, int, PyObject*, PyTypeObject*) Time_FromTime;
  PyObject* function(int, int, int, int, PyTypeObject*) Delta_FromDelta;

  PyObject* function(PyObject*, PyObject*, PyObject*) DateTime_FromTimestamp;
  PyObject* function(PyObject*, PyObject*) Date_FromTimestamp;
}

enum DATETIME_API_MAGIC = 0x414548d5;
PyDateTime_CAPI *PyDateTimeAPI;

PyDateTime_CAPI *PyDateTime_IMPORT()() {
  if (PyDateTimeAPI == null) {
    PyDateTimeAPI = cast(PyDateTime_CAPI *)
      PyCObject_Import("datetime".dup.ptr, "datetime_CAPI".dup.ptr);
  }
  return PyDateTimeAPI;
}

// D translations of C macros:
int PyDate_Check()(PyObject *op) {
  return PyObject_TypeCheck(op, PyDateTimeAPI.DateType);
}
int PyDate_CheckExact()(PyObject *op) {
  return op.ob_type == PyDateTimeAPI.DateType;
}
int PyDateTime_Check()(PyObject *op) {
  return PyObject_TypeCheck(op, PyDateTimeAPI.DateTimeType);
}
int PyDateTime_CheckExact()(PyObject *op) {
  return op.ob_type == PyDateTimeAPI.DateTimeType;
}
int PyTime_Check()(PyObject *op) {
  return PyObject_TypeCheck(op, PyDateTimeAPI.TimeType);
}
int PyTime_CheckExact()(PyObject *op) {
  return op.ob_type == PyDateTimeAPI.TimeType;
}
int PyDelta_Check()(PyObject *op) {
  return PyObject_TypeCheck(op, PyDateTimeAPI.DeltaType);
}
int PyDelta_CheckExact()(PyObject *op) {
  return op.ob_type == PyDateTimeAPI.DeltaType;
}
int PyTZInfo_Check()(PyObject *op) {
  return PyObject_TypeCheck(op, PyDateTimeAPI.TZInfoType);
}
int PyTZInfo_CheckExact()(PyObject *op) {
  return op.ob_type == PyDateTimeAPI.TZInfoType;
}

PyObject *PyDate_FromDate()(int year, int month, int day) {
  return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType);
}
PyObject *PyDateTime_FromDateAndTime()(int year, int month, int day, int hour, int min, int sec, int usec) {
  return PyDateTimeAPI.DateTime_FromDateAndTime(year, month, day, hour,
    min, sec, usec, Py_None, PyDateTimeAPI.DateTimeType);
}
PyObject *PyTime_FromTime()(int hour, int minute, int second, int usecond) {
  return PyDateTimeAPI.Time_FromTime(hour, minute, second, usecond,
    Py_None, PyDateTimeAPI.TimeType);
}
PyObject *PyDelta_FromDSU()(int days, int seconds, int useconds) {
  return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1,
    PyDateTimeAPI.DeltaType);
}
PyObject *PyDateTime_FromTimestamp()(PyObject *args) {
  return PyDateTimeAPI.DateTime_FromTimestamp(
    cast(PyObject*) (PyDateTimeAPI.DateTimeType), args, null);
}
PyObject *PyDate_FromTimestamp()(PyObject *args) {
  return PyDateTimeAPI.Date_FromTimestamp(
    cast(PyObject*) (PyDateTimeAPI.DateType), args);
}


///////////////////////////////////////////////////////////////////////////////
// Interface to execute compiled code
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/eval.h:
PyObject *PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *);
PyObject *PyEval_EvalCodeEx(
    PyCodeObject *co,
    PyObject *globals,
    PyObject *locals,
    PyObject **args, int argc,
    PyObject **kwds, int kwdc,
    PyObject **defs, int defc,
    PyObject *closure
  );
PyObject *_PyEval_CallTracing(PyObject *func, PyObject *args);


///////////////////////////////////////////////////////////////////////////////
// Generator object interface
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/genobject.h:
struct PyGenObject {
  mixin PyObject_HEAD;
  PyFrameObject *gi_frame;
  int gi_running;
  version(Python_2_6_Or_Later){
      /* The code object backing the generator */
      PyObject *gi_code;
  }
  PyObject *gi_weakreflist;
}

// &PyGen_Type is accessible via PyGen_Type_p.
// D translations of C macros:
int PyGen_Check()(PyObject *op) {
  return PyObject_TypeCheck(op, PyGen_Type_p);
}
int PyGen_CheckExact()(PyObject *op) {
  return op.ob_type == PyGen_Type_p;
}

PyObject *PyGen_New(PyFrameObject *);
int PyGen_NeedsFinalizing(PyGenObject *);


///////////////////////////////////////////////////////////////////////////////
// Interface for marshal.c
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/marshal.h:

version(Python_2_5_Or_Later){
    enum Py_MARSHAL_VERSION = 2;
} else version(Python_2_4_Or_Later){
    enum Py_MARSHAL_VERSION = 1;
}

void PyMarshal_WriteLongToFile(C_long, FILE *, int);
void PyMarshal_WriteObjectToFile(PyObject *, FILE *, int);
PyObject * PyMarshal_WriteObjectToString(PyObject *, int);

C_long PyMarshal_ReadLongFromFile(FILE *);
int PyMarshal_ReadShortFromFile(FILE *);
PyObject *PyMarshal_ReadObjectFromFile(FILE *);
PyObject *PyMarshal_ReadLastObjectFromFile(FILE *);
PyObject *PyMarshal_ReadObjectFromString(char *, Py_ssize_t);


///////////////////////////////////////////////////////////////////////////////
// Platform-independent wrappers around strod, etc (probably not needed in D)
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/pystrtod.h:

double PyOS_ascii_strtod(const(char) *str, char **ptr);
double PyOS_ascii_atof(const(char) *str);
char *PyOS_ascii_formatd(char *buffer, size_t buf_len, const(char) *format, double d);


///////////////////////////////////////////////////////////////////////////////
// INTERFACE TO THE STDLIB 'THREAD' MODULE
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/pythread.h:

alias void * PyThread_type_lock;
alias void * PyThread_type_sema;

void PyThread_init_thread();
C_long PyThread_start_new_thread(void function(void *), void *);
void PyThread_exit_thread();
void PyThread__PyThread_exit_thread();
C_long PyThread_get_thread_ident();

PyThread_type_lock PyThread_allocate_lock();
void PyThread_free_lock(PyThread_type_lock);
int PyThread_acquire_lock(PyThread_type_lock, int);
enum WAIT_LOCK = 1;
enum NOWAIT_LOCK = 0;
void PyThread_release_lock(PyThread_type_lock);

version(Python_2_5_Or_Later){
    size_t PyThread_get_stacksize();
    int PyThread_set_stacksize(size_t);
}

void PyThread_exit_prog(int);
void PyThread__PyThread_exit_prog(int);

int PyThread_create_key();
void PyThread_delete_key(int);
int PyThread_set_key_value(int, void *);
void *PyThread_get_key_value(int);
void PyThread_delete_key_value(int key);


///////////////////////////////////////////////////////////////////////////////
// SET INTERFACE (built-in types set and frozenset)
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/setobject.h:

version(Python_2_5_Or_Later){
    enum PySet_MINSIZE = 8;

    struct setentry {
        C_long hash;
        PyObject *key;
    }
}

struct PySetObject {
    mixin PyObject_HEAD;

    version(Python_2_5_Or_Later){
        Py_ssize_t fill;
        Py_ssize_t used;

        Py_ssize_t mask;

        setentry *table;
        setentry* function(PySetObject *so, PyObject *key, C_long hash) lookup;
        setentry smalltable[PySet_MINSIZE];
    }else{
        PyObject *data;
    }

    C_long hash;
    PyObject *weakreflist;
}

// &PySet_Type is accessible via PySet_Type_p.
// &PyFrozenSet_Type is accessible via PyFrozenSet_Type_p.

// D translations of C macros:
int PyFrozenSet_CheckExact()(PyObject *ob) {
    return ob.ob_type == PyFrozenSet_Type_p;
}
int PyAnySet_CheckExact()(PyObject* ob) {
    return ob.ob_type == PySet_Type_p || ob.ob_type == PyFrozenSet_Type_p;
}
int PyAnySet_Check()(PyObject *ob) {
    return (
         ob.ob_type == PySet_Type_p
      || ob.ob_type == PyFrozenSet_Type_p
      || PyType_IsSubtype(ob.ob_type, PySet_Type_p)
      || PyType_IsSubtype(ob.ob_type, PyFrozenSet_Type_p)
    );
}
version(Python_2_6_Or_Later){
    bool PySet_Check()(PyObject *ob) {
        return (ob.ob_type == &PySet_Type || 
                PyType_IsSubtype(ob.ob_type, &PySet_Type));
    }
    bool PyFrozenSet_Check()(PyObject *ob) {
        return (ob.ob_type == &PyFrozenSet_Type || 
                PyType_IsSubtype(ob.ob_type, &PyFrozenSet_Type));
    }
}

version(Python_2_5_Or_Later){
    PyObject *PySet_New(PyObject *);
    PyObject *PyFrozenSet_New(PyObject *);
    Py_ssize_t PySet_Size(PyObject *anyset);
    Py_ssize_t PySet_GET_SIZE()(PyObject* so) {
        return (cast(PySetObject*)so).used;
    }
    int PySet_Clear(PyObject *set);
    int PySet_Contains(PyObject *anyset, PyObject *key);
    int PySet_Discard(PyObject *set, PyObject *key);
    int PySet_Add(PyObject *set, PyObject *key);
    int _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **entry);
    PyObject *PySet_Pop(PyObject *set);
    int _PySet_Update(PyObject *set, PyObject *iterable);
}

///////////////////////////////////////////////////////////////////////////////
// Interface to map C struct members to Python object attributes
///////////////////////////////////////////////////////////////////////////////
// Python-header-file: Include/structmember.h:

struct PyMemberDef {
  char *name;
  int type;
  Py_ssize_t offset;
  int flags;
  char *doc;
}

enum T_SHORT = 0;
enum T_INT = 1;
enum T_LONG = 2;
enum T_FLOAT = 3;
enum T_DOUBLE = 4;
enum T_STRING = 5;
enum T_OBJECT = 6;
enum T_CHAR = 7;
enum T_BYTE = 8;
enum T_UBYTE = 9;
enum T_USHORT = 10;
enum T_UINT = 11;
enum T_ULONG = 12;
enum T_STRING_INPLACE = 13;
version(Python_2_6_Or_Later){
    enum T_BOOL = 14;
}
enum T_OBJECT_EX = 16;
version(Python_2_5_Or_Later){
    enum T_LONGLONG = 17;
    enum T_ULONGLONG = 18;
}
version(Python_2_6_Or_Later){
    enum T_PYSSIZET = 19;
}

enum READONLY = 1;
alias READONLY RO;
enum READ_RESTRICTED = 2;
enum WRITE_RESTRICTED = 4;
enum RESTRICTED = (READ_RESTRICTED | WRITE_RESTRICTED);

PyObject *PyMember_GetOne(Char1 *, PyMemberDef *);
int PyMember_SetOne(char *, PyMemberDef *, PyObject *);


///////////////////////////////////////////////////////////////////////////////
// INTERFACE FOR TUPLE-LIKE "STRUCTURED SEQUENCES"
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/structseq.h:

struct PyStructSequence_Field {
  char *name;
  char *doc;
}

struct PyStructSequence_Desc {
  char *name;
  char *doc;
  PyStructSequence_Field *fields;
  int n_in_sequence;
}

// XXX: What about global var PyStructSequence_UnnamedField?

void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc);
PyObject *PyStructSequence_New(PyTypeObject* type);

struct PyStructSequence {
  mixin PyObject_VAR_HEAD;
  // DSR:XXX:LAYOUT:
  // Will the D layout for a 1-obj array be the same as the C layout?  I
  // think the D array will be larger.
  PyObject *_ob_item[1];
  PyObject** ob_item()() {
    return _ob_item.ptr;
  }
}

// D translation of C macro:
PyObject *PyStructSequence_SET_ITEM()(PyObject *op, int i, PyObject *v) {
  PyStructSequence *ot = cast(PyStructSequence *) op;
  ot.ob_item[i] = v;
  return v;
}


///////////////////////////////////////////////////////////////////////////////
// UTILITY FUNCTION RELATED TO TIMEMODULE.C
///////////////////////////////////////////////////////////////////////////////
  // Python-header-file: Include/timefuncs.h:

  time_t _PyTime_DoubleToTimet(double x);



} /* extern (C) */


/* The following global variables will contain pointers to certain immutable
 * Python objects that Python/C API programmers expect.
 *
 * In order to make these global variables from the Python library available
 * to D, I tried the extern workaround documented at:
 *   http://www.digitalmars.com/d/archives/digitalmars/D/15427.html
 * but it didn't work (Python crashed when attempting to manipulate the
 * pointers).
 * Besides, in some cases, canonical use of the Python/C API *requires* macros.
 * I ultimately resorted to traversing the Python module structure and loading
 * pointers to the required objects manually (see
 * python_support.d/_loadPythonSupport). */

private {

/* Singletons: */
PyObject* m_Py_None;
PyObject* m_Py_NotImplemented;
PyObject* m_Py_Ellipsis;
PyObject* m_Py_True;
PyObject* m_Py_False;

/* Types: */
PyTypeObject* m_PyType_Type_p;
PyTypeObject* m_PyBaseObject_Type_p;
PyTypeObject* m_PySuper_Type_p;

PyTypeObject* m_PyNone_Type_p;

PyTypeObject* m_PyUnicode_Type_p;
PyTypeObject* m_PyInt_Type_p;
PyTypeObject* m_PyBool_Type_p;
PyTypeObject* m_PyLong_Type_p;
PyTypeObject* m_PyFloat_Type_p;
PyTypeObject* m_PyComplex_Type_p;
PyTypeObject* m_PyRange_Type_p;
PyTypeObject* m_PyBaseString_Type_p;
PyTypeObject* m_PyString_Type_p;
PyTypeObject* m_PyBuffer_Type_p;
PyTypeObject* m_PyTuple_Type_p;
PyTypeObject* m_PyList_Type_p;
PyTypeObject* m_PyDict_Type_p;
PyTypeObject* m_PyEnum_Type_p;
PyTypeObject* m_PyReversed_Type_p;
PyTypeObject* m_PyCFunction_Type_p;
PyTypeObject* m_PyModule_Type_p;
PyTypeObject* m_PyFunction_Type_p;
PyTypeObject* m_PyClassMethod_Type_p;
PyTypeObject* m_PyStaticMethod_Type_p;
PyTypeObject* m_PyClass_Type_p;
PyTypeObject* m_PyInstance_Type_p;
PyTypeObject* m_PyMethod_Type_p;
PyTypeObject* m_PyFile_Type_p;
PyTypeObject* m_PyCode_Type_p;
PyTypeObject* m_PyFrame_Type_p;
PyTypeObject* m_PyGen_Type_p;
PyTypeObject* m_PySet_Type_p;
PyTypeObject* m_PyFrozenSet_Type_p;

/* YYY: Python's default encoding can actually be changed during program
 * with sys.setdefaultencoding, so perhaps it would be better not to expose
 * this at all: */
char* m_Py_FileSystemDefaultEncoding;

PyTypeObject* m_PyCObject_Type_p;
PyTypeObject* m_PyTraceBack_Type_p;
PyTypeObject* m_PySlice_Type_p;
PyTypeObject* m_PyCell_Type_p;
PyTypeObject* m_PySeqIter_Type_p;
PyTypeObject* m_PyCallIter_Type_p;
/* PyWrapperDescr_Type_p omitted. */
PyTypeObject* m_PyProperty_Type_p;

PyTypeObject* m__PyWeakref_RefType_p;
PyTypeObject* m__PyWeakref_ProxyType_p;
PyTypeObject* m__PyWeakref_CallableProxyType_p;

/* Exceptions: */
PyObject* m_PyExc_Exception;
PyObject* m_PyExc_StopIteration;
PyObject* m_PyExc_StandardError;
PyObject* m_PyExc_ArithmeticError;
PyObject* m_PyExc_LookupError;

PyObject* m_PyExc_AssertionError;
PyObject* m_PyExc_AttributeError;
PyObject* m_PyExc_EOFError;
PyObject* m_PyExc_FloatingPointError;
PyObject* m_PyExc_EnvironmentError;
PyObject* m_PyExc_IOError;
PyObject* m_PyExc_OSError;
PyObject* m_PyExc_ImportError;
PyObject* m_PyExc_IndexError;
PyObject* m_PyExc_KeyError;
PyObject* m_PyExc_KeyboardInterrupt;
PyObject* m_PyExc_MemoryError;
PyObject* m_PyExc_NameError;
PyObject* m_PyExc_OverflowError;
PyObject* m_PyExc_RuntimeError;
PyObject* m_PyExc_NotImplementedError;
PyObject* m_PyExc_SyntaxError;
PyObject* m_PyExc_IndentationError;
PyObject* m_PyExc_TabError;
PyObject* m_PyExc_ReferenceError;
PyObject* m_PyExc_SystemError;
PyObject* m_PyExc_SystemExit;
PyObject* m_PyExc_TypeError;
PyObject* m_PyExc_UnboundLocalError;
PyObject* m_PyExc_UnicodeError;
PyObject* m_PyExc_UnicodeEncodeError;
PyObject* m_PyExc_UnicodeDecodeError;
PyObject* m_PyExc_UnicodeTranslateError;
PyObject* m_PyExc_ValueError;
PyObject* m_PyExc_ZeroDivisionError;
version (Windows) {
  PyObject* m_PyExc_WindowsError;
}
/* PyExc_MemoryErrorInst omitted. */

PyObject* m_PyExc_Warning;
PyObject* m_PyExc_UserWarning;
PyObject* m_PyExc_DeprecationWarning;
PyObject* m_PyExc_PendingDeprecationWarning;
PyObject* m_PyExc_SyntaxWarning;
/* PyExc_OverflowWarning omitted, because it'll go away in Python 2.5. */
PyObject* m_PyExc_RuntimeWarning;
PyObject* m_PyExc_FutureWarning;

PyObject *eval()(string code) {
    PyObject *pyGlobals = Py_INCREF(PyEval_GetGlobals()); /* borrowed ref */
    scope(exit) Py_DECREF(pyGlobals);
    PyObject *res = PyRun_String(toStringz(code), Py_eval_input,
        pyGlobals, pyGlobals
    ); /* New ref, or NULL on error. */
    if (res == null) {
        throw new Exception("XXX: write error message; make PythonException D class");
    }

    return res;
}

PyObject* m_builtins, m_types, m_weakref;

} /* end private */

// These template functions will lazily-load the various singleton objects,
// removing the need for a "load" function that does it all at once.
typeof(Ptr) lazy_sys(alias Ptr, string name) () {
    if (Ptr is null) {
        PyObject* sys_modules = PyImport_GetModuleDict();
        Ptr = cast(typeof(Ptr)) PyDict_GetItemString(sys_modules, 
                toStringz(name));
    }
    assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!");
    return Ptr;
}

alias lazy_sys!(m_builtins, "__builtin__") builtins;
alias lazy_sys!(m_types, "types") types;
alias lazy_sys!(m_weakref, "weakref") weakref;

@property typeof(Ptr) lazy_load(alias from, alias Ptr, string name) () {
    if (Ptr is null) {
        Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), toStringz(name));
    }
    assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!");
    return Ptr;
}

typeof(Ptr) lazy_eval(alias Ptr, string code) () {
    if (Ptr is null) {
        Ptr = cast(typeof(Ptr)) eval(code);
    }
    assert (Ptr !is null, "python.d couldn't lazily eval something...");
    return Ptr;
}


//void _loadPythonSupport() {
//static this() {
//printf("[_loadPythonSupport started (Py_None is null: %d)]\n", Py_None is null);

/+
  PyObject *sys_modules = PyImport_GetModuleDict();

  PyObject *builtins = PyDict_GetItemString(sys_modules, "__builtin__");
  assert (builtins != null);
  PyObject *types = PyDict_GetItemString(sys_modules, "types");
  assert (types != null);

  PyObject *weakref = PyImport_ImportModule("weakref");
  assert (weakref != null);
+/

  /* Since Python never unloads an extension module once it has been loaded,
   * we make no attempt to release these references. */

  /* Singletons: */
alias lazy_load!(builtins, m_Py_None, "None") Py_None;
alias lazy_load!(builtins, m_Py_NotImplemented, "NotImplemented") Py_NotImplemented;
alias lazy_load!(builtins, m_Py_Ellipsis, "Ellipsis") Py_Ellipsis;
alias lazy_load!(builtins, m_Py_True, "True") Py_True;
alias lazy_load!(builtins, m_Py_False, "False") Py_False;

  /* Types: */
alias lazy_load!(builtins, m_PyType_Type_p, "type") PyType_Type_p;
alias lazy_load!(builtins, m_PyBaseObject_Type_p, "object") PyBaseObject_Type_p;
alias lazy_load!(builtins, m_PySuper_Type_p, "super") PySuper_Type_p;

alias lazy_load!(types, m_PyNone_Type_p, "NoneType") PyNone_Type_p;

alias lazy_load!(builtins, m_PyUnicode_Type_p, "unicode") PyUnicode_Type_p;
alias lazy_load!(builtins, m_PyInt_Type_p, "int") PyInt_Type_p;
alias lazy_load!(builtins, m_PyBool_Type_p, "bool") PyBool_Type_p;
alias lazy_load!(builtins, m_PyLong_Type_p, "long") PyLong_Type_p;
alias lazy_load!(builtins, m_PyFloat_Type_p, "float") PyFloat_Type_p;
alias lazy_load!(builtins, m_PyComplex_Type_p, "complex") PyComplex_Type_p;
alias lazy_load!(builtins, m_PyRange_Type_p, "xrange") PyRange_Type_p;
alias lazy_load!(builtins, m_PyBaseString_Type_p, "basestring") PyBaseString_Type_p;
alias lazy_load!(builtins, m_PyString_Type_p, "str") PyString_Type_p;
alias lazy_load!(builtins, m_PyBuffer_Type_p, "buffer") PyBuffer_Type_p;
alias lazy_load!(builtins, m_PyTuple_Type_p, "tuple") PyTuple_Type_p;
alias lazy_load!(builtins, m_PyList_Type_p, "list") PyList_Type_p;
alias lazy_load!(builtins, m_PyDict_Type_p, "dict") PyDict_Type_p;
alias lazy_load!(builtins, m_PyEnum_Type_p, "enumerate") PyEnum_Type_p;
alias lazy_load!(builtins, m_PyReversed_Type_p, "reversed") PyReversed_Type_p;

alias lazy_load!(types, m_PyCFunction_Type_p, "BuiltinFunctionType") PyCFunction_Type_p;
alias lazy_load!(types, m_PyModule_Type_p, "ModuleType") PyModule_Type_p;
alias lazy_load!(types, m_PyFunction_Type_p, "FunctionType") PyFunction_Type_p;

alias lazy_load!(builtins, m_PyClassMethod_Type_p, "classmethod") PyClassMethod_Type_p;
alias lazy_load!(builtins, m_PyStaticMethod_Type_p, "staticmethod") PyStaticMethod_Type_p;

alias lazy_load!(types, m_PyClass_Type_p, "ClassType") PyClass_Type_p;
alias lazy_load!(types, m_PyInstance_Type_p, "InstanceType") PyInstance_Type_p;
alias lazy_load!(types, m_PyMethod_Type_p, "MethodType") PyMethod_Type_p;

alias lazy_load!(builtins, m_PyFile_Type_p, "file") PyFile_Type_p;

const(char)* Py_FileSystemDefaultEncoding()() {
    if (m_Py_FileSystemDefaultEncoding is null) {
        m_Py_FileSystemDefaultEncoding = PyUnicode_GetDefaultEncoding();
        assert (m_Py_FileSystemDefaultEncoding !is null,
            "python.d couldn't load PyUnicode_DefaultEncoding attribute!");
    }
    return m_Py_FileSystemDefaultEncoding;
}

  /* Python's "CObject" type is intended to serve as an opaque handle for
   * passing a C void pointer from C code to Python code and back. */
PyTypeObject* PyCObject_Type_p()() {
    if (m_PyCObject_Type_p is null) {
        PyObject *aCObject = PyCObject_FromVoidPtr(null, null);
        m_PyCObject_Type_p = cast(PyTypeObject *) PyObject_Type(aCObject);
        Py_DECREF(aCObject);
    }
    return m_PyCObject_Type_p;
}

alias lazy_load!(types, m_PyTraceBack_Type_p, "TracebackType") PyTraceBack_Type_p;
alias lazy_load!(types, m_PySlice_Type_p, "SliceType") PySlice_Type_p;

PyTypeObject* PyCell_Type_p()() {
    if (m_PyCell_Type_p is null) {
        PyObject *cell = PyCell_New(null);
        assert (cell != null);
        m_PyCell_Type_p = cast(PyTypeObject *) PyObject_Type(cell);
        assert (PyCell_Type_p != null);
        Py_DECREF(cell);
    }
    return m_PyCell_Type_p;
}

alias lazy_eval!(m_PySeqIter_Type_p, "type(iter(''))") PySeqIter_Type_p;
alias lazy_eval!(m_PyCallIter_Type_p, "type(iter(lambda: None, None))") PyCallIter_Type_p;

  /* PyWrapperDescr_Type_p omitted. */
alias lazy_load!(builtins, m_PyProperty_Type_p, "property") PyProperty_Type_p;

alias lazy_load!(weakref, m__PyWeakref_RefType_p, "ReferenceType") _PyWeakref_RefType_p;
alias lazy_load!(weakref, m__PyWeakref_ProxyType_p, "ProxyType") _PyWeakref_ProxyType_p;
alias lazy_load!(weakref, m__PyWeakref_CallableProxyType_p, "CallableProxyType") _PyWeakref_CallableProxyType_p;

alias lazy_load!(types, m_PyCode_Type_p, "CodeType") PyCode_Type_p;
alias lazy_load!(types, m_PyFrame_Type_p, "FrameType") PyFrame_Type_p;
alias lazy_load!(types, m_PyGen_Type_p, "GeneratorType") PyGen_Type_p;

alias lazy_load!(builtins, m_PySet_Type_p, "set") PySet_Type_p;
alias lazy_load!(builtins, m_PyFrozenSet_Type_p, "frozenset") PyFrozenSet_Type_p;

  /* Exceptions: */
alias lazy_load!(builtins, m_PyExc_ArithmeticError, "ArithmeticError") PyExc_ArithmeticError;
alias lazy_load!(builtins, m_PyExc_AssertionError, "AssertionError") PyExc_AssertionError;
alias lazy_load!(builtins, m_PyExc_AttributeError, "AttributeError") PyExc_AttributeError;
alias lazy_load!(builtins, m_PyExc_DeprecationWarning, "DeprecationWarning") PyExc_DeprecationWarning;
alias lazy_load!(builtins, m_PyExc_EOFError, "EOFError") PyExc_EOFError;
alias lazy_load!(builtins, m_PyExc_EnvironmentError, "EnvironmentError") PyExc_EnvironmentError;
alias lazy_load!(builtins, m_PyExc_Exception, "Exception") PyExc_Exception;
alias lazy_load!(builtins, m_PyExc_FloatingPointError, "FloatingPointError") PyExc_FloatingPointError;
alias lazy_load!(builtins, m_PyExc_FutureWarning, "FutureWarning") PyExc_FutureWarning;
alias lazy_load!(builtins, m_PyExc_IOError, "IOError") PyExc_IOError;
alias lazy_load!(builtins, m_PyExc_ImportError, "ImportError") PyExc_ImportError;
alias lazy_load!(builtins, m_PyExc_IndentationError, "IndentationError") PyExc_IndentationError;
alias lazy_load!(builtins, m_PyExc_IndexError, "IndexError") PyExc_IndexError;
alias lazy_load!(builtins, m_PyExc_KeyError, "KeyError") PyExc_KeyError;
alias lazy_load!(builtins, m_PyExc_KeyboardInterrupt, "KeyboardInterrupt") PyExc_KeyboardInterrupt;
alias lazy_load!(builtins, m_PyExc_LookupError, "LookupError") PyExc_LookupError;
alias lazy_load!(builtins, m_PyExc_MemoryError, "MemoryError") PyExc_MemoryError;
  /* PyExc_MemoryErrorInst omitted. */
alias lazy_load!(builtins, m_PyExc_NameError, "NameError") PyExc_NameError;
alias lazy_load!(builtins, m_PyExc_NotImplementedError, "NotImplementedError") PyExc_NotImplementedError;
alias lazy_load!(builtins, m_PyExc_OSError, "OSError") PyExc_OSError;
alias lazy_load!(builtins, m_PyExc_OverflowError, "OverflowError") PyExc_OverflowError;
alias lazy_load!(builtins, m_PyExc_PendingDeprecationWarning, "PendingDeprecationWarning") PyExc_PendingDeprecationWarning;
alias lazy_load!(builtins, m_PyExc_ReferenceError, "ReferenceError") PyExc_ReferenceError;
alias lazy_load!(builtins, m_PyExc_RuntimeError, "RuntimeError") PyExc_RuntimeError;
alias lazy_load!(builtins, m_PyExc_RuntimeWarning, "RuntimeWarning") PyExc_RuntimeWarning;
alias lazy_load!(builtins, m_PyExc_StandardError, "StandardError") PyExc_StandardError;
alias lazy_load!(builtins, m_PyExc_StopIteration, "StopIteration") PyExc_StopIteration;
alias lazy_load!(builtins, m_PyExc_SyntaxError, "SyntaxError") PyExc_SyntaxError;
alias lazy_load!(builtins, m_PyExc_SyntaxWarning, "SyntaxWarning") PyExc_SyntaxWarning;
alias lazy_load!(builtins, m_PyExc_SystemError, "SystemError") PyExc_SystemError;
alias lazy_load!(builtins, m_PyExc_SystemExit, "SystemExit") PyExc_SystemExit;
alias lazy_load!(builtins, m_PyExc_TabError, "TabError") PyExc_TabError;
alias lazy_load!(builtins, m_PyExc_TypeError, "TypeError") PyExc_TypeError;
alias lazy_load!(builtins, m_PyExc_UnboundLocalError, "UnboundLocalError") PyExc_UnboundLocalError;
alias lazy_load!(builtins, m_PyExc_UnicodeDecodeError, "UnicodeDecodeError") PyExc_UnicodeDecodeError;
alias lazy_load!(builtins, m_PyExc_UnicodeEncodeError, "UnicodeEncodeError") PyExc_UnicodeEncodeError;
alias lazy_load!(builtins, m_PyExc_UnicodeError, "UnicodeError") PyExc_UnicodeError;
alias lazy_load!(builtins, m_PyExc_UnicodeTranslateError, "UnicodeTranslateError") PyExc_UnicodeTranslateError;
alias lazy_load!(builtins, m_PyExc_UserWarning, "UserWarning") PyExc_UserWarning;
alias lazy_load!(builtins, m_PyExc_ValueError, "ValueError") PyExc_ValueError;
alias lazy_load!(builtins, m_PyExc_Warning, "Warning") PyExc_Warning;

version (Windows) {
    alias lazy_load!(builtins, m_PyExc_WindowsError, "WindowsError") PyExc_WindowsError;
}

alias lazy_load!(builtins, m_PyExc_ZeroDivisionError, "ZeroDivisionError") PyExc_ZeroDivisionError;

// Python-header-file: Modules/arraymodule.c:

struct arraydescr{
    int typecode;
    int itemsize;
    PyObject* function(arrayobject*, Py_ssize_t) getitem;
    int function(arrayobject*, Py_ssize_t, PyObject*) setitem;
}

struct arrayobject {
    mixin PyObject_VAR_HEAD;
    ubyte* ob_item;
    Py_ssize_t allocated;
    arraydescr* ob_descr;
    PyObject* weakreflist; /* List of weak references */
}