Source

cpython-withatomic / Modules / almodule.c

The branch 'legacy-trunk' does not exist.
   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
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.

While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.

STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

******************************************************************/

#define OLD_INTERFACE		/* define for pre-Irix 6 interface */

#include "Python.h"
#include "stringobject.h"
#include <audio.h>
#include <stdarg.h>

#ifndef AL_NO_ELEM
#ifndef OLD_INTERFACE
#define OLD_INTERFACE
#endif /* OLD_INTERFACE */
#endif /* AL_NO_ELEM */

static PyObject *ErrorObject;

/* ----------------------------------------------------- */

/* Declarations for objects of type port */

typedef struct {
	PyObject_HEAD
	/* XXXX Add your own stuff here */
	ALport port;
} alpobject;

staticforward PyTypeObject Alptype;



/* ---------------------------------------------------------------- */

/* Declarations for objects of type config */

typedef struct {
	PyObject_HEAD
	/* XXXX Add your own stuff here */
	ALconfig config;
} alcobject;

staticforward PyTypeObject Alctype;


static void
ErrorHandler(long code, const char *fmt, ...)
{
	va_list args;
	char buf[128];

	va_start(args, fmt);
	vsprintf(buf, fmt, args);
	va_end(args);
	PyErr_SetString(ErrorObject, buf);
}

#ifdef AL_NO_ELEM		/* IRIX 6 */

static PyObject *
param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo)
{
	ALparamInfo info;
	PyObject *v;

	if (pinfo == NULL) {
		pinfo = &info;
		if (alGetParamInfo(resource, param, &info) < 0)
			return NULL;
	}
	switch (pinfo->elementType) {
	case AL_PTR_ELEM:
		/* XXXX don't know how to handle this */
	case AL_NO_ELEM:
		Py_INCREF(Py_None);
		return Py_None;
	case AL_INT32_ELEM:
	case AL_RESOURCE_ELEM:
	case AL_ENUM_ELEM:
		return PyInt_FromLong((long) value.i);
	case AL_INT64_ELEM:
		return PyLong_FromLongLong(value.ll);
	case AL_FIXED_ELEM:
		return PyFloat_FromDouble(alFixedToDouble(value.ll));
	case AL_CHAR_ELEM:
		if (value.ptr == NULL) {
			Py_INCREF(Py_None);
			return Py_None;
		}
		return PyString_FromString((char *) value.ptr);
	default:
		PyErr_SetString(ErrorObject, "unknown element type");
		return NULL;
	}
}

static int
python2elem(PyObject *item, void *ptr, int elementType)
{
	switch (elementType) {
	case AL_INT32_ELEM:
	case AL_RESOURCE_ELEM:
	case AL_ENUM_ELEM:
		if (!PyInt_Check(item)) {
			PyErr_BadArgument();
			return -1;
		}
		*((int *) ptr) = PyInt_AsLong(item);
		break;
	case AL_INT64_ELEM:
		if (PyInt_Check(item))
			*((long long *) ptr) = PyInt_AsLong(item);
		else if (PyLong_Check(item))
			*((long long *) ptr) = PyLong_AsLongLong(item);
		else {
			PyErr_BadArgument();
			return -1;
		}
		break;
	case AL_FIXED_ELEM:
		if (PyInt_Check(item))
			*((long long *) ptr) = alDoubleToFixed((double) PyInt_AsLong(item));
		else if (PyFloat_Check(item))
			*((long long *) ptr) = alDoubleToFixed(PyFloat_AsDouble(item));
		else {
			PyErr_BadArgument();
			return -1;
		}
		break;
	default:
		PyErr_SetString(ErrorObject, "unknown element type");
		return -1;
	}
	return 0;
}

static int
python2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo)
{
	ALparamInfo info;
	int i, stepsize;
	PyObject *item;

	if (pinfo == NULL) {
		pinfo = &info;
		if (alGetParamInfo(resource, param->param, &info) < 0)
			return -1;
	}
	switch (pinfo->valueType) {
	case AL_STRING_VAL:
		if (pinfo->elementType != AL_CHAR_ELEM) {
			PyErr_SetString(ErrorObject, "unknown element type");
			return -1;
		}
		if (!PyString_Check(value)) {
			PyErr_BadArgument();
			return -1;
		}
		param->value.ptr = PyString_AS_STRING(value);
		param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/
		break;
	case AL_SET_VAL:
	case AL_VECTOR_VAL:
		if (!PyList_Check(value) && !PyTuple_Check(value)) {
			PyErr_BadArgument();
			return -1;
		}
		switch (pinfo->elementType) {
		case AL_INT32_ELEM:
		case AL_RESOURCE_ELEM:
		case AL_ENUM_ELEM:
			param->sizeIn = PySequence_Length(value);
			param->value.ptr = PyMem_NEW(int, param->sizeIn);
			stepsize = sizeof(int);
			break;
		case AL_INT64_ELEM:
		case AL_FIXED_ELEM:
			param->sizeIn = PySequence_Length(value);
			param->value.ptr = PyMem_NEW(long long, param->sizeIn);
			stepsize = sizeof(long long);
			break;
		}
		for (i = 0; i < param->sizeIn; i++) {
			item = PySequence_GetItem(value, i);
			if (python2elem(item, (void *) ((char *) param->value.ptr + i*stepsize), pinfo->elementType) < 0) {
				PyMem_DEL(param->value.ptr);
				return -1;
			}
		}
		break;
	case AL_SCALAR_VAL:
		switch (pinfo->elementType) {
		case AL_INT32_ELEM:
		case AL_RESOURCE_ELEM:
		case AL_ENUM_ELEM:
			return python2elem(value, (void *) &param->value.i,
					   pinfo->elementType);
		case AL_INT64_ELEM:
		case AL_FIXED_ELEM:
			return python2elem(value, (void *) &param->value.ll,
					   pinfo->elementType);
		default:
			PyErr_SetString(ErrorObject, "unknown element type");
			return -1;
		}
	}
	return 0;
}

static int
python2params(int resource1, int resource2, PyObject *list, ALpv **pvsp, ALparamInfo **pinfop)
{
	PyObject *item;
	ALpv *pvs;
	ALparamInfo *pinfo;
	int npvs, i;

	npvs = PyList_Size(list);
	pvs = PyMem_NEW(ALpv, npvs);
	pinfo = PyMem_NEW(ALparamInfo, npvs);
	for (i = 0; i < npvs; i++) {
		item = PyList_GetItem(list, i);
		if (!PyArg_ParseTuple(item, "iO", &pvs[i].param, &item))
			goto error;
		if (alGetParamInfo(resource1, pvs[i].param, &pinfo[i]) < 0 &&
		    alGetParamInfo(resource2, pvs[i].param, &pinfo[i]) < 0)
			goto error;
		if (python2param(resource1, &pvs[i], item, &pinfo[i]) < 0)
			goto error;
	}

	*pvsp = pvs;
	*pinfop = pinfo;
	return npvs;

  error:
	/* XXXX we should clean up everything */
	if (pvs)
		PyMem_DEL(pvs);
	if (pinfo)
		PyMem_DEL(pinfo);
	return -1;
}

/* -------------------------------------------------------- */


static PyObject *
SetConfig(self, args, func)
	alcobject *self;
	PyObject *args;
	int (*func)(ALconfig, int);
{
	int par;

	if (!PyArg_ParseTuple(args, "i:SetConfig", &par))
		return NULL;

	if ((*func)(self->config, par) == -1)
		return NULL;

	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
GetConfig(self, args, func)
	alcobject *self;
	PyObject *args;
	int (*func)(ALconfig);
{	
	int par;

	if (!PyArg_ParseTuple(args, ":GetConfig"))
		return NULL;
	
	if ((par = (*func)(self->config)) == -1)
		return NULL;

	return PyInt_FromLong((long) par);
}

static char alc_SetWidth__doc__[] = 
"alSetWidth: set the wordsize for integer audio data."
;

static PyObject *
alc_SetWidth(self, args)
	alcobject *self;
	PyObject *args;
{
	return SetConfig(self, args, alSetWidth);
}


static char alc_GetWidth__doc__[] = 
"alGetWidth: get the wordsize for integer audio data."
;

static PyObject *
alc_GetWidth(self, args)
	alcobject *self;
	PyObject *args;
{
	return GetConfig(self, args, alGetWidth);
}


static char alc_SetSampFmt__doc__[] = 
"alSetSampFmt: set the sample format setting in an audio ALconfig structure."
;

static PyObject *
alc_SetSampFmt(self, args)
	alcobject *self;
	PyObject *args;
{
	return SetConfig(self, args, alSetSampFmt);
}


static char alc_GetSampFmt__doc__[] = 
"alGetSampFmt: get the sample format setting in an audio ALconfig structure."
;

static PyObject *
alc_GetSampFmt(self, args)
	alcobject *self;
	PyObject *args;
{
	return GetConfig(self, args, alGetSampFmt);
}


static char alc_SetChannels__doc__[] = 
"alSetChannels: set the channel settings in an audio ALconfig."
;

static PyObject *
alc_SetChannels(self, args)
	alcobject *self;
	PyObject *args;
{
	return SetConfig(self, args, alSetChannels);
}


static char alc_GetChannels__doc__[] = 
"alGetChannels: get the channel settings in an audio ALconfig."
;

static PyObject *
alc_GetChannels(self, args)
	alcobject *self;
	PyObject *args;
{
	return GetConfig(self, args, alGetChannels);
}


static char alc_SetFloatMax__doc__[] = 
"alSetFloatMax: set the maximum value of floating point sample data."
;

static PyObject *
alc_SetFloatMax(self, args)
	alcobject *self;
	PyObject *args;
{
	double maximum_value;

	if (!PyArg_ParseTuple(args, "d:SetFloatMax", &maximum_value))
		return NULL;
	if (alSetFloatMax(self->config, maximum_value) < 0)
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}


static char alc_GetFloatMax__doc__[] = 
"alGetFloatMax: get the maximum value of floating point sample data."
;

static PyObject *
alc_GetFloatMax(self, args)
	alcobject *self;
	PyObject *args;
{
	double maximum_value;

	if (!PyArg_ParseTuple(args, ":GetFloatMax"))
		return NULL;
	if ((maximum_value = alGetFloatMax(self->config)) == 0)
		return NULL;
	return PyFloat_FromDouble(maximum_value);
}


static char alc_SetDevice__doc__[] = 
"alSetDevice: set the device setting in an audio ALconfig structure."
;

static PyObject *
alc_SetDevice(self, args)
	alcobject *self;
	PyObject *args;
{
	return SetConfig(self, args, alSetDevice);
}


static char alc_GetDevice__doc__[] = 
"alGetDevice: get the device setting in an audio ALconfig structure."
;

static PyObject *
alc_GetDevice(self, args)
	alcobject *self;
	PyObject *args;
{
	return GetConfig(self, args, alGetDevice);
}


static char alc_SetQueueSize__doc__[] = 
"alSetQueueSize: set audio port buffer size."
;

static PyObject *
alc_SetQueueSize(self, args)
	alcobject *self;
	PyObject *args;
{
	return SetConfig(self, args, alSetQueueSize);
}


static char alc_GetQueueSize__doc__[] = 
"alGetQueueSize: get audio port buffer size."
;

static PyObject *
alc_GetQueueSize(self, args)
	alcobject *self;
	PyObject *args;
{
	return GetConfig(self, args, alGetQueueSize);
}

#endif /* AL_NO_ELEM */

static PyObject *
setconfig(self, args, func)
	alcobject *self;
	PyObject *args;
	int (*func)(ALconfig, long);
{
	long par;

	if (!PyArg_ParseTuple(args, "l:SetConfig", &par))
		return NULL;

	if ((*func)(self->config, par) == -1)
		return NULL;

	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
getconfig(self, args, func)
	alcobject *self;
	PyObject *args;
	long (*func)(ALconfig);
{	
	long par;

	if (!PyArg_ParseTuple(args, ":GetConfig"))
		return NULL;
	
	if ((par = (*func)(self->config)) == -1)
		return NULL;

	return PyInt_FromLong((long) par);
}

static PyObject *
alc_setqueuesize (self, args)
	alcobject *self;
	PyObject *args;
{
	return setconfig(self, args, ALsetqueuesize);
}

static PyObject *
alc_getqueuesize (self, args)
	alcobject *self;
	PyObject *args;
{
	return getconfig(self, args, ALgetqueuesize);
}

static PyObject *
alc_setwidth (self, args)
	alcobject *self;
	PyObject *args;
{
	return setconfig(self, args, ALsetwidth);
}

static PyObject *
alc_getwidth (self, args)
	alcobject *self;
	PyObject *args;
{
	return getconfig(self, args, ALgetwidth);	
}

static PyObject *
alc_getchannels (self, args)
	alcobject *self;
	PyObject *args;
{
	return getconfig(self, args, ALgetchannels);	
}

static PyObject *
alc_setchannels (self, args)
	alcobject *self;
	PyObject *args;
{
	return setconfig(self, args, ALsetchannels);
}

#ifdef AL_405

static PyObject *
alc_getsampfmt (self, args)
	alcobject *self;
	PyObject *args;
{
	return getconfig(self, args, ALgetsampfmt);	
}

static PyObject *
alc_setsampfmt (self, args)
	alcobject *self;
	PyObject *args;
{
	return setconfig(self, args, ALsetsampfmt);
}

static PyObject *
alc_getfloatmax(self, args)
	alcobject *self;
	PyObject *args;
{
	double arg;

	if (!PyArg_ParseTuple(args, ":GetFloatMax"))
		return 0;
	if ((arg = ALgetfloatmax(self->config)) == 0)
		return NULL;
	return PyFloat_FromDouble(arg);
}

static PyObject *
alc_setfloatmax(self, args)
	alcobject *self;
	PyObject *args;
{
	double arg;

	if (!PyArg_ParseTuple(args, "d:SetFloatMax", &arg))
		return 0;
	if (ALsetfloatmax(self->config, arg) == -1)
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}
#endif /* AL_405 */
	
static struct PyMethodDef alc_methods[] = {
#ifdef AL_NO_ELEM		/* IRIX 6 */
	{"SetWidth",	(PyCFunction)alc_SetWidth,	METH_VARARGS,	alc_SetWidth__doc__},
	{"GetWidth",	(PyCFunction)alc_GetWidth,	METH_VARARGS,	alc_GetWidth__doc__},
	{"SetSampFmt",	(PyCFunction)alc_SetSampFmt,	METH_VARARGS,	alc_SetSampFmt__doc__},
	{"GetSampFmt",	(PyCFunction)alc_GetSampFmt,	METH_VARARGS,	alc_GetSampFmt__doc__},
	{"SetChannels",	(PyCFunction)alc_SetChannels,	METH_VARARGS,	alc_SetChannels__doc__},
	{"GetChannels",	(PyCFunction)alc_GetChannels,	METH_VARARGS,	alc_GetChannels__doc__},
	{"SetFloatMax",	(PyCFunction)alc_SetFloatMax,	METH_VARARGS,	alc_SetFloatMax__doc__},
	{"GetFloatMax",	(PyCFunction)alc_GetFloatMax,	METH_VARARGS,	alc_GetFloatMax__doc__},
	{"SetDevice",	(PyCFunction)alc_SetDevice,	METH_VARARGS,	alc_SetDevice__doc__},
	{"GetDevice",	(PyCFunction)alc_GetDevice,	METH_VARARGS,	alc_GetDevice__doc__},
	{"SetQueueSize",	(PyCFunction)alc_SetQueueSize,	METH_VARARGS,	alc_SetQueueSize__doc__},
	{"GetQueueSize",	(PyCFunction)alc_GetQueueSize,	METH_VARARGS,	alc_GetQueueSize__doc__},
#endif /* AL_NO_ELEM */
	{"getqueuesize",	(PyCFunction)alc_getqueuesize,	METH_VARARGS},
	{"setqueuesize",	(PyCFunction)alc_setqueuesize,	METH_VARARGS},
	{"getwidth",		(PyCFunction)alc_getwidth,	METH_VARARGS},
	{"setwidth",		(PyCFunction)alc_setwidth,	METH_VARARGS},
	{"getchannels",		(PyCFunction)alc_getchannels,	METH_VARARGS},
	{"setchannels",		(PyCFunction)alc_setchannels,	METH_VARARGS},
#ifdef AL_405
	{"getsampfmt",		(PyCFunction)alc_getsampfmt,	METH_VARARGS},
	{"setsampfmt",		(PyCFunction)alc_setsampfmt,	METH_VARARGS},
	{"getfloatmax",		(PyCFunction)alc_getfloatmax,	METH_VARARGS},
	{"setfloatmax",		(PyCFunction)alc_setfloatmax,	METH_VARARGS},
#endif /* AL_405 */

	{NULL,		NULL}		/* sentinel */
};

/* ---------- */


static PyObject *
newalcobject(ALconfig config)
{
	alcobject *self;
	
	self = PyObject_NEW(alcobject, &Alctype);
	if (self == NULL)
		return NULL;
	/* XXXX Add your own initializers here */
	self->config = config;
	return (PyObject *) self;
}


static void
alc_dealloc(self)
	alcobject *self;
{
	/* XXXX Add your own cleanup code here */
#ifdef AL_NO_ELEM		/* IRIX 6 */
	(void) alFreeConfig(self->config);	/* ignore errors */
#else
	(void) ALfreeconfig(self->config);	/* ignore errors */
#endif
	PyMem_DEL(self);
}

static PyObject *
alc_getattr(self, name)
	alcobject *self;
	char *name;
{
	/* XXXX Add your own getattr code here */
	return Py_FindMethod(alc_methods, (PyObject *)self, name);
}

static char Alctype__doc__[] = 
""
;

static PyTypeObject Alctype = {
	PyObject_HEAD_INIT(&PyType_Type)
	0,				/*ob_size*/
	"config",			/*tp_name*/
	sizeof(alcobject),		/*tp_basicsize*/
	0,				/*tp_itemsize*/
	/* methods */
	(destructor)alc_dealloc,	/*tp_dealloc*/
	(printfunc)0,		/*tp_print*/
	(getattrfunc)alc_getattr,	/*tp_getattr*/
	(setattrfunc)0,	/*tp_setattr*/
	(cmpfunc)0,		/*tp_compare*/
	(reprfunc)0,		/*tp_repr*/
	0,			/*tp_as_number*/
	0,		/*tp_as_sequence*/
	0,		/*tp_as_mapping*/
	(hashfunc)0,		/*tp_hash*/
	(ternaryfunc)0,		/*tp_call*/
	(reprfunc)0,		/*tp_str*/

	/* Space for future expansion */
	0L,0L,0L,0L,
	Alctype__doc__ /* Documentation string */
};

/* End of code for config objects */
/* ---------------------------------------------------------------- */

#ifdef AL_NO_ELEM		/* IRIX 6 */

static char alp_SetConfig__doc__[] = 
"alSetConfig: set the ALconfig of an audio ALport."
;

static PyObject *
alp_SetConfig(self, args)
	alpobject *self;
	PyObject *args;
{
	alcobject *config;
	if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
		return NULL;
	if (alSetConfig(self->port, config->config) < 0)
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}


static char alp_GetConfig__doc__[] = 
"alGetConfig: get the ALconfig of an audio ALport."
;

static PyObject *
alp_GetConfig(self, args)
	alpobject *self;
	PyObject *args;
{
	ALconfig config;
	if (!PyArg_ParseTuple(args, ":GetConfig"))
		return NULL;
	if ((config = alGetConfig(self->port)) == NULL)
		return NULL;
	return newalcobject(config);
}


static char alp_GetResource__doc__[] = 
"alGetResource: get the resource associated with an audio port."
;

static PyObject *
alp_GetResource(self, args)
	alpobject *self;
	PyObject *args;
{
	int resource;

	if (!PyArg_ParseTuple(args, ":GetResource"))
		return NULL;
	if ((resource = alGetResource(self->port)) == 0)
		return NULL;
	return PyInt_FromLong((long) resource);
}


static char alp_GetFD__doc__[] = 
"alGetFD: get the file descriptor for an audio port."
;

static PyObject *
alp_GetFD(self, args)
	alpobject *self;
	PyObject *args;
{
	int fd;

	if (!PyArg_ParseTuple(args, ":GetFD"))
		return NULL;

	if ((fd = alGetFD(self->port)) < 0)
		return NULL;

	return PyInt_FromLong((long) fd);
}


static char alp_GetFilled__doc__[] = 
"alGetFilled: return the number of filled sample frames in an audio port."
;

static PyObject *
alp_GetFilled(self, args)
	alpobject *self;
	PyObject *args;
{
	int filled;

	if (!PyArg_ParseTuple(args, ":GetFilled"))
		return NULL;
	if ((filled = alGetFilled(self->port)) < 0)
		return NULL;
	return PyInt_FromLong((long) filled);
}


static char alp_GetFillable__doc__[] = 
"alGetFillable: report the number of unfilled sample frames in an audio port."
;

static PyObject *
alp_GetFillable(self, args)
	alpobject *self;
	PyObject *args;
{
	int fillable;

	if (!PyArg_ParseTuple(args, ":GetFillable"))
		return NULL;
	if ((fillable = alGetFillable(self->port)) < 0)
		return NULL;
	return PyInt_FromLong((long) fillable);
}


static char alp_ReadFrames__doc__[] = 
"alReadFrames: read sample frames from an audio port."
;

static PyObject *
alp_ReadFrames(self, args)
	alpobject *self;
	PyObject *args;
{
	void *samples;
	int framecount;
	PyObject *v;
	int size;
	int ch;
	ALconfig c;

	if (!PyArg_ParseTuple(args, "i:ReadFrames", &framecount))
		return NULL;
	if (framecount < 0) {
		PyErr_SetString(ErrorObject, "negative framecount");
		return NULL;
	}
	c = alGetConfig(self->port);
	switch (alGetSampFmt(c)) {
	case AL_SAMPFMT_TWOSCOMP:
		switch (alGetWidth(c)) {
		case AL_SAMPLE_8:
			size = 1;
			break;
		case AL_SAMPLE_16:
			size = 2;
			break;
		case AL_SAMPLE_24:
			size = 4;
			break;
		default:
			PyErr_SetString(ErrorObject, "can't determine width");
			alFreeConfig(c);
			return NULL;
		}
		break;
	case AL_SAMPFMT_FLOAT:
		size = 4;
		break;
	case AL_SAMPFMT_DOUBLE:
		size = 8;
		break;
	default:
		PyErr_SetString(ErrorObject, "can't determine format");
		alFreeConfig(c);
		return NULL;
	}
	ch = alGetChannels(c);
	alFreeConfig(c);
	if (ch < 0) {
		PyErr_SetString(ErrorObject, "can't determine # of channels");
		return NULL;
	}
	size *= ch;
	v = PyString_FromStringAndSize((char *) NULL, size * framecount);
	if (v == NULL)
		return NULL;

	Py_BEGIN_ALLOW_THREADS
	alReadFrames(self->port, (void *) PyString_AS_STRING(v), framecount);
	Py_END_ALLOW_THREADS

	return v;
}


static char alp_DiscardFrames__doc__[] = 
"alDiscardFrames: discard audio from an audio port."
;

static PyObject *
alp_DiscardFrames(self, args)
	alpobject *self;
	PyObject *args;
{
	int framecount;

	if (!PyArg_ParseTuple(args, "i:DiscardFrames", &framecount))
		return NULL;

	Py_BEGIN_ALLOW_THREADS
	framecount = alDiscardFrames(self->port, framecount);
	Py_END_ALLOW_THREADS

	if (framecount < 0)
		return NULL;

	return PyInt_FromLong((long) framecount);
}


static char alp_ZeroFrames__doc__[] = 
"alZeroFrames: write zero-valued sample frames to an audio port."
;

static PyObject *
alp_ZeroFrames(self, args)
	alpobject *self;
	PyObject *args;
{
	int framecount;

	if (!PyArg_ParseTuple(args, "i:ZeroFrames", &framecount))
		return NULL;

	if (framecount < 0) {
		PyErr_SetString(ErrorObject, "negative framecount");
		return NULL;
	}

	Py_BEGIN_ALLOW_THREADS
	alZeroFrames(self->port, framecount);
	Py_END_ALLOW_THREADS

	Py_INCREF(Py_None);
	return Py_None;
}


static char alp_SetFillPoint__doc__[] = 
"alSetFillPoint: set low- or high-water mark for an audio port."
;

static PyObject *
alp_SetFillPoint(self, args)
	alpobject *self;
	PyObject *args;
{
	int fillpoint;

	if (!PyArg_ParseTuple(args, "i:SetFillPoint", &fillpoint))
		return NULL;

	if (alSetFillPoint(self->port, fillpoint) < 0)
		return NULL;

	Py_INCREF(Py_None);
	return Py_None;
}


static char alp_GetFillPoint__doc__[] = 
"alGetFillPoint: get low- or high-water mark for an audio port."
;

static PyObject *
alp_GetFillPoint(self, args)
	alpobject *self;
	PyObject *args;
{
	int fillpoint;

	if (!PyArg_ParseTuple(args, ":GetFillPoint"))
		return NULL;

	if ((fillpoint = alGetFillPoint(self->port)) < 0)
		return NULL;

	return PyInt_FromLong((long) fillpoint);
}


static char alp_GetFrameNumber__doc__[] = 
"alGetFrameNumber: get the absolute sample frame number associated with a port."
;

static PyObject *
alp_GetFrameNumber(self, args)
	alpobject *self;
	PyObject *args;
{
	stamp_t fnum;

	if (!PyArg_ParseTuple(args, ":GetFrameNumber"))
		return NULL;

	if (alGetFrameNumber(self->port, &fnum) < 0)
		return NULL;

	return PyLong_FromLongLong((long long) fnum);
}


static char alp_GetFrameTime__doc__[] = 
"alGetFrameTime: get the time at which a sample frame came in or will go out."
;

static PyObject *
alp_GetFrameTime(self, args)
	alpobject *self;
	PyObject *args;
{
	stamp_t fnum, time;
	PyObject *ret, *v0, *v1;

	if (!PyArg_ParseTuple(args, ":GetFrameTime"))
		return NULL;
	if (alGetFrameTime(self->port, &fnum, &time) < 0)
		return NULL;
	v0 = PyLong_FromLongLong((long long) fnum);
	v1 = PyLong_FromLongLong((long long) time);
	if (PyErr_Occurred()) {
		Py_XDECREF(v0);
		Py_XDECREF(v1);
		return NULL;
	}
	ret = Py_BuildValue("(OO)", v0, v1);
	Py_DECREF(v0);
	Py_DECREF(v1);
	return ret;
}


static char alp_WriteFrames__doc__[] = 
"alWriteFrames: write sample frames to an audio port."
;

static PyObject *
alp_WriteFrames(self, args)
	alpobject *self;
	PyObject *args;
{
	char *samples;
	int length;
	int size, ch;
	ALconfig c;

	if (!PyArg_ParseTuple(args, "s#:WriteFrames", &samples, &length))
		return NULL;
	c = alGetConfig(self->port);
	switch (alGetSampFmt(c)) {
	case AL_SAMPFMT_TWOSCOMP:
		switch (alGetWidth(c)) {
		case AL_SAMPLE_8:
			size = 1;
			break;
		case AL_SAMPLE_16:
			size = 2;
			break;
		case AL_SAMPLE_24:
			size = 4;
			break;
		default:
			PyErr_SetString(ErrorObject, "can't determine width");
			alFreeConfig(c);
			return NULL;
		}
		break;
	case AL_SAMPFMT_FLOAT:
		size = 4;
		break;
	case AL_SAMPFMT_DOUBLE:
		size = 8;
		break;
	default:
		PyErr_SetString(ErrorObject, "can't determine format");
		alFreeConfig(c);
		return NULL;
	}
	ch = alGetChannels(c);
	alFreeConfig(c);
	if (ch < 0) {
		PyErr_SetString(ErrorObject, "can't determine # of channels");
		return NULL;
	}
	size *= ch;
	if (length % size != 0) {
		PyErr_SetString(ErrorObject,
				"buffer length not whole number of frames");
		return NULL;
	}

	Py_BEGIN_ALLOW_THREADS
	alWriteFrames(self->port, (void *) samples, length / size);
	Py_END_ALLOW_THREADS

	Py_INCREF(Py_None);
	return Py_None;
}


static char alp_ClosePort__doc__[] = 
"alClosePort: close an audio port."
;

static PyObject *
alp_ClosePort(self, args)
	alpobject *self;
	PyObject *args;
{
	if (!PyArg_ParseTuple(args, ":ClosePort"))
		return NULL;
	if (alClosePort(self->port) < 0)
		return NULL;
	self->port = NULL;
	Py_INCREF(Py_None);
	return Py_None;
}

#endif /* AL_NO_ELEM */

#ifdef OLD_INTERFACE
static PyObject *
alp_closeport(self, args)
	alpobject *self;
	PyObject *args;
{
	if (!PyArg_ParseTuple(args, ":ClosePort"))
		return NULL;
	if (ALcloseport(self->port) < 0)
		return NULL;
	self->port = NULL;
	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
alp_getfd(self, args)
	alpobject *self;
	PyObject *args;
{
	int fd;

	if (!PyArg_ParseTuple(args, ":GetFD"))
		return NULL;
	if ((fd = ALgetfd(self-> port)) == -1)
		return NULL;
	return PyInt_FromLong(fd);
}

static PyObject *
alp_getfilled(self, args)
	alpobject *self;
	PyObject *args;
{
	long count;

	if (!PyArg_ParseTuple(args, ":GetFilled"))
		return NULL;
	if ((count = ALgetfilled(self-> port)) == -1)
		return NULL;
	return PyInt_FromLong(count);
}

static PyObject *
alp_getfillable(self, args)
	alpobject *self;
	PyObject *args;
{
	long count;

	if (!PyArg_ParseTuple(args, ":GetFillable"))
		return NULL;
	if ((count = ALgetfillable(self-> port)) == -1)
		return NULL;
	return PyInt_FromLong (count);
}

static PyObject *
alp_readsamps(self, args)
	alpobject *self;
	PyObject *args;
{
	long count;
	PyObject *v;
	ALconfig c;
	int width;
	int ret;

	if (!PyArg_ParseTuple(args, "l:readsamps", &count))
		return NULL;

	if (count <= 0) {
		PyErr_SetString(ErrorObject, "al.readsamps : arg <= 0");
		return NULL;
	}

	c = ALgetconfig(self->port);
#ifdef AL_405
	width = ALgetsampfmt(c);
	if (width == AL_SAMPFMT_FLOAT)
		width = sizeof(float);
	else if (width == AL_SAMPFMT_DOUBLE)
		width = sizeof(double);
	else
		width = ALgetwidth(c);
#else
	width = ALgetwidth(c);
#endif /* AL_405 */
	ALfreeconfig(c);
	v = PyString_FromStringAndSize((char *)NULL, width * count);
	if (v == NULL)
		return NULL;

	Py_BEGIN_ALLOW_THREADS
	ret = ALreadsamps(self->port, (void *) PyString_AsString(v), count);
	Py_END_ALLOW_THREADS
	if (ret == -1) {
		Py_DECREF(v);
		return NULL;
	}

	return (v);
}

static PyObject *
alp_writesamps(self, args)
	alpobject *self;
	PyObject *args;
{
	char *buf;
	int size, width;
	ALconfig c;
	int ret;

	if (!PyArg_ParseTuple(args, "s#:writesamps", &buf, &size))
		return NULL;

	c = ALgetconfig(self->port);
#ifdef AL_405
	width = ALgetsampfmt(c);
	if (width == AL_SAMPFMT_FLOAT)
		width = sizeof(float);
	else if (width == AL_SAMPFMT_DOUBLE)
		width = sizeof(double);
	else
		width = ALgetwidth(c);
#else
	width = ALgetwidth(c);
#endif /* AL_405 */
	ALfreeconfig(c);
	Py_BEGIN_ALLOW_THREADS
	ret = ALwritesamps (self->port, (void *) buf, (long) size / width);
	Py_END_ALLOW_THREADS
	if (ret == -1)
		return NULL;

	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
alp_getfillpoint(self, args)
	alpobject *self;
	PyObject *args;
{
	long count;

	if (!PyArg_ParseTuple(args, ":GetFillPoint"))
		return NULL;
	if ((count = ALgetfillpoint(self->port)) == -1)
		return NULL;
	return PyInt_FromLong(count);
}

static PyObject *
alp_setfillpoint(self, args)
	alpobject *self;
	PyObject *args;
{
	long count;

	if (!PyArg_ParseTuple(args, "l:SetFillPoint", &count))
		return NULL;
	if (ALsetfillpoint(self->port, count) == -1)
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
alp_setconfig(self, args)
	alpobject *self;
	PyObject *args;
{
	alcobject *config;

	if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
		return NULL;
	if (ALsetconfig(self->port, config->config) == -1)
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
alp_getconfig(self, args)
	alpobject *self;
	PyObject *args;
{
	ALconfig config;

	if (!PyArg_ParseTuple(args, ":GetConfig"))
		return NULL;
	config = ALgetconfig(self->port);
	if (config == NULL)
		return NULL;
	return newalcobject(config);
}

#ifdef AL_405
static PyObject *
alp_getstatus(self, args)
	alpobject *self;
	PyObject *args;
{
	PyObject *list, *v;
	long *PVbuffer;
	long length;
	int i;
	
	if (!PyArg_Parse(args, "O!", &PyList_Type, &list))
		return NULL;
	length = PyList_Size(list);
	PVbuffer = PyMem_NEW(long, length);
	if (PVbuffer == NULL)
		return PyErr_NoMemory();
	for (i = 0; i < length; i++) {
		v = PyList_GetItem(list, i);
		if (!PyInt_Check(v)) {
			PyMem_DEL(PVbuffer);
			PyErr_BadArgument();
			return NULL;
		}
		PVbuffer[i] = PyInt_AsLong(v);
	}

	if (ALgetstatus(self->port, PVbuffer, length) == -1)
		return NULL;

	for (i = 0; i < length; i++)
		PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));

	PyMem_DEL(PVbuffer);

	Py_INCREF(Py_None);
	return Py_None;
}
#endif /* AL_405 */

#endif /* OLD_INTERFACE */

static struct PyMethodDef alp_methods[] = {
#ifdef AL_NO_ELEM		/* IRIX 6 */
	{"SetConfig",	(PyCFunction)alp_SetConfig,	METH_VARARGS,	alp_SetConfig__doc__},
	{"GetConfig",	(PyCFunction)alp_GetConfig,	METH_VARARGS,	alp_GetConfig__doc__},
	{"GetResource",	(PyCFunction)alp_GetResource,	METH_VARARGS,	alp_GetResource__doc__},
	{"GetFD",	(PyCFunction)alp_GetFD,	METH_VARARGS,	alp_GetFD__doc__},
	{"GetFilled",	(PyCFunction)alp_GetFilled,	METH_VARARGS,	alp_GetFilled__doc__},
	{"GetFillable",	(PyCFunction)alp_GetFillable,	METH_VARARGS,	alp_GetFillable__doc__},
	{"ReadFrames",	(PyCFunction)alp_ReadFrames,	METH_VARARGS,	alp_ReadFrames__doc__},
	{"DiscardFrames",	(PyCFunction)alp_DiscardFrames,	METH_VARARGS,	alp_DiscardFrames__doc__},
	{"ZeroFrames",	(PyCFunction)alp_ZeroFrames,	METH_VARARGS,	alp_ZeroFrames__doc__},
	{"SetFillPoint",	(PyCFunction)alp_SetFillPoint,	METH_VARARGS,	alp_SetFillPoint__doc__},
	{"GetFillPoint",	(PyCFunction)alp_GetFillPoint,	METH_VARARGS,	alp_GetFillPoint__doc__},
	{"GetFrameNumber",	(PyCFunction)alp_GetFrameNumber,	METH_VARARGS,	alp_GetFrameNumber__doc__},
	{"GetFrameTime",	(PyCFunction)alp_GetFrameTime,	METH_VARARGS,	alp_GetFrameTime__doc__},
	{"WriteFrames",	(PyCFunction)alp_WriteFrames,	METH_VARARGS,	alp_WriteFrames__doc__},
	{"ClosePort",	(PyCFunction)alp_ClosePort,	METH_VARARGS,	alp_ClosePort__doc__},
#endif /* AL_NO_ELEM */
#ifdef OLD_INTERFACE
	{"closeport",		(PyCFunction)alp_closeport,	METH_VARARGS},
	{"getfd",		(PyCFunction)alp_getfd,	METH_VARARGS},
        {"fileno",		(PyCFunction)alp_getfd,	METH_VARARGS},
	{"getfilled",		(PyCFunction)alp_getfilled,	METH_VARARGS},
	{"getfillable",		(PyCFunction)alp_getfillable,	METH_VARARGS},
	{"readsamps",		(PyCFunction)alp_readsamps,	METH_VARARGS},
	{"writesamps",		(PyCFunction)alp_writesamps,	METH_VARARGS},
	{"setfillpoint",	(PyCFunction)alp_setfillpoint,	METH_VARARGS},
	{"getfillpoint",	(PyCFunction)alp_getfillpoint,	METH_VARARGS},
	{"setconfig",		(PyCFunction)alp_setconfig,	METH_VARARGS},
	{"getconfig",		(PyCFunction)alp_getconfig,	METH_VARARGS},
#ifdef AL_405
	{"getstatus",		(PyCFunction)alp_getstatus,	METH_VARARGS},
#endif /* AL_405 */	    
#endif /* OLD_INTERFACE */
 
	{NULL,		NULL}		/* sentinel */
};

/* ---------- */


static PyObject *
newalpobject(ALport port)
{
	alpobject *self;
	
	self = PyObject_NEW(alpobject, &Alptype);
	if (self == NULL)
		return NULL;
	/* XXXX Add your own initializers here */
	self->port = port;
	return (PyObject *) self;
}


static void
alp_dealloc(self)
	alpobject *self;
{
	/* XXXX Add your own cleanup code here */
	if (self->port) {
#ifdef AL_NO_ELEM		/* IRIX 6 */
		alClosePort(self->port);
#else
		ALcloseport(self->port);
#endif
	}
	PyMem_DEL(self);
}

static PyObject *
alp_getattr(self, name)
	alpobject *self;
	char *name;
{
	/* XXXX Add your own getattr code here */
	if (self->port == NULL) {
		PyErr_SetString(ErrorObject, "port already closed");
		return NULL;
	}
	return Py_FindMethod(alp_methods, (PyObject *)self, name);
}

static char Alptype__doc__[] = 
""
;

static PyTypeObject Alptype = {
	PyObject_HEAD_INIT(&PyType_Type)
	0,				/*ob_size*/
	"port",			/*tp_name*/
	sizeof(alpobject),		/*tp_basicsize*/
	0,				/*tp_itemsize*/
	/* methods */
	(destructor)alp_dealloc,	/*tp_dealloc*/
	(printfunc)0,		/*tp_print*/
	(getattrfunc)alp_getattr,	/*tp_getattr*/
	(setattrfunc)0,	/*tp_setattr*/
	(cmpfunc)0,		/*tp_compare*/
	(reprfunc)0,		/*tp_repr*/
	0,			/*tp_as_number*/
	0,		/*tp_as_sequence*/
	0,		/*tp_as_mapping*/
	(hashfunc)0,		/*tp_hash*/
	(ternaryfunc)0,		/*tp_call*/
	(reprfunc)0,		/*tp_str*/

	/* Space for future expansion */
	0L,0L,0L,0L,
	Alptype__doc__ /* Documentation string */
};

/* End of code for port objects */
/* -------------------------------------------------------- */


#ifdef AL_NO_ELEM		/* IRIX 6 */

static char al_NewConfig__doc__[] =
"alNewConfig: create and initialize an audio ALconfig structure."
;

static PyObject *
al_NewConfig(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	ALconfig config;

	if (!PyArg_ParseTuple(args, ":NewConfig"))
		return NULL;
	if ((config = alNewConfig()) == NULL)
		return NULL;
	return newalcobject(config);
}

static char al_OpenPort__doc__[] =
"alOpenPort: open an audio port."
;

static PyObject *
al_OpenPort(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	ALport port;
	char *name, *dir;
	alcobject *config = NULL;

	if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
		return NULL;
	if ((port = alOpenPort(name, dir, config ? config->config : NULL)) == NULL)
		return NULL;
	return newalpobject(port);
}

static char al_Connect__doc__[] =
"alConnect: connect two audio I/O resources."
;

static PyObject *
al_Connect(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int source, dest, nprops = 0, id, i;
	ALpv *props = NULL;
	ALparamInfo *propinfo = NULL;
	PyObject *propobj = NULL;

	if (!PyArg_ParseTuple(args, "ii|O!:Connect", &source, &dest, &PyList_Type, &propobj))
		return NULL;
	if (propobj != NULL) {
		nprops = python2params(source, dest, propobj, &props, &propinfo);
		if (nprops < 0)
			return NULL;
	}

	id = alConnect(source, dest, props, nprops);

	if (props) {
		for (i = 0; i < nprops; i++) {
			switch (propinfo[i].valueType) {
			case AL_SET_VAL:
			case AL_VECTOR_VAL:
				PyMem_DEL(props[i].value.ptr);
				break;
			}
		}
		PyMem_DEL(props);
		PyMem_DEL(propinfo);
	}

	if (id < 0)
		return NULL;
	return PyInt_FromLong((long) id);
}

static char al_Disconnect__doc__[] =
"alDisconnect: delete a connection between two audio I/O resources."
;

static PyObject *
al_Disconnect(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int res;

	if (!PyArg_ParseTuple(args, "i:Disconnect", &res))
		return NULL;
	if (alDisconnect(res) < 0)
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}

static char al_GetParams__doc__[] =
"alGetParams: get the values of audio resource parameters."
;

static PyObject *
al_GetParams(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int resource;
	PyObject *pvslist, *item = NULL, *v = NULL;
	ALpv *pvs;
	int i, j, npvs;
	ALparamInfo *pinfo;

	if (!PyArg_ParseTuple(args, "iO!:GetParams", &resource, &PyList_Type, &pvslist))
		return NULL;
	npvs = PyList_Size(pvslist);
	pvs = PyMem_NEW(ALpv, npvs);
	pinfo = PyMem_NEW(ALparamInfo, npvs);
	for (i = 0; i < npvs; i++) {
		item = PyList_GetItem(pvslist, i);
		if (!PyInt_Check(item)) {
			item = NULL;
			PyErr_SetString(ErrorObject, "list of integers expected");
			goto error;
		}
		pvs[i].param = (int) PyInt_AsLong(item);
		item = NULL;	/* not needed anymore */
		if (alGetParamInfo(resource, pvs[i].param, &pinfo[i]) < 0)
			goto error;
		switch (pinfo[i].valueType) {
		case AL_NO_VAL:
			break;
		case AL_MATRIX_VAL:
			pinfo[i].maxElems *= pinfo[i].maxElems2;
			/* fall through */
		case AL_STRING_VAL:
		case AL_SET_VAL:
		case AL_VECTOR_VAL:
			switch (pinfo[i].elementType) {
			case AL_INT32_ELEM:
			case AL_RESOURCE_ELEM:
			case AL_ENUM_ELEM:
				pvs[i].value.ptr = PyMem_NEW(int, pinfo[i].maxElems);
				pvs[i].sizeIn = pinfo[i].maxElems;
				break;
			case AL_INT64_ELEM:
			case AL_FIXED_ELEM:
				pvs[i].value.ptr = PyMem_NEW(long long, pinfo[i].maxElems);
				pvs[i].sizeIn = pinfo[i].maxElems;
				break;
			case AL_CHAR_ELEM:
				pvs[i].value.ptr = PyMem_NEW(char, 32);
				pvs[i].sizeIn = 32;
				break;
			case AL_NO_ELEM:
			case AL_PTR_ELEM:
			default:
				PyErr_SetString(ErrorObject, "internal error");
				goto error;
			}
			break;
		case AL_SCALAR_VAL:
			break;
		default:
			PyErr_SetString(ErrorObject, "internal error");
			goto error;
		}
		if (pinfo[i].valueType == AL_MATRIX_VAL) {
			pinfo[i].maxElems /= pinfo[i].maxElems2;
			pvs[i].sizeIn /= pinfo[i].maxElems2;
			pvs[i].size2In = pinfo[i].maxElems2;
		}
	}
	if (alGetParams(resource, pvs, npvs) < 0)
		goto error;
	v = PyList_New(npvs);
	for (i = 0; i < npvs; i++) {
		if (pvs[i].sizeOut < 0) {
			char buf[32];
			sprintf(buf, "problem with param %d", i);
			PyErr_SetString(ErrorObject, buf);
			goto error;
		}
		switch (pinfo[i].valueType) {
		case AL_NO_VAL:
			item = Py_None;
			Py_INCREF(item);
			break;
		case AL_STRING_VAL:
			item = PyString_FromString(pvs[i].value.ptr);
			PyMem_DEL(pvs[i].value.ptr);
			break;
		case AL_MATRIX_VAL:
			/* XXXX this is not right */
			pvs[i].sizeOut *= pvs[i].size2Out;
			/* fall through */
		case AL_SET_VAL:
		case AL_VECTOR_VAL:
			item = PyList_New(pvs[i].sizeOut);
			for (j = 0; j < pvs[i].sizeOut; j++) {
				switch (pinfo[i].elementType) {
				case AL_INT32_ELEM:
				case AL_RESOURCE_ELEM:
				case AL_ENUM_ELEM:
					PyList_SetItem(item, j, PyInt_FromLong((long) ((int *) pvs[i].value.ptr)[j]));
					break;
				case AL_INT64_ELEM:
					PyList_SetItem(item, j, PyLong_FromLongLong(((long long *) pvs[i].value.ptr)[j]));
					break;
				case AL_FIXED_ELEM:
					PyList_SetItem(item, j, PyFloat_FromDouble(alFixedToDouble(((long long *) pvs[i].value.ptr)[j])));
					break;
				default:
					PyErr_SetString(ErrorObject, "internal error");
					goto error;
				}
			}
			PyMem_DEL(pvs[i].value.ptr);
			break;
		case AL_SCALAR_VAL:
			item = param2python(resource, pvs[i].param, pvs[i].value, &pinfo[i]);
			break;
		}
		if (PyErr_Occurred() ||
		    PyList_SetItem(v, i, Py_BuildValue("(iO)", pvs[i].param,
						       item)) < 0 ||
		    PyErr_Occurred())
			goto error;
		Py_DECREF(item);
	}
	PyMem_DEL(pvs);
	PyMem_DEL(pinfo);
	return v;

  error:
	Py_XDECREF(v);
	Py_XDECREF(item);
	if (pvs)
		PyMem_DEL(pvs);
	if (pinfo)
		PyMem_DEL(pinfo);
	return NULL;
}

static char al_SetParams__doc__[] =
"alSetParams: set the values of audio resource parameters."
;

static PyObject *
al_SetParams(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int resource;
	PyObject *pvslist, *item;
	ALpv *pvs;
	ALparamInfo *pinfo;
	int npvs, i;

	if (!PyArg_ParseTuple(args, "iO!:SetParams", &resource, &PyList_Type, &pvslist))
		return NULL;
	npvs = python2params(resource, -1, pvslist, &pvs, &pinfo);
	if (npvs < 0)
		return NULL;

	if (alSetParams(resource, pvs, npvs) < 0)
		goto error;

	/* cleanup */
	for (i = 0; i < npvs; i++) {
		switch (pinfo[i].valueType) {
		case AL_SET_VAL:
		case AL_VECTOR_VAL:
			PyMem_DEL(pvs[i].value.ptr);
			break;
		}
	}
	PyMem_DEL(pvs);
	PyMem_DEL(pinfo);

	Py_INCREF(Py_None);
	return Py_None;

  error:
	/* XXXX we should clean up everything */
	if (pvs)
		PyMem_DEL(pvs);
	if (pinfo)
		PyMem_DEL(pinfo);
	return NULL;
}

static char al_QueryValues__doc__[] =
"alQueryValues: get the set of possible values for a parameter."
;

static PyObject *
al_QueryValues(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int resource, param;
	ALvalue *return_set = NULL;
	int setsize = 32, qualsize = 0, nvals, i;
	ALpv *quals = NULL;
	ALparamInfo pinfo;
	ALparamInfo *qualinfo = NULL;
	PyObject *qualobj = NULL;
	PyObject *res = NULL, *item;

	if (!PyArg_ParseTuple(args, "ii|O!:QueryValues", &resource, &param,
			      &PyList_Type, &qualobj))
		return NULL;
	if (qualobj != NULL) {
		qualsize = python2params(resource, param, qualobj, &quals, &qualinfo);
		if (qualsize < 0)
			return NULL;
	}
	setsize = 32;
	return_set = PyMem_NEW(ALvalue, setsize);
	if (return_set == NULL) {
		PyErr_NoMemory();
		goto cleanup;
	}

  retry:
	nvals = alQueryValues(resource, param, return_set, setsize, quals, qualsize);
	if (nvals < 0)
		goto cleanup;
	if (nvals > setsize) {
		setsize = nvals;
		PyMem_RESIZE(return_set, ALvalue, setsize);
		if (return_set == NULL) {
			PyErr_NoMemory();
			goto cleanup;
		}
		goto retry;
	}

	if (alGetParamInfo(resource, param, &pinfo) < 0)
		goto cleanup;

	res = PyList_New(nvals);
	if (res == NULL)
		goto cleanup;
	for (i = 0; i < nvals; i++) {
		item = param2python(resource, param, return_set[i], &pinfo);
		if (item == NULL ||
		    PyList_SetItem(res, i, item) < 0) {
			Py_DECREF(res);
			res = NULL;
			goto cleanup;
		}
	}

  cleanup:
	if (return_set)
		PyMem_DEL(return_set);
	if (quals) {
		for (i = 0; i < qualsize; i++) {
			switch (qualinfo[i].valueType) {
			case AL_SET_VAL:
			case AL_VECTOR_VAL:
				PyMem_DEL(quals[i].value.ptr);
				break;
			}
		}
		PyMem_DEL(quals);
		PyMem_DEL(qualinfo);
	}

	return res;
}

static char al_GetParamInfo__doc__[] =
"alGetParamInfo: get information about a parameter on a particular audio resource."
;

static PyObject *
al_GetParamInfo(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int res, param;
	ALparamInfo pinfo;
	PyObject *v, *item;;

	if (!PyArg_ParseTuple(args, "ii:GetParamInfo", &res, &param))
		return NULL;
	if (alGetParamInfo(res, param, &pinfo) < 0)
		return NULL;
	v = PyDict_New();

	item = PyInt_FromLong((long) pinfo.resource);
	PyDict_SetItemString(v, "resource", item);
	Py_DECREF(item);

	item = PyInt_FromLong((long) pinfo.param);
	PyDict_SetItemString(v, "param", item);
	Py_DECREF(item);

	item = PyInt_FromLong((long) pinfo.valueType);
	PyDict_SetItemString(v, "valueType", item);
	Py_DECREF(item);

	if (pinfo.valueType != AL_NO_VAL && pinfo.valueType != AL_SCALAR_VAL) {
		/* multiple values */
		item = PyInt_FromLong((long) pinfo.maxElems);
		PyDict_SetItemString(v, "maxElems", item);
		Py_DECREF(item);

		if (pinfo.valueType == AL_MATRIX_VAL) {
			/* 2 dimensional */
			item = PyInt_FromLong((long) pinfo.maxElems2);
			PyDict_SetItemString(v, "maxElems2", item);
			Py_DECREF(item);
		}
	}

	item = PyInt_FromLong((long) pinfo.elementType);
	PyDict_SetItemString(v, "elementType", item);
	Py_DECREF(item);

	item = PyString_FromString(pinfo.name);
	PyDict_SetItemString(v, "name", item);
	Py_DECREF(item);

	item = param2python(res, param, pinfo.initial, &pinfo);
	PyDict_SetItemString(v, "initial", item);
	Py_DECREF(item);

	if (pinfo.elementType != AL_ENUM_ELEM &&
	    pinfo.elementType != AL_RESOURCE_ELEM &&
	    pinfo.elementType != AL_CHAR_ELEM) {
		/* range param */
		item = param2python(res, param, pinfo.min, &pinfo);
		PyDict_SetItemString(v, "min", item);
		Py_DECREF(item);

		item = param2python(res, param, pinfo.max, &pinfo);
		PyDict_SetItemString(v, "max", item);
		Py_DECREF(item);

		item = param2python(res, param, pinfo.minDelta, &pinfo);
		PyDict_SetItemString(v, "minDelta", item);
		Py_DECREF(item);

		item = param2python(res, param, pinfo.maxDelta, &pinfo);
		PyDict_SetItemString(v, "maxDelta", item);
		Py_DECREF(item);

		item = PyInt_FromLong((long) pinfo.specialVals);
		PyDict_SetItemString(v, "specialVals", item);
		Py_DECREF(item);
	}

	return v;
}

static char al_GetResourceByName__doc__[] =
"alGetResourceByName: find an audio resource by name."
;

static PyObject *
al_GetResourceByName(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int res, start_res, type;
	char *name;

	if (!PyArg_ParseTuple(args, "isi:GetResourceByName", &start_res, &name, &type))
		return NULL;
	if ((res = alGetResourceByName(start_res, name, type)) == 0)
		return NULL;
	return PyInt_FromLong((long) res);
}

static char al_IsSubtype__doc__[] =
"alIsSubtype: indicate if one resource type is a subtype of another."
;

static PyObject *
al_IsSubtype(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{
	int type, subtype;

	if (!PyArg_ParseTuple(args, "ii:IsSubtype", &type, &subtype))
		return NULL;
	return PyInt_FromLong((long) alIsSubtype(type, subtype));
}

static char al_SetErrorHandler__doc__[] =
""
;

static PyObject *
al_SetErrorHandler(self, args)
	PyObject *self;	/* Not used */
	PyObject *args;
{

	if (!PyArg_ParseTuple(args, ":SetErrorHandler"))
		return NULL;
	Py_INCREF(Py_None);
	return Py_None;
}

#endif /* AL_NO_ELEM */

#ifdef OLD_INTERFACE

static PyObject *
al_openport(self, args)
	PyObject *self, *args;
{
	char *name, *dir;
	ALport port;
	alcobject *config = NULL;

	if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
		return NULL;
	if ((port = ALopenport(name, dir, config ? config->config : NULL)) == NULL)
		return NULL;
	return newalpobject(port);
}

static PyObject *
al_newconfig(self, args)
	PyObject *self, *args;
{
	ALconfig config;

	if (!PyArg_ParseTuple(args, ":NewConfig"))
		return NULL;
	if ((config = ALnewconfig ()) == NULL)
		return NULL;
	return newalcobject(config);
}

static PyObject *
al_queryparams(self, args)
	PyObject *self, *args;
{
	long device;
	long length;
	long *PVbuffer;
	long PVdummy[2];
	PyObject *v = NULL;
	int i;

	if (!PyArg_ParseTuple(args, "l:queryparams", &device))
		return NULL;
	if ((length = ALqueryparams(device, PVdummy, 2L)) == -1)
		return NULL;
	if ((PVbuffer = PyMem_NEW(long, length)) == NULL)
		return PyErr_NoMemory();
	if (ALqueryparams(device, PVbuffer, length) >= 0 &&
	    (v = PyList_New((int)length)) != NULL) {
		for (i = 0; i < length; i++)
			PyList_SetItem(v, i, PyInt_FromLong(PVbuffer[i]));
	}
	PyMem_DEL(PVbuffer);
	return v;
}

static PyObject *
doParams(args, func, modified)
	PyObject *args;
	int (*func)(long, long *, long);
	int modified;
{
	long device;
	PyObject *list, *v;
	long *PVbuffer;
	long length;
	int i;
	
	if (!PyArg_ParseTuple(args, "lO!", &device, &PyList_Type, &list))
		return NULL;
	length = PyList_Size(list);
	PVbuffer = PyMem_NEW(long, length);
	if (PVbuffer == NULL)
		return PyErr_NoMemory();
	for (i = 0; i < length; i++) {
		v = PyList_GetItem(list, i);
		if (!PyInt_Check(v)) {
			PyMem_DEL(PVbuffer);
			PyErr_BadArgument();
			return NULL;
		}
		PVbuffer[i] = PyInt_AsLong(v);
	}

	if ((*func)(device, PVbuffer, length) == -1) {
		PyMem_DEL(PVbuffer);
		return NULL;
	}

	if (modified) {
		for (i = 0; i < length; i++)
			PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
	}

	PyMem_DEL(PVbuffer);

	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
al_getparams(self, args)
	PyObject *self, *args;
{
	return doParams(args, ALgetparams, 1);
}

static PyObject *
al_setparams(self, args)
	PyObject *self, *args;
{
	return doParams(args, ALsetparams, 0);
}

static PyObject *
al_getname(self, args)
	PyObject *self, *args;
{
	long device, descriptor;
	char *name;

	if (!PyArg_ParseTuple(args, "ll:getname", &device, &descriptor))
		return NULL;
	if ((name = ALgetname(device, descriptor)) == NULL)
		return NULL;
	return PyString_FromString(name);
}

static PyObject *
al_getdefault(self, args)
	PyObject *self, *args;
{
	long device, descriptor, value;

	if (!PyArg_ParseTuple(args, "ll:getdefault", &device, &descriptor))
		return NULL;
	if ((value = ALgetdefault(device, descriptor)) == -1)
		return NULL;
	return PyLong_FromLong(value);
}

static PyObject *
al_getminmax(self, args)
	PyObject *self, *args;
{
	long device, descriptor, min, max;

	if (!PyArg_ParseTuple(args, "ll:getminmax", &device, &descriptor))
		return NULL;
	min = -1;
	max = -1;
	if (ALgetminmax(device, descriptor, &min, &max) == -1)
		return NULL;
	return Py_BuildValue("ll", min, max);
}

#endif /* OLD_INTERFACE */

/* List of methods defined in the module */

static struct PyMethodDef al_methods[] = {
#ifdef AL_NO_ELEM		/* IRIX 6 */
	{"NewConfig",	(PyCFunction)al_NewConfig,	METH_VARARGS,	al_NewConfig__doc__},
	{"OpenPort",	(PyCFunction)al_OpenPort,	METH_VARARGS,	al_OpenPort__doc__},
	{"Connect",	(PyCFunction)al_Connect,	METH_VARARGS,	al_Connect__doc__},
	{"Disconnect",	(PyCFunction)al_Disconnect,	METH_VARARGS,	al_Disconnect__doc__},
	{"GetParams",	(PyCFunction)al_GetParams,	METH_VARARGS,	al_GetParams__doc__},
	{"SetParams",	(PyCFunction)al_SetParams,	METH_VARARGS,	al_SetParams__doc__},
	{"QueryValues",	(PyCFunction)al_QueryValues,	METH_VARARGS,	al_QueryValues__doc__},
	{"GetParamInfo",	(PyCFunction)al_GetParamInfo,	METH_VARARGS,	al_GetParamInfo__doc__},
	{"GetResourceByName",	(PyCFunction)al_GetResourceByName,	METH_VARARGS,	al_GetResourceByName__doc__},
	{"IsSubtype",	(PyCFunction)al_IsSubtype,	METH_VARARGS,	al_IsSubtype__doc__},
#if 0
	/* this one not supported */
	{"SetErrorHandler",	(PyCFunction)al_SetErrorHandler,	METH_VARARGS,	al_SetErrorHandler__doc__},
#endif
#endif /* AL_NO_ELEM */
#ifdef OLD_INTERFACE
	{"openport",		(PyCFunction)al_openport,	METH_VARARGS},
	{"newconfig",		(PyCFunction)al_newconfig,	METH_VARARGS},
	{"queryparams",		(PyCFunction)al_queryparams,	METH_VARARGS},
	{"getparams",		(PyCFunction)al_getparams,	METH_VARARGS},
	{"setparams",		(PyCFunction)al_setparams,	METH_VARARGS},
	{"getname",		(PyCFunction)al_getname,	METH_VARARGS},
	{"getdefault",		(PyCFunction)al_getdefault,	METH_VARARGS},
	{"getminmax",		(PyCFunction)al_getminmax,	METH_VARARGS},
#endif /* OLD_INTERFACE */

	{NULL,	 (PyCFunction)NULL, 0, NULL}		/* sentinel */
};


/* Initialization function for the module (*must* be called inital) */

static char al_module_documentation[] = 
""
;

void
inital()
{
	PyObject *m, *d, *x;

	/* Create the module and add the functions */
	m = Py_InitModule4("al", al_methods,
		al_module_documentation,
		(PyObject*)NULL,PYTHON_API_VERSION);

	/* Add some symbolic constants to the module */
	d = PyModule_GetDict(m);
	ErrorObject = PyString_FromString("al.error");
	PyDict_SetItemString(d, "error", ErrorObject);

	/* XXXX Add constants here */
#ifdef AL_4CHANNEL
	x =  PyInt_FromLong((long) AL_4CHANNEL);
	if (x == NULL || PyDict_SetItemString(d, "FOURCHANNEL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ADAT_IF_TYPE
	x =  PyInt_FromLong((long) AL_ADAT_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "ADAT_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ADAT_MCLK_TYPE
	x =  PyInt_FromLong((long) AL_ADAT_MCLK_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "ADAT_MCLK_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_AES_IF_TYPE
	x =  PyInt_FromLong((long) AL_AES_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "AES_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_AES_MCLK_TYPE
	x =  PyInt_FromLong((long) AL_AES_MCLK_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "AES_MCLK_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ANALOG_IF_TYPE
	x =  PyInt_FromLong((long) AL_ANALOG_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "ANALOG_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ASSOCIATE
	x =  PyInt_FromLong((long) AL_ASSOCIATE);
	if (x == NULL || PyDict_SetItemString(d, "ASSOCIATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_BUFFER_NULL
	x =  PyInt_FromLong((long) AL_BAD_BUFFER_NULL);
	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFER_NULL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_BUFFERLENGTH
	x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH);
	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_BUFFERLENGTH_NEG
	x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_NEG);
	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_NEG", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_BUFFERLENGTH_ODD
	x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_ODD);
	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_ODD", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_CHANNELS
	x =  PyInt_FromLong((long) AL_BAD_CHANNELS);
	if (x == NULL || PyDict_SetItemString(d, "BAD_CHANNELS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_CONFIG
	x =  PyInt_FromLong((long) AL_BAD_CONFIG);
	if (x == NULL || PyDict_SetItemString(d, "BAD_CONFIG", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_COUNT_NEG
	x =  PyInt_FromLong((long) AL_BAD_COUNT_NEG);
	if (x == NULL || PyDict_SetItemString(d, "BAD_COUNT_NEG", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_DEVICE
	x =  PyInt_FromLong((long) AL_BAD_DEVICE);
	if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_DEVICE_ACCESS
	x =  PyInt_FromLong((long) AL_BAD_DEVICE_ACCESS);
	if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE_ACCESS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_DIRECTION
	x =  PyInt_FromLong((long) AL_BAD_DIRECTION);
	if (x == NULL || PyDict_SetItemString(d, "BAD_DIRECTION", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_FILLPOINT
	x =  PyInt_FromLong((long) AL_BAD_FILLPOINT);
	if (x == NULL || PyDict_SetItemString(d, "BAD_FILLPOINT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_FLOATMAX
	x =  PyInt_FromLong((long) AL_BAD_FLOATMAX);
	if (x == NULL || PyDict_SetItemString(d, "BAD_FLOATMAX", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_ILLEGAL_STATE
	x =  PyInt_FromLong((long) AL_BAD_ILLEGAL_STATE);
	if (x == NULL || PyDict_SetItemString(d, "BAD_ILLEGAL_STATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_NO_PORTS
	x =  PyInt_FromLong((long) AL_BAD_NO_PORTS);
	if (x == NULL || PyDict_SetItemString(d, "BAD_NO_PORTS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_NOT_FOUND
	x =  PyInt_FromLong((long) AL_BAD_NOT_FOUND);
	if (x == NULL || PyDict_SetItemString(d, "BAD_NOT_FOUND", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_NOT_IMPLEMENTED
	x =  PyInt_FromLong((long) AL_BAD_NOT_IMPLEMENTED);
	if (x == NULL || PyDict_SetItemString(d, "BAD_NOT_IMPLEMENTED", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_OUT_OF_MEM
	x =  PyInt_FromLong((long) AL_BAD_OUT_OF_MEM);
	if (x == NULL || PyDict_SetItemString(d, "BAD_OUT_OF_MEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_PARAM
	x =  PyInt_FromLong((long) AL_BAD_PARAM);
	if (x == NULL || PyDict_SetItemString(d, "BAD_PARAM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_PERMISSIONS
	x =  PyInt_FromLong((long) AL_BAD_PERMISSIONS);
	if (x == NULL || PyDict_SetItemString(d, "BAD_PERMISSIONS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_PORT
	x =  PyInt_FromLong((long) AL_BAD_PORT);
	if (x == NULL || PyDict_SetItemString(d, "BAD_PORT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_PORTSTYLE
	x =  PyInt_FromLong((long) AL_BAD_PORTSTYLE);
	if (x == NULL || PyDict_SetItemString(d, "BAD_PORTSTYLE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_PVBUFFER
	x =  PyInt_FromLong((long) AL_BAD_PVBUFFER);
	if (x == NULL || PyDict_SetItemString(d, "BAD_PVBUFFER", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_QSIZE
	x =  PyInt_FromLong((long) AL_BAD_QSIZE);
	if (x == NULL || PyDict_SetItemString(d, "BAD_QSIZE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_RATE
	x =  PyInt_FromLong((long) AL_BAD_RATE);
	if (x == NULL || PyDict_SetItemString(d, "BAD_RATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_RESOURCE
	x =  PyInt_FromLong((long) AL_BAD_RESOURCE);
	if (x == NULL || PyDict_SetItemString(d, "BAD_RESOURCE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_SAMPFMT
	x =  PyInt_FromLong((long) AL_BAD_SAMPFMT);
	if (x == NULL || PyDict_SetItemString(d, "BAD_SAMPFMT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_TRANSFER_SIZE
	x =  PyInt_FromLong((long) AL_BAD_TRANSFER_SIZE);
	if (x == NULL || PyDict_SetItemString(d, "BAD_TRANSFER_SIZE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_BAD_WIDTH
	x =  PyInt_FromLong((long) AL_BAD_WIDTH);
	if (x == NULL || PyDict_SetItemString(d, "BAD_WIDTH", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CHANNEL_MODE
	x =  PyInt_FromLong((long) AL_CHANNEL_MODE);
	if (x == NULL || PyDict_SetItemString(d, "CHANNEL_MODE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CHANNELS
	x =  PyInt_FromLong((long) AL_CHANNELS);
	if (x == NULL || PyDict_SetItemString(d, "CHANNELS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CHAR_ELEM
	x =  PyInt_FromLong((long) AL_CHAR_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "CHAR_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CLOCK_GEN
	x =  PyInt_FromLong((long) AL_CLOCK_GEN);
	if (x == NULL || PyDict_SetItemString(d, "CLOCK_GEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CLOCKGEN_TYPE
	x =  PyInt_FromLong((long) AL_CLOCKGEN_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "CLOCKGEN_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CONNECT
	x =  PyInt_FromLong((long) AL_CONNECT);
	if (x == NULL || PyDict_SetItemString(d, "CONNECT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CONNECTION_TYPE
	x =  PyInt_FromLong((long) AL_CONNECTION_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "CONNECTION_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CONNECTIONS
	x =  PyInt_FromLong((long) AL_CONNECTIONS);
	if (x == NULL || PyDict_SetItemString(d, "CONNECTIONS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_CRYSTAL_MCLK_TYPE
	x =  PyInt_FromLong((long) AL_CRYSTAL_MCLK_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "CRYSTAL_MCLK_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DEFAULT_DEVICE
	x =  PyInt_FromLong((long) AL_DEFAULT_DEVICE);
	if (x == NULL || PyDict_SetItemString(d, "DEFAULT_DEVICE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DEFAULT_INPUT
	x =  PyInt_FromLong((long) AL_DEFAULT_INPUT);
	if (x == NULL || PyDict_SetItemString(d, "DEFAULT_INPUT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DEFAULT_OUTPUT
	x =  PyInt_FromLong((long) AL_DEFAULT_OUTPUT);
	if (x == NULL || PyDict_SetItemString(d, "DEFAULT_OUTPUT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DEST
	x =  PyInt_FromLong((long) AL_DEST);
	if (x == NULL || PyDict_SetItemString(d, "DEST", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DEVICE_TYPE
	x =  PyInt_FromLong((long) AL_DEVICE_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "DEVICE_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DEVICES
	x =  PyInt_FromLong((long) AL_DEVICES);
	if (x == NULL || PyDict_SetItemString(d, "DEVICES", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DIGITAL_IF_TYPE
	x =  PyInt_FromLong((long) AL_DIGITAL_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "DIGITAL_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DIGITAL_INPUT_RATE
	x =  PyInt_FromLong((long) AL_DIGITAL_INPUT_RATE);
	if (x == NULL || PyDict_SetItemString(d, "DIGITAL_INPUT_RATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_DISCONNECT
	x =  PyInt_FromLong((long) AL_DISCONNECT);
	if (x == NULL || PyDict_SetItemString(d, "DISCONNECT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ENUM_ELEM
	x =  PyInt_FromLong((long) AL_ENUM_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "ENUM_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ENUM_VALUE
	x =  PyInt_FromLong((long) AL_ENUM_VALUE);
	if (x == NULL || PyDict_SetItemString(d, "ENUM_VALUE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ERROR_INPUT_OVERFLOW
	x =  PyInt_FromLong((long) AL_ERROR_INPUT_OVERFLOW);
	if (x == NULL || PyDict_SetItemString(d, "ERROR_INPUT_OVERFLOW", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ERROR_LENGTH
	x =  PyInt_FromLong((long) AL_ERROR_LENGTH);
	if (x == NULL || PyDict_SetItemString(d, "ERROR_LENGTH", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ERROR_LOCATION_LSP
	x =  PyInt_FromLong((long) AL_ERROR_LOCATION_LSP);
	if (x == NULL || PyDict_SetItemString(d, "ERROR_LOCATION_LSP", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ERROR_LOCATION_MSP
	x =  PyInt_FromLong((long) AL_ERROR_LOCATION_MSP);
	if (x == NULL || PyDict_SetItemString(d, "ERROR_LOCATION_MSP", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ERROR_NUMBER
	x =  PyInt_FromLong((long) AL_ERROR_NUMBER);
	if (x == NULL || PyDict_SetItemString(d, "ERROR_NUMBER", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ERROR_OUTPUT_UNDERFLOW
	x =  PyInt_FromLong((long) AL_ERROR_OUTPUT_UNDERFLOW);
	if (x == NULL || PyDict_SetItemString(d, "ERROR_OUTPUT_UNDERFLOW", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_ERROR_TYPE
	x =  PyInt_FromLong((long) AL_ERROR_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "ERROR_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_FIXED_ELEM
	x =  PyInt_FromLong((long) AL_FIXED_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "FIXED_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_FIXED_MCLK_TYPE
	x =  PyInt_FromLong((long) AL_FIXED_MCLK_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "FIXED_MCLK_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_GAIN
	x =  PyInt_FromLong((long) AL_GAIN);
	if (x == NULL || PyDict_SetItemString(d, "GAIN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_GAIN_REF
	x =  PyInt_FromLong((long) AL_GAIN_REF);
	if (x == NULL || PyDict_SetItemString(d, "GAIN_REF", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_HRB_TYPE
	x =  PyInt_FromLong((long) AL_HRB_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "HRB_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_COUNT
	x =  PyInt_FromLong((long) AL_INPUT_COUNT);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_COUNT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_DEVICE_TYPE
	x =  PyInt_FromLong((long) AL_INPUT_DEVICE_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_DEVICE_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_DIGITAL
	x =  PyInt_FromLong((long) AL_INPUT_DIGITAL);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_DIGITAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_HRB_TYPE
	x =  PyInt_FromLong((long) AL_INPUT_HRB_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_HRB_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_LINE
	x =  PyInt_FromLong((long) AL_INPUT_LINE);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_LINE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_MIC
	x =  PyInt_FromLong((long) AL_INPUT_MIC);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_MIC", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_PORT_TYPE
	x =  PyInt_FromLong((long) AL_INPUT_PORT_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_PORT_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_RATE
	x =  PyInt_FromLong((long) AL_INPUT_RATE);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_RATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INPUT_SOURCE
	x =  PyInt_FromLong((long) AL_INPUT_SOURCE);
	if (x == NULL || PyDict_SetItemString(d, "INPUT_SOURCE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INT32_ELEM
	x =  PyInt_FromLong((long) AL_INT32_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "INT32_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INT64_ELEM
	x =  PyInt_FromLong((long) AL_INT64_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "INT64_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INTERFACE
	x =  PyInt_FromLong((long) AL_INTERFACE);
	if (x == NULL || PyDict_SetItemString(d, "INTERFACE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INTERFACE_TYPE
	x =  PyInt_FromLong((long) AL_INTERFACE_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "INTERFACE_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INVALID_PARAM
	x =  PyInt_FromLong((long) AL_INVALID_PARAM);
	if (x == NULL || PyDict_SetItemString(d, "INVALID_PARAM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_INVALID_VALUE
	x =  PyInt_FromLong((long) AL_INVALID_VALUE);
	if (x == NULL || PyDict_SetItemString(d, "INVALID_VALUE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_JITTER
	x =  PyInt_FromLong((long) AL_JITTER);
	if (x == NULL || PyDict_SetItemString(d, "JITTER", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_LABEL
	x =  PyInt_FromLong((long) AL_LABEL);
	if (x == NULL || PyDict_SetItemString(d, "LABEL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_LEFT_INPUT_ATTEN
	x =  PyInt_FromLong((long) AL_LEFT_INPUT_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "LEFT_INPUT_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_LEFT_MONITOR_ATTEN
	x =  PyInt_FromLong((long) AL_LEFT_MONITOR_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "LEFT_MONITOR_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_LEFT_SPEAKER_GAIN
	x =  PyInt_FromLong((long) AL_LEFT_SPEAKER_GAIN);
	if (x == NULL || PyDict_SetItemString(d, "LEFT_SPEAKER_GAIN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_LEFT1_INPUT_ATTEN
	x =  PyInt_FromLong((long) AL_LEFT1_INPUT_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "LEFT1_INPUT_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_LEFT2_INPUT_ATTEN
	x =  PyInt_FromLong((long) AL_LEFT2_INPUT_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "LEFT2_INPUT_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_LINE_IF_TYPE
	x =  PyInt_FromLong((long) AL_LINE_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "LINE_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MASTER_CLOCK
	x =  PyInt_FromLong((long) AL_MASTER_CLOCK);
	if (x == NULL || PyDict_SetItemString(d, "MASTER_CLOCK", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MATRIX_VAL
	x =  PyInt_FromLong((long) AL_MATRIX_VAL);
	if (x == NULL || PyDict_SetItemString(d, "MATRIX_VAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MAX_ERROR
	x =  PyInt_FromLong((long) AL_MAX_ERROR);
	if (x == NULL || PyDict_SetItemString(d, "MAX_ERROR", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MAX_EVENT_PARAM
	x =  PyInt_FromLong((long) AL_MAX_EVENT_PARAM);
	if (x == NULL || PyDict_SetItemString(d, "MAX_EVENT_PARAM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MAX_PBUFSIZE
	x =  PyInt_FromLong((long) AL_MAX_PBUFSIZE);
	if (x == NULL || PyDict_SetItemString(d, "MAX_PBUFSIZE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MAX_PORTS
	x =  PyInt_FromLong((long) AL_MAX_PORTS);
	if (x == NULL || PyDict_SetItemString(d, "MAX_PORTS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MAX_RESOURCE_ID
	x =  PyInt_FromLong((long) AL_MAX_RESOURCE_ID);
	if (x == NULL || PyDict_SetItemString(d, "MAX_RESOURCE_ID", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MAX_SETSIZE
	x =  PyInt_FromLong((long) AL_MAX_SETSIZE);
	if (x == NULL || PyDict_SetItemString(d, "MAX_SETSIZE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MAX_STRLEN
	x =  PyInt_FromLong((long) AL_MAX_STRLEN);
	if (x == NULL || PyDict_SetItemString(d, "MAX_STRLEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MCLK_TYPE
	x =  PyInt_FromLong((long) AL_MCLK_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "MCLK_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MIC_IF_TYPE
	x =  PyInt_FromLong((long) AL_MIC_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "MIC_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MONITOR_CTL
	x =  PyInt_FromLong((long) AL_MONITOR_CTL);
	if (x == NULL || PyDict_SetItemString(d, "MONITOR_CTL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MONITOR_OFF
	x =  PyInt_FromLong((long) AL_MONITOR_OFF);
	if (x == NULL || PyDict_SetItemString(d, "MONITOR_OFF", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MONITOR_ON
	x =  PyInt_FromLong((long) AL_MONITOR_ON);
	if (x == NULL || PyDict_SetItemString(d, "MONITOR_ON", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MONO
	x =  PyInt_FromLong((long) AL_MONO);
	if (x == NULL || PyDict_SetItemString(d, "MONO", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_MUTE
	x =  PyInt_FromLong((long) AL_MUTE);
	if (x == NULL || PyDict_SetItemString(d, "MUTE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NAME
	x =  PyInt_FromLong((long) AL_NAME);
	if (x == NULL || PyDict_SetItemString(d, "NAME", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NEG_INFINITY
	x =  PyInt_FromLong((long) AL_NEG_INFINITY);
	if (x == NULL || PyDict_SetItemString(d, "NEG_INFINITY", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NEG_INFINITY_BIT
	x =  PyInt_FromLong((long) AL_NEG_INFINITY_BIT);
	if (x == NULL || PyDict_SetItemString(d, "NEG_INFINITY_BIT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NO_CHANGE
	x =  PyInt_FromLong((long) AL_NO_CHANGE);
	if (x == NULL || PyDict_SetItemString(d, "NO_CHANGE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NO_CHANGE_BIT
	x =  PyInt_FromLong((long) AL_NO_CHANGE_BIT);
	if (x == NULL || PyDict_SetItemString(d, "NO_CHANGE_BIT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NO_ELEM
	x =  PyInt_FromLong((long) AL_NO_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "NO_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NO_ERRORS
	x =  PyInt_FromLong((long) AL_NO_ERRORS);
	if (x == NULL || PyDict_SetItemString(d, "NO_ERRORS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NO_OP
	x =  PyInt_FromLong((long) AL_NO_OP);
	if (x == NULL || PyDict_SetItemString(d, "NO_OP", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NO_VAL
	x =  PyInt_FromLong((long) AL_NO_VAL);
	if (x == NULL || PyDict_SetItemString(d, "NO_VAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_NULL_RESOURCE
	x =  PyInt_FromLong((long) AL_NULL_RESOURCE);
	if (x == NULL || PyDict_SetItemString(d, "NULL_RESOURCE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_OUTPUT_COUNT
	x =  PyInt_FromLong((long) AL_OUTPUT_COUNT);
	if (x == NULL || PyDict_SetItemString(d, "OUTPUT_COUNT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_OUTPUT_DEVICE_TYPE
	x =  PyInt_FromLong((long) AL_OUTPUT_DEVICE_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "OUTPUT_DEVICE_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_OUTPUT_HRB_TYPE
	x =  PyInt_FromLong((long) AL_OUTPUT_HRB_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "OUTPUT_HRB_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_OUTPUT_PORT_TYPE
	x =  PyInt_FromLong((long) AL_OUTPUT_PORT_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "OUTPUT_PORT_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_OUTPUT_RATE
	x =  PyInt_FromLong((long) AL_OUTPUT_RATE);
	if (x == NULL || PyDict_SetItemString(d, "OUTPUT_RATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PARAM_BIT
	x =  PyInt_FromLong((long) AL_PARAM_BIT);
	if (x == NULL || PyDict_SetItemString(d, "PARAM_BIT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PARAMS
	x =  PyInt_FromLong((long) AL_PARAMS);
	if (x == NULL || PyDict_SetItemString(d, "PARAMS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PORT_COUNT
	x =  PyInt_FromLong((long) AL_PORT_COUNT);
	if (x == NULL || PyDict_SetItemString(d, "PORT_COUNT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PORT_TYPE
	x =  PyInt_FromLong((long) AL_PORT_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "PORT_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PORTS
	x =  PyInt_FromLong((long) AL_PORTS);
	if (x == NULL || PyDict_SetItemString(d, "PORTS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PORTSTYLE_DIRECT
	x =  PyInt_FromLong((long) AL_PORTSTYLE_DIRECT);
	if (x == NULL || PyDict_SetItemString(d, "PORTSTYLE_DIRECT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PORTSTYLE_SERIAL
	x =  PyInt_FromLong((long) AL_PORTSTYLE_SERIAL);
	if (x == NULL || PyDict_SetItemString(d, "PORTSTYLE_SERIAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PRINT_ERRORS
	x =  PyInt_FromLong((long) AL_PRINT_ERRORS);
	if (x == NULL || PyDict_SetItemString(d, "PRINT_ERRORS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_PTR_ELEM
	x =  PyInt_FromLong((long) AL_PTR_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "PTR_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RANGE_VALUE
	x =  PyInt_FromLong((long) AL_RANGE_VALUE);
	if (x == NULL || PyDict_SetItemString(d, "RANGE_VALUE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE
	x =  PyInt_FromLong((long) AL_RATE);
	if (x == NULL || PyDict_SetItemString(d, "RATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_11025
	x =  PyInt_FromLong((long) AL_RATE_11025);
	if (x == NULL || PyDict_SetItemString(d, "RATE_11025", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_16000
	x =  PyInt_FromLong((long) AL_RATE_16000);
	if (x == NULL || PyDict_SetItemString(d, "RATE_16000", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_22050
	x =  PyInt_FromLong((long) AL_RATE_22050);
	if (x == NULL || PyDict_SetItemString(d, "RATE_22050", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_32000
	x =  PyInt_FromLong((long) AL_RATE_32000);
	if (x == NULL || PyDict_SetItemString(d, "RATE_32000", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_44100
	x =  PyInt_FromLong((long) AL_RATE_44100);
	if (x == NULL || PyDict_SetItemString(d, "RATE_44100", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_48000
	x =  PyInt_FromLong((long) AL_RATE_48000);
	if (x == NULL || PyDict_SetItemString(d, "RATE_48000", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_8000
	x =  PyInt_FromLong((long) AL_RATE_8000);
	if (x == NULL || PyDict_SetItemString(d, "RATE_8000", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_AES_1
	x =  PyInt_FromLong((long) AL_RATE_AES_1);
	if (x == NULL || PyDict_SetItemString(d, "RATE_AES_1", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_AES_1s
	x =  PyInt_FromLong((long) AL_RATE_AES_1s);
	if (x == NULL || PyDict_SetItemString(d, "RATE_AES_1s", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_AES_2
	x =  PyInt_FromLong((long) AL_RATE_AES_2);
	if (x == NULL || PyDict_SetItemString(d, "RATE_AES_2", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_AES_3
	x =  PyInt_FromLong((long) AL_RATE_AES_3);
	if (x == NULL || PyDict_SetItemString(d, "RATE_AES_3", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_AES_4
	x =  PyInt_FromLong((long) AL_RATE_AES_4);
	if (x == NULL || PyDict_SetItemString(d, "RATE_AES_4", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_AES_6
	x =  PyInt_FromLong((long) AL_RATE_AES_6);
	if (x == NULL || PyDict_SetItemString(d, "RATE_AES_6", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_FRACTION_D
	x =  PyInt_FromLong((long) AL_RATE_FRACTION_D);
	if (x == NULL || PyDict_SetItemString(d, "RATE_FRACTION_D", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_FRACTION_N
	x =  PyInt_FromLong((long) AL_RATE_FRACTION_N);
	if (x == NULL || PyDict_SetItemString(d, "RATE_FRACTION_N", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_INPUTRATE
	x =  PyInt_FromLong((long) AL_RATE_INPUTRATE);
	if (x == NULL || PyDict_SetItemString(d, "RATE_INPUTRATE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_NO_DIGITAL_INPUT
	x =  PyInt_FromLong((long) AL_RATE_NO_DIGITAL_INPUT);
	if (x == NULL || PyDict_SetItemString(d, "RATE_NO_DIGITAL_INPUT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_UNACQUIRED
	x =  PyInt_FromLong((long) AL_RATE_UNACQUIRED);
	if (x == NULL || PyDict_SetItemString(d, "RATE_UNACQUIRED", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RATE_UNDEFINED
	x =  PyInt_FromLong((long) AL_RATE_UNDEFINED);
	if (x == NULL || PyDict_SetItemString(d, "RATE_UNDEFINED", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_REF_0DBV
	x =  PyInt_FromLong((long) AL_REF_0DBV);
	if (x == NULL || PyDict_SetItemString(d, "REF_0DBV", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_REF_NONE
	x =  PyInt_FromLong((long) AL_REF_NONE);
	if (x == NULL || PyDict_SetItemString(d, "REF_NONE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RESERVED1_TYPE
	x =  PyInt_FromLong((long) AL_RESERVED1_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "RESERVED1_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RESERVED2_TYPE
	x =  PyInt_FromLong((long) AL_RESERVED2_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "RESERVED2_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RESERVED3_TYPE
	x =  PyInt_FromLong((long) AL_RESERVED3_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "RESERVED3_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RESERVED4_TYPE
	x =  PyInt_FromLong((long) AL_RESERVED4_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "RESERVED4_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RESOURCE
	x =  PyInt_FromLong((long) AL_RESOURCE);
	if (x == NULL || PyDict_SetItemString(d, "RESOURCE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RESOURCE_ELEM
	x =  PyInt_FromLong((long) AL_RESOURCE_ELEM);
	if (x == NULL || PyDict_SetItemString(d, "RESOURCE_ELEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RESOURCE_TYPE
	x =  PyInt_FromLong((long) AL_RESOURCE_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "RESOURCE_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RIGHT_INPUT_ATTEN
	x =  PyInt_FromLong((long) AL_RIGHT_INPUT_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "RIGHT_INPUT_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RIGHT_MONITOR_ATTEN
	x =  PyInt_FromLong((long) AL_RIGHT_MONITOR_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "RIGHT_MONITOR_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RIGHT_SPEAKER_GAIN
	x =  PyInt_FromLong((long) AL_RIGHT_SPEAKER_GAIN);
	if (x == NULL || PyDict_SetItemString(d, "RIGHT_SPEAKER_GAIN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RIGHT1_INPUT_ATTEN
	x =  PyInt_FromLong((long) AL_RIGHT1_INPUT_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "RIGHT1_INPUT_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_RIGHT2_INPUT_ATTEN
	x =  PyInt_FromLong((long) AL_RIGHT2_INPUT_ATTEN);
	if (x == NULL || PyDict_SetItemString(d, "RIGHT2_INPUT_ATTEN", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SAMPFMT_DOUBLE
	x =  PyInt_FromLong((long) AL_SAMPFMT_DOUBLE);
	if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_DOUBLE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SAMPFMT_FLOAT
	x =  PyInt_FromLong((long) AL_SAMPFMT_FLOAT);
	if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_FLOAT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SAMPFMT_TWOSCOMP
	x =  PyInt_FromLong((long) AL_SAMPFMT_TWOSCOMP);
	if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_TWOSCOMP", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SAMPLE_16
	x =  PyInt_FromLong((long) AL_SAMPLE_16);
	if (x == NULL || PyDict_SetItemString(d, "SAMPLE_16", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SAMPLE_24
	x =  PyInt_FromLong((long) AL_SAMPLE_24);
	if (x == NULL || PyDict_SetItemString(d, "SAMPLE_24", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SAMPLE_8
	x =  PyInt_FromLong((long) AL_SAMPLE_8);
	if (x == NULL || PyDict_SetItemString(d, "SAMPLE_8", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SCALAR_VAL
	x =  PyInt_FromLong((long) AL_SCALAR_VAL);
	if (x == NULL || PyDict_SetItemString(d, "SCALAR_VAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SET_VAL
	x =  PyInt_FromLong((long) AL_SET_VAL);
	if (x == NULL || PyDict_SetItemString(d, "SET_VAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SHORT_NAME
	x =  PyInt_FromLong((long) AL_SHORT_NAME);
	if (x == NULL || PyDict_SetItemString(d, "SHORT_NAME", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SOURCE
	x =  PyInt_FromLong((long) AL_SOURCE);
	if (x == NULL || PyDict_SetItemString(d, "SOURCE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SPEAKER_IF_TYPE
	x =  PyInt_FromLong((long) AL_SPEAKER_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "SPEAKER_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SPEAKER_MUTE_CTL
	x =  PyInt_FromLong((long) AL_SPEAKER_MUTE_CTL);
	if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_CTL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SPEAKER_MUTE_OFF
	x =  PyInt_FromLong((long) AL_SPEAKER_MUTE_OFF);
	if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_OFF", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SPEAKER_MUTE_ON
	x =  PyInt_FromLong((long) AL_SPEAKER_MUTE_ON);
	if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_ON", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SPEAKER_PLUS_LINE_IF_TYPE
	x =  PyInt_FromLong((long) AL_SPEAKER_PLUS_LINE_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "SPEAKER_PLUS_LINE_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_STEREO
	x =  PyInt_FromLong((long) AL_STEREO);
	if (x == NULL || PyDict_SetItemString(d, "STEREO", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_STRING_VAL
	x =  PyInt_FromLong((long) AL_STRING_VAL);
	if (x == NULL || PyDict_SetItemString(d, "STRING_VAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SUBSYSTEM
	x =  PyInt_FromLong((long) AL_SUBSYSTEM);
	if (x == NULL || PyDict_SetItemString(d, "SUBSYSTEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SUBSYSTEM_TYPE
	x =  PyInt_FromLong((long) AL_SUBSYSTEM_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "SUBSYSTEM_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SYNC_INPUT_TO_AES
	x =  PyInt_FromLong((long) AL_SYNC_INPUT_TO_AES);
	if (x == NULL || PyDict_SetItemString(d, "SYNC_INPUT_TO_AES", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SYNC_OUTPUT_TO_AES
	x =  PyInt_FromLong((long) AL_SYNC_OUTPUT_TO_AES);
	if (x == NULL || PyDict_SetItemString(d, "SYNC_OUTPUT_TO_AES", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SYSTEM
	x =  PyInt_FromLong((long) AL_SYSTEM);
	if (x == NULL || PyDict_SetItemString(d, "SYSTEM", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_SYSTEM_TYPE
	x =  PyInt_FromLong((long) AL_SYSTEM_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "SYSTEM_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_TEST_IF_TYPE
	x =  PyInt_FromLong((long) AL_TEST_IF_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "TEST_IF_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_TYPE
	x =  PyInt_FromLong((long) AL_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_TYPE_BIT
	x =  PyInt_FromLong((long) AL_TYPE_BIT);
	if (x == NULL || PyDict_SetItemString(d, "TYPE_BIT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_UNUSED_COUNT
	x =  PyInt_FromLong((long) AL_UNUSED_COUNT);
	if (x == NULL || PyDict_SetItemString(d, "UNUSED_COUNT", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_UNUSED_PORTS
	x =  PyInt_FromLong((long) AL_UNUSED_PORTS);
	if (x == NULL || PyDict_SetItemString(d, "UNUSED_PORTS", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_VARIABLE_MCLK_TYPE
	x =  PyInt_FromLong((long) AL_VARIABLE_MCLK_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "VARIABLE_MCLK_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_VECTOR_VAL
	x =  PyInt_FromLong((long) AL_VECTOR_VAL);
	if (x == NULL || PyDict_SetItemString(d, "VECTOR_VAL", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_VIDEO_MCLK_TYPE
	x =  PyInt_FromLong((long) AL_VIDEO_MCLK_TYPE);
	if (x == NULL || PyDict_SetItemString(d, "VIDEO_MCLK_TYPE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif
#ifdef AL_WORDSIZE
	x =  PyInt_FromLong((long) AL_WORDSIZE);
	if (x == NULL || PyDict_SetItemString(d, "WORDSIZE", x) < 0)
		goto error;
	Py_DECREF(x);
#endif

#ifdef AL_NO_ELEM		/* IRIX 6 */
	(void) alSetErrorHandler(ErrorHandler);
#endif /* AL_NO_ELEM */
#ifdef OLD_INTERFACE
	(void) ALseterrorhandler(ErrorHandler);
#endif /* OLD_INTERFACE */
	
	/* Check for errors */
	if (PyErr_Occurred()) {
	  error:
		Py_FatalError("can't initialize module al");
	}
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.