summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
blob: 0cff157662fe78ffefe785a84c4c2a4b4a6de537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511

/* Execute compiled code */

/* XXX TO DO:
   XXX speed up searching for keywords by using a dictionary
   XXX document it!
   */

/* enable more aggressive intra-module optimizations, where available */
#define PY_LOCAL_AGGRESSIVE

#include "Python.h"

#include "code.h"
#include "frameobject.h"
#include "eval.h"
#include "opcode.h"
#include "structmember.h"

#include <ctype.h>

#ifndef WITH_TSC

#define READ_TIMESTAMP(var)

#else

typedef unsigned long long uint64;

#if defined(__ppc__) /* <- Don't know if this is the correct symbol; this
			   section should work for GCC on any PowerPC
			   platform, irrespective of OS.
			   POWER?  Who knows :-) */

#define READ_TIMESTAMP(var) ppc_getcounter(&var)

static void
ppc_getcounter(uint64 *v)
{
	register unsigned long tbu, tb, tbu2;

  loop:
	asm volatile ("mftbu %0" : "=r" (tbu) );
	asm volatile ("mftb  %0" : "=r" (tb)  );
	asm volatile ("mftbu %0" : "=r" (tbu2));
	if (__builtin_expect(tbu != tbu2, 0)) goto loop;

	/* The slightly peculiar way of writing the next lines is
	   compiled better by GCC than any other way I tried. */
	((long*)(v))[0] = tbu;
	((long*)(v))[1] = tb;
}

#else /* this is for linux/x86 (and probably any other GCC/x86 combo) */

#define READ_TIMESTAMP(val) \
     __asm__ __volatile__("rdtsc" : "=A" (val))

#endif

void dump_tsc(int opcode, int ticked, uint64 inst0, uint64 inst1,
	      uint64 loop0, uint64 loop1, uint64 intr0, uint64 intr1)
{
	uint64 intr, inst, loop;
	PyThreadState *tstate = PyThreadState_Get();
	if (!tstate->interp->tscdump)
		return;
	intr = intr1 - intr0;
	inst = inst1 - inst0 - intr;
	loop = loop1 - loop0 - intr;
	fprintf(stderr, "opcode=%03d t=%d inst=%06lld loop=%06lld\n",
		opcode, ticked, inst, loop);
}

#endif

/* Turn this on if your compiler chokes on the big switch: */
/* #define CASE_TOO_BIG 1 */

#ifdef Py_DEBUG
/* For debugging the interpreter: */
#define LLTRACE  1	/* Low-level trace feature */
#define CHECKEXC 1	/* Double-check exception checking */
#endif

typedef PyObject *(*callproc)(PyObject *, PyObject *, PyObject *);

/* Forward declarations */
#ifdef WITH_TSC
static PyObject * call_function(PyObject ***, int, uint64*, uint64*);
#else
static PyObject * call_function(PyObject ***, int);
#endif
static PyObject * fast_function(PyObject *, PyObject ***, int, int, int);
static PyObject * do_call(PyObject *, PyObject ***, int, int);
static PyObject * ext_do_call(PyObject *, PyObject ***, int, int, int);
static PyObject * update_keyword_args(PyObject *, int, PyObject ***,
				      PyObject *);
static PyObject * update_star_args(int, int, PyObject *, PyObject ***);
static PyObject * load_args(PyObject ***, int);
#define CALL_FLAG_VAR 1
#define CALL_FLAG_KW 2

#ifdef LLTRACE
static int lltrace;
static int prtrace(PyObject *, char *);
#endif
static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
		      int, PyObject *);
static int call_trace_protected(Py_tracefunc, PyObject *,
				 PyFrameObject *, int, PyObject *);
static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
static int maybe_call_line_trace(Py_tracefunc, PyObject *,
				  PyFrameObject *, int *, int *, int *);

static PyObject * apply_slice(PyObject *, PyObject *, PyObject *);
static int assign_slice(PyObject *, PyObject *,
			PyObject *, PyObject *);
static PyObject * cmp_outcome(int, PyObject *, PyObject *);
static PyObject * import_from(PyObject *, PyObject *);
static int import_all_from(PyObject *, PyObject *);
static PyObject * build_class(PyObject *, PyObject *, PyObject *);
static int exec_statement(PyFrameObject *,
			  PyObject *, PyObject *, PyObject *);
static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
static void reset_exc_info(PyThreadState *);
static void format_exc_check_arg(PyObject *, char *, PyObject *);
static PyObject * string_concatenate(PyObject *, PyObject *,
				    PyFrameObject *, unsigned char *);

#define NAME_ERROR_MSG \
	"name '%.200s' is not defined"
#define GLOBAL_NAME_ERROR_MSG \
	"global name '%.200s' is not defined"
#define UNBOUNDLOCAL_ERROR_MSG \
	"local variable '%.200s' referenced before assignment"
#define UNBOUNDFREE_ERROR_MSG \
	"free variable '%.200s' referenced before assignment" \
        " in enclosing scope"

/* Dynamic execution profile */
#ifdef DYNAMIC_EXECUTION_PROFILE
#ifdef DXPAIRS
static long dxpairs[257][256];
#define dxp dxpairs[256]
#else
static long dxp[256];
#endif
#endif

/* Function call profile */
#ifdef CALL_PROFILE
#define PCALL_NUM 11
static int pcall[PCALL_NUM];

#define PCALL_ALL 0
#define PCALL_FUNCTION 1
#define PCALL_FAST_FUNCTION 2
#define PCALL_FASTER_FUNCTION 3
#define PCALL_METHOD 4
#define PCALL_BOUND_METHOD 5
#define PCALL_CFUNCTION 6
#define PCALL_TYPE 7
#define PCALL_GENERATOR 8
#define PCALL_OTHER 9
#define PCALL_POP 10

/* Notes about the statistics

   PCALL_FAST stats

   FAST_FUNCTION means no argument tuple needs to be created.
   FASTER_FUNCTION means that the fast-path frame setup code is used.

   If there is a method call where the call can be optimized by changing
   the argument tuple and calling the function directly, it gets recorded
   twice.

   As a result, the relationship among the statistics appears to be
   PCALL_ALL == PCALL_FUNCTION + PCALL_METHOD - PCALL_BOUND_METHOD +
                PCALL_CFUNCTION + PCALL_TYPE + PCALL_GENERATOR + PCALL_OTHER
   PCALL_FUNCTION > PCALL_FAST_FUNCTION > PCALL_FASTER_FUNCTION
   PCALL_METHOD > PCALL_BOUND_METHOD
*/

#define PCALL(POS) pcall[POS]++

PyObject *
PyEval_GetCallStats(PyObject *self)
{
	return Py_BuildValue("iiiiiiiiiii",
			     pcall[0], pcall[1], pcall[2], pcall[3],
			     pcall[4], pcall[5], pcall[6], pcall[7],
			     pcall[8], pcall[9], pcall[10]);
}
#else
#define PCALL(O)

PyObject *
PyEval_GetCallStats(PyObject *self)
{
	Py_INCREF(Py_None);
	return Py_None;
}
#endif


#ifdef WITH_THREAD

#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include "pythread.h"

static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */
static long main_thread = 0;

int
PyEval_ThreadsInitialized(void)
{
	return interpreter_lock != 0;
}

void
PyEval_InitThreads(void)
{
	if (interpreter_lock)
		return;
	interpreter_lock = PyThread_allocate_lock();
	PyThread_acquire_lock(interpreter_lock, 1);
	main_thread = PyThread_get_thread_ident();
}

void
PyEval_AcquireLock(void)
{
	PyThread_acquire_lock(interpreter_lock, 1);
}

void
PyEval_ReleaseLock(void)
{
	PyThread_release_lock(interpreter_lock);
}

void
PyEval_AcquireThread(PyThreadState *tstate)
{
	if (tstate == NULL)
		Py_FatalError("PyEval_AcquireThread: NULL new thread state");
	/* Check someone has called PyEval_InitThreads() to create the lock */
	assert(interpreter_lock);
	PyThread_acquire_lock(interpreter_lock, 1);
	if (PyThreadState_Swap(tstate) != NULL)
		Py_FatalError(
			"PyEval_AcquireThread: non-NULL old thread state");
}

void
PyEval_ReleaseThread(PyThreadState *tstate)
{
	if (tstate == NULL)
		Py_FatalError("PyEval_ReleaseThread: NULL thread state");
	if (PyThreadState_Swap(NULL) != tstate)
		Py_FatalError("PyEval_ReleaseThread: wrong thread state");
	PyThread_release_lock(interpreter_lock);
}

/* This function is called from PyOS_AfterFork to ensure that newly
   created child processes don't hold locks referring to threads which
   are not running in the child process.  (This could also be done using
   pthread_atfork mechanism, at least for the pthreads implementation.) */

void
PyEval_ReInitThreads(void)
{
	if (!interpreter_lock)
		return;
	/*XXX Can't use PyThread_free_lock here because it does too
	  much error-checking.  Doing this cleanly would require
	  adding a new function to each thread_*.h.  Instead, just
	  create a new lock and waste a little bit of memory */
	interpreter_lock = PyThread_allocate_lock();
	PyThread_acquire_lock(interpreter_lock, 1);
	main_thread = PyThread_get_thread_ident();
}
#endif

/* Functions save_thread and restore_thread are always defined so
   dynamically loaded modules needn't be compiled separately for use
   with and without threads: */

PyThreadState *
PyEval_SaveThread(void)
{
	PyThreadState *tstate = PyThreadState_Swap(NULL);
	if (tstate == NULL)
		Py_FatalError("PyEval_SaveThread: NULL tstate");
#ifdef WITH_THREAD
	if (interpreter_lock)
		PyThread_release_lock(interpreter_lock);
#endif
	return tstate;
}

void
PyEval_RestoreThread(PyThreadState *tstate)
{
	if (tstate == NULL)
		Py_FatalError("PyEval_RestoreThread: NULL tstate");
#ifdef WITH_THREAD
	if (interpreter_lock) {
		int err = errno;
		PyThread_acquire_lock(interpreter_lock, 1);
		errno = err;
	}
#endif
	PyThreadState_Swap(tstate);
}


/* Mechanism whereby asynchronously executing callbacks (e.g. UNIX
   signal handlers or Mac I/O completion routines) can schedule calls
   to a function to be called synchronously.
   The synchronous function is called with one void* argument.
   It should return 0 for success or -1 for failure -- failure should
   be accompanied by an exception.

   If registry succeeds, the registry function returns 0; if it fails
   (e.g. due to too many pending calls) it returns -1 (without setting
   an exception condition).

   Note that because registry may occur from within signal handlers,
   or other asynchronous events, calling malloc() is unsafe!

#ifdef WITH_THREAD
   Any thread can schedule pending calls, but only the main thread
   will execute them.
#endif

   XXX WARNING!  ASYNCHRONOUSLY EXECUTING CODE!
   There are two possible race conditions:
   (1) nested asynchronous registry calls;
   (2) registry calls made while pending calls are being processed.
   While (1) is very unlikely, (2) is a real possibility.
   The current code is safe against (2), but not against (1).
   The safety against (2) is derived from the fact that only one
   thread (the main thread) ever takes things out of the queue.

   XXX Darn!  With the advent of thread state, we should have an array
   of pending calls per thread in the thread state!  Later...
*/

#define NPENDINGCALLS 32
static struct {
	int (*func)(void *);
	void *arg;
} pendingcalls[NPENDINGCALLS];
static volatile int pendingfirst = 0;
static volatile int pendinglast = 0;
static volatile int things_to_do = 0;

int
Py_AddPendingCall(int (*func)(void *), void *arg)
{
	static volatile int busy = 0;
	int i, j;
	/* XXX Begin critical section */
	/* XXX If you want this to be safe against nested
	   XXX asynchronous calls, you'll have to work harder! */
	if (busy)
		return -1;
	busy = 1;
	i = pendinglast;
	j = (i + 1) % NPENDINGCALLS;
	if (j == pendingfirst) {
		busy = 0;
		return -1; /* Queue full */
	}
	pendingcalls[i].func = func;
	pendingcalls[i].arg = arg;
	pendinglast = j;

	_Py_Ticker = 0;
	things_to_do = 1; /* Signal main loop */
	busy = 0;
	/* XXX End critical section */
	return 0;
}

int
Py_MakePendingCalls(void)
{
	static int busy = 0;
#ifdef WITH_THREAD
	if (main_thread && PyThread_get_thread_ident() != main_thread)
		return 0;
#endif
	if (busy)
		return 0;
	busy = 1;
	things_to_do = 0;
	for (;;) {
		int i;
		int (*func)(void *);
		void *arg;
		i = pendingfirst;
		if (i == pendinglast)
			break; /* Queue empty */
		func = pendingcalls[i].func;
		arg = pendingcalls[i].arg;
		pendingfirst = (i + 1) % NPENDINGCALLS;
		if (func(arg) < 0) {
			busy = 0;
			things_to_do = 1; /* We're not done yet */
			return -1;
		}
	}
	busy = 0;
	return 0;
}


/* The interpreter's recursion limit */

#ifndef Py_DEFAULT_RECURSION_LIMIT
#define Py_DEFAULT_RECURSION_LIMIT 1000
#endif
static int recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;

int
Py_GetRecursionLimit(void)
{
	return recursion_limit;
}

void
Py_SetRecursionLimit(int new_limit)
{
	recursion_limit = new_limit;
	_Py_CheckRecursionLimit = recursion_limit;
}

/* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
   if the recursion_depth reaches _Py_CheckRecursionLimit.
   If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit
   to guarantee that _Py_CheckRecursiveCall() is regularly called.
   Without USE_STACKCHECK, there is no need for this. */
int
_Py_CheckRecursiveCall(char *where)
{
	PyThreadState *tstate = PyThreadState_GET();

#ifdef USE_STACKCHECK
	if (PyOS_CheckStack()) {
		--tstate->recursion_depth;
		PyErr_SetString(PyExc_MemoryError, "Stack overflow");
		return -1;
	}
#endif
	if (tstate->recursion_depth > recursion_limit) {
		--tstate->recursion_depth;
		PyErr_Format(PyExc_RuntimeError,
			     "maximum recursion depth exceeded%s",
			     where);
		return -1;
	}
	_Py_CheckRecursionLimit = recursion_limit;
	return 0;
}

/* Status code for main loop (reason for stack unwind) */
enum why_code {
		WHY_NOT =	0x0001,	/* No error */
		WHY_EXCEPTION = 0x0002,	/* Exception occurred */
		WHY_RERAISE =	0x0004,	/* Exception re-raised by 'finally' */
		WHY_RETURN =	0x0008,	/* 'return' statement */
		WHY_BREAK =	0x0010,	/* 'break' statement */
		WHY_CONTINUE =	0x0020,	/* 'continue' statement */
		WHY_YIELD =	0x0040	/* 'yield' operator */
};

static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
static int unpack_iterable(PyObject *, int, PyObject **);

/* for manipulating the thread switch and periodic "stuff" - used to be
   per thread, now just a pair o' globals */
int _Py_CheckInterval = 100;
volatile int _Py_Ticker = 100;

PyObject *
PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
{
	return PyEval_EvalCodeEx(co,
			  globals, locals,
			  (PyObject **)NULL, 0,
			  (PyObject **)NULL, 0,
			  (PyObject **)NULL, 0,
			  NULL);
}


/* Interpreter main loop */

PyObject *
PyEval_EvalFrame(PyFrameObject *f) {
	/* This is for backward compatibility with extension modules that
           used this API; core interpreter code should call
           PyEval_EvalFrameEx() */
	return PyEval_EvalFrameEx(f, 0);
}

PyObject *
PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
{
#ifdef DXPAIRS
	int lastopcode = 0;
#endif
	register PyObject **stack_pointer;  /* Next free slot in value stack */
	register unsigned char *next_instr;
	register int opcode;	/* Current opcode */
	register int oparg;	/* Current opcode argument, if any */
	register enum why_code why; /* Reason for block stack unwind */
	register int err;	/* Error status -- nonzero if error */
	register PyObject *x;	/* Result object -- NULL if error */
	register PyObject *v;	/* Temporary objects popped off stack */
	register PyObject *w;
	register PyObject *u;
	register PyObject *t;
	register PyObject *stream = NULL;    /* for PRINT opcodes */
	register PyObject **fastlocals, **freevars;
	PyObject *retval = NULL;	/* Return value */
	PyThreadState *tstate = PyThreadState_GET();
	PyCodeObject *co;

	/* when tracing we set things up so that

               not (instr_lb <= current_bytecode_offset < instr_ub)

	   is true when the line being executed has changed.  The
           initial values are such as to make this false the first
           time it is tested. */
	int instr_ub = -1, instr_lb = 0, instr_prev = -1;

	unsigned char *first_instr;
	PyObject *names;
	PyObject *consts;
#if defined(Py_DEBUG) || defined(LLTRACE)
	/* Make it easier to find out where we are with a debugger */
	char *filename;
#endif

/* Tuple access macros */

#ifndef Py_DEBUG
#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
#else
#define GETITEM(v, i) PyTuple_GetItem((v), (i))
#endif

#ifdef WITH_TSC
/* Use Pentium timestamp counter to mark certain events:
   inst0 -- beginning of switch statement for opcode dispatch
   inst1 -- end of switch statement (may be skipped)
   loop0 -- the top of the mainloop
   loop1 -- place where control returns again to top of mainloop
            (may be skipped)
   intr1 -- beginning of long interruption
   intr2 -- end of long interruption

   Many opcodes call out to helper C functions.  In some cases, the
   time in those functions should be counted towards the time for the
   opcode, but not in all cases.  For example, a CALL_FUNCTION opcode
   calls another Python function; there's no point in charge all the
   bytecode executed by the called function to the caller.

   It's hard to make a useful judgement statically.  In the presence
   of operator overloading, it's impossible to tell if a call will
   execute new Python code or not.

   It's a case-by-case judgement.  I'll use intr1 for the following
   cases:

   EXEC_STMT
   IMPORT_STAR
   IMPORT_FROM
   CALL_FUNCTION (and friends)

 */
	uint64 inst0, inst1, loop0, loop1, intr0 = 0, intr1 = 0;
	int ticked = 0;

	READ_TIMESTAMP(inst0);
	READ_TIMESTAMP(inst1);
	READ_TIMESTAMP(loop0);
	READ_TIMESTAMP(loop1);

	/* shut up the compiler */
	opcode = 0;
#endif

/* Code access macros */

#define INSTR_OFFSET()	((int)(next_instr - first_instr))
#define NEXTOP()	(*next_instr++)
#define NEXTARG()	(next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
#define PEEKARG()	((next_instr[2]<<8) + next_instr[1])
#define JUMPTO(x)	(next_instr = first_instr + (x))
#define JUMPBY(x)	(next_instr += (x))

/* OpCode prediction macros
	Some opcodes tend to come in pairs thus making it possible to
	predict the second code when the first is run.  For example,
	COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE.  And,
	those opcodes are often followed by a POP_TOP.

	Verifying the prediction costs a single high-speed test of register
	variable against a constant.  If the pairing was good, then the
	processor has a high likelihood of making its own successful branch
	prediction which results in a nearly zero overhead transition to the
	next opcode.

	A successful prediction saves a trip through the eval-loop including
	its two unpredictable branches, the HAS_ARG test and the switch-case.

        If collecting opcode statistics, turn off prediction so that
	statistics are accurately maintained (the predictions bypass
	the opcode frequency counter updates).
*/

#ifdef DYNAMIC_EXECUTION_PROFILE
#define PREDICT(op)		if (0) goto PRED_##op
#else
#define PREDICT(op)		if (*next_instr == op) goto PRED_##op
#endif

#define PREDICTED(op)		PRED_##op: next_instr++
#define PREDICTED_WITH_ARG(op)	PRED_##op: oparg = PEEKARG(); next_instr += 3

/* Stack manipulation macros */

/* The stack can grow at most MAXINT deep, as co_nlocals and
   co_stacksize are ints. */
#define STACK_LEVEL()	((int)(stack_pointer - f->f_valuestack))
#define EMPTY()		(STACK_LEVEL() == 0)
#define TOP()		(stack_pointer[-1])
#define SECOND()	(stack_pointer[-2])
#define THIRD() 	(stack_pointer[-3])
#define FOURTH()	(stack_pointer[-4])
#define SET_TOP(v)	(stack_pointer[-1] = (v))
#define SET_SECOND(v)	(stack_pointer[-2] = (v))
#define SET_THIRD(v)	(stack_pointer[-3] = (v))
#define SET_FOURTH(v)	(stack_pointer[-4] = (v))
#define BASIC_STACKADJ(n)	(stack_pointer += n)
#define BASIC_PUSH(v)	(*stack_pointer++ = (v))
#define BASIC_POP()	(*--stack_pointer)

#ifdef LLTRACE
#define PUSH(v)		{ (void)(BASIC_PUSH(v), \
                               lltrace && prtrace(TOP(), "push")); \
                               assert(STACK_LEVEL() <= co->co_stacksize); }
#define POP()		((void)(lltrace && prtrace(TOP(), "pop")), \
			 BASIC_POP())
#define STACKADJ(n)	{ (void)(BASIC_STACKADJ(n), \
                               lltrace && prtrace(TOP(), "stackadj")); \
                               assert(STACK_LEVEL() <= co->co_stacksize); }
#define EXT_POP(STACK_POINTER) ((void)(lltrace && \
				prtrace((STACK_POINTER)[-1], "ext_pop")), \
				*--(STACK_POINTER))
#else
#define PUSH(v)		BASIC_PUSH(v)
#define POP()		BASIC_POP()
#define STACKADJ(n)	BASIC_STACKADJ(n)
#define EXT_POP(STACK_POINTER) (*--(STACK_POINTER))
#endif

/* Local variable macros */

#define GETLOCAL(i)	(fastlocals[i])

/* The SETLOCAL() macro must not DECREF the local variable in-place and
   then store the new value; it must copy the old value to a temporary
   value, then store the new value, and then DECREF the temporary value.
   This is because it is possible that during the DECREF the frame is
   accessed by other code (e.g. a __del__ method or gc.collect()) and the
   variable would be pointing to already-freed memory. */
#define SETLOCAL(i, value)	do { PyObject *tmp = GETLOCAL(i); \
				     GETLOCAL(i) = value; \
                                     Py_XDECREF(tmp); } while (0)

/* Start of code */

	if (f == NULL)
		return NULL;

	/* push frame */
	if (Py_EnterRecursiveCall(""))
		return NULL;

	tstate->frame = f;

	if (tstate->use_tracing) {
		if (tstate->c_tracefunc != NULL) {
			/* tstate->c_tracefunc, if defined, is a
			   function that will be called on *every* entry
			   to a code block.  Its return value, if not
			   None, is a function that will be called at
			   the start of each executed line of code.
			   (Actually, the function must return itself
			   in order to continue tracing.)  The trace
			   functions are called with three arguments:
			   a pointer to the current frame, a string
			   indicating why the function is called, and
			   an argument which depends on the situation.
			   The global trace function is also called
			   whenever an exception is detected. */
			if (call_trace_protected(tstate->c_tracefunc, 
						 tstate->c_traceobj,
						 f, PyTrace_CALL, Py_None)) {
				/* Trace function raised an error */
				goto exit_eval_frame;
			}
		}
		if (tstate->c_profilefunc != NULL) {
			/* Similar for c_profilefunc, except it needn't
			   return itself and isn't called for "line" events */
			if (call_trace_protected(tstate->c_profilefunc,
						 tstate->c_profileobj,
						 f, PyTrace_CALL, Py_None)) {
				/* Profile function raised an error */
				goto exit_eval_frame;
			}
		}
	}

	co = f->f_code;
	names = co->co_names;
	consts = co->co_consts;
	fastlocals = f->f_localsplus;
	freevars = f->f_localsplus + co->co_nlocals;
	first_instr = (unsigned char*) PyString_AS_STRING(co->co_code);
	/* An explanation is in order for the next line.

	   f->f_lasti now refers to the index of the last instruction
	   executed.  You might think this was obvious from the name, but
	   this wasn't always true before 2.3!  PyFrame_New now sets
	   f->f_lasti to -1 (i.e. the index *before* the first instruction)
	   and YIELD_VALUE doesn't fiddle with f_lasti any more.  So this
	   does work.  Promise. 

	   When the PREDICT() macros are enabled, some opcode pairs follow in
           direct succession without updating f->f_lasti.  A successful 
           prediction effectively links the two codes together as if they
           were a single new opcode; accordingly,f->f_lasti will point to
           the first code in the pair (for instance, GET_ITER followed by
           FOR_ITER is effectively a single opcode and f->f_lasti will point
           at to the beginning of the combined pair.)
	*/
	next_instr = first_instr + f->f_lasti + 1;
	stack_pointer = f->f_stacktop;
	assert(stack_pointer != NULL);
	f->f_stacktop = NULL;	/* remains NULL unless yield suspends frame */

#ifdef LLTRACE
	lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != NULL;
#endif
#if defined(Py_DEBUG) || defined(LLTRACE)
	filename = PyString_AsString(co->co_filename);
#endif

	why = WHY_NOT;
	err = 0;
	x = Py_None;	/* Not a reference, just anything non-NULL */
	w = NULL;

	if (throwflag) { /* support for generator.throw() */
		why = WHY_EXCEPTION;
		goto on_error;
	}

	for (;;) {
#ifdef WITH_TSC
		if (inst1 == 0) {
			/* Almost surely, the opcode executed a break
			   or a continue, preventing inst1 from being set
			   on the way out of the loop.
			*/
			READ_TIMESTAMP(inst1);
			loop1 = inst1;
		}
		dump_tsc(opcode, ticked, inst0, inst1, loop0, loop1,
			 intr0, intr1);
		ticked = 0;
		inst1 = 0;
		intr0 = 0;
		intr1 = 0;
		READ_TIMESTAMP(loop0);
#endif
		assert(stack_pointer >= f->f_valuestack); /* else underflow */
		assert(STACK_LEVEL() <= co->co_stacksize);  /* else overflow */

		/* Do periodic things.  Doing this every time through
		   the loop would add too much overhead, so we do it
		   only every Nth instruction.  We also do it if
		   ``things_to_do'' is set, i.e. when an asynchronous
		   event needs attention (e.g. a signal handler or
		   async I/O handler); see Py_AddPendingCall() and
		   Py_MakePendingCalls() above. */

		if (--_Py_Ticker < 0) {
			if (*next_instr == SETUP_FINALLY) {
				/* Make the last opcode before
				   a try: finally: block uninterruptable. */
				goto fast_next_opcode;
			}
			_Py_Ticker = _Py_CheckInterval;
			tstate->tick_counter++;
#ifdef WITH_TSC
			ticked = 1;
#endif
			if (things_to_do) {
				if (Py_MakePendingCalls() < 0) {
					why = WHY_EXCEPTION;
					goto on_error;
				}
				if (things_to_do)
					/* MakePendingCalls() didn't succeed.
					   Force early re-execution of this
					   "periodic" code, possibly after
					   a thread switch */
					_Py_Ticker = 0;
			}
#ifdef WITH_THREAD
			if (interpreter_lock) {
				/* Give another thread a chance */

				if (PyThreadState_Swap(NULL) != tstate)
					Py_FatalError("ceval: tstate mix-up");
				PyThread_release_lock(interpreter_lock);

				/* Other threads may run now */

				PyThread_acquire_lock(interpreter_lock, 1);
				if (PyThreadState_Swap(tstate) != NULL)
					Py_FatalError("ceval: orphan tstate");

				/* Check for thread interrupts */

				if (tstate->async_exc != NULL) {
					x = tstate->async_exc;
					tstate->async_exc = NULL;
					PyErr_SetNone(x);
					Py_DECREF(x);
					why = WHY_EXCEPTION;
					goto on_error;
				}
			}
#endif
		}

	fast_next_opcode:
		f->f_lasti = INSTR_OFFSET();

		/* line-by-line tracing support */

		if (tstate->c_tracefunc != NULL && !tstate->tracing) {
			/* see maybe_call_line_trace
			   for expository comments */
			f->f_stacktop = stack_pointer;

			err = maybe_call_line_trace(tstate->c_tracefunc,
						    tstate->c_traceobj,
						    f, &instr_lb, &instr_ub,
						    &instr_prev);
			/* Reload possibly changed frame fields */
			JUMPTO(f->f_lasti);
			if (f->f_stacktop != NULL) {
				stack_pointer = f->f_stacktop;
				f->f_stacktop = NULL;
			}
			if (err) {
				/* trace function raised an exception */
				goto on_error;
			}
		}

		/* Extract opcode and argument */

		opcode = NEXTOP();
		oparg = 0;   /* allows oparg to be stored in a register because
			it doesn't have to be remembered across a full loop */
		if (HAS_ARG(opcode))
			oparg = NEXTARG();
	  dispatch_opcode:
#ifdef DYNAMIC_EXECUTION_PROFILE
#ifdef DXPAIRS
		dxpairs[lastopcode][opcode]++;
		lastopcode = opcode;
#endif
		dxp[opcode]++;
#endif

#ifdef LLTRACE
		/* Instruction tracing */

		if (lltrace) {
			if (HAS_ARG(opcode)) {
				printf("%d: %d, %d\n",
				       f->f_lasti, opcode, oparg);
			}
			else {
				printf("%d: %d\n",
				       f->f_lasti, opcode);
			}
		}
#endif

		/* Main switch on opcode */
		READ_TIMESTAMP(inst0);

		switch (opcode) {

		/* BEWARE!
		   It is essential that any operation that fails sets either
		   x to NULL, err to nonzero, or why to anything but WHY_NOT,
		   and that no operation that succeeds does this! */

		/* case STOP_CODE: this is an error! */

		case NOP:
			goto fast_next_opcode;

		case LOAD_FAST:
			x = GETLOCAL(oparg);
			if (x != NULL) {
				Py_INCREF(x);
				PUSH(x);
				goto fast_next_opcode;
			}
			format_exc_check_arg(PyExc_UnboundLocalError,
				UNBOUNDLOCAL_ERROR_MSG,
				PyTuple_GetItem(co->co_varnames, oparg));
			break;

		case LOAD_CONST:
			x = GETITEM(consts, oparg);
			Py_INCREF(x);
			PUSH(x);
			goto fast_next_opcode;

		PREDICTED_WITH_ARG(STORE_FAST);
		case STORE_FAST:
			v = POP();
			SETLOCAL(oparg, v);
			goto fast_next_opcode;

		PREDICTED(POP_TOP);
		case POP_TOP:
			v = POP();
			Py_DECREF(v);
			goto fast_next_opcode;

		case ROT_TWO:
			v = TOP();
			w = SECOND();
			SET_TOP(w);
			SET_SECOND(v);
			goto fast_next_opcode;

		case ROT_THREE:
			v = TOP();
			w = SECOND();
			x = THIRD();
			SET_TOP(w);
			SET_SECOND(x);
			SET_THIRD(v);
			goto fast_next_opcode;

		case ROT_FOUR:
			u = TOP();
			v = SECOND();
			w = THIRD();
			x = FOURTH();
			SET_TOP(v);
			SET_SECOND(w);
			SET_THIRD(x);
			SET_FOURTH(u);
			goto fast_next_opcode;

		case DUP_TOP:
			v = TOP();
			Py_INCREF(v);
			PUSH(v);
			goto fast_next_opcode;

		case DUP_TOPX:
			if (oparg == 2) {
				x = TOP();
				Py_INCREF(x);
				w = SECOND();
				Py_INCREF(w);
				STACKADJ(2);
				SET_TOP(x);
				SET_SECOND(w);
				goto fast_next_opcode;
			} else if (oparg == 3) {
				x = TOP();
				Py_INCREF(x);
				w = SECOND();
				Py_INCREF(w);
				v = THIRD();
				Py_INCREF(v);
				STACKADJ(3);
				SET_TOP(x);
				SET_SECOND(w);
				SET_THIRD(v);
				goto fast_next_opcode;
			}
			Py_FatalError("invalid argument to DUP_TOPX"
				      " (bytecode corruption?)");
			break;

		case UNARY_POSITIVE:
			v = TOP();
			x = PyNumber_Positive(v);
			Py_DECREF(v);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case UNARY_NEGATIVE:
			v = TOP();
			x = PyNumber_Negative(v);
			Py_DECREF(v);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case UNARY_NOT:
			v = TOP();
			err = PyObject_IsTrue(v);
			Py_DECREF(v);
			if (err == 0) {
				Py_INCREF(Py_True);
				SET_TOP(Py_True);
				continue;
			}
			else if (err > 0) {
				Py_INCREF(Py_False);
				SET_TOP(Py_False);
				err = 0;
				continue;
			}
			STACKADJ(-1);
			break;

		case UNARY_CONVERT:
			v = TOP();
			x = PyObject_Repr(v);
			Py_DECREF(v);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case UNARY_INVERT:
			v = TOP();
			x = PyNumber_Invert(v);
			Py_DECREF(v);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_POWER:
			w = POP();
			v = TOP();
			x = PyNumber_Power(v, w, Py_None);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_MULTIPLY:
			w = POP();
			v = TOP();
			x = PyNumber_Multiply(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_DIVIDE:
			if (!_Py_QnewFlag) {
				w = POP();
				v = TOP();
				x = PyNumber_Divide(v, w);
				Py_DECREF(v);
				Py_DECREF(w);
				SET_TOP(x);
				if (x != NULL) continue;
				break;
			}
			/* -Qnew is in effect:	fall through to
			   BINARY_TRUE_DIVIDE */
		case BINARY_TRUE_DIVIDE:
			w = POP();
			v = TOP();
			x = PyNumber_TrueDivide(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_FLOOR_DIVIDE:
			w = POP();
			v = TOP();
			x = PyNumber_FloorDivide(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_MODULO:
			w = POP();
			v = TOP();
			x = PyNumber_Remainder(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_ADD:
			w = POP();
			v = TOP();
			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
				/* INLINE: int + int */
				register long a, b, i;
				a = PyInt_AS_LONG(v);
				b = PyInt_AS_LONG(w);
				i = a + b;
				if ((i^a) < 0 && (i^b) < 0)
					goto slow_add;
				x = PyInt_FromLong(i);
			}
			else if (PyString_CheckExact(v) &&
				 PyString_CheckExact(w)) {
				x = string_concatenate(v, w, f, next_instr);
				/* string_concatenate consumed the ref to v */
				goto skip_decref_vx;
			}
			else {
			  slow_add:
				x = PyNumber_Add(v, w);
			}
			Py_DECREF(v);
		  skip_decref_vx:
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_SUBTRACT:
			w = POP();
			v = TOP();
			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
				/* INLINE: int - int */
				register long a, b, i;
				a = PyInt_AS_LONG(v);
				b = PyInt_AS_LONG(w);
				i = a - b;
				if ((i^a) < 0 && (i^~b) < 0)
					goto slow_sub;
				x = PyInt_FromLong(i);
			}
			else {
			  slow_sub:
				x = PyNumber_Subtract(v, w);
			}
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_SUBSCR:
			w = POP();
			v = TOP();
			if (PyList_CheckExact(v) && PyInt_CheckExact(w)) {
				/* INLINE: list[int] */
				Py_ssize_t i = PyInt_AsSsize_t(w);
				if (i < 0)
					i += PyList_GET_SIZE(v);
				if (i >= 0 && i < PyList_GET_SIZE(v)) {
					x = PyList_GET_ITEM(v, i);
					Py_INCREF(x);
				}
				else
					goto slow_get;
			}
			else
			  slow_get:
				x = PyObject_GetItem(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_LSHIFT:
			w = POP();
			v = TOP();
			x = PyNumber_Lshift(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_RSHIFT:
			w = POP();
			v = TOP();
			x = PyNumber_Rshift(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_AND:
			w = POP();
			v = TOP();
			x = PyNumber_And(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_XOR:
			w = POP();
			v = TOP();
			x = PyNumber_Xor(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case BINARY_OR:
			w = POP();
			v = TOP();
			x = PyNumber_Or(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case LIST_APPEND:
			w = POP();
			v = POP();
			err = PyList_Append(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			if (err == 0) {
				PREDICT(JUMP_ABSOLUTE);
				continue;
			}
			break;

		case INPLACE_POWER:
			w = POP();
			v = TOP();
			x = PyNumber_InPlacePower(v, w, Py_None);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_MULTIPLY:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceMultiply(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_DIVIDE:
			if (!_Py_QnewFlag) {
				w = POP();
				v = TOP();
				x = PyNumber_InPlaceDivide(v, w);
				Py_DECREF(v);
				Py_DECREF(w);
				SET_TOP(x);
				if (x != NULL) continue;
				break;
			}
			/* -Qnew is in effect:	fall through to
			   INPLACE_TRUE_DIVIDE */
		case INPLACE_TRUE_DIVIDE:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceTrueDivide(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_FLOOR_DIVIDE:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceFloorDivide(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_MODULO:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceRemainder(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_ADD:
			w = POP();
			v = TOP();
			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
				/* INLINE: int + int */
				register long a, b, i;
				a = PyInt_AS_LONG(v);
				b = PyInt_AS_LONG(w);
				i = a + b;
				if ((i^a) < 0 && (i^b) < 0)
					goto slow_iadd;
				x = PyInt_FromLong(i);
			}
			else if (PyString_CheckExact(v) &&
				 PyString_CheckExact(w)) {
				x = string_concatenate(v, w, f, next_instr);
				/* string_concatenate consumed the ref to v */
				goto skip_decref_v;
			}
			else {
			  slow_iadd:
				x = PyNumber_InPlaceAdd(v, w);
			}
			Py_DECREF(v);
		  skip_decref_v:
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_SUBTRACT:
			w = POP();
			v = TOP();
			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
				/* INLINE: int - int */
				register long a, b, i;
				a = PyInt_AS_LONG(v);
				b = PyInt_AS_LONG(w);
				i = a - b;
				if ((i^a) < 0 && (i^~b) < 0)
					goto slow_isub;
				x = PyInt_FromLong(i);
			}
			else {
			  slow_isub:
				x = PyNumber_InPlaceSubtract(v, w);
			}
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_LSHIFT:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceLshift(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_RSHIFT:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceRshift(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_AND:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceAnd(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_XOR:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceXor(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case INPLACE_OR:
			w = POP();
			v = TOP();
			x = PyNumber_InPlaceOr(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case SLICE+0:
		case SLICE+1:
		case SLICE+2:
		case SLICE+3:
			if ((opcode-SLICE) & 2)
				w = POP();
			else
				w = NULL;
			if ((opcode-SLICE) & 1)
				v = POP();
			else
				v = NULL;
			u = TOP();
			x = apply_slice(u, v, w);
			Py_DECREF(u);
			Py_XDECREF(v);
			Py_XDECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case STORE_SLICE+0:
		case STORE_SLICE+1:
		case STORE_SLICE+2:
		case STORE_SLICE+3:
			if ((opcode-STORE_SLICE) & 2)
				w = POP();
			else
				w = NULL;
			if ((opcode-STORE_SLICE) & 1)
				v = POP();
			else
				v = NULL;
			u = POP();
			t = POP();
			err = assign_slice(u, v, w, t); /* u[v:w] = t */
			Py_DECREF(t);
			Py_DECREF(u);
			Py_XDECREF(v);
			Py_XDECREF(w);
			if (err == 0) continue;
			break;

		case DELETE_SLICE+0:
		case DELETE_SLICE+1:
		case DELETE_SLICE+2:
		case DELETE_SLICE+3:
			if ((opcode-DELETE_SLICE) & 2)
				w = POP();
			else
				w = NULL;
			if ((opcode-DELETE_SLICE) & 1)
				v = POP();
			else
				v = NULL;
			u = POP();
			err = assign_slice(u, v, w, (PyObject *)NULL);
							/* del u[v:w] */
			Py_DECREF(u);
			Py_XDECREF(v);
			Py_XDECREF(w);
			if (err == 0) continue;
			break;

		case STORE_SUBSCR:
			w = TOP();
			v = SECOND();
			u = THIRD();
			STACKADJ(-3);
			/* v[w] = u */
			err = PyObject_SetItem(v, w, u);
			Py_DECREF(u);
			Py_DECREF(v);
			Py_DECREF(w);
			if (err == 0) continue;
			break;

		case DELETE_SUBSCR:
			w = TOP();
			v = SECOND();
			STACKADJ(-2);
			/* del v[w] */
			err = PyObject_DelItem(v, w);
			Py_DECREF(v);
			Py_DECREF(w);
			if (err == 0) continue;
			break;

		case PRINT_EXPR:
			v = POP();
			w = PySys_GetObject("displayhook");
			if (w == NULL) {
				PyErr_SetString(PyExc_RuntimeError,
						"lost sys.displayhook");
				err = -1;
				x = NULL;
			}
			if (err == 0) {
				x = PyTuple_Pack(1, v);
				if (x == NULL)
					err = -1;
			}
			if (err == 0) {
				w = PyEval_CallObject(w, x);
				Py_XDECREF(w);
				if (w == NULL)
					err = -1;
			}
			Py_DECREF(v);
			Py_XDECREF(x);
			break;

		case PRINT_ITEM_TO:
			w = stream = POP();
			/* fall through to PRINT_ITEM */

		case PRINT_ITEM:
			v = POP();
			if (stream == NULL || stream == Py_None) {
				w = PySys_GetObject("stdout");
				if (w == NULL) {
					PyErr_SetString(PyExc_RuntimeError,
							"lost sys.stdout");
					err = -1;
				}
			}
			/* PyFile_SoftSpace() can exececute arbitrary code
			   if sys.stdout is an instance with a __getattr__.
			   If __getattr__ raises an exception, w will
			   be freed, so we need to prevent that temporarily. */
			Py_XINCREF(w);
			if (w != NULL && PyFile_SoftSpace(w, 0))
				err = PyFile_WriteString(" ", w);
			if (err == 0)
				err = PyFile_WriteObject(v, w, Py_PRINT_RAW);
			if (err == 0) {
			    /* XXX move into writeobject() ? */
			    if (PyString_Check(v)) {
				char *s = PyString_AS_STRING(v);
				Py_ssize_t len = PyString_GET_SIZE(v);
				if (len == 0 ||
				    !isspace(Py_CHARMASK(s[len-1])) ||
				    s[len-1] == ' ')
					PyFile_SoftSpace(w, 1);
			    }
#ifdef Py_USING_UNICODE
			    else if (PyUnicode_Check(v)) {
				Py_UNICODE *s = PyUnicode_AS_UNICODE(v);
				Py_ssize_t len = PyUnicode_GET_SIZE(v);
				if (len == 0 ||
				    !Py_UNICODE_ISSPACE(s[len-1]) ||
				    s[len-1] == ' ')
				    PyFile_SoftSpace(w, 1);
			    }
#endif
			    else
			    	PyFile_SoftSpace(w, 1);
			}
			Py_XDECREF(w);
			Py_DECREF(v);
			Py_XDECREF(stream);
			stream = NULL;
			if (err == 0)
				continue;
			break;

		case PRINT_NEWLINE_TO:
			w = stream = POP();
			/* fall through to PRINT_NEWLINE */

		case PRINT_NEWLINE:
			if (stream == NULL || stream == Py_None) {
				w = PySys_GetObject("stdout");
				if (w == NULL)
					PyErr_SetString(PyExc_RuntimeError,
							"lost sys.stdout");
			}
			if (w != NULL) {
				err = PyFile_WriteString("\n", w);
				if (err == 0)
					PyFile_SoftSpace(w, 0);
			}
			Py_XDECREF(stream);
			stream = NULL;
			break;


#ifdef CASE_TOO_BIG
		default: switch (opcode) {
#endif
		case RAISE_VARARGS:
			u = v = w = NULL;
			switch (oparg) {
			case 3:
				u = POP(); /* traceback */
				/* Fallthrough */
			case 2:
				v = POP(); /* value */
				/* Fallthrough */
			case 1:
				w = POP(); /* exc */
			case 0: /* Fallthrough */
				why = do_raise(w, v, u);
				break;
			default:
				PyErr_SetString(PyExc_SystemError,
					   "bad RAISE_VARARGS oparg");
				why = WHY_EXCEPTION;
				break;
			}
			break;

		case LOAD_LOCALS:
			if ((x = f->f_locals) != NULL) {
				Py_INCREF(x);
				PUSH(x);
				continue;
			}
			PyErr_SetString(PyExc_SystemError, "no locals");
			break;

		case RETURN_VALUE:
			retval = POP();
			why = WHY_RETURN;
			goto fast_block_end;

		case YIELD_VALUE:
			retval = POP();
			f->f_stacktop = stack_pointer;
			why = WHY_YIELD;
			goto fast_yield;

		case EXEC_STMT:
			w = TOP();
			v = SECOND();
			u = THIRD();
			STACKADJ(-3);
			READ_TIMESTAMP(intr0);
			err = exec_statement(f, u, v, w);
			READ_TIMESTAMP(intr1);
			Py_DECREF(u);
			Py_DECREF(v);
			Py_DECREF(w);
			break;

		case POP_BLOCK:
			{
				PyTryBlock *b = PyFrame_BlockPop(f);
				while (STACK_LEVEL() > b->b_level) {
					v = POP();
					Py_DECREF(v);
				}
			}
			continue;

		PREDICTED(END_FINALLY);
		case END_FINALLY:
			v = POP();
			if (PyInt_Check(v)) {
				why = (enum why_code) PyInt_AS_LONG(v);
				assert(why != WHY_YIELD);
				if (why == WHY_RETURN ||
				    why == WHY_CONTINUE)
					retval = POP();
			}
			else if (PyExceptionClass_Check(v) ||
			         PyString_Check(v)) {
				w = POP();
				u = POP();
				PyErr_Restore(v, w, u);
				why = WHY_RERAISE;
				break;
			}
			else if (v != Py_None) {
				PyErr_SetString(PyExc_SystemError,
					"'finally' pops bad exception");
				why = WHY_EXCEPTION;
			}
			Py_DECREF(v);
			break;

		case BUILD_CLASS:
			u = TOP();
			v = SECOND();
			w = THIRD();
			STACKADJ(-2);
			x = build_class(u, v, w);
			SET_TOP(x);
			Py_DECREF(u);
			Py_DECREF(v);
			Py_DECREF(w);
			break;

		case STORE_NAME:
			w = GETITEM(names, oparg);
			v = POP();
			if ((x = f->f_locals) != NULL) {
				if (PyDict_CheckExact(x))
					err = PyDict_SetItem(x, w, v);
				else
					err = PyObject_SetItem(x, w, v);
				Py_DECREF(v);
				if (err == 0) continue;
				break;
			}
			PyErr_Format(PyExc_SystemError,
				     "no locals found when storing %s",
				     PyObject_REPR(w));
			break;

		case DELETE_NAME:
			w = GETITEM(names, oparg);
			if ((x = f->f_locals) != NULL) {
				if ((err = PyObject_DelItem(x, w)) != 0)
					format_exc_check_arg(PyExc_NameError,
							     NAME_ERROR_MSG,
							     w);
				break;
			}
			PyErr_Format(PyExc_SystemError,
				     "no locals when deleting %s",
				     PyObject_REPR(w));
			break;

		PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
		case UNPACK_SEQUENCE:
			v = POP();
			if (PyTuple_CheckExact(v) &&
			    PyTuple_GET_SIZE(v) == oparg) {
				PyObject **items = \
					((PyTupleObject *)v)->ob_item;
				while (oparg--) {
					w = items[oparg];
					Py_INCREF(w);
					PUSH(w);
				}
				Py_DECREF(v);
				continue;
			} else if (PyList_CheckExact(v) &&
				   PyList_GET_SIZE(v) == oparg) {
				PyObject **items = \
					((PyListObject *)v)->ob_item;
				while (oparg--) {
					w = items[oparg];
					Py_INCREF(w);
					PUSH(w);
				}
			} else if (unpack_iterable(v, oparg,
						   stack_pointer + oparg)) {
				stack_pointer += oparg;
			} else {
				/* unpack_iterable() raised an exception */
				why = WHY_EXCEPTION;
			}
			Py_DECREF(v);
			break;

		case STORE_ATTR:
			w = GETITEM(names, oparg);
			v = TOP();
			u = SECOND();
			STACKADJ(-2);
			err = PyObject_SetAttr(v, w, u); /* v.w = u */
			Py_DECREF(v);
			Py_DECREF(u);
			if (err == 0) continue;
			break;

		case DELETE_ATTR:
			w = GETITEM(names, oparg);
			v = POP();
			err = PyObject_SetAttr(v, w, (PyObject *)NULL);
							/* del v.w */
			Py_DECREF(v);
			break;

		case STORE_GLOBAL:
			w = GETITEM(names, oparg);
			v = POP();
			err = PyDict_SetItem(f->f_globals, w, v);
			Py_DECREF(v);
			if (err == 0) continue;
			break;

		case DELETE_GLOBAL:
			w = GETITEM(names, oparg);
			if ((err = PyDict_DelItem(f->f_globals, w)) != 0)
				format_exc_check_arg(
				    PyExc_NameError, GLOBAL_NAME_ERROR_MSG, w);
			break;

		case LOAD_NAME:
			w = GETITEM(names, oparg);
			if ((v = f->f_locals) == NULL) {
				PyErr_Format(PyExc_SystemError,
					     "no locals when loading %s",
					     PyObject_REPR(w));
				break;
			}
			if (PyDict_CheckExact(v)) {
				x = PyDict_GetItem(v, w);
				Py_XINCREF(x);
			}
			else {
				x = PyObject_GetItem(v, w);
				if (x == NULL && PyErr_Occurred()) {
					if (!PyErr_ExceptionMatches(
							PyExc_KeyError))
						break;
					PyErr_Clear();
				}
			}
			if (x == NULL) {
				x = PyDict_GetItem(f->f_globals, w);
				if (x == NULL) {
					x = PyDict_GetItem(f->f_builtins, w);
					if (x == NULL) {
						format_exc_check_arg(
							    PyExc_NameError,
							    NAME_ERROR_MSG, w);
						break;
					}
				}
				Py_INCREF(x);
			}
			PUSH(x);
			continue;

		case LOAD_GLOBAL:
			w = GETITEM(names, oparg);
			if (PyString_CheckExact(w)) {
				/* Inline the PyDict_GetItem() calls.
				   WARNING: this is an extreme speed hack.
				   Do not try this at home. */
				long hash = ((PyStringObject *)w)->ob_shash;
				if (hash != -1) {
					PyDictObject *d;
					PyDictEntry *e;
					d = (PyDictObject *)(f->f_globals);
					e = d->ma_lookup(d, w, hash);
					if (e == NULL) {
						x = NULL;
						break;
					}
					x = e->me_value;
					if (x != NULL) {
						Py_INCREF(x);
						PUSH(x);
						continue;
					}
					d = (PyDictObject *)(f->f_builtins);
					e = d->ma_lookup(d, w, hash);
					if (e == NULL) {
						x = NULL;
						break;
					}
					x = e->me_value;
					if (x != NULL) {
						Py_INCREF(x);
						PUSH(x);
						continue;
					}
					goto load_global_error;
				}
			}
			/* This is the un-inlined version of the code above */
			x = PyDict_GetItem(f->f_globals, w);
			if (x == NULL) {
				x = PyDict_GetItem(f->f_builtins, w);
				if (x == NULL) {
				  load_global_error:
					format_exc_check_arg(
						    PyExc_NameError,
						    GLOBAL_NAME_ERROR_MSG, w);
					break;
				}
			}
			Py_INCREF(x);
			PUSH(x);
			continue;

		case DELETE_FAST:
			x = GETLOCAL(oparg);
			if (x != NULL) {
				SETLOCAL(oparg, NULL);
				continue;
			}
			format_exc_check_arg(
				PyExc_UnboundLocalError,
				UNBOUNDLOCAL_ERROR_MSG,
				PyTuple_GetItem(co->co_varnames, oparg)
				);
			break;

		case LOAD_CLOSURE:
			x = freevars[oparg];
			Py_INCREF(x);
			PUSH(x);
			if (x != NULL) continue;
			break;

		case LOAD_DEREF:
			x = freevars[oparg];
			w = PyCell_Get(x);
			if (w != NULL) {
				PUSH(w);
				continue;
			}
			err = -1;
			/* Don't stomp existing exception */
			if (PyErr_Occurred())
				break;
			if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) {
				v = PyTuple_GET_ITEM(co->co_cellvars,
						       oparg);
			       format_exc_check_arg(
				       PyExc_UnboundLocalError,
				       UNBOUNDLOCAL_ERROR_MSG,
				       v);
			} else {
				v = PyTuple_GET_ITEM(co->co_freevars, oparg -
					PyTuple_GET_SIZE(co->co_cellvars));
				format_exc_check_arg(PyExc_NameError,
						     UNBOUNDFREE_ERROR_MSG, v);
			}
			break;

		case STORE_DEREF:
			w = POP();
			x = freevars[oparg];
			PyCell_Set(x, w);
			Py_DECREF(w);
			continue;

		case BUILD_TUPLE:
			x = PyTuple_New(oparg);
			if (x != NULL) {
				for (; --oparg >= 0;) {
					w = POP();
					PyTuple_SET_ITEM(x, oparg, w);
				}
				PUSH(x);
				continue;
			}
			break;

		case BUILD_LIST:
			x =  PyList_New(oparg);
			if (x != NULL) {
				for (; --oparg >= 0;) {
					w = POP();
					PyList_SET_ITEM(x, oparg, w);
				}
				PUSH(x);
				continue;
			}
			break;

		case BUILD_MAP:
			x = _PyDict_NewPresized((Py_ssize_t)oparg);
			PUSH(x);
			if (x != NULL) continue;
			break;

		case STORE_MAP:
			w = TOP();     /* key */
			u = SECOND();  /* value */
			v = THIRD();   /* dict */
			STACKADJ(-2);
			assert (PyDict_CheckExact(v));
			err = PyDict_SetItem(v, w, u);  /* v[w] = u */
			Py_DECREF(u);
			Py_DECREF(w);
			if (err == 0) continue;
			break;

		case LOAD_ATTR:
			w = GETITEM(names, oparg);
			v = TOP();
			x = PyObject_GetAttr(v, w);
			Py_DECREF(v);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case COMPARE_OP:
			w = POP();
			v = TOP();
			if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) {
				/* INLINE: cmp(int, int) */
				register long a, b;
				register int res;
				a = PyInt_AS_LONG(v);
				b = PyInt_AS_LONG(w);
				switch (oparg) {
				case PyCmp_LT: res = a <  b; break;
				case PyCmp_LE: res = a <= b; break;
				case PyCmp_EQ: res = a == b; break;
				case PyCmp_NE: res = a != b; break;
				case PyCmp_GT: res = a >  b; break;
				case PyCmp_GE: res = a >= b; break;
				case PyCmp_IS: res = v == w; break;
				case PyCmp_IS_NOT: res = v != w; break;
				default: goto slow_compare;
				}
				x = res ? Py_True : Py_False;
				Py_INCREF(x);
			}
			else {
			  slow_compare:
				x = cmp_outcome(oparg, v, w);
			}
			Py_DECREF(v);
			Py_DECREF(w);
			SET_TOP(x);
			if (x == NULL) break;
			PREDICT(JUMP_IF_FALSE);
			PREDICT(JUMP_IF_TRUE);
			continue;

		case IMPORT_NAME:
			w = GETITEM(names, oparg);
			x = PyDict_GetItemString(f->f_builtins, "__import__");
			if (x == NULL) {
				PyErr_SetString(PyExc_ImportError,
						"__import__ not found");
				break;
			}
			Py_INCREF(x);
			v = POP();
			u = TOP();
			if (PyInt_AsLong(u) != -1 || PyErr_Occurred())
				w = PyTuple_Pack(5,
					    w,
					    f->f_globals,
					    f->f_locals == NULL ?
						  Py_None : f->f_locals,
					    v,
					    u);
			else
				w = PyTuple_Pack(4,
					    w,
					    f->f_globals,
					    f->f_locals == NULL ?
						  Py_None : f->f_locals,
					    v);
			Py_DECREF(v);
			Py_DECREF(u);
			if (w == NULL) {
				u = POP();
				Py_DECREF(x);
				x = NULL;
				break;
			}
			READ_TIMESTAMP(intr0);
			v = x;
			x = PyEval_CallObject(v, w);
			Py_DECREF(v);
			READ_TIMESTAMP(intr1);
			Py_DECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case IMPORT_STAR:
			v = POP();
			PyFrame_FastToLocals(f);
			if ((x = f->f_locals) == NULL) {
				PyErr_SetString(PyExc_SystemError,
					"no locals found during 'import *'");
				break;
			}
			READ_TIMESTAMP(intr0);
			err = import_all_from(x, v);
			READ_TIMESTAMP(intr1);
			PyFrame_LocalsToFast(f, 0);
			Py_DECREF(v);
			if (err == 0) continue;
			break;

		case IMPORT_FROM:
			w = GETITEM(names, oparg);
			v = TOP();
			READ_TIMESTAMP(intr0);
			x = import_from(v, w);
			READ_TIMESTAMP(intr1);
			PUSH(x);
			if (x != NULL) continue;
			break;

		case JUMP_FORWARD:
			JUMPBY(oparg);
			goto fast_next_opcode;

		PREDICTED_WITH_ARG(JUMP_IF_FALSE);
		case JUMP_IF_FALSE:
			w = TOP();
			if (w == Py_True) {
				PREDICT(POP_TOP);
				goto fast_next_opcode;
			}
			if (w == Py_False) {
				JUMPBY(oparg);
				goto fast_next_opcode;
			}
			err = PyObject_IsTrue(w);
			if (err > 0)
				err = 0;
			else if (err == 0)
				JUMPBY(oparg);
			else
				break;
			continue;

		PREDICTED_WITH_ARG(JUMP_IF_TRUE);
		case JUMP_IF_TRUE:
			w = TOP();
			if (w == Py_False) {
				PREDICT(POP_TOP);
				goto fast_next_opcode;
			}
			if (w == Py_True) {
				JUMPBY(oparg);
				goto fast_next_opcode;
			}
			err = PyObject_IsTrue(w);
			if (err > 0) {
				err = 0;
				JUMPBY(oparg);
			}
			else if (err == 0)
				;
			else
				break;
			continue;

		PREDICTED_WITH_ARG(JUMP_ABSOLUTE);
		case JUMP_ABSOLUTE:
			JUMPTO(oparg);
#if FAST_LOOPS
			/* Enabling this path speeds-up all while and for-loops by bypassing
                           the per-loop checks for signals.  By default, this should be turned-off
                           because it prevents detection of a control-break in tight loops like
                           "while 1: pass".  Compile with this option turned-on when you need
                           the speed-up and do not need break checking inside tight loops (ones
                           that contain only instructions ending with goto fast_next_opcode). 
                        */
			goto fast_next_opcode;
#else
			continue;
#endif

		case GET_ITER:
			/* before: [obj]; after [getiter(obj)] */
			v = TOP();
			x = PyObject_GetIter(v);
			Py_DECREF(v);
			if (x != NULL) {
				SET_TOP(x);
				PREDICT(FOR_ITER);
				continue;
			}
			STACKADJ(-1);
			break;

		PREDICTED_WITH_ARG(FOR_ITER);
		case FOR_ITER:
			/* before: [iter]; after: [iter, iter()] *or* [] */
			v = TOP();
			x = (*v->ob_type->tp_iternext)(v);
			if (x != NULL) {
				PUSH(x);
				PREDICT(STORE_FAST);
				PREDICT(UNPACK_SEQUENCE);
				continue;
			}
			if (PyErr_Occurred()) {
				if (!PyErr_ExceptionMatches(
						PyExc_StopIteration))
					break;
				PyErr_Clear();
			}
			/* iterator ended normally */
 			x = v = POP();
			Py_DECREF(v);
			JUMPBY(oparg);
			continue;

		case BREAK_LOOP:
			why = WHY_BREAK;
			goto fast_block_end;

		case CONTINUE_LOOP:
			retval = PyInt_FromLong(oparg);
			if (!retval) {
				x = NULL;
				break;
			}
			why = WHY_CONTINUE;
			goto fast_block_end;

		case SETUP_LOOP:
		case SETUP_EXCEPT:
		case SETUP_FINALLY:
			/* NOTE: If you add any new block-setup opcodes that
		           are not try/except/finally handlers, you may need
		           to update the PyGen_NeedsFinalizing() function.
		           */

			PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
					   STACK_LEVEL());
			continue;

		case WITH_CLEANUP:
		{
			/* At the top of the stack are 1-3 values indicating
			   how/why we entered the finally clause:
			   - TOP = None
			   - (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval
			   - TOP = WHY_*; no retval below it
			   - (TOP, SECOND, THIRD) = exc_info()
			   Below them is EXIT, the context.__exit__ bound method.
			   In the last case, we must call
			     EXIT(TOP, SECOND, THIRD)
			   otherwise we must call
			     EXIT(None, None, None)

			   In all cases, we remove EXIT from the stack, leaving
			   the rest in the same order.

			   In addition, if the stack represents an exception,
			   *and* the function call returns a 'true' value, we
			   "zap" this information, to prevent END_FINALLY from
			   re-raising the exception.  (But non-local gotos
			   should still be resumed.)
			*/

			PyObject *exit_func;

			u = POP();
			if (u == Py_None) {
			       	exit_func = TOP();
				SET_TOP(u);
				v = w = Py_None;
			}
			else if (PyInt_Check(u)) {
				switch(PyInt_AS_LONG(u)) {
				case WHY_RETURN:
				case WHY_CONTINUE:
					/* Retval in TOP. */
					exit_func = SECOND();
					SET_SECOND(TOP());
					SET_TOP(u);
					break;
				default:
					exit_func = TOP();
					SET_TOP(u);
					break;
				}
				u = v = w = Py_None;
			}
			else {
				v = TOP();
				w = SECOND();
				exit_func = THIRD();
				SET_TOP(u);
				SET_SECOND(v);
				SET_THIRD(w);
			}
			/* XXX Not the fastest way to call it... */
			x = PyObject_CallFunctionObjArgs(exit_func, u, v, w,
							 NULL);
			if (x == NULL) {
				Py_DECREF(exit_func);
				break; /* Go to error exit */
			}
			if (u != Py_None && PyObject_IsTrue(x)) {
				/* There was an exception and a true return */
				STACKADJ(-2);
				Py_INCREF(Py_None);
				SET_TOP(Py_None);
				Py_DECREF(u);
				Py_DECREF(v);
				Py_DECREF(w);
			} else {
				/* The stack was rearranged to remove EXIT
				   above. Let END_FINALLY do its thing */
			}
			Py_DECREF(x);
			Py_DECREF(exit_func);
			PREDICT(END_FINALLY);
			break;
		}

		case CALL_FUNCTION:
		{
			PyObject **sp;
			PCALL(PCALL_ALL);
			sp = stack_pointer;
#ifdef WITH_TSC
			x = call_function(&sp, oparg, &intr0, &intr1);
#else
			x = call_function(&sp, oparg);
#endif
			stack_pointer = sp;
			PUSH(x);
			if (x != NULL)
				continue;
			break;
		}

		case CALL_FUNCTION_VAR:
		case CALL_FUNCTION_KW:
		case CALL_FUNCTION_VAR_KW:
		{
		    int na = oparg & 0xff;
		    int nk = (oparg>>8) & 0xff;
		    int flags = (opcode - CALL_FUNCTION) & 3;
		    int n = na + 2 * nk;
		    PyObject **pfunc, *func, **sp;
		    PCALL(PCALL_ALL);
		    if (flags & CALL_FLAG_VAR)
			    n++;
		    if (flags & CALL_FLAG_KW)
			    n++;
		    pfunc = stack_pointer - n - 1;
		    func = *pfunc;

		    if (PyMethod_Check(func)
			&& PyMethod_GET_SELF(func) != NULL) {
			    PyObject *self = PyMethod_GET_SELF(func);
			    Py_INCREF(self);
			    func = PyMethod_GET_FUNCTION(func);
			    Py_INCREF(func);
			    Py_DECREF(*pfunc);
			    *pfunc = self;
			    na++;
			    n++;
		    } else
			    Py_INCREF(func);
		    sp = stack_pointer;
		    READ_TIMESTAMP(intr0);
		    x = ext_do_call(func, &sp, flags, na, nk);
		    READ_TIMESTAMP(intr1);
		    stack_pointer = sp;
		    Py_DECREF(func);

		    while (stack_pointer > pfunc) {
			    w = POP();
			    Py_DECREF(w);
		    }
		    PUSH(x);
		    if (x != NULL)
			    continue;
		    break;
		}

		case MAKE_FUNCTION:
			v = POP(); /* code object */
			x = PyFunction_New(v, f->f_globals);
			Py_DECREF(v);
			/* XXX Maybe this should be a separate opcode? */
			if (x != NULL && oparg > 0) {
				v = PyTuple_New(oparg);
				if (v == NULL) {
					Py_DECREF(x);
					x = NULL;
					break;
				}
				while (--oparg >= 0) {
					w = POP();
					PyTuple_SET_ITEM(v, oparg, w);
				}
				err = PyFunction_SetDefaults(x, v);
				Py_DECREF(v);
			}
			PUSH(x);
			break;

		case MAKE_CLOSURE:
		{
			v = POP(); /* code object */
			x = PyFunction_New(v, f->f_globals);
			Py_DECREF(v);
			if (x != NULL) {
				v = POP();
				err = PyFunction_SetClosure(x, v);
				Py_DECREF(v);
			}
			if (x != NULL && oparg > 0) {
				v = PyTuple_New(oparg);
				if (v == NULL) {
					Py_DECREF(x);
					x = NULL;
					break;
				}
				while (--oparg >= 0) {
					w = POP();
					PyTuple_SET_ITEM(v, oparg, w);
				}
				err = PyFunction_SetDefaults(x, v);
				Py_DECREF(v);
			}
			PUSH(x);
			break;
		}

		case BUILD_SLICE:
			if (oparg == 3)
				w = POP();
			else
				w = NULL;
			v = POP();
			u = TOP();
			x = PySlice_New(u, v, w);
			Py_DECREF(u);
			Py_DECREF(v);
			Py_XDECREF(w);
			SET_TOP(x);
			if (x != NULL) continue;
			break;

		case EXTENDED_ARG:
			opcode = NEXTOP();
			oparg = oparg<<16 | NEXTARG();
			goto dispatch_opcode;

		default:
			fprintf(stderr,
				"XXX lineno: %d, opcode: %d\n",
				PyCode_Addr2Line(f->f_code, f->f_lasti),
				opcode);
			PyErr_SetString(PyExc_SystemError, "unknown opcode");
			why = WHY_EXCEPTION;
			break;

#ifdef CASE_TOO_BIG
		}
#endif

		} /* switch */

	    on_error:

		READ_TIMESTAMP(inst1);

		/* Quickly continue if no error occurred */

		if (why == WHY_NOT) {
			if (err == 0 && x != NULL) {
#ifdef CHECKEXC
				/* This check is expensive! */
				if (PyErr_Occurred())
					fprintf(stderr,
						"XXX undetected error\n");
				else {
#endif
					READ_TIMESTAMP(loop1);
					continue; /* Normal, fast path */
#ifdef CHECKEXC
				}
#endif
			}
			why = WHY_EXCEPTION;
			x = Py_None;
			err = 0;
		}

		/* Double-check exception status */

		if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
			if (!PyErr_Occurred()) {
				PyErr_SetString(PyExc_SystemError,
					"error return without exception set");
				why = WHY_EXCEPTION;
			}
		}
#ifdef CHECKEXC
		else {
			/* This check is expensive! */
			if (PyErr_Occurred()) {
				char buf[128];
				sprintf(buf, "Stack unwind with exception "
					"set and why=%d", why);
				Py_FatalError(buf);
			}
		}
#endif

		/* Log traceback info if this is a real exception */

		if (why == WHY_EXCEPTION) {
			PyTraceBack_Here(f);

			if (tstate->c_tracefunc != NULL)
				call_exc_trace(tstate->c_tracefunc,
					       tstate->c_traceobj, f);
		}

		/* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */

		if (why == WHY_RERAISE)
			why = WHY_EXCEPTION;

		/* Unwind stacks if a (pseudo) exception occurred */

fast_block_end:
		while (why != WHY_NOT && f->f_iblock > 0) {
			PyTryBlock *b = PyFrame_BlockPop(f);

			assert(why != WHY_YIELD);
			if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) {
				/* For a continue inside a try block,
				   don't pop the block for the loop. */
				PyFrame_BlockSetup(f, b->b_type, b->b_handler,
						   b->b_level);
				why = WHY_NOT;
				JUMPTO(PyInt_AS_LONG(retval));
				Py_DECREF(retval);
				break;
			}

			while (STACK_LEVEL() > b->b_level) {
				v = POP();
				Py_XDECREF(v);
			}
			if (b->b_type == SETUP_LOOP && why == WHY_BREAK) {
				why = WHY_NOT;
				JUMPTO(b->b_handler);
				break;
			}
			if (b->b_type == SETUP_FINALLY ||
			    (b->b_type == SETUP_EXCEPT &&
			     why == WHY_EXCEPTION)) {
				if (why == WHY_EXCEPTION) {
					PyObject *exc, *val, *tb;
					PyErr_Fetch(&exc, &val, &tb);
					if (val == NULL) {
						val = Py_None;
						Py_INCREF(val);
					}
					/* Make the raw exception data
					   available to the handler,
					   so a program can emulate the
					   Python main loop.  Don't do
					   this for 'finally'. */
					if (b->b_type == SETUP_EXCEPT) {
						PyErr_NormalizeException(
							&exc, &val, &tb);
						set_exc_info(tstate,
							     exc, val, tb);
					}
					if (tb == NULL) {
						Py_INCREF(Py_None);
						PUSH(Py_None);
					} else
						PUSH(tb);
					PUSH(val);
					PUSH(exc);
				}
				else {
					if (why & (WHY_RETURN | WHY_CONTINUE))
						PUSH(retval);
					v = PyInt_FromLong((long)why);
					PUSH(v);
				}
				why = WHY_NOT;
				JUMPTO(b->b_handler);
				break;
			}
		} /* unwind stack */

		/* End the loop if we still have an error (or return) */

		if (why != WHY_NOT)
			break;
		READ_TIMESTAMP(loop1);

	} /* main loop */

	assert(why != WHY_YIELD);
	/* Pop remaining stack entries. */
	while (!EMPTY()) {
		v = POP();
		Py_XDECREF(v);
	}

	if (why != WHY_RETURN)
		retval = NULL;

fast_yield:
	if (tstate->use_tracing) {
		if (tstate->c_tracefunc) {
			if (why == WHY_RETURN || why == WHY_YIELD) {
				if (call_trace(tstate->c_tracefunc,
					       tstate->c_traceobj, f,
					       PyTrace_RETURN, retval)) {
					Py_XDECREF(retval);
					retval = NULL;
					why = WHY_EXCEPTION;
				}
			}
			else if (why == WHY_EXCEPTION) {
				call_trace_protected(tstate->c_tracefunc,
						     tstate->c_traceobj, f,
						     PyTrace_RETURN, NULL);
			}
		}
		if (tstate->c_profilefunc) {
			if (why == WHY_EXCEPTION)
				call_trace_protected(tstate->c_profilefunc,
						     tstate->c_profileobj, f,
						     PyTrace_RETURN, NULL);
			else if (call_trace(tstate->c_profilefunc,
					    tstate->c_profileobj, f,
					    PyTrace_RETURN, retval)) {
				Py_XDECREF(retval);
				retval = NULL;
				why = WHY_EXCEPTION;
			}
		}
	}

	if (tstate->frame->f_exc_type != NULL)
		reset_exc_info(tstate);
	else {
		assert(tstate->frame->f_exc_value == NULL);
		assert(tstate->frame->f_exc_traceback == NULL);
	}

	/* pop frame */
exit_eval_frame:
	Py_LeaveRecursiveCall();
	tstate->frame = f->f_back;

	return retval;
}

/* This is gonna seem *real weird*, but if you put some other code between
   PyEval_EvalFrame() and PyEval_EvalCodeEx() you will need to adjust
   the test in the if statements in Misc/gdbinit (pystack and pystackv). */

PyObject *
PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
	   PyObject **args, int argcount, PyObject **kws, int kwcount,
	   PyObject **defs, int defcount, PyObject *closure)
{
	register PyFrameObject *f;
	register PyObject *retval = NULL;
	register PyObject **fastlocals, **freevars;
	PyThreadState *tstate = PyThreadState_GET();
	PyObject *x, *u;

	if (globals == NULL) {
		PyErr_SetString(PyExc_SystemError,
				"PyEval_EvalCodeEx: NULL globals");
		return NULL;
	}

	assert(tstate != NULL);
	assert(globals != NULL);
	f = PyFrame_New(tstate, co, globals, locals);
	if (f == NULL)
		return NULL;

	fastlocals = f->f_localsplus;
	freevars = f->f_localsplus + co->co_nlocals;

	if (co->co_argcount > 0 ||
	    co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
		int i;
		int n = argcount;
		PyObject *kwdict = NULL;
		if (co->co_flags & CO_VARKEYWORDS) {
			kwdict = PyDict_New();
			if (kwdict == NULL)
				goto fail;
			i = co->co_argcount;
			if (co->co_flags & CO_VARARGS)
				i++;
			SETLOCAL(i, kwdict);
		}
		if (argcount > co->co_argcount) {
			if (!(co->co_flags & CO_VARARGS)) {
				PyErr_Format(PyExc_TypeError,
				    "%.200s() takes %s %d "
				    "%sargument%s (%d given)",
				    PyString_AsString(co->co_name),
				    defcount ? "at most" : "exactly",
				    co->co_argcount,
				    kwcount ? "non-keyword " : "",
				    co->co_argcount == 1 ? "" : "s",
				    argcount);
				goto fail;
			}
			n = co->co_argcount;
		}
		for (i = 0; i < n; i++) {
			x = args[i];
			Py_INCREF(x);
			SETLOCAL(i, x);
		}
		if (co->co_flags & CO_VARARGS) {
			u = PyTuple_New(argcount - n);
			if (u == NULL)
				goto fail;
			SETLOCAL(co->co_argcount, u);
			for (i = n; i < argcount; i++) {
				x = args[i];
				Py_INCREF(x);
				PyTuple_SET_ITEM(u, i-n, x);
			}
		}
		for (i = 0; i < kwcount; i++) {
			PyObject *keyword = kws[2*i];
			PyObject *value = kws[2*i + 1];
			int j;
			if (keyword == NULL || !PyString_Check(keyword)) {
				PyErr_Format(PyExc_TypeError,
				    "%.200s() keywords must be strings",
				    PyString_AsString(co->co_name));
				goto fail;
			}
			/* XXX slow -- speed up using dictionary? */
			for (j = 0; j < co->co_argcount; j++) {
				PyObject *nm = PyTuple_GET_ITEM(
					co->co_varnames, j);
				int cmp = PyObject_RichCompareBool(
					keyword, nm, Py_EQ);
				if (cmp > 0)
					break;
				else if (cmp < 0)
					goto fail;
			}
			/* Check errors from Compare */
			if (PyErr_Occurred())
				goto fail;
			if (j >= co->co_argcount) {
				if (kwdict == NULL) {
					PyErr_Format(PyExc_TypeError,
					    "%.200s() got an unexpected "
					    "keyword argument '%.400s'",
					    PyString_AsString(co->co_name),
					    PyString_AsString(keyword));
					goto fail;
				}
				PyDict_SetItem(kwdict, keyword, value);
			}
			else {
				if (GETLOCAL(j) != NULL) {
					PyErr_Format(PyExc_TypeError,
					     "%.200s() got multiple "
					     "values for keyword "
					     "argument '%.400s'",
					     PyString_AsString(co->co_name),
					     PyString_AsString(keyword));
					goto fail;
				}
				Py_INCREF(value);
				SETLOCAL(j, value);
			}
		}
		if (argcount < co->co_argcount) {
			int m = co->co_argcount - defcount;
			for (i = argcount; i < m; i++) {
				if (GETLOCAL(i) == NULL) {
					PyErr_Format(PyExc_TypeError,
					    "%.200s() takes %s %d "
					    "%sargument%s (%d given)",
					    PyString_AsString(co->co_name),
					    ((co->co_flags & CO_VARARGS) ||
					     defcount) ? "at least"
						       : "exactly",
					    m, kwcount ? "non-keyword " : "",
					    m == 1 ? "" : "s", i);
					goto fail;
				}
			}
			if (n > m)
				i = n - m;
			else
				i = 0;
			for (; i < defcount; i++) {
				if (GETLOCAL(m+i) == NULL) {
					PyObject *def = defs[i];
					Py_INCREF(def);
					SETLOCAL(m+i, def);
				}
			}
		}
	}
	else {
		if (argcount > 0 || kwcount > 0) {
			PyErr_Format(PyExc_TypeError,
				     "%.200s() takes no arguments (%d given)",
				     PyString_AsString(co->co_name),
				     argcount + kwcount);
			goto fail;
		}
	}
	/* Allocate and initialize storage for cell vars, and copy free
	   vars into frame.  This isn't too efficient right now. */
	if (PyTuple_GET_SIZE(co->co_cellvars)) {
		int i, j, nargs, found;
		char *cellname, *argname;
		PyObject *c;

		nargs = co->co_argcount;
		if (co->co_flags & CO_VARARGS)
			nargs++;
		if (co->co_flags & CO_VARKEYWORDS)
			nargs++;

		/* Initialize each cell var, taking into account
		   cell vars that are initialized from arguments.

		   Should arrange for the compiler to put cellvars
		   that are arguments at the beginning of the cellvars
		   list so that we can march over it more efficiently?
		*/
		for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) {
			cellname = PyString_AS_STRING(
				PyTuple_GET_ITEM(co->co_cellvars, i));
			found = 0;
			for (j = 0; j < nargs; j++) {
				argname = PyString_AS_STRING(
					PyTuple_GET_ITEM(co->co_varnames, j));
				if (strcmp(cellname, argname) == 0) {
					c = PyCell_New(GETLOCAL(j));
					if (c == NULL)
						goto fail;
					GETLOCAL(co->co_nlocals + i) = c;
					found = 1;
					break;
				}
			}
			if (found == 0) {
				c = PyCell_New(NULL);
				if (c == NULL)
					goto fail;
				SETLOCAL(co->co_nlocals + i, c);
			}
		}
	}
	if (PyTuple_GET_SIZE(co->co_freevars)) {
		int i;
		for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) {
			PyObject *o = PyTuple_GET_ITEM(closure, i);
			Py_INCREF(o);
			freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o;
		}
	}

	if (co->co_flags & CO_GENERATOR) {
		/* Don't need to keep the reference to f_back, it will be set
		 * when the generator is resumed. */
		Py_XDECREF(f->f_back);
		f->f_back = NULL;

		PCALL(PCALL_GENERATOR);

		/* Create a new generator that owns the ready to run frame
		 * and return that as the value. */
		return PyGen_New(f);
	}

	retval = PyEval_EvalFrameEx(f,0);

fail: /* Jump here from prelude on failure */

	/* decref'ing the frame can cause __del__ methods to get invoked,
	   which can call back into Python.  While we're done with the
	   current Python frame (f), the associated C stack is still in use,
	   so recursion_depth must be boosted for the duration.
	*/
	assert(tstate != NULL);
	++tstate->recursion_depth;
	Py_DECREF(f);
	--tstate->recursion_depth;
	return retval;
}


/* Implementation notes for set_exc_info() and reset_exc_info():

- Below, 'exc_ZZZ' stands for 'exc_type', 'exc_value' and
  'exc_traceback'.  These always travel together.

- tstate->curexc_ZZZ is the "hot" exception that is set by
  PyErr_SetString(), cleared by PyErr_Clear(), and so on.

- Once an exception is caught by an except clause, it is transferred
  from tstate->curexc_ZZZ to tstate->exc_ZZZ, from which sys.exc_info()
  can pick it up.  This is the primary task of set_exc_info().
  XXX That can't be right:  set_exc_info() doesn't look at tstate->curexc_ZZZ.

- Now let me explain the complicated dance with frame->f_exc_ZZZ.

  Long ago, when none of this existed, there were just a few globals:
  one set corresponding to the "hot" exception, and one set
  corresponding to sys.exc_ZZZ.  (Actually, the latter weren't C
  globals; they were simply stored as sys.exc_ZZZ.  For backwards
  compatibility, they still are!)  The problem was that in code like
  this:

     try:
	"something that may fail"
     except "some exception":
	"do something else first"
	"print the exception from sys.exc_ZZZ."

  if "do something else first" invoked something that raised and caught
  an exception, sys.exc_ZZZ were overwritten.  That was a frequent
  cause of subtle bugs.  I fixed this by changing the semantics as
  follows:

    - Within one frame, sys.exc_ZZZ will hold the last exception caught
      *in that frame*.

    - But initially, and as long as no exception is caught in a given
      frame, sys.exc_ZZZ will hold the last exception caught in the
      previous frame (or the frame before that, etc.).

  The first bullet fixed the bug in the above example.  The second
  bullet was for backwards compatibility: it was (and is) common to
  have a function that is called when an exception is caught, and to
  have that function access the caught exception via sys.exc_ZZZ.
  (Example: traceback.print_exc()).

  At the same time I fixed the problem that sys.exc_ZZZ weren't
  thread-safe, by introducing sys.exc_info() which gets it from tstate;
  but that's really a separate improvement.

  The reset_exc_info() function in ceval.c restores the tstate->exc_ZZZ
  variables to what they were before the current frame was called.  The
  set_exc_info() function saves them on the frame so that
  reset_exc_info() can restore them.  The invariant is that
  frame->f_exc_ZZZ is NULL iff the current frame never caught an
  exception (where "catching" an exception applies only to successful
  except clauses); and if the current frame ever caught an exception,
  frame->f_exc_ZZZ is the exception that was stored in tstate->exc_ZZZ
  at the start of the current frame.

*/

static void
set_exc_info(PyThreadState *tstate,
	     PyObject *type, PyObject *value, PyObject *tb)
{
	PyFrameObject *frame = tstate->frame;
	PyObject *tmp_type, *tmp_value, *tmp_tb;

	assert(type != NULL);
	assert(frame != NULL);
	if (frame->f_exc_type == NULL) {
		assert(frame->f_exc_value == NULL);
		assert(frame->f_exc_traceback == NULL);
		/* This frame didn't catch an exception before. */
		/* Save previous exception of this thread in this frame. */
		if (tstate->exc_type == NULL) {
			/* XXX Why is this set to Py_None? */
			Py_INCREF(Py_None);
			tstate->exc_type = Py_None;
		}
		Py_INCREF(tstate->exc_type);
		Py_XINCREF(tstate->exc_value);
		Py_XINCREF(tstate->exc_traceback);
		frame->f_exc_type = tstate->exc_type;
		frame->f_exc_value = tstate->exc_value;
		frame->f_exc_traceback = tstate->exc_traceback;
	}
	/* Set new exception for this thread. */
	tmp_type = tstate->exc_type;
	tmp_value = tstate->exc_value;
	tmp_tb = tstate->exc_traceback;
	Py_INCREF(type);
	Py_XINCREF(value);
	Py_XINCREF(tb);
	tstate->exc_type = type;
	tstate->exc_value = value;
	tstate->exc_traceback = tb;
	Py_XDECREF(tmp_type);
	Py_XDECREF(tmp_value);
	Py_XDECREF(tmp_tb);
	/* For b/w compatibility */
	PySys_SetObject("exc_type", type);
	PySys_SetObject("exc_value", value);
	PySys_SetObject("exc_traceback", tb);
}

static void
reset_exc_info(PyThreadState *tstate)
{
	PyFrameObject *frame;
	PyObject *tmp_type, *tmp_value, *tmp_tb;

	/* It's a precondition that the thread state's frame caught an
	 * exception -- verify in a debug build.
	 */
	assert(tstate != NULL);
	frame = tstate->frame;
	assert(frame != NULL);
	assert(frame->f_exc_type != NULL);

	/* Copy the frame's exception info back to the thread state. */
	tmp_type = tstate->exc_type;
	tmp_value = tstate->exc_value;
	tmp_tb = tstate->exc_traceback;
	Py_INCREF(frame->f_exc_type);
	Py_XINCREF(frame->f_exc_value);
	Py_XINCREF(frame->f_exc_traceback);
	tstate->exc_type = frame->f_exc_type;
	tstate->exc_value = frame->f_exc_value;
	tstate->exc_traceback = frame->f_exc_traceback;
	Py_XDECREF(tmp_type);
	Py_XDECREF(tmp_value);
	Py_XDECREF(tmp_tb);

	/* For b/w compatibility */
	PySys_SetObject("exc_type", frame->f_exc_type);
	PySys_SetObject("exc_value", frame->f_exc_value);
	PySys_SetObject("exc_traceback", frame->f_exc_traceback);

	/* Clear the frame's exception info. */
	tmp_type = frame->f_exc_type;
	tmp_value = frame->f_exc_value;
	tmp_tb = frame->f_exc_traceback;
	frame->f_exc_type = NULL;
	frame->f_exc_value = NULL;
	frame->f_exc_traceback = NULL;
	Py_DECREF(tmp_type);
	Py_XDECREF(tmp_value);
	Py_XDECREF(tmp_tb);
}

/* Logic for the raise statement (too complicated for inlining).
   This *consumes* a reference count to each of its arguments. */
static enum why_code
do_raise(PyObject *type, PyObject *value, PyObject *tb)
{
	if (type == NULL) {
		/* Reraise */
		PyThreadState *tstate = PyThreadState_GET();
		type = tstate->exc_type == NULL ? Py_None : tstate->exc_type;
		value = tstate->exc_value;
		tb = tstate->exc_traceback;
		Py_XINCREF(type);
		Py_XINCREF(value);
		Py_XINCREF(tb);
	}

	/* We support the following forms of raise:
	   raise <class>, <classinstance>
	   raise <class>, <argument tuple>
	   raise <class>, None
	   raise <class>, <argument>
	   raise <classinstance>, None
	   raise <string>, <object>
	   raise <string>, None

	   An omitted second argument is the same as None.

	   In addition, raise <tuple>, <anything> is the same as
	   raising the tuple's first item (and it better have one!);
	   this rule is applied recursively.

	   Finally, an optional third argument can be supplied, which
	   gives the traceback to be substituted (useful when
	   re-raising an exception after examining it).  */

	/* First, check the traceback argument, replacing None with
	   NULL. */
	if (tb == Py_None) {
		Py_DECREF(tb);
		tb = NULL;
	}
	else if (tb != NULL && !PyTraceBack_Check(tb)) {
		PyErr_SetString(PyExc_TypeError,
			   "raise: arg 3 must be a traceback or None");
		goto raise_error;
	}

	/* Next, replace a missing value with None */
	if (value == NULL) {
		value = Py_None;
		Py_INCREF(value);
	}

	/* Next, repeatedly, replace a tuple exception with its first item */
	while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
		PyObject *tmp = type;
		type = PyTuple_GET_ITEM(type, 0);
		Py_INCREF(type);
		Py_DECREF(tmp);
	}

	if (PyExceptionClass_Check(type))
		PyErr_NormalizeException(&type, &value, &tb);

	else if (PyExceptionInstance_Check(type)) {
		/* Raising an instance.  The value should be a dummy. */
		if (value != Py_None) {
			PyErr_SetString(PyExc_TypeError,
			  "instance exception may not have a separate value");
			goto raise_error;
		}
		else {
			/* Normalize to raise <class>, <instance> */
			Py_DECREF(value);
			value = type;
			type = PyExceptionInstance_Class(type);
			Py_INCREF(type);
		}
	}
	else {
		/* Not something you can raise.  You get an exception
		   anyway, just not what you specified :-) */
		PyErr_Format(PyExc_TypeError,
			"exceptions must be classes or instances, not %s",
			type->ob_type->tp_name);
		goto raise_error;
	}

	assert(PyExceptionClass_Check(type));
	if (Py_Py3kWarningFlag && PyClass_Check(type)) {
		if (PyErr_WarnEx(PyExc_DeprecationWarning,
				"exceptions must derive from BaseException "
				"in 3.x", 1) < 0)
			goto raise_error;
	}

	PyErr_Restore(type, value, tb);
	if (tb == NULL)
		return WHY_EXCEPTION;
	else
		return WHY_RERAISE;
 raise_error:
	Py_XDECREF(value);
	Py_XDECREF(type);
	Py_XDECREF(tb);
	return WHY_EXCEPTION;
}

/* Iterate v argcnt times and store the results on the stack (via decreasing
   sp).  Return 1 for success, 0 if error. */

static int
unpack_iterable(PyObject *v, int argcnt, PyObject **sp)
{
	int i = 0;
	PyObject *it;  /* iter(v) */
	PyObject *w;

	assert(v != NULL);

	it = PyObject_GetIter(v);
	if (it == NULL)
		goto Error;

	for (; i < argcnt; i++) {
		w = PyIter_Next(it);
		if (w == NULL) {
			/* Iterator done, via error or exhaustion. */
			if (!PyErr_Occurred()) {
				PyErr_Format(PyExc_ValueError,
					"need more than %d value%s to unpack",
					i, i == 1 ? "" : "s");
			}
			goto Error;
		}
		*--sp = w;
	}

	/* We better have exhausted the iterator now. */
	w = PyIter_Next(it);
	if (w == NULL) {
		if (PyErr_Occurred())
			goto Error;
		Py_DECREF(it);
		return 1;
	}
	Py_DECREF(w);
	PyErr_SetString(PyExc_ValueError, "too many values to unpack");
	/* fall through */
Error:
	for (; i > 0; i--, sp++)
		Py_DECREF(*sp);
	Py_XDECREF(it);
	return 0;
}


#ifdef LLTRACE
static int
prtrace(PyObject *v, char *str)
{
	printf("%s ", str);
	if (PyObject_Print(v, stdout, 0) != 0)
		PyErr_Clear(); /* Don't know what else to do */
	printf("\n");
	return 1;
}
#endif

static void
call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
{
	PyObject *type, *value, *traceback, *arg;
	int err;
	PyErr_Fetch(&type, &value, &traceback);
	if (value == NULL) {
		value = Py_None;
		Py_INCREF(value);
	}
	arg = PyTuple_Pack(3, type, value, traceback);
	if (arg == NULL) {
		PyErr_Restore(type, value, traceback);
		return;
	}
	err = call_trace(func, self, f, PyTrace_EXCEPTION, arg);
	Py_DECREF(arg);
	if (err == 0)
		PyErr_Restore(type, value, traceback);
	else {
		Py_XDECREF(type);
		Py_XDECREF(value);
		Py_XDECREF(traceback);
	}
}

static int
call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
		     int what, PyObject *arg)
{
	PyObject *type, *value, *traceback;
	int err;
	PyErr_Fetch(&type, &value, &traceback);
	err = call_trace(func, obj, frame, what, arg);
	if (err == 0)
	{
		PyErr_Restore(type, value, traceback);
		return 0;
	}
	else {
		Py_XDECREF(type);
		Py_XDECREF(value);
		Py_XDECREF(traceback);
		return -1;
	}
}

static int
call_trace(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
	   int what, PyObject *arg)
{
	register PyThreadState *tstate = frame->f_tstate;
	int result;
	if (tstate->tracing)
		return 0;
	tstate->tracing++;
	tstate->use_tracing = 0;
	result = func(obj, frame, what, arg);
	tstate->use_tracing = ((tstate->c_tracefunc != NULL)
			       || (tstate->c_profilefunc != NULL));
	tstate->tracing--;
	return result;
}

PyObject *
_PyEval_CallTracing(PyObject *func, PyObject *args)
{
	PyFrameObject *frame = PyEval_GetFrame();
	PyThreadState *tstate = frame->f_tstate;
	int save_tracing = tstate->tracing;
	int save_use_tracing = tstate->use_tracing;
	PyObject *result;

	tstate->tracing = 0;
	tstate->use_tracing = ((tstate->c_tracefunc != NULL)
			       || (tstate->c_profilefunc != NULL));
	result = PyObject_Call(func, args, NULL);
	tstate->tracing = save_tracing;
	tstate->use_tracing = save_use_tracing;
	return result;
}

static int
maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
		      PyFrameObject *frame, int *instr_lb, int *instr_ub,
		      int *instr_prev)
{
	int result = 0;

        /* If the last instruction executed isn't in the current
           instruction window, reset the window.  If the last
           instruction happens to fall at the start of a line or if it
           represents a jump backwards, call the trace function.
        */
	if ((frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub)) {
		int line;
		PyAddrPair bounds;

		line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
					      &bounds);
		if (line >= 0) {
			frame->f_lineno = line;
			result = call_trace(func, obj, frame,
					    PyTrace_LINE, Py_None);
		}
		*instr_lb = bounds.ap_lower;
		*instr_ub = bounds.ap_upper;
	}
	else if (frame->f_lasti <= *instr_prev) {
		result = call_trace(func, obj, frame, PyTrace_LINE, Py_None);
	}
	*instr_prev = frame->f_lasti;
	return result;
}

void
PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
{
	PyThreadState *tstate = PyThreadState_GET();
	PyObject *temp = tstate->c_profileobj;
	Py_XINCREF(arg);
	tstate->c_profilefunc = NULL;
	tstate->c_profileobj = NULL;
	/* Must make sure that tracing is not ignored if 'temp' is freed */
	tstate->use_tracing = tstate->c_tracefunc != NULL;
	Py_XDECREF(temp);
	tstate->c_profilefunc = func;
	tstate->c_profileobj = arg;
	/* Flag that tracing or profiling is turned on */
	tstate->use_tracing = (func != NULL) || (tstate->c_tracefunc != NULL);
}

void
PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
{
	PyThreadState *tstate = PyThreadState_GET();
	PyObject *temp = tstate->c_traceobj;
	Py_XINCREF(arg);
	tstate->c_tracefunc = NULL;
	tstate->c_traceobj = NULL;
	/* Must make sure that profiling is not ignored if 'temp' is freed */
	tstate->use_tracing = tstate->c_profilefunc != NULL;
	Py_XDECREF(temp);
	tstate->c_tracefunc = func;
	tstate->c_traceobj = arg;
	/* Flag that tracing or profiling is turned on */
	tstate->use_tracing = ((func != NULL)
			       || (tstate->c_profilefunc != NULL));
}

PyObject *
PyEval_GetBuiltins(void)
{
	PyFrameObject *current_frame = PyEval_GetFrame();
	if (current_frame == NULL)
		return PyThreadState_GET()->interp->builtins;
	else
		return current_frame->f_builtins;
}

PyObject *
PyEval_GetLocals(void)
{
	PyFrameObject *current_frame = PyEval_GetFrame();
	if (current_frame == NULL)
		return NULL;
	PyFrame_FastToLocals(current_frame);
	return current_frame->f_locals;
}

PyObject *
PyEval_GetGlobals(void)
{
	PyFrameObject *current_frame = PyEval_GetFrame();
	if (current_frame == NULL)
		return NULL;
	else
		return current_frame->f_globals;
}

PyFrameObject *
PyEval_GetFrame(void)
{
	PyThreadState *tstate = PyThreadState_GET();
	return _PyThreadState_GetFrame(tstate);
}

int
PyEval_GetRestricted(void)
{
	PyFrameObject *current_frame = PyEval_GetFrame();
	return current_frame == NULL ? 0 : PyFrame_IsRestricted(current_frame);
}

int
PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
{
	PyFrameObject *current_frame = PyEval_GetFrame();
	int result = cf->cf_flags != 0;

	if (current_frame != NULL) {
		const int codeflags = current_frame->f_code->co_flags;
		const int compilerflags = codeflags & PyCF_MASK;
		if (compilerflags) {
			result = 1;
			cf->cf_flags |= compilerflags;
		}
#if 0 /* future keyword */
		if (codeflags & CO_GENERATOR_ALLOWED) {
			result = 1;
			cf->cf_flags |= CO_GENERATOR_ALLOWED;
		}
#endif
	}
	return result;
}

int
Py_FlushLine(void)
{
	PyObject *f = PySys_GetObject("stdout");
	if (f == NULL)
		return 0;
	if (!PyFile_SoftSpace(f, 0))
		return 0;
	return PyFile_WriteString("\n", f);
}


/* External interface to call any callable object.
   The arg must be a tuple or NULL. */

#undef PyEval_CallObject
/* for backward compatibility: export this interface */

PyObject *
PyEval_CallObject(PyObject *func, PyObject *arg)
{
	return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL);
}
#define PyEval_CallObject(func,arg) \
        PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)

PyObject *
PyEval_CallObjectWithKeywords(PyObject *func, PyObject *arg, PyObject *kw)
{
	PyObject *result;

	if (arg == NULL) {
		arg = PyTuple_New(0);
		if (arg == NULL)
			return NULL;
	}
	else if (!PyTuple_Check(arg)) {
		PyErr_SetString(PyExc_TypeError,
				"argument list must be a tuple");
		return NULL;
	}
	else
		Py_INCREF(arg);

	if (kw != NULL && !PyDict_Check(kw)) {
		PyErr_SetString(PyExc_TypeError,
				"keyword list must be a dictionary");
		Py_DECREF(arg);
		return NULL;
	}

	result = PyObject_Call(func, arg, kw);
	Py_DECREF(arg);
	return result;
}

const char *
PyEval_GetFuncName(PyObject *func)
{
	if (PyMethod_Check(func))
		return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func));
	else if (PyFunction_Check(func))
		return PyString_AsString(((PyFunctionObject*)func)->func_name);
	else if (PyCFunction_Check(func))
		return ((PyCFunctionObject*)func)->m_ml->ml_name;
	else if (PyClass_Check(func))
		return PyString_AsString(((PyClassObject*)func)->cl_name);
	else if (PyInstance_Check(func)) {
		return PyString_AsString(
			((PyInstanceObject*)func)->in_class->cl_name);
	} else {
		return func->ob_type->tp_name;
	}
}

const char *
PyEval_GetFuncDesc(PyObject *func)
{
	if (PyMethod_Check(func))
		return "()";
	else if (PyFunction_Check(func))
		return "()";
	else if (PyCFunction_Check(func))
		return "()";
	else if (PyClass_Check(func))
		return " constructor";
	else if (PyInstance_Check(func)) {
		return " instance";
	} else {
		return " object";
	}
}

static void
err_args(PyObject *func, int flags, int nargs)
{
	if (flags & METH_NOARGS)
		PyErr_Format(PyExc_TypeError,
			     "%.200s() takes no arguments (%d given)",
			     ((PyCFunctionObject *)func)->m_ml->ml_name,
			     nargs);
	else
		PyErr_Format(PyExc_TypeError,
			     "%.200s() takes exactly one argument (%d given)",
			     ((PyCFunctionObject *)func)->m_ml->ml_name,
			     nargs);
}

#define C_TRACE(x, call) \
if (tstate->use_tracing && tstate->c_profilefunc) { \
	if (call_trace(tstate->c_profilefunc, \
		tstate->c_profileobj, \
		tstate->frame, PyTrace_C_CALL, \
		func)) { \
		x = NULL; \
	} \
	else { \
		x = call; \
		if (tstate->c_profilefunc != NULL) { \
			if (x == NULL) { \
				call_trace_protected(tstate->c_profilefunc, \
					tstate->c_profileobj, \
					tstate->frame, PyTrace_C_EXCEPTION, \
					func); \
				/* XXX should pass (type, value, tb) */ \
			} else { \
				if (call_trace(tstate->c_profilefunc, \
					tstate->c_profileobj, \
					tstate->frame, PyTrace_C_RETURN, \
					func)) { \
					Py_DECREF(x); \
					x = NULL; \
				} \
			} \
		} \
	} \
} else { \
	x = call; \
	}

static PyObject *
call_function(PyObject ***pp_stack, int oparg
#ifdef WITH_TSC
		, uint64* pintr0, uint64* pintr1
#endif
		)
{
	int na = oparg & 0xff;
	int nk = (oparg>>8) & 0xff;
	int n = na + 2 * nk;
	PyObject **pfunc = (*pp_stack) - n - 1;
	PyObject *func = *pfunc;
	PyObject *x, *w;

	/* Always dispatch PyCFunction first, because these are
	   presumed to be the most frequent callable object.
	*/
	if (PyCFunction_Check(func) && nk == 0) {
		int flags = PyCFunction_GET_FLAGS(func);
		PyThreadState *tstate = PyThreadState_GET();

		PCALL(PCALL_CFUNCTION);
		if (flags & (METH_NOARGS | METH_O)) {
			PyCFunction meth = PyCFunction_GET_FUNCTION(func);
			PyObject *self = PyCFunction_GET_SELF(func);
			if (flags & METH_NOARGS && na == 0) {
				C_TRACE(x, (*meth)(self,NULL));
			}
			else if (flags & METH_O && na == 1) {
				PyObject *arg = EXT_POP(*pp_stack);
				C_TRACE(x, (*meth)(self,arg));
				Py_DECREF(arg);
			}
			else {
				err_args(func, flags, na);
				x = NULL;
			}
		}
		else {
			PyObject *callargs;
			callargs = load_args(pp_stack, na);
			READ_TIMESTAMP(*pintr0);
			C_TRACE(x, PyCFunction_Call(func,callargs,NULL));
			READ_TIMESTAMP(*pintr1);
			Py_XDECREF(callargs);
		}
	} else {
		if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {
			/* optimize access to bound methods */
			PyObject *self = PyMethod_GET_SELF(func);
			PCALL(PCALL_METHOD);
			PCALL(PCALL_BOUND_METHOD);
			Py_INCREF(self);
			func = PyMethod_GET_FUNCTION(func);
			Py_INCREF(func);
			Py_DECREF(*pfunc);
			*pfunc = self;
			na++;
			n++;
		} else
			Py_INCREF(func);
		READ_TIMESTAMP(*pintr0);
		if (PyFunction_Check(func))
			x = fast_function(func, pp_stack, n, na, nk);
		else
			x = do_call(func, pp_stack, na, nk);
		READ_TIMESTAMP(*pintr1);
		Py_DECREF(func);
	}

	/* Clear the stack of the function object.  Also removes
           the arguments in case they weren't consumed already
           (fast_function() and err_args() leave them on the stack).
	 */
	while ((*pp_stack) > pfunc) {
		w = EXT_POP(*pp_stack);
		Py_DECREF(w);
		PCALL(PCALL_POP);
	}
	return x;
}

/* The fast_function() function optimize calls for which no argument
   tuple is necessary; the objects are passed directly from the stack.
   For the simplest case -- a function that takes only positional
   arguments and is called with only positional arguments -- it
   inlines the most primitive frame setup code from
   PyEval_EvalCodeEx(), which vastly reduces the checks that must be
   done before evaluating the frame.
*/

static PyObject *
fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk)
{
	PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
	PyObject *globals = PyFunction_GET_GLOBALS(func);
	PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
	PyObject **d = NULL;
	int nd = 0;

	PCALL(PCALL_FUNCTION);
	PCALL(PCALL_FAST_FUNCTION);
	if (argdefs == NULL && co->co_argcount == n && nk==0 &&
	    co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
		PyFrameObject *f;
		PyObject *retval = NULL;
		PyThreadState *tstate = PyThreadState_GET();
		PyObject **fastlocals, **stack;
		int i;

		PCALL(PCALL_FASTER_FUNCTION);
		assert(globals != NULL);
		/* XXX Perhaps we should create a specialized
		   PyFrame_New() that doesn't take locals, but does
		   take builtins without sanity checking them.
		*/
		assert(tstate != NULL);
		f = PyFrame_New(tstate, co, globals, NULL);
		if (f == NULL)
			return NULL;

		fastlocals = f->f_localsplus;
		stack = (*pp_stack) - n;

		for (i = 0; i < n; i++) {
			Py_INCREF(*stack);
			fastlocals[i] = *stack++;
		}
		retval = PyEval_EvalFrameEx(f,0);
		++tstate->recursion_depth;
		Py_DECREF(f);
		--tstate->recursion_depth;
		return retval;
	}
	if (argdefs != NULL) {
		d = &PyTuple_GET_ITEM(argdefs, 0);
		nd = Py_SIZE(argdefs);
	}
	return PyEval_EvalCodeEx(co, globals,
				 (PyObject *)NULL, (*pp_stack)-n, na,
				 (*pp_stack)-2*nk, nk, d, nd,
				 PyFunction_GET_CLOSURE(func));
}

static PyObject *
update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,
                    PyObject *func)
{
	PyObject *kwdict = NULL;
	if (orig_kwdict == NULL)
		kwdict = PyDict_New();
	else {
		kwdict = PyDict_Copy(orig_kwdict);
		Py_DECREF(orig_kwdict);
	}
	if (kwdict == NULL)
		return NULL;
	while (--nk >= 0) {
		int err;
		PyObject *value = EXT_POP(*pp_stack);
		PyObject *key = EXT_POP(*pp_stack);
		if (PyDict_GetItem(kwdict, key) != NULL) {
			PyErr_Format(PyExc_TypeError,
				     "%.200s%s got multiple values "
				     "for keyword argument '%.200s'",
				     PyEval_GetFuncName(func),
				     PyEval_GetFuncDesc(func),
				     PyString_AsString(key));
			Py_DECREF(key);
			Py_DECREF(value);
			Py_DECREF(kwdict);
			return NULL;
		}
		err = PyDict_SetItem(kwdict, key, value);
		Py_DECREF(key);
		Py_DECREF(value);
		if (err) {
			Py_DECREF(kwdict);
			return NULL;
		}
	}
	return kwdict;
}

static PyObject *
update_star_args(int nstack, int nstar, PyObject *stararg,
		 PyObject ***pp_stack)
{
	PyObject *callargs, *w;

	callargs = PyTuple_New(nstack + nstar);
	if (callargs == NULL) {
		return NULL;
	}
	if (nstar) {
		int i;
		for (i = 0; i < nstar; i++) {
			PyObject *a = PyTuple_GET_ITEM(stararg, i);
			Py_INCREF(a);
			PyTuple_SET_ITEM(callargs, nstack + i, a);
		}
	}
	while (--nstack >= 0) {
		w = EXT_POP(*pp_stack);
		PyTuple_SET_ITEM(callargs, nstack, w);
	}
	return callargs;
}

static PyObject *
load_args(PyObject ***pp_stack, int na)
{
	PyObject *args = PyTuple_New(na);
	PyObject *w;

	if (args == NULL)
		return NULL;
	while (--na >= 0) {
		w = EXT_POP(*pp_stack);
		PyTuple_SET_ITEM(args, na, w);
	}
	return args;
}

static PyObject *
do_call(PyObject *func, PyObject ***pp_stack, int na, int nk)
{
	PyObject *callargs = NULL;
	PyObject *kwdict = NULL;
	PyObject *result = NULL;

	if (nk > 0) {
		kwdict = update_keyword_args(NULL, nk, pp_stack, func);
		if (kwdict == NULL)
			goto call_fail;
	}
	callargs = load_args(pp_stack, na);
	if (callargs == NULL)
		goto call_fail;
#ifdef CALL_PROFILE
	/* At this point, we have to look at the type of func to
	   update the call stats properly.  Do it here so as to avoid
	   exposing the call stats machinery outside ceval.c
	*/
	if (PyFunction_Check(func))
		PCALL(PCALL_FUNCTION);
	else if (PyMethod_Check(func))
		PCALL(PCALL_METHOD);
	else if (PyType_Check(func))
		PCALL(PCALL_TYPE);
	else
		PCALL(PCALL_OTHER);
#endif
	result = PyObject_Call(func, callargs, kwdict);
 call_fail:
	Py_XDECREF(callargs);
	Py_XDECREF(kwdict);
	return result;
}

static PyObject *
ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
{
	int nstar = 0;
	PyObject *callargs = NULL;
	PyObject *stararg = NULL;
	PyObject *kwdict = NULL;
	PyObject *result = NULL;

	if (flags & CALL_FLAG_KW) {
		kwdict = EXT_POP(*pp_stack);
		if (!PyDict_Check(kwdict)) {
			PyObject *d;
			d = PyDict_New();
			if (d == NULL)
				goto ext_call_fail;
			if (PyDict_Update(d, kwdict) != 0) {
				Py_DECREF(d);
				/* PyDict_Update raises attribute
				 * error (percolated from an attempt
				 * to get 'keys' attribute) instead of
				 * a type error if its second argument
				 * is not a mapping.
				 */
				if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
					PyErr_Format(PyExc_TypeError,
						     "%.200s%.200s argument after ** "
						     "must be a mapping, not %.200s",
						     PyEval_GetFuncName(func),
						     PyEval_GetFuncDesc(func),
						     kwdict->ob_type->tp_name);
				}
				goto ext_call_fail;
			}
			Py_DECREF(kwdict);
			kwdict = d;
		}
	}
	if (flags & CALL_FLAG_VAR) {
		stararg = EXT_POP(*pp_stack);
		if (!PyTuple_Check(stararg)) {
			PyObject *t = NULL;
			t = PySequence_Tuple(stararg);
			if (t == NULL) {
				if (PyErr_ExceptionMatches(PyExc_TypeError)) {
					PyErr_Format(PyExc_TypeError,
						     "%.200s%.200s argument after * "
						     "must be a sequence, not %200s",
						     PyEval_GetFuncName(func),
						     PyEval_GetFuncDesc(func),
						     stararg->ob_type->tp_name);
				}
				goto ext_call_fail;
			}
			Py_DECREF(stararg);
			stararg = t;
		}
		nstar = PyTuple_GET_SIZE(stararg);
	}
	if (nk > 0) {
		kwdict = update_keyword_args(kwdict, nk, pp_stack, func);
		if (kwdict == NULL)
			goto ext_call_fail;
	}
	callargs = update_star_args(na, nstar, stararg, pp_stack);
	if (callargs == NULL)
		goto ext_call_fail;
#ifdef CALL_PROFILE
	/* At this point, we have to look at the type of func to
	   update the call stats properly.  Do it here so as to avoid
	   exposing the call stats machinery outside ceval.c
	*/
	if (PyFunction_Check(func))
		PCALL(PCALL_FUNCTION);
	else if (PyMethod_Check(func))
		PCALL(PCALL_METHOD);
	else if (PyType_Check(func))
		PCALL(PCALL_TYPE);
	else
		PCALL(PCALL_OTHER);
#endif
	result = PyObject_Call(func, callargs, kwdict);
ext_call_fail:
	Py_XDECREF(callargs);
	Py_XDECREF(kwdict);
	Py_XDECREF(stararg);
	return result;
}

/* Extract a slice index from a PyInt or PyLong or an object with the
   nb_index slot defined, and store in *pi.
   Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
   and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1.
   Return 0 on error, 1 on success.
*/
/* Note:  If v is NULL, return success without storing into *pi.  This
   is because_PyEval_SliceIndex() is called by apply_slice(), which can be
   called by the SLICE opcode with v and/or w equal to NULL.
*/
int
_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
{
	if (v != NULL) {
		Py_ssize_t x;
		if (PyInt_Check(v)) {
			/* XXX(nnorwitz): I think PyInt_AS_LONG is correct,
			   however, it looks like it should be AsSsize_t.
			   There should be a comment here explaining why.
			*/
			x = PyInt_AS_LONG(v);
		}
		else if (PyIndex_Check(v)) {
			x = PyNumber_AsSsize_t(v, NULL);
			if (x == -1 && PyErr_Occurred())
				return 0;
		}
		else {
			PyErr_SetString(PyExc_TypeError,
					"slice indices must be integers or "
					"None or have an __index__ method");
			return 0;
		}
		*pi = x;
	}
	return 1;
}

#undef ISINDEX
#define ISINDEX(x) ((x) == NULL || \
		    PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x))

static PyObject *
apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
{
	PyTypeObject *tp = u->ob_type;
	PySequenceMethods *sq = tp->tp_as_sequence;

	if (sq && sq->sq_slice && ISINDEX(v) && ISINDEX(w)) {
		Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
		if (!_PyEval_SliceIndex(v, &ilow))
			return NULL;
		if (!_PyEval_SliceIndex(w, &ihigh))
			return NULL;
		return PySequence_GetSlice(u, ilow, ihigh);
	}
	else {
		PyObject *slice = PySlice_New(v, w, NULL);
		if (slice != NULL) {
			PyObject *res = PyObject_GetItem(u, slice);
			Py_DECREF(slice);
			return res;
		}
		else
			return NULL;
	}
}

static int
assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
	/* u[v:w] = x */
{
	PyTypeObject *tp = u->ob_type;
	PySequenceMethods *sq = tp->tp_as_sequence;

	if (sq && sq->sq_ass_slice && ISINDEX(v) && ISINDEX(w)) {
		Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
		if (!_PyEval_SliceIndex(v, &ilow))
			return -1;
		if (!_PyEval_SliceIndex(w, &ihigh))
			return -1;
		if (x == NULL)
			return PySequence_DelSlice(u, ilow, ihigh);
		else
			return PySequence_SetSlice(u, ilow, ihigh, x);
	}
	else {
		PyObject *slice = PySlice_New(v, w, NULL);
		if (slice != NULL) {
			int res;
			if (x != NULL)
				res = PyObject_SetItem(u, slice, x);
			else
				res = PyObject_DelItem(u, slice);
			Py_DECREF(slice);
			return res;
		}
		else
			return -1;
	}
}

#define Py3kExceptionClass_Check(x)     \
    (PyType_Check((x)) &&               \
     PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))

#define CANNOT_CATCH_MSG "catching classes that don't inherit from " \
			 "BaseException is not allowed in 3.x"

static PyObject *
cmp_outcome(int op, register PyObject *v, register PyObject *w)
{
	int res = 0;
	switch (op) {
	case PyCmp_IS:
		res = (v == w);
		break;
	case PyCmp_IS_NOT:
		res = (v != w);
		break;
	case PyCmp_IN:
		res = PySequence_Contains(w, v);
		if (res < 0)
			return NULL;
		break;
	case PyCmp_NOT_IN:
		res = PySequence_Contains(w, v);
		if (res < 0)
			return NULL;
		res = !res;
		break;
	case PyCmp_EXC_MATCH:
		if (PyTuple_Check(w)) {
			Py_ssize_t i, length;
			length = PyTuple_Size(w);
			for (i = 0; i < length; i += 1) {
				PyObject *exc = PyTuple_GET_ITEM(w, i);
				if (PyString_Check(exc)) {
					int ret_val;
					ret_val = PyErr_WarnEx(
						PyExc_DeprecationWarning,
						"catching of string "
						"exceptions is deprecated", 1);
					if (ret_val < 0)
						return NULL;
				}
				else if (Py_Py3kWarningFlag  &&
					 !PyTuple_Check(exc) &&
					 !Py3kExceptionClass_Check(exc))
				{
					int ret_val;
					ret_val = PyErr_WarnEx(
						PyExc_DeprecationWarning,
						CANNOT_CATCH_MSG, 1);
					if (ret_val < 0)
						return NULL;
				}
			}
		}
		else {
			if (PyString_Check(w)) {
				int ret_val;
				ret_val = PyErr_WarnEx(
						PyExc_DeprecationWarning,
						"catching of string "
						"exceptions is deprecated", 1);
				if (ret_val < 0)
					return NULL;
			}
			else if (Py_Py3kWarningFlag  &&
				 !PyTuple_Check(w) &&
				 !Py3kExceptionClass_Check(w))
			{
				int ret_val;
				ret_val = PyErr_WarnEx(
					PyExc_DeprecationWarning,
					CANNOT_CATCH_MSG, 1);
				if (ret_val < 0)
					return NULL;
			}
		}
		res = PyErr_GivenExceptionMatches(v, w);
		break;
	default:
		return PyObject_RichCompare(v, w, op);
	}
	v = res ? Py_True : Py_False;
	Py_INCREF(v);
	return v;
}

static PyObject *
import_from(PyObject *v, PyObject *name)
{
	PyObject *x;

	x = PyObject_GetAttr(v, name);
	if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
		PyErr_Format(PyExc_ImportError,
			     "cannot import name %.230s",
			     PyString_AsString(name));
	}
	return x;
}

static int
import_all_from(PyObject *locals, PyObject *v)
{
	PyObject *all = PyObject_GetAttrString(v, "__all__");
	PyObject *dict, *name, *value;
	int skip_leading_underscores = 0;
	int pos, err;

	if (all == NULL) {
		if (!PyErr_ExceptionMatches(PyExc_AttributeError))
			return -1; /* Unexpected error */
		PyErr_Clear();
		dict = PyObject_GetAttrString(v, "__dict__");
		if (dict == NULL) {
			if (!PyErr_ExceptionMatches(PyExc_AttributeError))
				return -1;
			PyErr_SetString(PyExc_ImportError,
			"from-import-* object has no __dict__ and no __all__");
			return -1;
		}
		all = PyMapping_Keys(dict);
		Py_DECREF(dict);
		if (all == NULL)
			return -1;
		skip_leading_underscores = 1;
	}

	for (pos = 0, err = 0; ; pos++) {
		name = PySequence_GetItem(all, pos);
		if (name == NULL) {
			if (!PyErr_ExceptionMatches(PyExc_IndexError))
				err = -1;
			else
				PyErr_Clear();
			break;
		}
		if (skip_leading_underscores &&
		    PyString_Check(name) &&
		    PyString_AS_STRING(name)[0] == '_')
		{
			Py_DECREF(name);
			continue;
		}
		value = PyObject_GetAttr(v, name);
		if (value == NULL)
			err = -1;
		else if (PyDict_CheckExact(locals))
			err = PyDict_SetItem(locals, name, value);
		else
			err = PyObject_SetItem(locals, name, value);
		Py_DECREF(name);
		Py_XDECREF(value);
		if (err != 0)
			break;
	}
	Py_DECREF(all);
	return err;
}

static PyObject *
build_class(PyObject *methods, PyObject *bases, PyObject *name)
{
	PyObject *metaclass = NULL, *result, *base;

	if (PyDict_Check(methods))
		metaclass = PyDict_GetItemString(methods, "__metaclass__");
	if (metaclass != NULL)
		Py_INCREF(metaclass);
	else if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
		base = PyTuple_GET_ITEM(bases, 0);
		metaclass = PyObject_GetAttrString(base, "__class__");
		if (metaclass == NULL) {
			PyErr_Clear();
			metaclass = (PyObject *)base->ob_type;
			Py_INCREF(metaclass);
		}
	}
	else {
		PyObject *g = PyEval_GetGlobals();
		if (g != NULL && PyDict_Check(g))
			metaclass = PyDict_GetItemString(g, "__metaclass__");
		if (metaclass == NULL)
			metaclass = (PyObject *) &PyClass_Type;
		Py_INCREF(metaclass);
	}
	result = PyObject_CallFunctionObjArgs(metaclass, name, bases, methods,
					      NULL);
	Py_DECREF(metaclass);
	if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {
		/* A type error here likely means that the user passed
		   in a base that was not a class (such the random module
		   instead of the random.random type).  Help them out with
		   by augmenting the error message with more information.*/

		PyObject *ptype, *pvalue, *ptraceback;

		PyErr_Fetch(&ptype, &pvalue, &ptraceback);
		if (PyString_Check(pvalue)) {
			PyObject *newmsg;
			newmsg = PyString_FromFormat(
				"Error when calling the metaclass bases\n"
				"    %s",
				PyString_AS_STRING(pvalue));
			if (newmsg != NULL) {
				Py_DECREF(pvalue);
				pvalue = newmsg;
			}
		}
		PyErr_Restore(ptype, pvalue, ptraceback);
	}
	return result;
}

static int
exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
	       PyObject *locals)
{
	int n;
	PyObject *v;
	int plain = 0;

	if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None &&
	    ((n = PyTuple_Size(prog)) == 2 || n == 3)) {
		/* Backward compatibility hack */
		globals = PyTuple_GetItem(prog, 1);
		if (n == 3)
			locals = PyTuple_GetItem(prog, 2);
		prog = PyTuple_GetItem(prog, 0);
	}
	if (globals == Py_None) {
		globals = PyEval_GetGlobals();
		if (locals == Py_None) {
			locals = PyEval_GetLocals();
			plain = 1;
		}
		if (!globals || !locals) {
			PyErr_SetString(PyExc_SystemError,
					"globals and locals cannot be NULL");
			return -1;
		}
	}
	else if (locals == Py_None)
		locals = globals;
	if (!PyString_Check(prog) &&
	    !PyUnicode_Check(prog) &&
	    !PyCode_Check(prog) &&
	    !PyFile_Check(prog)) {
		PyErr_SetString(PyExc_TypeError,
			"exec: arg 1 must be a string, file, or code object");
		return -1;
	}
	if (!PyDict_Check(globals)) {
		PyErr_SetString(PyExc_TypeError,
		    "exec: arg 2 must be a dictionary or None");
		return -1;
	}
	if (!PyMapping_Check(locals)) {
		PyErr_SetString(PyExc_TypeError,
		    "exec: arg 3 must be a mapping or None");
		return -1;
	}
	if (PyDict_GetItemString(globals, "__builtins__") == NULL)
		PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
	if (PyCode_Check(prog)) {
		if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) {
			PyErr_SetString(PyExc_TypeError,
		"code object passed to exec may not contain free variables");
			return -1;
		}
		v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);
	}
	else if (PyFile_Check(prog)) {
		FILE *fp = PyFile_AsFile(prog);
		char *name = PyString_AsString(PyFile_Name(prog));
		PyCompilerFlags cf;
		if (name == NULL)
			return -1;
		cf.cf_flags = 0;
		if (PyEval_MergeCompilerFlags(&cf))
			v = PyRun_FileFlags(fp, name, Py_file_input, globals,
					    locals, &cf);
		else
			v = PyRun_File(fp, name, Py_file_input, globals,
				       locals);
	}
	else {
		PyObject *tmp = NULL;
		char *str;
		PyCompilerFlags cf;
		cf.cf_flags = 0;
#ifdef Py_USING_UNICODE
		if (PyUnicode_Check(prog)) {
			tmp = PyUnicode_AsUTF8String(prog);
			if (tmp == NULL)
				return -1;
			prog = tmp;
			cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
		}
#endif
		if (PyString_AsStringAndSize(prog, &str, NULL))
			return -1;
		if (PyEval_MergeCompilerFlags(&cf))
			v = PyRun_StringFlags(str, Py_file_input, globals,
					      locals, &cf);
		else
			v = PyRun_String(str, Py_file_input, globals, locals);
		Py_XDECREF(tmp);
	}
	if (plain)
		PyFrame_LocalsToFast(f, 0);
	if (v == NULL)
		return -1;
	Py_DECREF(v);
	return 0;
}

static void
format_exc_check_arg(PyObject *exc, char *format_str, PyObject *obj)
{
	char *obj_str;

	if (!obj)
		return;

	obj_str = PyString_AsString(obj);
	if (!obj_str)
		return;

	PyErr_Format(exc, format_str, obj_str);
}

static PyObject *
string_concatenate(PyObject *v, PyObject *w,
		   PyFrameObject *f, unsigned char *next_instr)
{
	/* This function implements 'variable += expr' when both arguments
	   are strings. */
	Py_ssize_t v_len = PyString_GET_SIZE(v);
	Py_ssize_t w_len = PyString_GET_SIZE(w);
	Py_ssize_t new_len = v_len + w_len;
	if (new_len < 0) {
		PyErr_SetString(PyExc_OverflowError,
				"strings are too large to concat");
		return NULL;
	}

	if (v->ob_refcnt == 2) {
		/* In the common case, there are 2 references to the value
		 * stored in 'variable' when the += is performed: one on the
		 * value stack (in 'v') and one still stored in the
		 * 'variable'.  We try to delete the variable now to reduce
		 * the refcnt to 1.
		 */
		switch (*next_instr) {
		case STORE_FAST:
		{
			int oparg = PEEKARG();
			PyObject **fastlocals = f->f_localsplus;
			if (GETLOCAL(oparg) == v)
				SETLOCAL(oparg, NULL);
			break;
		}
		case STORE_DEREF:
		{
			PyObject **freevars = (f->f_localsplus +
					       f->f_code->co_nlocals);
			PyObject *c = freevars[PEEKARG()];
			if (PyCell_GET(c) == v)
				PyCell_Set(c, NULL);
			break;
		}
		case STORE_NAME:
		{
			PyObject *names = f->f_code->co_names;
			PyObject *name = GETITEM(names, PEEKARG());
			PyObject *locals = f->f_locals;
			if (PyDict_CheckExact(locals) &&
			    PyDict_GetItem(locals, name) == v) {
				if (PyDict_DelItem(locals, name) != 0) {
					PyErr_Clear();
				}
			}
			break;
		}
		}
	}

	if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) {
		/* Now we own the last reference to 'v', so we can resize it
		 * in-place.
		 */
		if (_PyString_Resize(&v, new_len) != 0) {
			/* XXX if _PyString_Resize() fails, 'v' has been
			 * deallocated so it cannot be put back into
			 * 'variable'.  The MemoryError is raised when there
			 * is no value in 'variable', which might (very
			 * remotely) be a cause of incompatibilities.
			 */
			return NULL;
		}
		/* copy 'w' into the newly allocated area of 'v' */
		memcpy(PyString_AS_STRING(v) + v_len,
		       PyString_AS_STRING(w), w_len);
		return v;
	}
	else {
		/* When in-place resizing is not an option. */
		PyString_Concat(&v, w);
		return v;
	}
}

#ifdef DYNAMIC_EXECUTION_PROFILE

static PyObject *
getarray(long a[256])
{
	int i;
	PyObject *l = PyList_New(256);
	if (l == NULL) return NULL;
	for (i = 0; i < 256; i++) {
		PyObject *x = PyInt_FromLong(a[i]);
		if (x == NULL) {
			Py_DECREF(l);
			return NULL;
		}
		PyList_SetItem(l, i, x);
	}
	for (i = 0; i < 256; i++)
		a[i] = 0;
	return l;
}

PyObject *
_Py_GetDXProfile(PyObject *self, PyObject *args)
{
#ifndef DXPAIRS
	return getarray(dxp);
#else
	int i;
	PyObject *l = PyList_New(257);
	if (l == NULL) return NULL;
	for (i = 0; i < 257; i++) {
		PyObject *x = getarray(dxpairs[i]);
		if (x == NULL) {
			Py_DECREF(l);
			return NULL;
		}
		PyList_SetItem(l, i, x);
	}
	return l;
#endif
}

#endif
nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 ..\..\..\zlib-1.1.4\zlib.lib /nologo /base:"0x1e1B0000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./zlib.pyd" -# SUBTRACT LINK32 /pdb:none -# Begin Special Build Tool -SOURCE="$(InputPath)" -PreLink_Desc=Checking static zlib has been built -PreLink_Cmds=cd ..\..\..\zlib-1.1.4 nmake -nologo -f msdos\makefile.w32 zlib.lib -# End Special Build Tool - -!ELSEIF "$(CFG)" == "zlib - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "." -# PROP Intermediate_Dir "x86-temp-debug\zlib" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -F90=df.exe -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\Include" /I ".." /I "..\..\..\zlib-1.1.4" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX /FD /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 ..\..\..\zlib-1.1.4\zlib.lib /nologo /base:"0x1e1B0000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./zlib_d.pyd" /pdbtype:sept -# SUBTRACT LINK32 /pdb:none -# Begin Special Build Tool -SOURCE="$(InputPath)" -PreLink_Desc=Checking static zlib has been built -PreLink_Cmds=cd ..\..\..\zlib-1.1.4 nmake -nologo -f msdos\makefile.w32 zlib.lib -# End Special Build Tool - -!ENDIF - -# Begin Target - -# Name "zlib - Win32 Release" -# Name "zlib - Win32 Debug" -# Begin Source File - -SOURCE=..\..\Modules\zlibmodule.c -# End Source File -# End Target -# End Project -- cgit v0.12 From 0805f956223c442e8ca88b5306c768a41ea46341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Tue, 17 Oct 2006 18:10:09 +0000 Subject: Remove obsolete file. --- PC/VC6/zlib.dsp | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 PC/VC6/zlib.dsp diff --git a/PC/VC6/zlib.dsp b/PC/VC6/zlib.dsp deleted file mode 100644 index e69de29..0000000 -- cgit v0.12 From ca362b6937aecf5177d832b3e44aa6697e6d5d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Tue, 17 Oct 2006 18:59:06 +0000 Subject: Forward-port r52358: - Bug #1578513: Cross compilation was broken by a change to configure. Repair so that it's back to how it was in 2.4.3. --- Misc/NEWS | 3 +++ configure | 51 +++++++++++++++++---------------------------------- configure.in | 23 +++++++++++++++++++++-- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 4cabe95..2bdbbc4 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,9 @@ Library Build ----- +- Bug #1578513: Cross compilation was broken by a change to configure. + Repair so that it's back to how it was in 2.4.3. + - Patch #1576954: Update VC6 build directory; remove redundant files in VC7. diff --git a/configure b/configure index 55f278c..c17dbd7 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 52087 . +# From configure.in Revision: 52090 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for python 2.5. # @@ -22051,55 +22051,38 @@ rm -f conftest.err conftest.$ac_objext conftest.$ac_ext echo "$as_me:$LINENO: checking for /dev/ptmx" >&5 echo $ECHO_N "checking for /dev/ptmx... $ECHO_C" >&6 -if test "${ac_cv_file__dev_ptmx+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - test "$cross_compiling" = yes && - { { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5 -echo "$as_me: error: cannot check for file existence when cross compiling" >&2;} - { (exit 1); exit 1; }; } -if test -r "/dev/ptmx"; then - ac_cv_file__dev_ptmx=yes -else - ac_cv_file__dev_ptmx=no -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_file__dev_ptmx" >&5 -echo "${ECHO_T}$ac_cv_file__dev_ptmx" >&6 -if test $ac_cv_file__dev_ptmx = yes; then + +if test -r /dev/ptmx +then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 cat >>confdefs.h <<\_ACEOF #define HAVE_DEV_PTMX 1 _ACEOF +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 fi echo "$as_me:$LINENO: checking for /dev/ptc" >&5 echo $ECHO_N "checking for /dev/ptc... $ECHO_C" >&6 -if test "${ac_cv_file__dev_ptc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - test "$cross_compiling" = yes && - { { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5 -echo "$as_me: error: cannot check for file existence when cross compiling" >&2;} - { (exit 1); exit 1; }; } -if test -r "/dev/ptc"; then - ac_cv_file__dev_ptc=yes -else - ac_cv_file__dev_ptc=no -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_file__dev_ptc" >&5 -echo "${ECHO_T}$ac_cv_file__dev_ptc" >&6 -if test $ac_cv_file__dev_ptc = yes; then + +if test -r /dev/ptc +then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 cat >>confdefs.h <<\_ACEOF #define HAVE_DEV_PTC 1 _ACEOF +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 fi - echo "$as_me:$LINENO: checking for %zd printf() format support" >&5 echo $ECHO_N "checking for %zd printf() format support... $ECHO_C" >&6 if test "$cross_compiling" = yes; then diff --git a/configure.in b/configure.in index ba3f445..cd9161b 100644 --- a/configure.in +++ b/configure.in @@ -3338,8 +3338,27 @@ AC_TRY_COMPILE([#include ], void *x=resizeterm, AC_MSG_RESULT(no) ) -AC_CHECK_FILE(/dev/ptmx, AC_DEFINE(HAVE_DEV_PTMX, 1, [Define if we have /dev/ptmx.])) -AC_CHECK_FILE(/dev/ptc, AC_DEFINE(HAVE_DEV_PTC, 1, [Define if we have /dev/ptc.])) +AC_MSG_CHECKING(for /dev/ptmx) + +if test -r /dev/ptmx +then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_DEV_PTMX, 1, + [Define if we have /dev/ptmx.]) +else + AC_MSG_RESULT(no) +fi + +AC_MSG_CHECKING(for /dev/ptc) + +if test -r /dev/ptc +then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_DEV_PTC, 1, + [Define if we have /dev/ptc.]) +else + AC_MSG_RESULT(no) +fi AC_MSG_CHECKING(for %zd printf() format support) AC_TRY_RUN([#include -- cgit v0.12 From dcbf64d34ddef32cb49ebbd19958ddd426cbdab6 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Tue, 17 Oct 2006 19:41:10 +0000 Subject: ctypes callback functions only support 'fundamental' result types. Check this and raise an error when something else is used - before this change ctypes would hang or crash when such a callback was called. This is a partial fix for #1574584. Backported from trunk. --- Lib/ctypes/test/test_callbacks.py | 13 +++++++++++++ Misc/NEWS | 4 ++++ Modules/_ctypes/callbacks.c | 7 +++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py index 9d96a54..f47fc37 100644 --- a/Lib/ctypes/test/test_callbacks.py +++ b/Lib/ctypes/test/test_callbacks.py @@ -101,6 +101,19 @@ class Callbacks(unittest.TestCase): after = grc(o) self.failUnlessEqual((after, o), (before, o)) + def test_unsupported_restype_1(self): + # Only "fundamental" result types are supported for callback + # functions, the type must have a non-NULL stgdict->setfunc. + # POINTER(c_double), for example, is not supported. + + prototype = self.functype.im_func(POINTER(c_double)) + # The type is checked when the prototype is called + self.assertRaises(TypeError, prototype, lambda: None) + + def test_unsupported_restype_2(self): + prototype = self.functype.im_func(object) + self.assertRaises(TypeError, prototype, lambda: None) + try: WINFUNCTYPE except NameError: diff --git a/Misc/NEWS b/Misc/NEWS index 2bdbbc4..7313802 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -75,6 +75,10 @@ Extension Modules Library ------- +- ctypes callback functions only support 'fundamental' data types as + result type. Raise an error when something else is used. This is a + partial fix for Bug #1574584. + - Bug #813342: Start the IDLE subprocess with -Qnew if the parent is started with that option. diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index c8e669a..e332f00 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -293,8 +293,11 @@ ffi_info *AllocFunctionCallback(PyObject *callable, p->restype = &ffi_type_void; } else { StgDictObject *dict = PyType_stgdict(restype); - if (dict == NULL) - goto error; + if (dict == NULL || dict->setfunc == NULL) { + PyErr_SetString(PyExc_TypeError, + "invalid result type for callback function"); + goto error; + } p->setfunc = dict->setfunc; p->restype = &dict->ffi_type_pointer; } -- cgit v0.12 From fbbfb4b976dcbeed8e3e5acde1be182449e43178 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Wed, 18 Oct 2006 05:30:25 +0000 Subject: C:\Code\python>type c.txt Merge rev 52377 from trunk: newIobject(): repaired incorrect cast to quiet MSVC warning. --- Modules/cStringIO.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index 03ef461..100891b 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -657,7 +657,7 @@ newIobject(PyObject *s) { char *buf; Py_ssize_t size; - if (PyObject_AsCharBuffer(s, (const void **)&buf, &size) != 0) + if (PyObject_AsCharBuffer(s, (const char **)&buf, &size) != 0) return NULL; self = PyObject_New(Iobject, &Itype); -- cgit v0.12 From 51c4105617c349aa93ffc1cd88777f171e47b846 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Thu, 19 Oct 2006 21:56:14 +0000 Subject: [Bug #1576348] Fix typo in example --- Doc/inst/inst.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/inst/inst.tex b/Doc/inst/inst.tex index df7c656..6db22ac 100644 --- a/Doc/inst/inst.tex +++ b/Doc/inst/inst.tex @@ -632,7 +632,7 @@ Note that these two are \emph{not} equivalent if you supply a different installation base directory when you run the setup script. For example, \begin{verbatim} -python setup.py --install-base=/tmp +python setup.py install --install-base=/tmp \end{verbatim} would install pure modules to \filevar{/tmp/python/lib} in the first -- cgit v0.12 -- cgit v0.12 -- cgit v0.12 From e67b3497c95c7ce869f8d4f25934d57f56fb2557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 22 Oct 2006 10:47:28 +0000 Subject: Patch #1580872: Remove duplicate declaration of PyCallable_Check. --- Include/abstract.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Include/abstract.h b/Include/abstract.h index 9b0b3f0..14510c6 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -288,9 +288,10 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ */ + /* Declared elsewhere + PyAPI_FUNC(int) PyCallable_Check(PyObject *o); - /* Determine if the object, o, is callable. Return 1 if the object is callable and 0 otherwise. -- cgit v0.12 From 63a9b8b0679903ca1cfc17daf0a881c74a6ef1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 22 Oct 2006 10:55:25 +0000 Subject: - Patch #1560695: Add .note.GNU-stack to ctypes' sysv.S so that ctypes isn't considered as requiring executable stacks. --- Misc/NEWS | 3 +++ Modules/_ctypes/libffi/src/x86/sysv.S | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 7313802..0b7fdc3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -52,6 +52,9 @@ Core and builtins Extension Modules ----------------- +- Patch #1560695: Add .note.GNU-stack to ctypes' sysv.S so that + ctypes isn't considered as requiring executable stacks. + - Bug #1567666: Emulate GetFileAttributesExA for Win95. - Bug #1548891: The cStringIO.StringIO() constructor now encodes unicode diff --git a/Modules/_ctypes/libffi/src/x86/sysv.S b/Modules/_ctypes/libffi/src/x86/sysv.S index 46759f4..9542fba 100644 --- a/Modules/_ctypes/libffi/src/x86/sysv.S +++ b/Modules/_ctypes/libffi/src/x86/sysv.S @@ -376,3 +376,7 @@ ffi_closure_raw_SYSV: #endif #endif /* ifndef __x86_64__ */ + +#ifdef __ELF__ +.section .note.GNU-stack,"",%progbits +#endif -- cgit v0.12 From 920fa6a102f8d5f46a2e0552e85ae295882a92bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 22 Oct 2006 13:46:23 +0000 Subject: Remove passwd.adjunct.byname from list of maps for test_nis. --- Lib/test/test_nis.py | 7 +++++++ Misc/NEWS | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Lib/test/test_nis.py b/Lib/test/test_nis.py index f5224fe..74ceeea 100644 --- a/Lib/test/test_nis.py +++ b/Lib/test/test_nis.py @@ -11,6 +11,13 @@ except nis.error, msg: # only do this if running under the regression suite raise TestSkipped, msg +try: + # On some systems, this map is only accessible to the + # super user + maps.remove("passwd.adjunct.byname") +except ValueError: + pass + done = 0 for nismap in maps: if verbose: diff --git a/Misc/NEWS b/Misc/NEWS index 0b7fdc3..8b822e9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,13 @@ Library the close_fds arg to subprocess.Popen is not supported). +Tests +----- + +- Remove passwd.adjunct.byname from list of maps + for test_nis. + + Build ----- -- cgit v0.12 From ee23f4bba73f704b59c590a94b4731a22b72c7e7 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 24 Oct 2006 16:54:23 +0000 Subject: Patch [ 1583506 ] tarfile.py: 100-char filenames are truncated (backport from rev. 52431) --- Lib/tarfile.py | 2 +- Lib/test/test_tarfile.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 8d5f021..7c140da 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -136,7 +136,7 @@ TOEXEC = 0001 # execute/search by other def stn(s, length): """Convert a python string to a null-terminated string buffer. """ - return s[:length-1] + (length - len(s) - 1) * NUL + NUL + return s[:length] + (length - len(s)) * NUL def nti(s): """Convert a number field to a python number. diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index ebcb8c5..ee83cbe 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -280,6 +280,32 @@ class WriteTest(BaseTest): else: self.dst.addfile(tarinfo, f) + +class Write100Test(BaseTest): + # The name field in a tar header stores strings of at most 100 chars. + # If a string is shorter than 100 chars it has to be padded with '\0', + # which implies that a string of exactly 100 chars is stored without + # a trailing '\0'. + + def setUp(self): + self.name = "01234567890123456789012345678901234567890123456789" + self.name += "01234567890123456789012345678901234567890123456789" + + self.tar = tarfile.open(tmpname(), "w") + t = tarfile.TarInfo(self.name) + self.tar.addfile(t) + self.tar.close() + + self.tar = tarfile.open(tmpname()) + + def tearDown(self): + self.tar.close() + + def test(self): + self.assertEqual(self.tar.getnames()[0], self.name, + "failed to store 100 char filename") + + class WriteSize0Test(BaseTest): mode = 'w' @@ -623,6 +649,7 @@ def test_main(): ReadAsteriskTest, ReadStreamAsteriskTest, WriteTest, + Write100Test, WriteSize0Test, WriteStreamTest, WriteGNULongTest, -- cgit v0.12 From 1121e735368a918ad45b06cca39612f4fce419fc Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Thu, 26 Oct 2006 19:11:06 +0000 Subject: [Bug #1579796] Wrong syntax for PyDateTime_IMPORT in documentation. Reported by David Faure. --- Doc/api/concrete.tex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/api/concrete.tex b/Doc/api/concrete.tex index 764c6aa..97ef134 100644 --- a/Doc/api/concrete.tex +++ b/Doc/api/concrete.tex @@ -2879,10 +2879,10 @@ rather than explicitly calling \cfunction{PyGen_New}. Various date and time objects are supplied by the \module{datetime} module. Before using any of these functions, the header file \file{datetime.h} must be included in your source (note that this is -not include by \file{Python.h}), and macro \cfunction{PyDateTime_IMPORT()} -must be invoked. The macro arranges to put a pointer to a C structure -in a static variable \code{PyDateTimeAPI}, which is used by the following -macros. +not included by \file{Python.h}), and the macro +\cfunction{PyDateTime_IMPORT} must be invoked. The macro puts a +pointer to a C structure into a static variable, +\code{PyDateTimeAPI}, that is used by the following macros. Type-check macros: -- cgit v0.12 From 62e58040c1c5fce264eb8d6c31cd6c05f4c6e265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 27 Oct 2006 06:17:21 +0000 Subject: [Backport of r52452] Patch #1549049: Rewrite type conversion in structmember. Fixes #1545696 and #1566140. The new warnings have been omitted in the backport. --- Lib/test/test_structmembers.py | 48 +++++++++++++++ Misc/NEWS | 2 + Modules/_testcapimodule.c | 129 ++++++++++++++++++++++++++++++++++++++--- Python/structmember.c | 128 +++++++++++++++++++++++----------------- 4 files changed, 246 insertions(+), 61 deletions(-) create mode 100644 Lib/test/test_structmembers.py diff --git a/Lib/test/test_structmembers.py b/Lib/test/test_structmembers.py new file mode 100644 index 0000000..7fcf785 --- /dev/null +++ b/Lib/test/test_structmembers.py @@ -0,0 +1,48 @@ +from _testcapi import test_structmembersType, \ + CHAR_MAX, CHAR_MIN, UCHAR_MAX, \ + SHRT_MAX, SHRT_MIN, USHRT_MAX, \ + INT_MAX, INT_MIN, UINT_MAX, \ + LONG_MAX, LONG_MIN, ULONG_MAX + +import warnings, exceptions, unittest, test.test_warnings +from test import test_support + +ts=test_structmembersType(1,2,3,4,5,6,7,8,9.99999,10.1010101010) + +class ReadWriteTests(unittest.TestCase): + def test_types(self): + ts.T_BYTE=CHAR_MAX + self.assertEquals(ts.T_BYTE, CHAR_MAX) + ts.T_BYTE=CHAR_MIN + self.assertEquals(ts.T_BYTE, CHAR_MIN) + ts.T_UBYTE=UCHAR_MAX + self.assertEquals(ts.T_UBYTE, UCHAR_MAX) + + ts.T_SHORT=SHRT_MAX + self.assertEquals(ts.T_SHORT, SHRT_MAX) + ts.T_SHORT=SHRT_MIN + self.assertEquals(ts.T_SHORT, SHRT_MIN) + ts.T_USHORT=USHRT_MAX + self.assertEquals(ts.T_USHORT, USHRT_MAX) + + ts.T_INT=INT_MAX + self.assertEquals(ts.T_INT, INT_MAX) + ts.T_INT=INT_MIN + self.assertEquals(ts.T_INT, INT_MIN) + ts.T_UINT=UINT_MAX + self.assertEquals(ts.T_UINT, UINT_MAX) + + ts.T_LONG=LONG_MAX + self.assertEquals(ts.T_LONG, LONG_MAX) + ts.T_LONG=LONG_MIN + self.assertEquals(ts.T_LONG, LONG_MIN) + ts.T_ULONG=ULONG_MAX + self.assertEquals(ts.T_ULONG, ULONG_MAX) + +def test_main(verbose=None): + test_support.run_unittest( + ReadWriteTests + ) + +if __name__ == "__main__": + test_main(verbose=True) diff --git a/Misc/NEWS b/Misc/NEWS index 8b822e9..c79a55a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Patch #1549049: Support long values in structmember. + - Bug #1545497: when given an explicit base, int() did ignore NULs embedded in the string to convert. diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index f5f3ab2..0236c83 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -6,6 +6,8 @@ */ #include "Python.h" +#include +#include "structmember.h" #ifdef WITH_THREAD #include "pythread.h" @@ -35,13 +37,13 @@ raiseTestError(const char* test_name, const char* msg) platforms have these hardcoded. Better safe than sorry. */ static PyObject* -sizeof_error(const char* fatname, const char* typename, +sizeof_error(const char* fatname, const char* typname, int expected, int got) { char buf[1024]; PyOS_snprintf(buf, sizeof(buf), "%.200s #define == %d but sizeof(%.200s) == %d", - fatname, expected, typename, got); + fatname, expected, typname, got); PyErr_SetString(TestError, buf); return (PyObject*)NULL; } @@ -615,7 +617,7 @@ _make_call(void *callable) { PyObject *rc; PyGILState_STATE s = PyGILState_Ensure(); - rc = PyObject_CallFunction(callable, ""); + rc = PyObject_CallFunction((PyObject *)callable, ""); Py_XDECREF(rc); PyGILState_Release(s); } @@ -756,6 +758,105 @@ static PyMethodDef TestMethods[] = { #define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);} +typedef struct { + char byte_member; + unsigned char ubyte_member; + short short_member; + unsigned short ushort_member; + int int_member; + unsigned int uint_member; + long long_member; + unsigned long ulong_member; + float float_member; + double double_member; +} all_structmembers; + +typedef struct { + PyObject_HEAD + all_structmembers structmembers; +} test_structmembers; + +static struct PyMemberDef test_members[] = { + {"T_BYTE", T_BYTE, offsetof(test_structmembers, structmembers.byte_member), 0, NULL}, + {"T_UBYTE", T_UBYTE, offsetof(test_structmembers, structmembers.ubyte_member), 0, NULL}, + {"T_SHORT", T_SHORT, offsetof(test_structmembers, structmembers.short_member), 0, NULL}, + {"T_USHORT", T_USHORT, offsetof(test_structmembers, structmembers.ushort_member), 0, NULL}, + {"T_INT", T_INT, offsetof(test_structmembers, structmembers.int_member), 0, NULL}, + {"T_UINT", T_UINT, offsetof(test_structmembers, structmembers.uint_member), 0, NULL}, + {"T_LONG", T_LONG, offsetof(test_structmembers, structmembers.long_member), 0, NULL}, + {"T_ULONG", T_ULONG, offsetof(test_structmembers, structmembers.ulong_member), 0, NULL}, + {"T_FLOAT", T_FLOAT, offsetof(test_structmembers, structmembers.float_member), 0, NULL}, + {"T_DOUBLE", T_DOUBLE, offsetof(test_structmembers, structmembers.double_member), 0, NULL}, + {NULL} +}; + + +static PyObject *test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs){ + static char *keywords[]={"T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", "T_INT", "T_UINT", + "T_LONG", "T_ULONG", "T_FLOAT", "T_DOUBLE", NULL}; + test_structmembers *ob=PyObject_New(test_structmembers, type); + if (ob==NULL) + return NULL; + memset(&ob->structmembers, 0, sizeof(all_structmembers)); + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|bBhHiIlkfd", keywords, + &ob->structmembers.byte_member, &ob->structmembers.ubyte_member, + &ob->structmembers.short_member, &ob->structmembers.ushort_member, + &ob->structmembers.int_member, &ob->structmembers.uint_member, + &ob->structmembers.long_member, &ob->structmembers.ulong_member, + &ob->structmembers.float_member, &ob->structmembers.double_member)){ + Py_DECREF(ob); + return NULL; + } + return (PyObject *)ob; +} + +static void test_structmembers_free(PyObject *ob){ + PyObject_FREE(ob); +} + +static PyTypeObject test_structmembersType = { + PyObject_HEAD_INIT(NULL) + 0, + "test_structmembersType", + sizeof(test_structmembers), /* tp_basicsize */ + 0, /* tp_itemsize */ + test_structmembers_free, /* destructor tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, + PyObject_GenericSetAttr, + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + "Type containing all structmember types", + 0, /* traverseproc tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + test_members, /* tp_members */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + test_structmembers_new, /* tp_new */ +}; + + PyMODINIT_FUNC init_testcapi(void) { @@ -765,16 +866,28 @@ init_testcapi(void) if (m == NULL) return; + test_structmembersType.ob_type=&PyType_Type; + Py_INCREF(&test_structmembersType); + PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType); + + PyModule_AddObject(m, "CHAR_MAX", PyInt_FromLong(CHAR_MAX)); + PyModule_AddObject(m, "CHAR_MIN", PyInt_FromLong(CHAR_MIN)); PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX)); + PyModule_AddObject(m, "SHRT_MAX", PyInt_FromLong(SHRT_MAX)); + PyModule_AddObject(m, "SHRT_MIN", PyInt_FromLong(SHRT_MIN)); PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX)); + PyModule_AddObject(m, "INT_MAX", PyLong_FromLong(INT_MAX)); + PyModule_AddObject(m, "INT_MIN", PyLong_FromLong(INT_MIN)); PyModule_AddObject(m, "UINT_MAX", PyLong_FromUnsignedLong(UINT_MAX)); - PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX)); - PyModule_AddObject(m, "INT_MIN", PyInt_FromLong(INT_MIN)); - PyModule_AddObject(m, "LONG_MIN", PyInt_FromLong(LONG_MIN)); - PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN)); - PyModule_AddObject(m, "INT_MAX", PyInt_FromLong(INT_MAX)); PyModule_AddObject(m, "LONG_MAX", PyInt_FromLong(LONG_MAX)); + PyModule_AddObject(m, "LONG_MIN", PyInt_FromLong(LONG_MIN)); + PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX)); + PyModule_AddObject(m, "FLT_MAX", PyFloat_FromDouble(FLT_MAX)); + PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN)); + PyModule_AddObject(m, "DBL_MAX", PyFloat_FromDouble(DBL_MAX)); + PyModule_AddObject(m, "DBL_MIN", PyFloat_FromDouble(DBL_MIN)); PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX)); + PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN)); TestError = PyErr_NewException("_testcapi.error", NULL, NULL); Py_INCREF(TestError); diff --git a/Python/structmember.c b/Python/structmember.c index 54eb055..03934c0 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -62,29 +62,28 @@ PyMember_GetOne(const char *addr, PyMemberDef *l) addr += l->offset; switch (l->type) { case T_BYTE: - v = PyInt_FromLong( - (long) (((*(char*)addr & 0xff) ^ 0x80) - 0x80)); + v = PyInt_FromLong(*(char*)addr); break; case T_UBYTE: - v = PyInt_FromLong((long) *(char*)addr & 0xff); + v = PyLong_FromUnsignedLong(*(unsigned char*)addr); break; case T_SHORT: - v = PyInt_FromLong((long) *(short*)addr); + v = PyInt_FromLong(*(short*)addr); break; case T_USHORT: - v = PyInt_FromLong((long) *(unsigned short*)addr); + v = PyLong_FromUnsignedLong(*(unsigned short*)addr); break; case T_INT: - v = PyInt_FromLong((long) *(int*)addr); + v = PyInt_FromLong(*(int*)addr); break; case T_UINT: - v = PyInt_FromLong((long) *(unsigned int*)addr); + v = PyLong_FromUnsignedLong(*(unsigned int*)addr); break; case T_LONG: v = PyInt_FromLong(*(long*)addr); break; case T_ULONG: - v = PyLong_FromDouble((double) *(unsigned long*)addr); + v = PyLong_FromUnsignedLong(*(unsigned long*)addr); break; case T_FLOAT: v = PyFloat_FromDouble((double)*(float*)addr); @@ -175,68 +174,91 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) } addr += l->offset; switch (l->type) { - case T_BYTE: - case T_UBYTE: - if (!PyInt_Check(v)) { - PyErr_BadArgument(); + case T_BYTE:{ + long long_val; + long_val = PyInt_AsLong(v); + if ((long_val == -1) && PyErr_Occurred()) return -1; - } - *(char*)addr = (char) PyInt_AsLong(v); + *(char*)addr = (char)long_val; break; - case T_SHORT: - case T_USHORT: - if (!PyInt_Check(v)) { - PyErr_BadArgument(); - return -1; } - *(short*)addr = (short) PyInt_AsLong(v); + case T_UBYTE:{ + long long_val; + long_val = PyInt_AsLong(v); + if ((long_val == -1) && PyErr_Occurred()) + return -1; + *(unsigned char*)addr = (unsigned char)long_val; break; - case T_UINT: - case T_INT: - if (!PyInt_Check(v)) { - PyErr_BadArgument(); + } + case T_SHORT:{ + long long_val; + long_val = PyInt_AsLong(v); + if ((long_val == -1) && PyErr_Occurred()) return -1; + *(short*)addr = (short)long_val; + break; } - *(int*)addr = (int) PyInt_AsLong(v); + case T_USHORT:{ + long long_val; + long_val = PyInt_AsLong(v); + if ((long_val == -1) && PyErr_Occurred()) + return -1; + *(unsigned short*)addr = (unsigned short)long_val; break; - case T_LONG: - if (!PyInt_Check(v)) { - PyErr_BadArgument(); + } + case T_INT:{ + long long_val; + long_val = PyInt_AsLong(v); + if ((long_val == -1) && PyErr_Occurred()) return -1; + *(int *)addr = (int)long_val; + break; + } + case T_UINT:{ + unsigned long ulong_val; + ulong_val = PyLong_AsUnsignedLong(v); + if ((ulong_val == (unsigned int)-1) && PyErr_Occurred()) { + /* XXX: For compatibility, accept negative int values + as well. */ + PyErr_Clear(); + ulong_val = PyLong_AsLong(v); + if ((ulong_val == (unsigned int)-1) && PyErr_Occurred()) + return -1; } - *(long*)addr = PyInt_AsLong(v); + *(unsigned int *)addr = (unsigned int)ulong_val; break; - case T_ULONG: - if (PyInt_Check(v)) - *(long*)addr = PyInt_AsLong(v); - else if (PyLong_Check(v)) - *(long*)addr = PyLong_AsLong(v); - else { - PyErr_BadArgument(); + } + case T_LONG:{ + *(long*)addr = PyLong_AsLong(v); + if ((*(long*)addr == -1) && PyErr_Occurred()) return -1; + break; + } + case T_ULONG:{ + *(unsigned long*)addr = PyLong_AsUnsignedLong(v); + if ((*(unsigned long*)addr == (unsigned long)-1) + && PyErr_Occurred()) { + /* XXX: For compatibility, accept negative int values + as well. */ + PyErr_Clear(); + *(unsigned long*)addr = PyLong_AsLong(v); + if ((*(unsigned long*)addr == (unsigned int)-1) && PyErr_Occurred()) + return -1; } break; - case T_FLOAT: - if (PyInt_Check(v)) - *(float*)addr = - (float) PyInt_AsLong(v); - else if (PyFloat_Check(v)) - *(float*)addr = - (float) PyFloat_AsDouble(v); - else { - PyErr_BadArgument(); - return -1; } + case T_FLOAT:{ + double double_val; + double_val = PyFloat_AsDouble(v); + if ((double_val == -1) && PyErr_Occurred()) + return -1; + *(float*)addr = (float)double_val; break; + } case T_DOUBLE: - if (PyInt_Check(v)) - *(double*)addr = (double) PyInt_AsLong(v); - else if (PyFloat_Check(v)) - *(double*)addr = PyFloat_AsDouble(v); - else { - PyErr_BadArgument(); + *(double*)addr = PyFloat_AsDouble(v); + if ((*(double*)addr == -1) && PyErr_Occurred()) return -1; - } break; case T_OBJECT: case T_OBJECT_EX: -- cgit v0.12 From 2ec1df27855435f42a2181aef9d25b73e72a9e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 27 Oct 2006 06:43:00 +0000 Subject: Check for values.h. --- Modules/_testcapimodule.c | 2 ++ configure | 5 +++-- configure.in | 2 +- pyconfig.h.in | 3 +++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 0236c83..c5068ef 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -6,7 +6,9 @@ */ #include "Python.h" +#ifdef HAVE_VALUES_H #include +#endif #include "structmember.h" #ifdef WITH_THREAD diff --git a/configure b/configure index c17dbd7..2990456 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 52090 . +# From configure.in Revision: 52362 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for python 2.5. # @@ -4632,6 +4632,7 @@ done + for ac_header in asm/types.h conio.h curses.h direct.h dlfcn.h errno.h \ fcntl.h grp.h \ io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \ @@ -4642,7 +4643,7 @@ sys/modem.h \ sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h \ sys/time.h \ sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \ -sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ +sys/resource.h netpacket/packet.h sysexits.h values.h bluetooth.h \ bluetooth/bluetooth.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` diff --git a/configure.in b/configure.in index cd9161b..8c2b954 100644 --- a/configure.in +++ b/configure.in @@ -1076,7 +1076,7 @@ sys/modem.h \ sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h \ sys/time.h \ sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \ -sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ +sys/resource.h netpacket/packet.h sysexits.h values.h bluetooth.h \ bluetooth/bluetooth.h) AC_HEADER_DIRENT AC_HEADER_MAJOR diff --git a/pyconfig.h.in b/pyconfig.h.in index 8448439..750de15 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -700,6 +700,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UTIME_H +/* Define to 1 if you have the header file. */ +#undef HAVE_VALUES_H + /* Define to 1 if you have the `wait3' function. */ #undef HAVE_WAIT3 -- cgit v0.12 From 64cd9efd80679a4ccd6a50c4e916913222816239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 27 Oct 2006 07:06:59 +0000 Subject: Get DBL_MAX from float.h not values.h. --- Modules/_testcapimodule.c | 4 +--- configure | 5 ++--- configure.in | 2 +- pyconfig.h.in | 3 --- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c5068ef..edfe8ad 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -6,9 +6,7 @@ */ #include "Python.h" -#ifdef HAVE_VALUES_H -#include -#endif +#include #include "structmember.h" #ifdef WITH_THREAD diff --git a/configure b/configure index 2990456..8b4e544 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 52362 . +# From configure.in Revision: 52455 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for python 2.5. # @@ -4632,7 +4632,6 @@ done - for ac_header in asm/types.h conio.h curses.h direct.h dlfcn.h errno.h \ fcntl.h grp.h \ io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \ @@ -4643,7 +4642,7 @@ sys/modem.h \ sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h \ sys/time.h \ sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \ -sys/resource.h netpacket/packet.h sysexits.h values.h bluetooth.h \ +sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ bluetooth/bluetooth.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` diff --git a/configure.in b/configure.in index 8c2b954..cd9161b 100644 --- a/configure.in +++ b/configure.in @@ -1076,7 +1076,7 @@ sys/modem.h \ sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h \ sys/time.h \ sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \ -sys/resource.h netpacket/packet.h sysexits.h values.h bluetooth.h \ +sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ bluetooth/bluetooth.h) AC_HEADER_DIRENT AC_HEADER_MAJOR diff --git a/pyconfig.h.in b/pyconfig.h.in index 750de15..8448439 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -700,9 +700,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UTIME_H -/* Define to 1 if you have the header file. */ -#undef HAVE_VALUES_H - /* Define to 1 if you have the `wait3' function. */ #undef HAVE_WAIT3 -- cgit v0.12 From 11b69e5c52ceca4bbbe9ec01cfc9d2ad8c64cec7 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 12:18:58 +0000 Subject: [Bug #1585690] Note that line_num was added in Python 2.5 --- Doc/lib/libcsv.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/lib/libcsv.tex b/Doc/lib/libcsv.tex index 02a176c..e965e31 100644 --- a/Doc/lib/libcsv.tex +++ b/Doc/lib/libcsv.tex @@ -345,6 +345,7 @@ A read-only description of the dialect in use by the parser. \begin{memberdesc}[csv reader]{line_num} The number of lines read from the source iterator. This is not the same as the number of records returned, as records can span multiple lines. + \versionadded{2.5} \end{memberdesc} -- cgit v0.12 From 35094a6962f7353cf13ab748dfb4685b769cfce1 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 12:50:55 +0000 Subject: [Bug #1583946] Reword description of server and issuer --- Doc/lib/libsocket.tex | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/lib/libsocket.tex b/Doc/lib/libsocket.tex index aa75ec9..ececea4 100644 --- a/Doc/lib/libsocket.tex +++ b/Doc/lib/libsocket.tex @@ -712,14 +712,15 @@ read until EOF. The return value is a string of the bytes read. \end{methoddesc} \begin{methoddesc}{server}{} -Returns a string containing the ASN.1 distinguished name identifying the -server's certificate. (See below for an example -showing what distinguished names look like.) +Returns a string describing the server's certificate. +Useful for debugging purposes; do not parse the content of this string +because its format can't be parsed unambiguously. \end{methoddesc} \begin{methoddesc}{issuer}{} -Returns a string containing the ASN.1 distinguished name identifying the -issuer of the server's certificate. +Returns a string describing the issuer of the server's certificate. +Useful for debugging purposes; do not parse the content of this string +because its format can't be parsed unambiguously. \end{methoddesc} \subsection{Example \label{socket-example}} -- cgit v0.12 From 935add1d302e452ea4ae48484bbde16fe2af1412 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 13:06:41 +0000 Subject: [Bug #1562583] Mention the set_reuse_addr() method --- Doc/lib/libasyncore.tex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/lib/libasyncore.tex b/Doc/lib/libasyncore.tex index 4425da7..2067839 100644 --- a/Doc/lib/libasyncore.tex +++ b/Doc/lib/libasyncore.tex @@ -198,9 +198,11 @@ Most of these are nearly identical to their socket partners. \end{methoddesc} \begin{methoddesc}{bind}{address} - Bind the socket to \var{address}. The socket must not already - be bound. (The format of \var{address} depends on the address - family --- see above.) + Bind the socket to \var{address}. The socket must not already be + bound. (The format of \var{address} depends on the address family + --- see above.) To mark the socket as re-usable (setting the + \constant{SO_REUSEADDR} option), call the \class{dispatcher} + object's \method{set_reuse_addr()} method. \end{methoddesc} \begin{methoddesc}{accept}{} -- cgit v0.12 From 5f958708685c3345290d625041b877c413723f76 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 13:29:41 +0000 Subject: [Bug #1542016] Report PCALL_POP value. This makes the return value of sys.callstats() match its docstring. Backport candidate. Though it's an API change, this is a pretty obscure portion of the API. --- Misc/NEWS | 3 +++ Python/ceval.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index c79a55a..a1033bf 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -14,6 +14,9 @@ Core and builtins - Patch #1549049: Support long values in structmember. +- Bug #1542016: make sys.callstats() match its docstring and return an + 11-tuple (only relevant when Python is compiled with -DCALL_PROFILE). + - Bug #1545497: when given an explicit base, int() did ignore NULs embedded in the string to convert. diff --git a/Python/ceval.c b/Python/ceval.c index 99e87e8..73e8dee 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -186,10 +186,10 @@ static int pcall[PCALL_NUM]; PyObject * PyEval_GetCallStats(PyObject *self) { - return Py_BuildValue("iiiiiiiiii", + return Py_BuildValue("iiiiiiiiiii", pcall[0], pcall[1], pcall[2], pcall[3], pcall[4], pcall[5], pcall[6], pcall[7], - pcall[8], pcall[9]); + pcall[8], pcall[9], pcall[10]); } #else #define PCALL(O) -- cgit v0.12 From d2ee30b4851905b00fb77c67f828171b45b043ed Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 14:54:43 +0000 Subject: Point users to the subprocess module in the docs for os.system, os.spawn*, os.popen2, and the popen2 and commands modules --- Doc/lib/libcommands.tex | 9 +++++++++ Doc/lib/libos.tex | 23 +++++++++++++++++++++-- Doc/lib/libpopen2.tex | 12 ++++++++---- Doc/lib/libsubprocess.tex | 3 --- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Doc/lib/libcommands.tex b/Doc/lib/libcommands.tex index 74e7023..53b8a20 100644 --- a/Doc/lib/libcommands.tex +++ b/Doc/lib/libcommands.tex @@ -12,6 +12,11 @@ The \module{commands} module contains wrapper functions for return any output generated by the command and, optionally, the exit status. +The \module{subprocess} module provides more powerful facilities for +spawning new processes and retrieving their results. Using the +\module{subprocess} module is preferable to using the \module{commands} +module. + The \module{commands} module defines the following functions: @@ -51,3 +56,7 @@ Example: >>> commands.getstatus('/bin/ls') '-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls' \end{verbatim} + +\begin{seealso} + \seemodule{subprocess}{Module for spawning and managing subprocesses.} +\end{seealso} diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex index 9ded3ae..7844028 100644 --- a/Doc/lib/libos.tex +++ b/Doc/lib/libos.tex @@ -361,6 +361,10 @@ object, except that when the exit status is zero (termination without errors), \code{None} is returned. Availability: Macintosh, \UNIX, Windows. +The \module{subprocess} module provides more powerful facilities for +spawning new processes and retrieving their results; using that module +is preferable to using this function. + \versionchanged[This function worked unreliably under Windows in earlier versions of Python. This was due to the use of the \cfunction{_popen()} function from the libraries provided with @@ -375,8 +379,13 @@ deleted once there are no file descriptors for the file. Availability: Macintosh, \UNIX, Windows. \end{funcdesc} +There are a number of different \function{popen*()} functions that +provide slightly different ways to create subprocesses. Note that the +\module{subprocess} module is easier to use and more powerful; +consider using that module before writing code using the +lower-level \function{popen*()} functions. -For each of the following \function{popen()} variants, if \var{bufsize} is +For each of the \function{popen*()} variants, if \var{bufsize} is specified, it specifies the buffer size for the I/O pipes. \var{mode}, if provided, should be the string \code{'b'} or \code{'t'}; on Windows this is needed to determine whether the file @@ -1545,7 +1554,13 @@ functions are described in section \ref{os-newstreams}. \funcline{spawnve}{mode, path, args, env} \funcline{spawnvp}{mode, file, args} \funcline{spawnvpe}{mode, file, args, env} -Execute the program \var{path} in a new process. If \var{mode} is +Execute the program \var{path} in a new process. + +(Note that the \module{subprocess} module provides more powerful +facilities for spawning new processes and retrieving their results; +using that module is preferable to using these functions.) + +If \var{mode} is \constant{P_NOWAIT}, this function returns the process ID of the new process; if \var{mode} is \constant{P_WAIT}, returns the process's exit code if it exits normally, or \code{-\var{signal}}, where @@ -1682,6 +1697,10 @@ and XP) this is the exit status of the command run; on systems using a non-native shell, consult your shell documentation. Availability: Macintosh, \UNIX, Windows. + +The \module{subprocess} module provides more powerful facilities for +spawning new processes and retrieving their results; using that module +is preferable to using this function. \end{funcdesc} \begin{funcdesc}{times}{} diff --git a/Doc/lib/libpopen2.tex b/Doc/lib/libpopen2.tex index 985f580..fa0c1a6 100644 --- a/Doc/lib/libpopen2.tex +++ b/Doc/lib/libpopen2.tex @@ -11,10 +11,10 @@ This module allows you to spawn processes and connect to their input/output/error pipes and obtain their return codes under \UNIX{} and Windows. -Note that starting with Python 2.0, this functionality is available -using functions from the \refmodule{os} module which have the same -names as the factory functions here, but the order of the return -values is more intuitive in the \refmodule{os} module variants. +The \module{subprocess} module provides more powerful facilities for +spawning new processes and retrieving their results. Using the +\module{subprocess} module is preferable to using the \module{popen2} +module. The primary interface offered by this module is a trio of factory functions. For each of these, if \var{bufsize} is specified, @@ -184,3 +184,7 @@ integrate I/O over pipes with their \function{select()} loops, or use separate threads to read each of the individual files provided by whichever \function{popen*()} function or \class{Popen*} class was used. + +\begin{seealso} + \seemodule{subprocess}{Module for spawning and managing subprocesses.} +\end{seealso} diff --git a/Doc/lib/libsubprocess.tex b/Doc/lib/libsubprocess.tex index 03072f7..f639710 100644 --- a/Doc/lib/libsubprocess.tex +++ b/Doc/lib/libsubprocess.tex @@ -12,9 +12,6 @@ connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several other, older modules and functions, such as: -% XXX Should add pointers to this module to at least the popen2 -% and commands sections. - \begin{verbatim} os.system os.spawn* -- cgit v0.12 From 3d6a834e29f83d043bd0bb239000cd0361eb94f6 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 16:42:19 +0000 Subject: [Bug #1576241] Let functools.wraps work with built-in functions --- Lib/functools.py | 2 +- Lib/test/test_functools.py | 7 +++++++ Misc/NEWS | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/functools.py b/Lib/functools.py index 8783f08..9643036 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -32,7 +32,7 @@ def update_wrapper(wrapper, for attr in assigned: setattr(wrapper, attr, getattr(wrapped, attr)) for attr in updated: - getattr(wrapper, attr).update(getattr(wrapped, attr)) + getattr(wrapper, attr).update(getattr(wrapped, attr, {})) # Return the wrapper so this can be used as a decorator via partial() return wrapper diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 8dc185b..6012f9f 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -210,6 +210,13 @@ class TestUpdateWrapper(unittest.TestCase): self.assertEqual(wrapper.attr, 'This is a different test') self.assertEqual(wrapper.dict_attr, f.dict_attr) + def test_builtin_update(self): + # Test for bug #1576241 + def wrapper(): + pass + functools.update_wrapper(wrapper, max) + self.assertEqual(wrapper.__name__, 'max') + self.assert_(wrapper.__doc__.startswith('max(')) class TestWraps(TestUpdateWrapper): diff --git a/Misc/NEWS b/Misc/NEWS index a1033bf..13f52a7 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -105,6 +105,8 @@ Library - Bug #1565661: in webbrowser, split() the command for the default GNOME browser in case it is a command with args. +- Bug #1576241: fix functools.wraps() to work on built-in functions. + - Fix a bug in traceback.format_exception_only() that led to an error being raised when print_exc() was called without an exception set. In version 2.4, this printed "None", restored that behavior. -- cgit v0.12 From 7d1d540cc371e7c6ebfb3bc1c99699e5dcbdafe5 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 16:57:44 +0000 Subject: [Bug #1575506] The _singlefileMailbox class was using the wrong file object in its flush() method, causing an error --- Lib/mailbox.py | 2 +- Lib/test/test_mailbox.py | 16 ++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index b72128b..eab03af 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -578,7 +578,7 @@ class _singlefileMailbox(Mailbox): self._toc = new_toc self._pending = False if self._locked: - _lock_file(new_file, dotlock=False) + _lock_file(self._file, dotlock=False) def _pre_mailbox_hook(self, f): """Called before writing the mailbox to file f.""" diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 6cdc441..40cf192 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -747,6 +747,22 @@ class _TestMboxMMDF(TestMailbox): self._box.lock() self._box.unlock() + def test_relock(self): + # Test case for bug #1575506: the mailbox class was locking the + # wrong file object in its flush() method. + msg = "Subject: sub\n\nbody\n" + key1 = self._box.add(msg) + self._box.flush() + self._box.close() + + self._box = self._factory(self._path) + self._box.lock() + key2 = self._box.add(msg) + self._box.flush() + self.assert_(self._box._locked) + self._box.close() + + class TestMbox(_TestMboxMMDF): diff --git a/Misc/NEWS b/Misc/NEWS index 13f52a7..64fa7bf 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -105,6 +105,9 @@ Library - Bug #1565661: in webbrowser, split() the command for the default GNOME browser in case it is a command with args. +- Bug #1575506: Single-file mailboxes didn't re-lock properly in + their flush() method. + - Bug #1576241: fix functools.wraps() to work on built-in functions. - Fix a bug in traceback.format_exception_only() that led to an error -- cgit v0.12 From ff9e7abac8df84480bcfd7e3ce3a3dd912e69537 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 27 Oct 2006 17:13:33 +0000 Subject: [Patch #1574068 by Scott Dial] urllib and urllib2 were using base64.encodestring() for encoding authentication data. encodestring() can include newlines for very long input, which produced broken HTTP headers. 2.4 backport candidate, probably. --- Lib/urllib.py | 8 ++++---- Lib/urllib2.py | 4 ++-- Misc/NEWS | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Lib/urllib.py b/Lib/urllib.py index 8d56690..064632c 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -302,13 +302,13 @@ class URLopener: if proxy_passwd: import base64 - proxy_auth = base64.encodestring(proxy_passwd).strip() + proxy_auth = base64.b64encode(proxy_passwd).strip() else: proxy_auth = None if user_passwd: import base64 - auth = base64.encodestring(user_passwd).strip() + auth = base64.b64encode(user_passwd).strip() else: auth = None h = httplib.HTTP(host) @@ -387,12 +387,12 @@ class URLopener: if not host: raise IOError, ('https error', 'no host given') if proxy_passwd: import base64 - proxy_auth = base64.encodestring(proxy_passwd).strip() + proxy_auth = base64.b64encode(proxy_passwd).strip() else: proxy_auth = None if user_passwd: import base64 - auth = base64.encodestring(user_passwd).strip() + auth = base64.b64encode(user_passwd).strip() else: auth = None h = httplib.HTTPS(host, 0, diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 3459f0d..890d3d4 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -674,7 +674,7 @@ class ProxyHandler(BaseHandler): proxy_type = orig_type if user and password: user_pass = '%s:%s' % (unquote(user), unquote(password)) - creds = base64.encodestring(user_pass).strip() + creds = base64.b64encode(user_pass).strip() req.add_header('Proxy-authorization', 'Basic ' + creds) hostport = unquote(hostport) req.set_proxy(hostport, proxy_type) @@ -798,7 +798,7 @@ class AbstractBasicAuthHandler: user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) - auth = 'Basic %s' % base64.encodestring(raw).strip() + auth = 'Basic %s' % base64.b64encode(raw).strip() if req.headers.get(self.auth_header, None) == auth: return None req.add_header(self.auth_header, auth) diff --git a/Misc/NEWS b/Misc/NEWS index 64fa7bf..57e5ad0 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -110,6 +110,9 @@ Library - Bug #1576241: fix functools.wraps() to work on built-in functions. +- Patch #1574068: fix urllib/urllib2 to not insert line breaks when + HTTP authentication data was very long. + - Fix a bug in traceback.format_exception_only() that led to an error being raised when print_exc() was called without an exception set. In version 2.4, this printed "None", restored that behavior. -- cgit v0.12 From a0a50feea816fef21c525212dd867f7d7f3f9ab4 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Fri, 27 Oct 2006 18:47:29 +0000 Subject: WindowsError.str should display the windows error code, not the posix error code; with test. Fixes #1576174. Backported from trunk, revision 52485. --- Lib/test/test_exceptions.py | 13 +++++++++++++ Misc/NEWS | 3 +++ Objects/exceptions.c | 14 +++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 1d94046..05666a8 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -183,6 +183,19 @@ class ExceptionTests(unittest.TestCase): test_capi1() test_capi2() + def test_WindowsError(self): + try: + WindowsError + except NameError: + pass + else: + self.failUnlessEqual(str(WindowsError(1001)), + "1001") + self.failUnlessEqual(str(WindowsError(1001, "message")), + "[Error 1001] message") + self.failUnlessEqual(WindowsError(1001, "message").errno, 22) + self.failUnlessEqual(WindowsError(1001, "message").winerror, 1001) + def testAttributes(self): # test that exception attributes are happy diff --git a/Misc/NEWS b/Misc/NEWS index 57e5ad0..9ad45fc 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1576174: WindowsError now displays the windows error code + again, no longer the posix error code. + - Patch #1549049: Support long values in structmember. - Bug #1542016: make sys.callstats() match its docstring and return an diff --git a/Objects/exceptions.c b/Objects/exceptions.c index c0b813d..0cd819c 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -828,9 +828,9 @@ WindowsError_str(PyWindowsErrorObject *self) return NULL; } - if (self->myerrno) { - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); + if (self->winerror) { + Py_INCREF(self->winerror); + PyTuple_SET_ITEM(tuple, 0, self->winerror); } else { Py_INCREF(Py_None); @@ -852,7 +852,7 @@ WindowsError_str(PyWindowsErrorObject *self) Py_DECREF(fmt); Py_DECREF(tuple); } - else if (self->myerrno && self->strerror) { + else if (self->winerror && self->strerror) { PyObject *fmt; PyObject *tuple; @@ -866,9 +866,9 @@ WindowsError_str(PyWindowsErrorObject *self) return NULL; } - if (self->myerrno) { - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); + if (self->winerror) { + Py_INCREF(self->winerror); + PyTuple_SET_ITEM(tuple, 0, self->winerror); } else { Py_INCREF(Py_None); -- cgit v0.12 From a35f8e05382aa53b98f423b918ae5f4bd030923a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 27 Oct 2006 20:39:47 +0000 Subject: Patch #1552024: add decorator support to unparse.py demo script. (backport from rev. 52488) --- Demo/parser/unparse.py | 3 +++ Misc/NEWS | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/Demo/parser/unparse.py b/Demo/parser/unparse.py index 510cdb0..f4dd90c 100644 --- a/Demo/parser/unparse.py +++ b/Demo/parser/unparse.py @@ -223,6 +223,9 @@ class Unparser: def _FunctionDef(self, t): self.write("\n") + for deco in t.decorators: + self.fill("@") + self.dispatch(deco) self.fill("def "+t.name + "(") self.dispatch(t.args) self.write(")") diff --git a/Misc/NEWS b/Misc/NEWS index 9ad45fc..4150444 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -57,6 +57,7 @@ Core and builtins - fixed a bug with bsddb.DB.stat: the flags and txn keyword arguments were transposed. + Extension Modules ----------------- @@ -83,6 +84,7 @@ Extension Modules - Make regex engine raise MemoryError if allocating memory fails. + Library ------- @@ -124,6 +126,12 @@ Library the close_fds arg to subprocess.Popen is not supported). +Tools/Demos +----------- + +- Patch #1552024: add decorator support to unparse.py demo script. + + Tests ----- -- cgit v0.12 From aabdd5480c23120eae18cdf1c45ae71814ac2eb9 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 28 Oct 2006 16:04:07 +0000 Subject: Fix nth() itertool recipe. (backport from rev. 52497) --- Doc/lib/libitertools.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index 20bbc8d..59fbd98 100644 --- a/Doc/lib/libitertools.tex +++ b/Doc/lib/libitertools.tex @@ -474,8 +474,8 @@ def iteritems(mapping): return izip(mapping.iterkeys(), mapping.itervalues()) def nth(iterable, n): - "Returns the nth item" - return list(islice(iterable, n, n+1)) + "Returns the nth item or raise IndexError" + return list(islice(iterable, n, n+1))[0] def all(seq, pred=None): "Returns True if pred(x) is true for every element in the iterable" -- cgit v0.12 From b5fdf0da2151527b9f7625e41ac40cfdceb0f8f3 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 28 Oct 2006 21:36:37 +0000 Subject: Backport 52501: Add some asserts. In sysmodule, I think these were to try to silence some warnings from Klokwork. They verify the assumptions of the format of svn version output. The assert in the thread module helped debug a problem on HP-UX. --- Modules/threadmodule.c | 1 + Python/sysmodule.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c index 448b11c..036619a 100644 --- a/Modules/threadmodule.c +++ b/Modules/threadmodule.c @@ -25,6 +25,7 @@ typedef struct { static void lock_dealloc(lockobject *self) { + assert(self->lock_lock); /* Unlock the lock so it's safe to free it */ PyThread_acquire_lock(self->lock_lock, 0); PyThread_release_lock(self->lock_lock); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 6fbaba50..4970adf 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -983,6 +983,8 @@ svnversion_init(void) br_start = python + 8; br_end = strchr(br_start, '/'); + assert(br_end); + /* Works even for trunk, as we are in trunk/Python/sysmodule.c */ br_end2 = strchr(br_end+1, '/'); @@ -995,6 +997,8 @@ svnversion_init(void) } else if (istag || strncmp(br_start, "branches", 8) == 0) { len = br_end2 - br_start; + assert(len >= 13); + assert(len < (sizeof(patchlevel_revision) - 13)); strncpy(branch, br_start, len); branch[len] = '\0'; -- cgit v0.12 From 7e3ec048f988b08392cc04c8cb7cf4d66da11580 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 28 Oct 2006 21:37:16 +0000 Subject: Backport 52502: Fix warnings with HP's C compiler. It doesn't recognize that infinite loops are, um, infinite. These conditions should not be able to happen. --- Objects/dictobject.c | 4 ++++ Objects/setobject.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 4e82798..e127d96 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -307,6 +307,8 @@ lookdict(dictobject *mp, PyObject *key, register long hash) else if (ep->me_key == dummy && freeslot == NULL) freeslot = ep; } + assert(0); /* NOT REACHED */ + return 0; } /* @@ -366,6 +368,8 @@ lookdict_string(dictobject *mp, PyObject *key, register long hash) if (ep->me_key == dummy && freeslot == NULL) freeslot = ep; } + assert(0); /* NOT REACHED */ + return 0; } /* diff --git a/Objects/setobject.c b/Objects/setobject.c index 440b2fb..9d72b33 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -179,6 +179,8 @@ set_lookkey_string(PySetObject *so, PyObject *key, register long hash) if (entry->key == dummy && freeslot == NULL) freeslot = entry; } + assert(0); /* NOT REACHED */ + return 0; } /* -- cgit v0.12 From c975b9477b8181db2f9076be43f53ef32397319b Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 28 Oct 2006 21:37:42 +0000 Subject: Backport 52503: Fix crash in test on HP-UX. Apparently, it's not possible to delete a lock if it's held (even by the current thread). --- Modules/_testcapimodule.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index edfe8ad..b11f0ae 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -667,6 +667,9 @@ test_thread_state(PyObject *self, PyObject *args) PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */ Py_END_ALLOW_THREADS + /* Release lock we acquired above. This is required on HP-UX. */ + PyThread_release_lock(thread_done); + PyThread_free_lock(thread_done); Py_RETURN_NONE; } -- cgit v0.12 From 2f0940b6cab766f039dc22d361f52e25b22e9fa8 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 28 Oct 2006 21:38:43 +0000 Subject: Backport 52504: Fix bug #1565514, SystemError not raised on too many nested blocks. It seems like this should be a different error than SystemError, but I don't have any great ideas and SystemError was raised in 2.4 and earlier. --- Lib/test/test_syntax.py | 31 +++++++++++++++++++++++++++++++ Misc/NEWS | 2 ++ Python/compile.c | 5 ++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 521789f..4099149 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -333,6 +333,37 @@ isn't, there should be a syntax error. Traceback (most recent call last): ... SyntaxError: 'break' outside loop (, line 3) + +This should probably raise a better error than a SystemError (or none at all). +In 2.5 there was a missing exception and an assert was triggered in a debug +build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514 + + >>> while 1: + ... while 2: + ... while 3: + ... while 4: + ... while 5: + ... while 6: + ... while 8: + ... while 9: + ... while 10: + ... while 11: + ... while 12: + ... while 13: + ... while 14: + ... while 15: + ... while 16: + ... while 17: + ... while 18: + ... while 19: + ... while 20: + ... while 21: + ... while 22: + ... break + Traceback (most recent call last): + ... + SystemError: too many statically nested blocks + """ import re diff --git a/Misc/NEWS b/Misc/NEWS index 4150444..f47c4e9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1565514, SystemError not raised on too many nested blocks. + - Bug #1576174: WindowsError now displays the windows error code again, no longer the posix error code. diff --git a/Python/compile.c b/Python/compile.c index 038bc2f..8be3d79 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3738,8 +3738,11 @@ static int compiler_push_fblock(struct compiler *c, enum fblocktype t, basicblock *b) { struct fblockinfo *f; - if (c->u->u_nfblocks >= CO_MAXBLOCKS) + if (c->u->u_nfblocks >= CO_MAXBLOCKS) { + PyErr_SetString(PyExc_SystemError, + "too many statically nested blocks"); return 0; + } f = &c->u->u_fblock[c->u->u_nfblocks++]; f->fb_type = t; f->fb_block = b; -- cgit v0.12 From e0cf624747a35a6db2f632607e7788b8e66d0954 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 28 Oct 2006 21:39:10 +0000 Subject: Backport 52505: Prevent crash if alloc of garbage fails. Found by Typo.pl. --- Objects/listobject.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Objects/listobject.c b/Objects/listobject.c index 7afea12..739a571 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2606,6 +2606,11 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) garbage = (PyObject**) PyMem_MALLOC(slicelength*sizeof(PyObject*)); + if (!garbage) { + Py_DECREF(seq); + PyErr_NoMemory(); + return -1; + } selfitems = self->ob_item; seqitems = PySequence_Fast_ITEMS(seq); -- cgit v0.12 From ca63121553ac1ce98d7c2608e99fc813651524d3 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 28 Oct 2006 21:39:31 +0000 Subject: Backport 52506: Don't inline Py_ADDRESS_IN_RANGE with gcc 4+ either. --- Objects/obmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 0ca8f2b..840570e 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -691,7 +691,8 @@ extremely desirable that it be this fast. #undef Py_ADDRESS_IN_RANGE -#if defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) +#if defined(__GNUC__) && ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) || \ + (__GNUC__ >= 4)) #define Py_NO_INLINE __attribute__((__noinline__)) #else #define Py_NO_INLINE -- cgit v0.12 From 7f2075a490718c0fbdbddcb806a4319b9c04db9f Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 28 Oct 2006 22:13:22 +0000 Subject: From SF 1557890, fix problem of using wrong type in example. --- Doc/lib/libctypes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libctypes.tex b/Doc/lib/libctypes.tex index b2e488a..5f486d4 100755 --- a/Doc/lib/libctypes.tex +++ b/Doc/lib/libctypes.tex @@ -1821,7 +1821,7 @@ Here is the wrapping with \code{ctypes}: \begin{quote} \begin{verbatim}>>> from ctypes import c_int, WINFUNCTYPE, windll >>> from ctypes.wintypes import HWND, LPCSTR, UINT ->>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, c_uint) +>>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT) >>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0) >>> MessageBox = prototype(("MessageBoxA", windll.user32), paramflags) >>>\end{verbatim} -- cgit v0.12 From 2a5a3027f23a2c03e20e1c382be08ebb390f3ea7 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 08:39:27 +0000 Subject: Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and fix all codecs file wrappers to work correctly with the "with" statement (bug #1586513). (backport from rev. 52517) --- Lib/codecs.py | 33 ++++++++++++++++++++++++++++++--- Lib/test/test_codecs.py | 30 +++++++++++++++++++++++++++++- Misc/NEWS | 4 ++++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/Lib/codecs.py b/Lib/codecs.py index 1518d75..f834b8d 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -329,6 +329,12 @@ class StreamWriter(Codec): """ return getattr(self.stream, name) + def __enter__(self): + return self + + def __exit__(self, type, value, tb): + self.stream.close() + ### class StreamReader(Codec): @@ -568,6 +574,12 @@ class StreamReader(Codec): """ return getattr(self.stream, name) + def __enter__(self): + return self + + def __exit__(self, type, value, tb): + self.stream.close() + ### class StreamReaderWriter: @@ -641,6 +653,14 @@ class StreamReaderWriter: """ return getattr(self.stream, name) + # these are needed to make "with codecs.open(...)" work properly + + def __enter__(self): + return self + + def __exit__(self, type, value, tb): + self.stream.close() + ### class StreamRecoder: @@ -751,6 +771,12 @@ class StreamRecoder: """ return getattr(self.stream, name) + def __enter__(self): + return self + + def __exit__(self, type, value, tb): + self.stream.close() + ### Shortcuts def open(filename, mode='rb', encoding=None, errors='strict', buffering=1): @@ -824,9 +850,10 @@ def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'): """ if file_encoding is None: file_encoding = data_encoding - info = lookup(data_encoding) - sr = StreamRecoder(file, info.encode, info.decode, - info.streamreader, info.streamwriter, errors) + data_info = lookup(data_encoding) + file_info = lookup(file_encoding) + sr = StreamRecoder(file, data_info.encode, data_info.decode, + file_info.streamreader, file_info.streamwriter, errors) # Add attributes to simplify introspection sr.data_encoding = data_encoding sr.file_encoding = file_encoding diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 8153979..90340bb 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1,3 +1,4 @@ +from __future__ import with_statement from test import test_support import unittest import codecs @@ -910,6 +911,18 @@ class StreamReaderTest(unittest.TestCase): f = self.reader(self.stream) self.assertEquals(f.readlines(), [u'\ud55c\n', u'\uae00']) +class EncodedFileTest(unittest.TestCase): + + def test_basic(self): + f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80') + ef = codecs.EncodedFile(f, 'utf-16', 'utf-8') + self.assertEquals(ef.read(), '\xff\xfe\\\xd5\n\x00\x00\xae') + + f = StringIO.StringIO() + ef = codecs.EncodedFile(f, 'utf-8', 'latin1') + ef.write('\xc3\xbc') + self.assertEquals(f.getvalue(), '\xfc') + class Str2StrTest(unittest.TestCase): def test_read(self): @@ -1214,6 +1227,19 @@ class CharmapTest(unittest.TestCase): (u"", len(allbytes)) ) +class WithStmtTest(unittest.TestCase): + def test_encodedfile(self): + f = StringIO.StringIO("\xc3\xbc") + with codecs.EncodedFile(f, "latin-1", "utf-8") as ef: + self.assertEquals(ef.read(), "\xfc") + + def test_streamreaderwriter(self): + f = StringIO.StringIO("\xc3\xbc") + info = codecs.lookup("utf-8") + with codecs.StreamReaderWriter(f, info.streamreader, + info.streamwriter, 'strict') as srw: + self.assertEquals(srw.read(), u"\xfc") + def test_main(): test_support.run_unittest( @@ -1234,10 +1260,12 @@ def test_main(): IDNACodecTest, CodecsModuleTest, StreamReaderTest, + EncodedFileTest, Str2StrTest, BasicUnicodeTest, BasicStrTest, - CharmapTest + CharmapTest, + WithStmtTest, ) diff --git a/Misc/NEWS b/Misc/NEWS index f47c4e9..b8a6f7e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -90,6 +90,10 @@ Extension Modules Library ------- +- Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and + fix all codecs file wrappers to work correctly with the "with" + statement (bug #1586513). + - ctypes callback functions only support 'fundamental' data types as result type. Raise an error when something else is used. This is a partial fix for Bug #1574584. -- cgit v0.12 From 0d3de7612cec5b8613142d517c3bc04906433967 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 09:05:08 +0000 Subject: Bug #1357915: allow all sequence types for shell arguments in subprocess. (backport from rev. 52522) --- Lib/subprocess.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 7c229dc..5d79ea6 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -965,6 +965,8 @@ class Popen(object): if isinstance(args, types.StringTypes): args = [args] + else: + args = list(args) if shell: args = ["/bin/sh", "-c"] + args -- cgit v0.12 From 2527f7fee0f20946aa3162fae4ffe6181aee1eb1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 09:16:15 +0000 Subject: Patch #1583880: fix tarfile's problems with long names and posix/ GNU modes. (backport from rev. 52524) --- Lib/tarfile.py | 169 +++++++++++++++++++++++++++------------------------------ Misc/NEWS | 3 + 2 files changed, 84 insertions(+), 88 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 7c140da..b5f9f30 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -49,6 +49,7 @@ import stat import errno import time import struct +import copy if sys.platform == 'mac': # This module needs work for MacOS9, especially in the area of pathname @@ -793,7 +794,6 @@ class TarInfo(object): """Construct a TarInfo object. name is the optional name of the member. """ - self.name = name # member name (dirnames must end with '/') self.mode = 0666 # file permissions self.uid = 0 # user id @@ -807,8 +807,6 @@ class TarInfo(object): self.gname = "group" # group name self.devmajor = 0 # device major number self.devminor = 0 # device minor number - self.prefix = "" # prefix to filename or information - # about sparse files self.offset = 0 # the tar header starts here self.offset_data = 0 # the file's data starts here @@ -840,24 +838,70 @@ class TarInfo(object): tarinfo.gname = buf[297:329].rstrip(NUL) tarinfo.devmajor = nti(buf[329:337]) tarinfo.devminor = nti(buf[337:345]) - tarinfo.prefix = buf[345:500] + prefix = buf[345:500].rstrip(NUL) + + if prefix and not tarinfo.issparse(): + tarinfo.name = prefix + "/" + tarinfo.name if tarinfo.chksum not in calc_chksums(buf): raise ValueError("invalid header") return tarinfo def tobuf(self, posix=False): - """Return a tar header block as a 512 byte string. + """Return a tar header as a string of 512 byte blocks. """ + buf = "" + type = self.type + prefix = "" + + if self.name.endswith("/"): + type = DIRTYPE + + name = normpath(self.name) + + if type == DIRTYPE: + # directories should end with '/' + name += "/" + + linkname = self.linkname + if linkname: + # if linkname is empty we end up with a '.' + linkname = normpath(linkname) + + if posix: + if self.size > MAXSIZE_MEMBER: + raise ValueError("file is too large (>= 8 GB)") + + if len(self.linkname) > LENGTH_LINK: + raise ValueError("linkname is too long (>%d)" % (LENGTH_LINK)) + + if len(name) > LENGTH_NAME: + prefix = name[:LENGTH_PREFIX + 1] + while prefix and prefix[-1] != "/": + prefix = prefix[:-1] + + name = name[len(prefix):] + prefix = prefix[:-1] + + if not prefix or len(name) > LENGTH_NAME: + raise ValueError("name is too long") + + else: + if len(self.linkname) > LENGTH_LINK: + buf += self._create_gnulong(self.linkname, GNUTYPE_LONGLINK) + + if len(name) > LENGTH_NAME: + buf += self._create_gnulong(name, GNUTYPE_LONGNAME) + parts = [ - stn(self.name, 100), + stn(name, 100), itn(self.mode & 07777, 8, posix), itn(self.uid, 8, posix), itn(self.gid, 8, posix), itn(self.size, 12, posix), itn(self.mtime, 12, posix), " ", # checksum field - self.type, + type, stn(self.linkname, 100), stn(MAGIC, 6), stn(VERSION, 2), @@ -865,15 +909,38 @@ class TarInfo(object): stn(self.gname, 32), itn(self.devmajor, 8, posix), itn(self.devminor, 8, posix), - stn(self.prefix, 155) + stn(prefix, 155) ] - buf = struct.pack("%ds" % BLOCKSIZE, "".join(parts)) + buf += struct.pack("%ds" % BLOCKSIZE, "".join(parts)) chksum = calc_chksums(buf)[0] - buf = buf[:148] + "%06o\0" % chksum + buf[155:] + buf = buf[:-364] + "%06o\0" % chksum + buf[-357:] self.buf = buf return buf + def _create_gnulong(self, name, type): + """Create a GNU longname/longlink header from name. + It consists of an extended tar header, with the length + of the longname as size, followed by data blocks, + which contain the longname as a null terminated string. + """ + name += NUL + + tarinfo = self.__class__() + tarinfo.name = "././@LongLink" + tarinfo.type = type + tarinfo.mode = 0 + tarinfo.size = len(name) + + # create extended header + buf = tarinfo.tobuf() + # create name blocks + buf += name + blocks, remainder = divmod(len(name), BLOCKSIZE) + if remainder > 0: + buf += (BLOCKSIZE - remainder) * NUL + return buf + def isreg(self): return self.type in REGULAR_TYPES def isfile(self): @@ -1377,50 +1444,11 @@ class TarFile(object): """ self._check("aw") - tarinfo.name = normpath(tarinfo.name) - if tarinfo.isdir(): - # directories should end with '/' - tarinfo.name += "/" - - if tarinfo.linkname: - tarinfo.linkname = normpath(tarinfo.linkname) - - if tarinfo.size > MAXSIZE_MEMBER: - if self.posix: - raise ValueError("file is too large (>= 8 GB)") - else: - self._dbg(2, "tarfile: Created GNU tar largefile header") - - - if len(tarinfo.linkname) > LENGTH_LINK: - if self.posix: - raise ValueError("linkname is too long (>%d)" % (LENGTH_LINK)) - else: - self._create_gnulong(tarinfo.linkname, GNUTYPE_LONGLINK) - tarinfo.linkname = tarinfo.linkname[:LENGTH_LINK -1] - self._dbg(2, "tarfile: Created GNU tar extension LONGLINK") - - if len(tarinfo.name) > LENGTH_NAME: - if self.posix: - prefix = tarinfo.name[:LENGTH_PREFIX + 1] - while prefix and prefix[-1] != "/": - prefix = prefix[:-1] - - name = tarinfo.name[len(prefix):] - prefix = prefix[:-1] - - if not prefix or len(name) > LENGTH_NAME: - raise ValueError("name is too long (>%d)" % (LENGTH_NAME)) - - tarinfo.name = name - tarinfo.prefix = prefix - else: - self._create_gnulong(tarinfo.name, GNUTYPE_LONGNAME) - tarinfo.name = tarinfo.name[:LENGTH_NAME - 1] - self._dbg(2, "tarfile: Created GNU tar extension LONGNAME") + tarinfo = copy.copy(tarinfo) - self.fileobj.write(tarinfo.tobuf(self.posix)) - self.offset += BLOCKSIZE + buf = tarinfo.tobuf(self.posix) + self.fileobj.write(buf) + self.offset += len(buf) # If there's data to follow, append it. if fileobj is not None: @@ -1779,12 +1807,6 @@ class TarFile(object): if tarinfo.isreg() and tarinfo.name.endswith("/"): tarinfo.type = DIRTYPE - # The prefix field is used for filenames > 100 in - # the POSIX standard. - # name = prefix + '/' + name - tarinfo.name = normpath(os.path.join(tarinfo.prefix.rstrip(NUL), - tarinfo.name)) - # Directory names should have a '/' at the end. if tarinfo.isdir(): tarinfo.name += "/" @@ -1909,10 +1931,6 @@ class TarFile(object): self.offset += self._block(tarinfo.size) tarinfo.size = origsize - # Clear the prefix field so that it is not used - # as a pathname in next(). - tarinfo.prefix = "" - return tarinfo #-------------------------------------------------------------------------- @@ -1970,31 +1988,6 @@ class TarFile(object): else: return TarIter(self) - def _create_gnulong(self, name, type): - """Write a GNU longname/longlink member to the TarFile. - It consists of an extended tar header, with the length - of the longname as size, followed by data blocks, - which contain the longname as a null terminated string. - """ - name += NUL - - tarinfo = TarInfo() - tarinfo.name = "././@LongLink" - tarinfo.type = type - tarinfo.mode = 0 - tarinfo.size = len(name) - - # write extended header - self.fileobj.write(tarinfo.tobuf()) - self.offset += BLOCKSIZE - # write name blocks - self.fileobj.write(name) - blocks, remainder = divmod(tarinfo.size, BLOCKSIZE) - if remainder > 0: - self.fileobj.write(NUL * (BLOCKSIZE - remainder)) - blocks += 1 - self.offset += blocks * BLOCKSIZE - def _dbg(self, level, msg): """Write debugging output to sys.stderr. """ diff --git a/Misc/NEWS b/Misc/NEWS index b8a6f7e..fc613c6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -90,6 +90,9 @@ Extension Modules Library ------- +- Patch #1583880: fix tarfile's problems with long names and posix/ + GNU modes. + - Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and fix all codecs file wrappers to work correctly with the "with" statement (bug #1586513). -- cgit v0.12 From b8205a11882161968fe9b67871d4000c4b3efb08 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 09:32:19 +0000 Subject: Fix the new EncodedFile test to work with big endian platforms. (backport from rev. 52527) --- Lib/test/test_codecs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 90340bb..60b8a72 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -915,7 +915,7 @@ class EncodedFileTest(unittest.TestCase): def test_basic(self): f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80') - ef = codecs.EncodedFile(f, 'utf-16', 'utf-8') + ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8') self.assertEquals(ef.read(), '\xff\xfe\\\xd5\n\x00\x00\xae') f = StringIO.StringIO() -- cgit v0.12 From c68d2cc3f2950d8132ea83bcf2c9fc1359e99a4d Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 14:39:13 +0000 Subject: Bug #1586613: fix zlib and bz2 codecs' incremental en/decoders. (backport from rev. 52529) --- Lib/encodings/bz2_codec.py | 29 +++++++++++++++++++++++++---- Lib/encodings/zlib_codec.py | 30 ++++++++++++++++++++++++++---- Lib/test/test_codecs.py | 2 ++ Misc/NEWS | 2 ++ 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Lib/encodings/bz2_codec.py b/Lib/encodings/bz2_codec.py index 81e84b6..054b36b 100644 --- a/Lib/encodings/bz2_codec.py +++ b/Lib/encodings/bz2_codec.py @@ -52,14 +52,35 @@ class Codec(codecs.Codec): return bz2_decode(input, errors) class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict'): + assert errors == 'strict' + self.errors = errors + self.compressobj = bz2.BZ2Compressor() + def encode(self, input, final=False): - assert self.errors == 'strict' - return bz2.compress(input) + if final: + c = self.compressobj.compress(input) + return c + self.compressobj.flush() + else: + return self.compressobj.compress(input) + + def reset(self): + self.compressobj = bz2.BZ2Compressor() class IncrementalDecoder(codecs.IncrementalDecoder): + def __init__(self, errors='strict'): + assert errors == 'strict' + self.errors = errors + self.decompressobj = bz2.BZ2Decompressor() + def decode(self, input, final=False): - assert self.errors == 'strict' - return bz2.decompress(input) + try: + return self.decompressobj.decompress(input) + except EOFError: + return '' + + def reset(self): + self.decompressobj = bz2.BZ2Decompressor() class StreamWriter(Codec,codecs.StreamWriter): pass diff --git a/Lib/encodings/zlib_codec.py b/Lib/encodings/zlib_codec.py index 2694f15..3419f9f 100644 --- a/Lib/encodings/zlib_codec.py +++ b/Lib/encodings/zlib_codec.py @@ -51,14 +51,36 @@ class Codec(codecs.Codec): return zlib_decode(input, errors) class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict'): + assert errors == 'strict' + self.errors = errors + self.compressobj = zlib.compressobj() + def encode(self, input, final=False): - assert self.errors == 'strict' - return zlib.compress(input) + if final: + c = self.compressobj.compress(input) + return c + self.compressobj.flush() + else: + return self.compressobj.compress(input) + + def reset(self): + self.compressobj = zlib.compressobj() class IncrementalDecoder(codecs.IncrementalDecoder): + def __init__(self, errors='strict'): + assert errors == 'strict' + self.errors = errors + self.decompressobj = zlib.decompressobj() + def decode(self, input, final=False): - assert self.errors == 'strict' - return zlib.decompress(input) + if final: + c = self.decompressobj.decompress(input) + return c + self.decompressobj.flush() + else: + return self.decompressobj.decompress(input) + + def reset(self): + self.decompressobj = zlib.decompressobj() class StreamWriter(Codec,codecs.StreamWriter): pass diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 60b8a72..e64e781 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1063,6 +1063,7 @@ broken_unicode_with_streams = [ "punycode", "unicode_internal" ] +broken_incremental_coders = broken_unicode_with_streams[:] try: import bz2 @@ -1112,6 +1113,7 @@ class BasicUnicodeTest(unittest.TestCase): decodedresult += reader.read() self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + if encoding not in broken_incremental_coders: # check incremental decoder/encoder (fetched via the Python # and C API) and iterencode()/iterdecode() try: diff --git a/Misc/NEWS b/Misc/NEWS index fc613c6..7bbd688 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -90,6 +90,8 @@ Extension Modules Library ------- +- Bug #1586613: fix zlib and bz2 codecs' incremental en/decoders. + - Patch #1583880: fix tarfile's problems with long names and posix/ GNU modes. -- cgit v0.12 From f96b162b683543f076c67d97d1d86d38c3c215eb Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 15:22:43 +0000 Subject: I thought I had already fixed this error in the test. --- Lib/test/test_codecs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index e64e781..62cd163 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -916,7 +916,7 @@ class EncodedFileTest(unittest.TestCase): def test_basic(self): f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80') ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8') - self.assertEquals(ef.read(), '\xff\xfe\\\xd5\n\x00\x00\xae') + self.assertEquals(ef.read(), '\\\xd5\n\x00\x00\xae') f = StringIO.StringIO() ef = codecs.EncodedFile(f, 'utf-8', 'latin1') -- cgit v0.12 From 6dc39987c94993c4828a9668e04d92e6e4b506f3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 18:01:12 +0000 Subject: Bug #1586773: extend hashlib docstring. (backport from rev. 52532) --- Lib/hashlib.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Lib/hashlib.py b/Lib/hashlib.py index 48fc56c..3d8826f 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -18,8 +18,37 @@ md5(), sha1(), sha224(), sha256(), sha384(), and sha512() More algorithms may be available on your platform but the above are guaranteed to exist. -Choose your hash function wisely. Some have known weaknesses. +Choose your hash function wisely. Some have known collision weaknesses. sha384 and sha512 will be slow on 32 bit platforms. + +Hash objects have these methods: + - update(arg): Update the hash object with the string arg. Repeated calls + are equivalent to a single call with the concatenation of all + the arguments. + - digest(): Return the digest of the strings passed to the update() method + so far. This may contain non-ASCII characters, including + NUL bytes. + - hexdigest(): Like digest() except the digest is returned as a string of + double length, containing only hexadecimal digits. + - copy(): Return a copy (clone) of the hash object. This can be used to + efficiently compute the digests of strings that share a common + initial substring. + +For example, to obtain the digest of the string 'Nobody inspects the +spammish repetition': + + >>> import hashlib + >>> m = hashlib.md5() + >>> m.update("Nobody inspects") + >>> m.update(" the spammish repetition") + >>> m.digest() + '\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9' + +More condensed: + + >>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest() + 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' + """ -- cgit v0.12 From 5e9f94ac7a2febae674ff501dd3900844486e277 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Oct 2006 18:31:45 +0000 Subject: Bug #1576657: when setting a KeyError for a tuple key, make sure that the tuple isn't used as the "exception arguments tuple". (backport from rev. 52535) --- Lib/test/test_dict.py | 10 ++++++++++ Misc/NEWS | 3 +++ Objects/dictobject.c | 19 ++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index bbca798..218f7cc 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -444,6 +444,16 @@ class DictTest(unittest.TestCase): else: self.fail_("g[42] didn't raise KeyError") + def test_tuple_keyerror(self): + # SF #1576657 + d = {} + try: + d[(1,)] + except KeyError, e: + self.assertEqual(e.args, ((1,),)) + else: + self.fail("missing KeyError") + from test import mapping_tests diff --git a/Misc/NEWS b/Misc/NEWS index 7bbd688..f007dd3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1576657: when setting a KeyError for a tuple key, make sure that + the tuple isn't used as the "exception arguments tuple". + - Bug #1565514, SystemError not raised on too many nested blocks. - Bug #1576174: WindowsError now displays the windows error code diff --git a/Objects/dictobject.c b/Objects/dictobject.c index e127d96..1fcfe1c 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -12,6 +12,19 @@ typedef PyDictEntry dictentry; typedef PyDictObject dictobject; +/* Set a key error with the specified argument, wrapping it in a + * tuple automatically so that tuple keys are not unpacked as the + * exception arguments. */ +static void +set_key_error(PyObject *arg) +{ + PyObject *tup; + tup = PyTuple_Pack(1, arg); + if (!tup) + return; /* caller will expect error to be set anyway */ + PyErr_SetObject(PyExc_KeyError, tup); +} + /* Define this out if you don't want conversion statistics on exit. */ #undef SHOW_CONVERSION_COUNTS @@ -665,7 +678,7 @@ PyDict_DelItem(PyObject *op, PyObject *key) if (ep == NULL) return -1; if (ep->me_value == NULL) { - PyErr_SetObject(PyExc_KeyError, key); + set_key_error(key); return -1; } old_key = ep->me_key; @@ -974,7 +987,7 @@ dict_subscript(dictobject *mp, register PyObject *key) return PyObject_CallFunctionObjArgs(missing, (PyObject *)mp, key, NULL); } - PyErr_SetObject(PyExc_KeyError, key); + set_key_error(key); return NULL; } else @@ -1746,7 +1759,7 @@ dict_pop(dictobject *mp, PyObject *args) Py_INCREF(deflt); return deflt; } - PyErr_SetObject(PyExc_KeyError, key); + set_key_error(key); return NULL; } old_key = ep->me_key; -- cgit v0.12 From ae6b84184b8de1a07f0ff3e8712f5130f88a4d63 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sun, 29 Oct 2006 23:42:59 +0000 Subject: Fix refleak --- Objects/dictobject.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 1fcfe1c..5a5f860 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -23,6 +23,7 @@ set_key_error(PyObject *arg) if (!tup) return; /* caller will expect error to be set anyway */ PyErr_SetObject(PyExc_KeyError, tup); + Py_DECREF(tup); } /* Define this out if you don't want conversion statistics on exit. */ -- cgit v0.12 From 906681b4d6373931cd6c4e0834b65ba3ece64bce Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Thu, 2 Nov 2006 19:52:43 +0000 Subject: Replace the XXX marker in the 'Arrays and pointers' reference manual section with a link to the tutorial sections. Backported from trunk. --- Doc/lib/libctypes.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/lib/libctypes.tex b/Doc/lib/libctypes.tex index 5f486d4..2bae25b 100755 --- a/Doc/lib/libctypes.tex +++ b/Doc/lib/libctypes.tex @@ -2440,5 +2440,6 @@ attributes for names not present in \member{{\_}fields{\_}}. \subsubsection{Arrays and pointers\label{ctypes-arrays-pointers}} -XXX +Not yet written - please see section~\ref{ctypes-pointers}, pointers and +section~\ref{ctypes-arrays}, arrays in the tutorial. -- cgit v0.12 From 5aafe92822e1358222d15981c167491caed35c9f Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Thu, 2 Nov 2006 20:24:26 +0000 Subject: Fix code example by adding a missing import. Fixes #1557890. Backported from trunk. --- Doc/lib/libctypes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libctypes.tex b/Doc/lib/libctypes.tex index 2bae25b..8474a44 100755 --- a/Doc/lib/libctypes.tex +++ b/Doc/lib/libctypes.tex @@ -1848,7 +1848,7 @@ GetWindowRect( Here is the wrapping with \code{ctypes}: \begin{quote} -\begin{verbatim}>>> from ctypes import POINTER, WINFUNCTYPE, windll +\begin{verbatim}>>> from ctypes import POINTER, WINFUNCTYPE, windll, WinError >>> from ctypes.wintypes import BOOL, HWND, RECT >>> prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT)) >>> paramflags = (1, "hwnd"), (2, "lprect") -- cgit v0.12 From 56602a14e63ef610d45a4f443c3b7410453895e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 4 Nov 2006 18:14:22 +0000 Subject: Patch #1060577: Extract list of RPM files from spec file in bdist_rpm --- Lib/distutils/command/bdist_rpm.py | 60 ++++++++++++++++++++++---------------- Misc/NEWS | 3 ++ 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/Lib/distutils/command/bdist_rpm.py b/Lib/distutils/command/bdist_rpm.py index 5b09965..03ef070 100644 --- a/Lib/distutils/command/bdist_rpm.py +++ b/Lib/distutils/command/bdist_rpm.py @@ -337,37 +337,47 @@ class bdist_rpm (Command): if not self.keep_temp: rpm_cmd.append('--clean') rpm_cmd.append(spec_path) + # Determine the binary rpm names that should be built out of this spec + # file + # Note that some of these may not be really built (if the file + # list is empty) + nvr_string = "%{name}-%{version}-%{release}" + src_rpm = nvr_string + ".src.rpm" + non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm" + q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % ( + src_rpm, non_src_rpm, spec_path) + + out = os.popen(q_cmd) + binary_rpms = [] + source_rpm = None + while 1: + line = out.readline() + if not line: + break + l = string.split(string.strip(line)) + assert(len(l) == 2) + binary_rpms.append(l[1]) + # The source rpm is named after the first entry in the spec file + if source_rpm is None: + source_rpm = l[0] + + status = out.close() + if status: + raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) + self.spawn(rpm_cmd) - # XXX this is a nasty hack -- we really should have a proper way to - # find out the names of the RPM files created; also, this assumes - # that RPM creates exactly one source and one binary RPM. if not self.dry_run: if not self.binary_only: - srpms = glob.glob(os.path.join(rpm_dir['SRPMS'], "*.rpm")) - assert len(srpms) == 1, \ - "unexpected number of SRPM files found: %s" % srpms - dist_file = ('bdist_rpm', 'any', - self._dist_path(srpms[0])) - self.distribution.dist_files.append(dist_file) - self.move_file(srpms[0], self.dist_dir) + srpm = os.path.join(rpm_dir['SRPMS'], source_rpm) + assert(os.path.exists(srpm)) + self.move_file(srpm, self.dist_dir) if not self.source_only: - rpms = glob.glob(os.path.join(rpm_dir['RPMS'], "*/*.rpm")) - debuginfo = glob.glob(os.path.join(rpm_dir['RPMS'], - "*/*debuginfo*.rpm")) - if debuginfo: - rpms.remove(debuginfo[0]) - assert len(rpms) == 1, \ - "unexpected number of RPM files found: %s" % rpms - dist_file = ('bdist_rpm', get_python_version(), - self._dist_path(rpms[0])) - self.distribution.dist_files.append(dist_file) - self.move_file(rpms[0], self.dist_dir) - if debuginfo: - dist_file = ('bdist_rpm', get_python_version(), - self._dist_path(debuginfo[0])) - self.move_file(debuginfo[0], self.dist_dir) + for rpm in binary_rpms: + rpm = os.path.join(rpm_dir['RPMS'], rpm) + if os.path.exists(rpm): + self.move_file(rpm, self.dist_dir) # run() def _dist_path(self, path): diff --git a/Misc/NEWS b/Misc/NEWS index f007dd3..8db0bc4 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -93,6 +93,9 @@ Extension Modules Library ------- +- Patch #1060577: Extract list of RPM files from spec file in + bdist_rpm + - Bug #1586613: fix zlib and bz2 codecs' incremental en/decoders. - Patch #1583880: fix tarfile's problems with long names and posix/ -- cgit v0.12 From a3ce6aa8b73ef32865c5d42fea61d045e3ce8d4e Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sat, 4 Nov 2006 19:32:54 +0000 Subject: Backport 52621: Bug #1588287: fix invalid assertion for `1,2` in debug builds. --- Lib/test/test_grammar.py | 1 + Misc/NEWS | 2 ++ Python/ast.c | 1 + 3 files changed, 4 insertions(+) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index c39e416..76483f6 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -709,6 +709,7 @@ x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6} x = `x` x = `1 or 2 or 3` +x = `1,2` x = x x = 'x' x = 123 diff --git a/Misc/NEWS b/Misc/NEWS index 8db0bc4..9631d4f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1588287: fix invalid assertion for `1,2` in debug builds. + - Bug #1576657: when setting a KeyError for a tuple key, make sure that the tuple isn't used as the "exception arguments tuple". diff --git a/Python/ast.c b/Python/ast.c index 52c098f..6551063 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -538,6 +538,7 @@ seq_for_testlist(struct compiling *c, const node *n) || TYPE(n) == listmaker || TYPE(n) == testlist_gexp || TYPE(n) == testlist_safe + || TYPE(n) == testlist1 ); seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); -- cgit v0.12 From da65c6496d0f28b704f32d1788b2f9c0a95d852d Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Mon, 6 Nov 2006 14:35:34 +0000 Subject: backport: note that user can control directory location even if default dir is used --- Doc/lib/libtempfile.tex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/lib/libtempfile.tex b/Doc/lib/libtempfile.tex index 9da8663..9b4d848 100644 --- a/Doc/lib/libtempfile.tex +++ b/Doc/lib/libtempfile.tex @@ -86,7 +86,12 @@ If \var{prefix} is specified, the file name will begin with that prefix; otherwise, a default prefix is used. If \var{dir} is specified, the file will be created in that directory; -otherwise, a default directory is used. +otherwise, a default directory is used. The default directory is chosen +from a platform-dependent list, but the user of the application can control +the directory location by setting the \var{TMPDIR}, \var{TEMP} or \var{TMP} +environment variables. There is thus no guarantee that the generated +filename will have any nice properties, such as not requiring quoting when +passed to external commands via \code{os.popen()}. If \var{text} is specified, it indicates whether to open the file in binary mode (the default) or text mode. On some platforms, this makes -- cgit v0.12 From 72e405b769884cbbf1f6a558dfffc1d6d68af010 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Tue, 7 Nov 2006 15:54:38 +0000 Subject: backport of revision 52644 --- Mac/BuildScript/build-installer.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index 69241d2..75cbf0a 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -33,7 +33,7 @@ except ImportError: def shellQuote(value): """ - Return the string value in a form that can savely be inserted into + Return the string value in a form that can safely be inserted into a shell command. """ return "'%s'"%(value.replace("'", "'\"'\"'")) @@ -56,10 +56,10 @@ def getFullVersion(): raise RuntimeError, "Cannot find full version??" -# The directory we'll use to create the build, will be erased and recreated +# The directory we'll use to create the build (will be erased and recreated) WORKDIR="/tmp/_py" -# The directory we'll use to store third-party sources, set this to something +# The directory we'll use to store third-party sources. Set this to something # else if you don't want to re-fetch required libraries every time. DEPSRC=os.path.join(WORKDIR, 'third-party') DEPSRC=os.path.expanduser('~/Universal/other-sources') @@ -201,7 +201,7 @@ PKG_RECIPES=[ long_name="GUI Applications", source="/Applications/MacPython %(VER)s", readme="""\ - This package installs IDLE (an interactive Python IDLE), + This package installs IDLE (an interactive Python IDE), Python Launcher and Build Applet (create application bundles from python scripts). @@ -257,8 +257,7 @@ PKG_RECIPES=[ readme="""\ This package updates the system python installation on Mac OS X 10.3 to ensure that you can build new python extensions - using that copy of python after installing this version of - python. + using that copy of python after installing this version. """, postflight="../Tools/fixapplepython23.py", topdir="/Library/Frameworks/Python.framework", @@ -637,15 +636,15 @@ def buildPython(): print "Running make" runCommand("make") - print "Runing make frameworkinstall" + print "Running make frameworkinstall" runCommand("make frameworkinstall DESTDIR=%s"%( shellQuote(rootDir))) - print "Runing make frameworkinstallextras" + print "Running make frameworkinstallextras" runCommand("make frameworkinstallextras DESTDIR=%s"%( shellQuote(rootDir))) - print "Copy required shared libraries" + print "Copying required shared libraries" if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): runCommand("mv %s/* %s"%( shellQuote(os.path.join( @@ -735,8 +734,8 @@ def patchScript(inPath, outPath): def packageFromRecipe(targetDir, recipe): curdir = os.getcwd() try: - # The major version (such as 2.5) is included in the pacakge name - # because haveing two version of python installed at the same time is + # The major version (such as 2.5) is included in the package name + # because having two version of python installed at the same time is # common. pkgname = '%s-%s'%(recipe['name'], getVersion()) srcdir = recipe.get('source') @@ -910,7 +909,7 @@ def installSize(clear=False, _saved=[]): def buildDMG(): """ - Create DMG containing the rootDir + Create DMG containing the rootDir. """ outdir = os.path.join(WORKDIR, 'diskimage') if os.path.exists(outdir): @@ -923,7 +922,7 @@ def buildDMG(): imagepath = imagepath + '.dmg' os.mkdir(outdir) - runCommand("hdiutil create -volname 'Univeral MacPython %s' -srcfolder %s %s"%( + runCommand("hdiutil create -volname 'Universal MacPython %s' -srcfolder %s %s"%( getFullVersion(), shellQuote(os.path.join(WORKDIR, 'installer')), shellQuote(imagepath))) -- cgit v0.12 From 27021f1cb8e0c8c60a315a101a364bd6a09ff2e7 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Tue, 7 Nov 2006 18:23:14 +0000 Subject: Fix markup and grammatical errors. Backport from trunk --- Doc/lib/libctypes.tex | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Doc/lib/libctypes.tex b/Doc/lib/libctypes.tex index 8474a44..c0e2310 100755 --- a/Doc/lib/libctypes.tex +++ b/Doc/lib/libctypes.tex @@ -2299,12 +2299,10 @@ Windows only: Represents a \class{HRESULT} value, which contains success or error information for a function or method call. \end{classdesc*} -\code{py{\_}object} : classdesc* -\begin{quote} - -Represents the C \code{PyObject *} datatype. Calling this with an -without an argument creates a \code{NULL} \code{PyObject *} pointer. -\end{quote} +\begin{classdesc*}{py_object} +Represents the C \code{PyObject *} datatype. Calling this without an +argument creates a \code{NULL} \code{PyObject *} pointer. +\end{classdesc*} The \code{ctypes.wintypes} module provides quite some other Windows specific data types, for example \code{HWND}, \code{WPARAM}, or \code{DWORD}. -- cgit v0.12 From cf1e760d3e91977f64336890d3dd0aa898b7fa25 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Tue, 7 Nov 2006 20:39:58 +0000 Subject: Add missing word --- Doc/whatsnew/whatsnew25.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/whatsnew25.tex b/Doc/whatsnew/whatsnew25.tex index 33b7c0c..9affb7f 100644 --- a/Doc/whatsnew/whatsnew25.tex +++ b/Doc/whatsnew/whatsnew25.tex @@ -540,7 +540,7 @@ Traceback (most recent call last): StopIteration \end{verbatim} -\keyword{yield} will usually return \constant{None}, you +\keyword{yield} will usually return \constant{None}, so you should always check for this case. Don't just use its value in expressions unless you're sure that the \method{send()} method will be the only method used to resume your generator function. -- cgit v0.12 From a1e3422205333a15c8f90c09c0883cf5e5139145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Wed, 8 Nov 2006 06:46:49 +0000 Subject: Correctly forward exception in instance_contains(). Fixes #1591996. Patch contributed by Neal Norwitz. --- Lib/test/test_class.py | 8 ++++++++ Misc/NEWS | 2 ++ Objects/classobject.c | 10 ++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 6c91deb..26b8e7a 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -172,6 +172,14 @@ testme ^ 1 # List/dict operations +class Empty: pass + +try: + 1 in Empty() + print 'failed, should have raised TypeError' +except TypeError: + pass + 1 in testme testme[1] diff --git a/Misc/NEWS b/Misc/NEWS index 9631d4f..5c575c9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1591996: Correctly forward exception in instance_contains(). + - Bug #1588287: fix invalid assertion for `1,2` in debug builds. - Bug #1576657: when setting a KeyError for a tuple key, make sure that diff --git a/Objects/classobject.c b/Objects/classobject.c index 7680a3d..8560b68 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -1318,15 +1318,17 @@ instance_contains(PyInstanceObject *inst, PyObject *member) /* Couldn't find __contains__. */ if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + Py_ssize_t rc; /* Assume the failure was simply due to that there is no * __contains__ attribute, and try iterating instead. */ PyErr_Clear(); - return _PySequence_IterSearch((PyObject *)inst, member, - PY_ITERSEARCH_CONTAINS) > 0; + rc = _PySequence_IterSearch((PyObject *)inst, member, + PY_ITERSEARCH_CONTAINS); + if (rc >= 0) + return rc > 0; } - else - return -1; + return -1; } static PySequenceMethods -- cgit v0.12 From 082f14b61c567f9f54fbfad69d5fb35857ead72c Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 8 Nov 2006 07:46:01 +0000 Subject: Patch #1592072: fix docs for return value of PyErr_CheckSignals. (backport from rev. 52666) --- Doc/api/exceptions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/api/exceptions.tex b/Doc/api/exceptions.tex index 057c1da..2dabeee 100644 --- a/Doc/api/exceptions.tex +++ b/Doc/api/exceptions.tex @@ -328,7 +328,7 @@ for each thread. default effect for \constant{SIGINT}\ttindex{SIGINT} is to raise the \withsubitem{(built-in exception)}{\ttindex{KeyboardInterrupt}} \exception{KeyboardInterrupt} exception. If an exception is raised - the error indicator is set and the function returns \code{1}; + the error indicator is set and the function returns \code{-1}; otherwise the function returns \code{0}. The error indicator may or may not be cleared if it was previously set. \end{cfuncdesc} -- cgit v0.12 From 3ed5c2a277fcc2da2b52aa923e32d267e4be0dd5 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 8 Nov 2006 10:04:32 +0000 Subject: Bug #1592533: rename variable in heapq doc example, to avoid shadowing "sorted". (backport from rev. 52668) --- Doc/lib/libheapq.tex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/lib/libheapq.tex b/Doc/lib/libheapq.tex index eaf7051..5f3d8c5 100644 --- a/Doc/lib/libheapq.tex +++ b/Doc/lib/libheapq.tex @@ -76,14 +76,14 @@ Example of use: >>> for item in data: ... heappush(heap, item) ... ->>> sorted = [] +>>> ordered = [] >>> while heap: -... sorted.append(heappop(heap)) +... ordered.append(heappop(heap)) ... ->>> print sorted +>>> print ordered [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> data.sort() ->>> print data == sorted +>>> print data == ordered True >>> \end{verbatim} -- cgit v0.12 From 3f63454e2258f8b187764066fca2cc2a9361b628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Thu, 9 Nov 2006 11:06:30 +0000 Subject: Patch #838546: Make terminal become controlling in pty.fork(). --- Lib/pty.py | 4 ++++ Misc/NEWS | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Lib/pty.py b/Lib/pty.py index fae162d..889113c 100644 --- a/Lib/pty.py +++ b/Lib/pty.py @@ -118,6 +118,10 @@ def fork(): if (slave_fd > STDERR_FILENO): os.close (slave_fd) + # Explicitly open the tty to make it become a controlling tty. + tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR) + os.close(tmp_fd) + # Parent and child process. return pid, master_fd diff --git a/Misc/NEWS b/Misc/NEWS index 5c575c9..6753554 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -70,6 +70,8 @@ Core and builtins Extension Modules ----------------- +- Patch #838546: Make terminal become controlling in pty.fork() + - Patch #1560695: Add .note.GNU-stack to ctypes' sysv.S so that ctypes isn't considered as requiring executable stacks. -- cgit v0.12 From d52a0b85830e22d9bde8d3d25e5b047645716497 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Thu, 9 Nov 2006 13:33:53 +0000 Subject: [Bug #1569790] mailbox.Maildir.get_folder() loses factory information Both the Maildir and MH classes had this bug; the patch fixes both classes and adds a test. --- Lib/mailbox.py | 12 ++++++++---- Lib/test/test_mailbox.py | 24 +++++++++++++++++++++++- Misc/NEWS | 4 ++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index eab03af..e66ddde 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -367,12 +367,14 @@ class Maildir(Mailbox): def get_folder(self, folder): """Return a Maildir instance for the named folder.""" - return Maildir(os.path.join(self._path, '.' + folder), create=False) + return Maildir(os.path.join(self._path, '.' + folder), + factory=self._factory, + create=False) def add_folder(self, folder): """Create a folder and return a Maildir instance representing it.""" path = os.path.join(self._path, '.' + folder) - result = Maildir(path) + result = Maildir(path, factory=self._factory) maildirfolder_path = os.path.join(path, 'maildirfolder') if not os.path.exists(maildirfolder_path): os.close(os.open(maildirfolder_path, os.O_CREAT | os.O_WRONLY)) @@ -944,11 +946,13 @@ class MH(Mailbox): def get_folder(self, folder): """Return an MH instance for the named folder.""" - return MH(os.path.join(self._path, folder), create=False) + return MH(os.path.join(self._path, folder), + factory=self._factory, create=False) def add_folder(self, folder): """Create a folder and return an MH instance representing it.""" - return MH(os.path.join(self._path, folder)) + return MH(os.path.join(self._path, folder), + factory=self._factory) def remove_folder(self, folder): """Delete the named folder, which must be empty.""" diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 40cf192..aaf4097 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -673,6 +673,19 @@ class TestMaildir(TestMailbox): self._box.lock() self._box.unlock() + def test_folder (self): + # Test for bug #1569790: verify that folders returned by .get_folder() + # use the same factory function. + def dummy_factory (s): + return None + box = self._factory(self._path, factory=dummy_factory) + folder = box.add_folder('folder1') + self.assert_(folder._factory is dummy_factory) + + folder1_alias = box.get_folder('folder1') + self.assert_(folder1_alias._factory is dummy_factory) + + class _TestMboxMMDF(TestMailbox): @@ -789,7 +802,11 @@ class TestMH(TestMailbox): def test_get_folder(self): # Open folders - self._box.add_folder('foo.bar') + def dummy_factory (s): + return None + self._box = self._factory(self._path, dummy_factory) + + new_folder = self._box.add_folder('foo.bar') folder0 = self._box.get_folder('foo.bar') folder0.add(self._template % 'bar') self.assert_(os.path.isdir(os.path.join(self._path, 'foo.bar'))) @@ -797,6 +814,11 @@ class TestMH(TestMailbox): self.assert_(folder1.get_string(folder1.keys()[0]) == \ self._template % 'bar') + # Test for bug #1569790: verify that folders returned by .get_folder() + # use the same factory function. + self.assert_(new_folder._factory is self._box._factory) + self.assert_(folder0._factory is self._box._factory) + def test_add_and_remove_folders(self): # Delete folders self._box.add_folder('one') diff --git a/Misc/NEWS b/Misc/NEWS index 6753554..8e258a4 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -133,6 +133,10 @@ Library - Bug #1565661: in webbrowser, split() the command for the default GNOME browser in case it is a command with args. +- Bug #1569790: mailbox.py: Maildir.get_folder() and MH.get_folder() + weren't passing the message factory on to newly created Maildir/MH + objects. + - Bug #1575506: Single-file mailboxes didn't re-lock properly in their flush() method. -- cgit v0.12 From f2d5c6d117db77aab41e4d54eccdb2a0afcd57b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Thu, 9 Nov 2006 16:30:39 +0000 Subject: Backport checkin: Replace C++ comment with C comment (fixes SF bug #1593525). --- Modules/unicodedata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index a11a0b7..a30d30c 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -75,7 +75,7 @@ static PyMemberDef DB_members[] = { {NULL} }; -// forward declaration +/* forward declaration */ static PyTypeObject UCD_Type; static PyObject* -- cgit v0.12 From bb876b9c69f80c253621937ad734eafef3086e5f Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 10 Nov 2006 13:08:03 +0000 Subject: [Patch #1514544 by David Watson] use fsync() to ensure data is really on disk --- Lib/mailbox.py | 30 +++++++++++++++++++++++------- Misc/NEWS | 8 ++++++-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index e66ddde..51c2ccc 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -2,6 +2,12 @@ """Read/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.""" +# Notes for authors of new mailbox subclasses: +# +# Remember to fsync() changes to disk before closing a modified file +# or returning from a flush() method. See functions _sync_flush() and +# _sync_close(). + import sys import os import time @@ -238,7 +244,7 @@ class Maildir(Mailbox): try: self._dump_message(message, tmp_file) finally: - tmp_file.close() + _sync_close(tmp_file) if isinstance(message, MaildirMessage): subdir = message.get_subdir() suffix = self.colon + message.get_info() @@ -565,7 +571,8 @@ class _singlefileMailbox(Mailbox): new_file.close() os.remove(new_file.name) raise - new_file.close() + _sync_close(new_file) + # self._file is about to get replaced, so no need to sync. self._file.close() try: os.rename(new_file.name, self._path) @@ -599,7 +606,7 @@ class _singlefileMailbox(Mailbox): self.flush() if self._locked: self.unlock() - self._file.close() + self._file.close() # Sync has been done by self.flush() above. def _lookup(self, key=None): """Return (start, stop) or raise KeyError.""" @@ -789,7 +796,7 @@ class MH(Mailbox): if self._locked: _unlock_file(f) finally: - f.close() + _sync_close(f) return new_key def remove(self, key): @@ -836,7 +843,7 @@ class MH(Mailbox): if self._locked: _unlock_file(f) finally: - f.close() + _sync_close(f) def get_message(self, key): """Return a Message representation or raise a KeyError.""" @@ -923,7 +930,7 @@ class MH(Mailbox): """Unlock the mailbox if it is locked.""" if self._locked: _unlock_file(self._file) - self._file.close() + _sync_close(self._file) del self._file self._locked = False @@ -1020,7 +1027,7 @@ class MH(Mailbox): else: f.write('\n') finally: - f.close() + _sync_close(f) def pack(self): """Re-name messages to eliminate numbering gaps. Invalidates keys.""" @@ -1874,6 +1881,15 @@ def _create_temporary(path): socket.gethostname(), os.getpid())) +def _sync_flush(f): + """Ensure changes to file f are physically on disk.""" + f.flush() + os.fsync(f.fileno()) + +def _sync_close(f): + """Close file f, ensuring all changes are physically on disk.""" + _sync_flush(f) + f.close() ## Start: classes from the original module (for backward compatibility). diff --git a/Misc/NEWS b/Misc/NEWS index 8e258a4..d91e64d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -137,8 +137,12 @@ Library weren't passing the message factory on to newly created Maildir/MH objects. -- Bug #1575506: Single-file mailboxes didn't re-lock properly in - their flush() method. +- Bug #1575506: mailbox.py: Single-file mailboxes didn't re-lock + properly in their flush() method. + +- Patch #1514544: mailbox.py: Try to ensure that messages/indexes have + been physically written to disk after calling .flush() or + .close(). (Patch by David Watson.) - Bug #1576241: fix functools.wraps() to work on built-in functions. -- cgit v0.12 From 7ea928c452e2baaa929e5a078d796ece3720e765 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 10 Nov 2006 13:15:58 +0000 Subject: [Patch #1514543] mailbox (Maildir): avoid losing messages on name clash Two changes: Where possible, use link()/remove() to move files into a directory; this makes it easier to avoid overwriting an existing file. Use _create_carefully() to create files in tmp/, which uses O_EXCL. --- Lib/mailbox.py | 27 ++++++++++++++++++++++----- Misc/NEWS | 4 ++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 51c2ccc..c6b0fa0 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -255,7 +255,19 @@ class Maildir(Mailbox): suffix = '' uniq = os.path.basename(tmp_file.name).split(self.colon)[0] dest = os.path.join(self._path, subdir, uniq + suffix) - os.rename(tmp_file.name, dest) + try: + if hasattr(os, 'link'): + os.link(tmp_file.name, dest) + os.remove(tmp_file.name) + else: + os.rename(tmp_file.name, dest) + except OSError, e: + os.remove(tmp_file.name) + if e.errno == errno.EEXIST: + raise ExternalClashError('Name clash with existing message: %s' + % dest) + else: + raise if isinstance(message, MaildirMessage): os.utime(dest, (os.path.getatime(dest), message.get_date())) return uniq @@ -431,12 +443,17 @@ class Maildir(Mailbox): except OSError, e: if e.errno == errno.ENOENT: Maildir._count += 1 - return open(path, 'wb+') + try: + return _create_carefully(path) + except OSError, e: + if e.errno != errno.EEXIST: + raise else: raise - else: - raise ExternalClashError('Name clash prevented file creation: %s' % - path) + + # Fall through to here if stat succeeded or open raised EEXIST. + raise ExternalClashError('Name clash prevented file creation: %s' % + path) def _refresh(self): """Update table of contents mapping.""" diff --git a/Misc/NEWS b/Misc/NEWS index d91e64d..d41d7cc 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -140,6 +140,10 @@ Library - Bug #1575506: mailbox.py: Single-file mailboxes didn't re-lock properly in their flush() method. +- Patch #1514543: mailbox.py: In the Maildir class, report errors if there's + a filename clash instead of possibly losing a message. (Patch by David + Watson.) + - Patch #1514544: mailbox.py: Try to ensure that messages/indexes have been physically written to disk after calling .flush() or .close(). (Patch by David Watson.) -- cgit v0.12 From 6d974784491d6894fbb69a7a8e7c45c68adbb520 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 10 Nov 2006 14:39:17 +0000 Subject: [Feature request #1542920] Link to wsgi.org --- Doc/lib/libwsgiref.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/lib/libwsgiref.tex b/Doc/lib/libwsgiref.tex index 4b12e9d..37ded9f 100755 --- a/Doc/lib/libwsgiref.tex +++ b/Doc/lib/libwsgiref.tex @@ -26,8 +26,9 @@ checks WSGI servers and applications for conformance to the WSGI specification (\pep{333}). % XXX If you're just trying to write a web application... -% XXX should create a URL on python.org to point people to. +See \url{http://www.wsgi.org} for more information about WSGI, +and links to tutorials and other resources. -- cgit v0.12 From 511350bee97d68d58aaa78fb045d4ef103dc4bfa Mon Sep 17 00:00:00 2001 From: "Phillip J. Eby" Date: Fri, 10 Nov 2006 17:13:29 +0000 Subject: Fix SF#1566719: not creating site-packages (or other target directory) when installing .egg-info for a project that contains no modules or packages, while using --root (as in bdist_rpm). (Backport from trunk) --- Lib/distutils/command/install_egg_info.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/distutils/command/install_egg_info.py b/Lib/distutils/command/install_egg_info.py index c31ac29..c888031 100644 --- a/Lib/distutils/command/install_egg_info.py +++ b/Lib/distutils/command/install_egg_info.py @@ -35,6 +35,9 @@ class install_egg_info(Command): dir_util.remove_tree(target, dry_run=self.dry_run) elif os.path.exists(target): self.execute(os.unlink,(self.target,),"Removing "+target) + elif not os.path.isdir(self.install_dir): + self.execute(os.makedirs, (self.install_dir,), + "Creating "+self.install_dir) log.info("Writing %s", target) if not self.dry_run: f = open(target, 'w') -- cgit v0.12 From c33b7488de1dcdbcff709503d7b4ada8bbc0a620 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 11 Nov 2006 18:29:15 +0000 Subject: Bug #1594742: wrong word in stringobject doc. (backport from rev. 52731) --- Doc/lib/libstdtypes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex index 84ca938..5bd6590 100644 --- a/Doc/lib/libstdtypes.tex +++ b/Doc/lib/libstdtypes.tex @@ -834,7 +834,7 @@ boundaries. Line breaks are not included in the resulting list unless start\optional{, end}}} Return \code{True} if string starts with the \var{prefix}, otherwise return \code{False}. \var{prefix} can also be a tuple of -suffixes to look for. With optional \var{start}, test string beginning at +prefixes to look for. With optional \var{start}, test string beginning at that position. With optional \var{end}, stop comparing string at that position. -- cgit v0.12 From 8fc42c8aad7fa874a1aad9a16a112c9809fe7b9c Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 11 Nov 2006 18:32:50 +0000 Subject: Bug #1594758: wording improvement for dict.update() docs. (backport from rev. 52733) --- Doc/lib/libstdtypes.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex index 5bd6590..a9fb19b 100644 --- a/Doc/lib/libstdtypes.tex +++ b/Doc/lib/libstdtypes.tex @@ -1424,7 +1424,8 @@ arbitrary objects): {(3)} \lineiii{\var{a}.keys()}{a copy of \var{a}'s list of keys}{(3)} \lineiii{\var{a}.update(\optional{\var{b}})} - {updates (and overwrites) key/value pairs from \var{b}} + {updates \var{a} with key/value pairs from \var{b}, overwriting + existing keys, returns \code{None}} {(9)} \lineiii{\var{a}.fromkeys(\var{seq}\optional{, \var{value}})} {Creates a new dictionary with keys from \var{seq} and values set to \var{value}} -- cgit v0.12 From 867ef13436d7f2e5b8895153059c5df68fd4bc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 12 Nov 2006 18:48:30 +0000 Subject: Patch #1359217: Ignore 2xx response before 150 response. --- Lib/ftplib.py | 11 +++++++++++ Misc/NEWS | 3 +++ 2 files changed, 14 insertions(+) diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 937ee4e..9cb67dd 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -325,6 +325,14 @@ class FTP: if rest is not None: self.sendcmd("REST %s" % rest) resp = self.sendcmd(cmd) + # Some servers apparently send a 200 reply to + # a LIST or STOR command, before the 150 reply + # (and way before the 226 reply). This seems to + # be in violation of the protocol (which only allows + # 1xx or error messages for LIST), so we just discard + # this response. + if resp[0] == '2': + resp = self.getresp() if resp[0] != '1': raise error_reply, resp else: @@ -332,6 +340,9 @@ class FTP: if rest is not None: self.sendcmd("REST %s" % rest) resp = self.sendcmd(cmd) + # See above. + if resp[0] == '2': + resp = self.getresp() if resp[0] != '1': raise error_reply, resp conn, sockaddr = sock.accept() diff --git a/Misc/NEWS b/Misc/NEWS index d41d7cc..d632043 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,9 @@ Extension Modules Library ------- +- Patch #1359217: Process 2xx response in an ftplib transfer + that precedes an 1xx response. + - Patch #1060577: Extract list of RPM files from spec file in bdist_rpm -- cgit v0.12 From 962e4317bc925d284d960e04ef304586cabaf479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 12 Nov 2006 18:56:18 +0000 Subject: Patch #1360200: Use unmangled_version RPM spec field to deal with file name mangling. --- Lib/distutils/command/bdist_rpm.py | 7 ++++--- Misc/NEWS | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/distutils/command/bdist_rpm.py b/Lib/distutils/command/bdist_rpm.py index 03ef070..6f0e0d8 100644 --- a/Lib/distutils/command/bdist_rpm.py +++ b/Lib/distutils/command/bdist_rpm.py @@ -391,6 +391,7 @@ class bdist_rpm (Command): spec_file = [ '%define name ' + self.distribution.get_name(), '%define version ' + self.distribution.get_version().replace('-','_'), + '%define unmangled_version ' + self.distribution.get_version(), '%define release ' + self.release.replace('-','_'), '', 'Summary: ' + self.distribution.get_description(), @@ -412,9 +413,9 @@ class bdist_rpm (Command): # but only after it has run: and we create the spec file before # running "sdist", in case of --spec-only. if self.use_bzip2: - spec_file.append('Source0: %{name}-%{version}.tar.bz2') + spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2') else: - spec_file.append('Source0: %{name}-%{version}.tar.gz') + spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz') spec_file.extend([ 'License: ' + self.distribution.get_license(), @@ -489,7 +490,7 @@ class bdist_rpm (Command): # are just text that we drop in as-is. Hmmm. script_options = [ - ('prep', 'prep_script', "%setup"), + ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"), ('build', 'build_script', def_build), ('install', 'install_script', ("%s install " diff --git a/Misc/NEWS b/Misc/NEWS index d632043..d619308 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,9 @@ Extension Modules Library ------- +- Patch #1360200: Use unmangled_version RPM spec field to deal with + file name mangling. + - Patch #1359217: Process 2xx response in an ftplib transfer that precedes an 1xx response. -- cgit v0.12 From fb4da1d7ca95ff919381fac114ae2e9a7a5323f6 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 15 Nov 2006 17:42:07 +0000 Subject: Bug #1594809: add a note to README regarding PYTHONPATH and make install. (backport from rev. 52754) --- README | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README b/README index fd5d4ff..7e4c3aa 100644 --- a/README +++ b/README @@ -223,6 +223,11 @@ old K&R-C-only compilers is no longer possible. ANSI C compilers are available for all modern systems, either in the form of updated compilers from the vendor, or one of the free compilers (gcc). +If "make install" fails mysteriously during the "compiling the library" +step, make sure that you don't have any of the PYTHONPATH or PYTHONHOME +environment variables set, as they may interfere with the newly built +executable which is compiling the library. + Unsupported systems ------------------- -- cgit v0.12 From 7563191cf6d6794c58c2ae3a4d0aa8e59f91f5db Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 16 Nov 2006 15:05:19 +0000 Subject: Bug #1597576: mention that the new base64 api has been introduced in py2.4. (backport from rev. 52762) --- Doc/lib/libbase64.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libbase64.tex b/Doc/lib/libbase64.tex index 0039c84..d7eccbd 100644 --- a/Doc/lib/libbase64.tex +++ b/Doc/lib/libbase64.tex @@ -21,7 +21,7 @@ three alphabets. The legacy interface provides for encoding and decoding to and from file-like objects as well as strings, but only using the Base64 standard alphabet. -The modern interface provides: +The modern interface, which was introduced in Python 2.4, provides: \begin{funcdesc}{b64encode}{s\optional{, altchars}} Encode a string use Base64. -- cgit v0.12 From dd3bffb679f8c76ffb1ac9a9a4a7fb515e0f4447 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 16 Nov 2006 17:08:48 +0000 Subject: Bug #1588217: don't parse "= " as a soft line break in binascii's a2b_qp() function, instead leave it in the string as quopri.decode() does. (backport from rev. 52765) --- Lib/test/test_binascii.py | 2 +- Misc/NEWS | 4 ++++ Modules/binascii.c | 3 +-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 8df4504..8272ad9 100755 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -134,7 +134,7 @@ class BinASCIITest(unittest.TestCase): pass else: self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError") - self.assertEqual(binascii.a2b_qp("= "), "") + self.assertEqual(binascii.a2b_qp("= "), "= ") self.assertEqual(binascii.a2b_qp("=="), "=") self.assertEqual(binascii.a2b_qp("=AX"), "=AX") self.assertRaises(TypeError, binascii.b2a_qp, foo="bar") diff --git a/Misc/NEWS b/Misc/NEWS index d619308..221acbb 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -70,6 +70,10 @@ Core and builtins Extension Modules ----------------- +- Bug #1588217: don't parse "= " as a soft line break in binascii's + a2b_qp() function, instead leave it in the string as quopri.decode() + does. + - Patch #838546: Make terminal become controlling in pty.fork() - Patch #1560695: Add .note.GNU-stack to ctypes' sysv.S so that diff --git a/Modules/binascii.c b/Modules/binascii.c index 3b2c8b2..4dee451 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -1057,8 +1057,7 @@ binascii_a2b_qp(PyObject *self, PyObject *args, PyObject *kwargs) in++; if (in >= datalen) break; /* Soft line breaks */ - if ((data[in] == '\n') || (data[in] == '\r') || - (data[in] == ' ') || (data[in] == '\t')) { + if ((data[in] == '\n') || (data[in] == '\r')) { if (data[in] != '\n') { while (in < datalen && data[in] != '\n') in++; } -- cgit v0.12 From 830358af099ebafe0e32fb4bcbcf931d608664b5 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 17 Nov 2006 16:16:28 +0000 Subject: Remove locking of individual message files in MH.pack(). [Backport of rev52776 from the trunk.] --- Lib/mailbox.py | 28 +++++++--------------------- Lib/test/test_mailbox.py | 15 +++++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index c6b0fa0..108d874 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1054,27 +1054,13 @@ class MH(Mailbox): for key in self.iterkeys(): if key - 1 != prev: changes.append((key, prev + 1)) - f = open(os.path.join(self._path, str(key)), 'r+') - try: - if self._locked: - _lock_file(f) - try: - if hasattr(os, 'link'): - os.link(os.path.join(self._path, str(key)), - os.path.join(self._path, str(prev + 1))) - if sys.platform == 'os2emx': - # cannot unlink an open file on OS/2 - f.close() - os.unlink(os.path.join(self._path, str(key))) - else: - f.close() - os.rename(os.path.join(self._path, str(key)), - os.path.join(self._path, str(prev + 1))) - finally: - if self._locked: - _unlock_file(f) - finally: - f.close() + if hasattr(os, 'link'): + os.link(os.path.join(self._path, str(key)), + os.path.join(self._path, str(prev + 1))) + os.unlink(os.path.join(self._path, str(key))) + else: + os.rename(os.path.join(self._path, str(key)), + os.path.join(self._path, str(prev + 1))) prev += 1 self._next_key = prev + 1 if len(changes) == 0: diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index aaf4097..264e237 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -887,6 +887,21 @@ class TestMH(TestMailbox): self.assert_(self._box.get_sequences() == {'foo':[1, 2, 3], 'unseen':[1], 'bar':[3], 'replied':[3]}) + # Test case for packing while holding the mailbox locked. + key0 = self._box.add(msg1) + key1 = self._box.add(msg1) + key2 = self._box.add(msg1) + key3 = self._box.add(msg1) + + self._box.remove(key0) + self._box.remove(key2) + self._box.lock() + self._box.pack() + self._box.unlock() + self.assert_(self._box.get_sequences() == + {'foo':[1, 2, 3, 4, 5], + 'unseen':[1], 'bar':[3], 'replied':[3]}) + def _get_lock_path(self): return os.path.join(self._path, '.mh_sequences.lock') diff --git a/Misc/NEWS b/Misc/NEWS index 221acbb..8324a05 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -158,6 +158,10 @@ Library been physically written to disk after calling .flush() or .close(). (Patch by David Watson.) +- mailbox.py: Change MH.pack() to not lock individual message files; this + wasn't consistent with existing implementations of message packing, and + was buggy on some platforms. + - Bug #1576241: fix functools.wraps() to work on built-in functions. - Patch #1574068: fix urllib/urllib2 to not insert line breaks when -- cgit v0.12 From ce9212f018fbd074aba7a37cef4291ebd2e428d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 18 Nov 2006 18:00:34 +0000 Subject: Patch #1538878: Don't make tkSimpleDialog dialogs transient if the parent window is withdrawn. This mirrors what dialog.tcl does. --- Lib/lib-tk/tkSimpleDialog.py | 7 ++++++- Misc/NEWS | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/lib-tk/tkSimpleDialog.py b/Lib/lib-tk/tkSimpleDialog.py index 4d11ce0..02ea034 100644 --- a/Lib/lib-tk/tkSimpleDialog.py +++ b/Lib/lib-tk/tkSimpleDialog.py @@ -46,8 +46,13 @@ class Dialog(Toplevel): title -- the dialog title ''' Toplevel.__init__(self, parent) - self.transient(parent) + # If the master is not viewable, don't + # make the child transient, or else it + # would be opened withdrawn + if parent.winfo_viewable(): + self.transient(parent) + if title: self.title(title) diff --git a/Misc/NEWS b/Misc/NEWS index 8324a05..6e50ed3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -103,6 +103,9 @@ Extension Modules Library ------- +- Patch #1538878: Don't make tkSimpleDialog dialogs transient if + the parent window is withdrawn. + - Patch #1360200: Use unmangled_version RPM spec field to deal with file name mangling. -- cgit v0.12 From e350c840b389f645b25f00f1fa35f6ea1fec03b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 18 Nov 2006 18:05:57 +0000 Subject: Patch #1594554: Always close a tkSimpleDialog on ok(), even if an exception occurs. --- Lib/lib-tk/tkSimpleDialog.py | 7 ++++--- Misc/NEWS | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/lib-tk/tkSimpleDialog.py b/Lib/lib-tk/tkSimpleDialog.py index 02ea034..4450484 100644 --- a/Lib/lib-tk/tkSimpleDialog.py +++ b/Lib/lib-tk/tkSimpleDialog.py @@ -129,9 +129,10 @@ class Dialog(Toplevel): self.withdraw() self.update_idletasks() - self.apply() - - self.cancel() + try: + self.apply() + finally: + self.cancel() def cancel(self, event=None): diff --git a/Misc/NEWS b/Misc/NEWS index 6e50ed3..5b98155 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -103,6 +103,9 @@ Extension Modules Library ------- +- Patch #1594554: Always close a tkSimpleDialog on ok(), even + if an exception occurs. + - Patch #1538878: Don't make tkSimpleDialog dialogs transient if the parent window is withdrawn. -- cgit v0.12 From 0e64202fd7e8802fc99fff5243b06ca4602f7f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 18 Nov 2006 18:42:22 +0000 Subject: Patch #1472877: Fix Tix subwidget name resolution. --- Lib/lib-tk/Tix.py | 5 ++++- Misc/NEWS | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/lib-tk/Tix.py b/Lib/lib-tk/Tix.py index 33ac519..b7a0fc0 100755 --- a/Lib/lib-tk/Tix.py +++ b/Lib/lib-tk/Tix.py @@ -421,7 +421,7 @@ class TixSubWidget(TixWidget): except: plist = [] - if (not check_intermediate) or len(plist) < 2: + if not check_intermediate: # immediate descendant TixWidget.__init__(self, master, None, None, {'name' : name}) else: @@ -437,6 +437,9 @@ class TixSubWidget(TixWidget): parent = TixSubWidget(parent, plist[i], destroy_physically=0, check_intermediate=0) + # The Tk widget name is in plist, not in name + if plist: + name = plist[-1] TixWidget.__init__(self, parent, None, None, {'name' : name}) self.destroy_physically = destroy_physically diff --git a/Misc/NEWS b/Misc/NEWS index 5b98155..28543f6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -103,6 +103,8 @@ Extension Modules Library ------- +- Patch #1472877: Fix Tix subwidget name resolution. + - Patch #1594554: Always close a tkSimpleDialog on ok(), even if an exception occurs. -- cgit v0.12 From 90e23c47692df172c512881d0a35a07db2a43cbf Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Mon, 20 Nov 2006 13:31:09 +0000 Subject: Add extra SHA tests --- Lib/test/test_sha.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_sha.py b/Lib/test/test_sha.py index c438cc6..ea224e4 100644 --- a/Lib/test/test_sha.py +++ b/Lib/test/test_sha.py @@ -11,9 +11,23 @@ from test import test_support class SHATestCase(unittest.TestCase): def check(self, data, digest): - computed = sha.new(data).hexdigest() + # Check digest matches the expected value + obj = sha.new(data) + computed = obj.hexdigest() self.assert_(computed == digest) + # Verify that the value doesn't change between two consecutive + # digest operations. + computed_again = obj.hexdigest() + self.assert_(computed == computed_again) + + # Check hexdigest() output matches digest()'s output + digest = obj.digest() + hexd = "" + for c in digest: + hexd += '%02x' % ord(c) + self.assert_(computed == hexd) + def test_case_1(self): self.check("abc", "a9993e364706816aba3e25717850c26c9cd0d89d") @@ -26,6 +40,9 @@ class SHATestCase(unittest.TestCase): self.check("a" * 1000000, "34aa973cd4c4daa4f61eeb2bdbad27316534016f") + def test_case_4(self): + self.check(chr(0xAA) * 80, + '4ca0ef38f1794b28a8f8ee110ee79d48ce13be25') def test_main(): test_support.run_unittest(SHATestCase) -- cgit v0.12 From bb4e6dcff51ea03a762f12a1e9c1fbdcfcdbbe38 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Mon, 20 Nov 2006 13:39:57 +0000 Subject: Jython compatibility fix: if uu.decode() opened its output file, be sure to close it. --- Lib/uu.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/uu.py b/Lib/uu.py index 3ccedb0..da89f72 100755 --- a/Lib/uu.py +++ b/Lib/uu.py @@ -114,6 +114,7 @@ def decode(in_file, out_file=None, mode=None, quiet=0): # # Open the output file # + opened = False if out_file == '-': out_file = sys.stdout elif isinstance(out_file, basestring): @@ -123,6 +124,7 @@ def decode(in_file, out_file=None, mode=None, quiet=0): except AttributeError: pass out_file = fp + opened = True # # Main decoding loop # @@ -140,6 +142,8 @@ def decode(in_file, out_file=None, mode=None, quiet=0): s = in_file.readline() if not s: raise Error('Truncated input file') + if opened: + out_file.close() def test(): """uuencode/uudecode main program""" -- cgit v0.12 From 5890a6a8a68eb5658b7002501ec30e2e30eba144 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Tue, 21 Nov 2006 05:29:34 +0000 Subject: Backport of 52811: Bug #1599782: Fix segfault on bsddb.db.DB().type(). The problem is that _DB_get_type() can't be called without the GIL because it calls a bunch of PyErr_* APIs when an error occurs. There were no other cases in this file that it was called without the GIL. Removing the BEGIN/END THREAD around _DB_get_type() made everything work. --- Lib/bsddb/test/test_dbobj.py | 4 ++++ Misc/NEWS | 2 ++ Modules/_bsddb.c | 2 -- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/bsddb/test/test_dbobj.py b/Lib/bsddb/test/test_dbobj.py index 6799fc9..af494e1 100644 --- a/Lib/bsddb/test/test_dbobj.py +++ b/Lib/bsddb/test/test_dbobj.py @@ -69,6 +69,10 @@ class dbobjTestCase(unittest.TestCase): self.db.close() self.env.close() + def test03_dbobj_type_before_open(self): + # Ensure this doesn't cause a segfault. + self.assertRaises(db.DBInvalidArgError, db.DB().type) + #---------------------------------------------------------------------- def test_suite(): diff --git a/Misc/NEWS b/Misc/NEWS index 28543f6..231004d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -276,6 +276,8 @@ Library Extension Modules ----------------- +- Bug #1599782: fix segfault on bsddb.db.DB().type(). + - Fix bugs in ctypes: - anonymous structure fields that have a bit-width specified did not work - cast function did not accept c_char_p or c_wchar_p instances as first arg diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index 9d56e27..8e343a6 100644 --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -1779,9 +1779,7 @@ DB_get_type(DBObject* self, PyObject* args) return NULL; CHECK_DB_NOT_CLOSED(self); - MYDB_BEGIN_ALLOW_THREADS; type = _DB_get_type(self); - MYDB_END_ALLOW_THREADS; if (type == -1) return NULL; return PyInt_FromLong(type); -- cgit v0.12 From 88b5d2bf30ca3d3618e2785a31c352d3eb0d7033 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Tue, 21 Nov 2006 05:49:41 +0000 Subject: Oops, convert tabs to spaces --- Lib/bsddb/test/test_dbobj.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/bsddb/test/test_dbobj.py b/Lib/bsddb/test/test_dbobj.py index af494e1..1ef382e 100644 --- a/Lib/bsddb/test/test_dbobj.py +++ b/Lib/bsddb/test/test_dbobj.py @@ -70,8 +70,8 @@ class dbobjTestCase(unittest.TestCase): self.env.close() def test03_dbobj_type_before_open(self): - # Ensure this doesn't cause a segfault. - self.assertRaises(db.DBInvalidArgError, db.DB().type) + # Ensure this doesn't cause a segfault. + self.assertRaises(db.DBInvalidArgError, db.DB().type) #---------------------------------------------------------------------- -- cgit v0.12 From 6a3955e99d14b8e4b79d0dd1addae281e5e75318 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Tue, 21 Nov 2006 06:25:09 +0000 Subject: Fix SF #1599879, socket.gethostname should ref getfqdn directly. --- Doc/lib/libsocket.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/lib/libsocket.tex b/Doc/lib/libsocket.tex index ececea4..f510fd4 100644 --- a/Doc/lib/libsocket.tex +++ b/Doc/lib/libsocket.tex @@ -241,8 +241,8 @@ If you want to know the current machine's IP address, you may want to use This operation assumes that there is a valid address-to-host mapping for the host, and the assumption does not always hold. Note: \function{gethostname()} doesn't always return the fully qualified -domain name; use \code{gethostbyaddr(gethostname())} -(see below). +domain name; use \code{getfqdn()} +(see above). \end{funcdesc} \begin{funcdesc}{gethostbyaddr}{ip_address} -- cgit v0.12 From 2396f4c3b1b54a7749d4fa7a6cabac389bff6a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Tue, 21 Nov 2006 18:21:34 +0000 Subject: Conditionalize definition of _CRT_SECURE_NO_DEPRECATE and _CRT_NONSTDC_NO_DEPRECATE. --- Misc/NEWS | 7 +++++++ PC/pyconfig.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 231004d..0cf1c4b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -206,6 +206,13 @@ Build files in VC7. +Windows +------- + +- Conditionalize definition of _CRT_SECURE_NO_DEPRECATE + and _CRT_NONSTDC_NO_DEPRECATE. + + What's New in Python 2.5 (final) ================================ diff --git a/PC/pyconfig.h b/PC/pyconfig.h index e0df673..20201d0 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -39,8 +39,12 @@ MS_CORE_DLL. would be ISO C conforming). Neither renaming is feasible, so we just silence the warnings. */ +#ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE 1 +#endif +#ifndef _CRT_NONSTDC_NO_DEPRECATE #define _CRT_NONSTDC_NO_DEPRECATE 1 +#endif /* Windows CE does not have these */ #ifndef MS_WINCE -- cgit v0.12 From 9ff1d394027c1ae08d15df149bb1ee5a62f566de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Thu, 23 Nov 2006 05:06:31 +0000 Subject: Backport checkin: Change decode() so that it works with a buffer (i.e. unicode(..., 'utf-8-sig')) SF bug #1601501. --- Lib/encodings/utf_8_sig.py | 2 +- Lib/test/test_codecs.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/encodings/utf_8_sig.py b/Lib/encodings/utf_8_sig.py index f05f6b8..d751da6 100644 --- a/Lib/encodings/utf_8_sig.py +++ b/Lib/encodings/utf_8_sig.py @@ -16,7 +16,7 @@ def encode(input, errors='strict'): def decode(input, errors='strict'): prefix = 0 - if input.startswith(codecs.BOM_UTF8): + if input[:3] == codecs.BOM_UTF8: input = input[3:] prefix = 3 (output, consumed) = codecs.utf_8_decode(input, errors, True) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 62cd163..185670b 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -426,6 +426,10 @@ class UTF8SigTest(ReadTest): ] ) + def test_bug1601501(self): + # SF bug #1601501: check that the codec works with a buffer + unicode("\xef\xbb\xbf", "utf-8-sig") + class EscapeDecodeTest(unittest.TestCase): def test_empty(self): self.assertEquals(codecs.escape_decode(""), ("", 0)) -- cgit v0.12 From 0c55236d39c5c3066903ace1c28e6a88c4efa2d0 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 23 Nov 2006 09:55:10 +0000 Subject: Bug #1601630: little improvement to getopt docs (backport from rev. 52833) --- Doc/lib/libgetopt.tex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Doc/lib/libgetopt.tex b/Doc/lib/libgetopt.tex index e8b16a3..b38fcd8 100644 --- a/Doc/lib/libgetopt.tex +++ b/Doc/lib/libgetopt.tex @@ -126,8 +126,9 @@ import getopt, sys def main(): try: opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="]) - except getopt.GetoptError: + except getopt.GetoptError, err: # print help information and exit: + print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) output = None @@ -135,11 +136,13 @@ def main(): for o, a in opts: if o == "-v": verbose = True - if o in ("-h", "--help"): + elif o in ("-h", "--help"): usage() sys.exit() - if o in ("-o", "--output"): + elif o in ("-o", "--output"): output = a + else: + assert False, "unhandled option" # ... if __name__ == "__main__": -- cgit v0.12 From 558e56d5995a2c167070b397e7fcc1f4eb1f3c0a Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Fri, 24 Nov 2006 19:00:39 +0000 Subject: Fix bug #1598620: A ctypes structure cannot contain itself. Backport from trunk. --- Lib/ctypes/test/test_structures.py | 30 ++++++++++++++++++++++++++++++ Misc/NEWS | 2 ++ Modules/_ctypes/stgdict.c | 16 +++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index 8a4531d..613163d 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -381,5 +381,35 @@ class PointerMemberTestCase(unittest.TestCase): s.p = None self.failUnlessEqual(s.x, 12345678) +class TestRecursiveStructure(unittest.TestCase): + def test_contains_itself(self): + class Recursive(Structure): + pass + + try: + Recursive._fields_ = [("next", Recursive)] + except AttributeError, details: + self.failUnless("Structure or union cannot contain itself" in + str(details)) + else: + self.fail("Structure or union cannot contain itself") + + + def test_vice_versa(self): + class First(Structure): + pass + class Second(Structure): + pass + + First._fields_ = [("second", Second)] + + try: + Second._fields_ = [("first", First)] + except AttributeError, details: + self.failUnless("_fields_ is final" in + str(details)) + else: + self.fail("AttributeError not raised") + if __name__ == '__main__': unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS index 0cf1c4b..9b8fc27 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -70,6 +70,8 @@ Core and builtins Extension Modules ----------------- +- Bug #1598620: A ctypes Structure cannot contain itself. + - Bug #1588217: don't parse "= " as a soft line break in binascii's a2b_qp() function, instead leave it in the string as quopri.decode() does. diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index d701f9e..8fd9a1e 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -339,14 +339,14 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) stgdict = PyType_stgdict(type); if (!stgdict) return -1; + /* If this structure/union is already marked final we cannot assign + _fields_ anymore. */ + if (stgdict->flags & DICTFLAG_FINAL) {/* is final ? */ PyErr_SetString(PyExc_AttributeError, "_fields_ is final"); return -1; } - /* XXX This should probably be moved to a point when all this - stuff is sucessfully finished. */ - stgdict->flags |= DICTFLAG_FINAL; /* set final */ if (stgdict->ffi_type_pointer.elements) PyMem_Free(stgdict->ffi_type_pointer.elements); @@ -480,5 +480,15 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) stgdict->size = size; stgdict->align = total_align; stgdict->length = len; /* ADD ffi_ofs? */ + + /* We did check that this flag was NOT set above, it must not + have been set until now. */ + if (stgdict->flags & DICTFLAG_FINAL) { + PyErr_SetString(PyExc_AttributeError, + "Structure or union cannot contain itself"); + return -1; + } + stgdict->flags |= DICTFLAG_FINAL; + return MakeAnonFields(type); } -- cgit v0.12 From 9147f7ed8bca93527f05be82ae741320e8374ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 25 Nov 2006 15:39:28 +0000 Subject: Disable _XOPEN_SOURCE on NetBSD 1.x. --- Misc/NEWS | 2 ++ configure | 7 ++++++- configure.in | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 9b8fc27..2d790f2 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -201,6 +201,8 @@ Tests Build ----- +- Disable _XOPEN_SOURCE on NetBSD 1.x. + - Bug #1578513: Cross compilation was broken by a change to configure. Repair so that it's back to how it was in 2.4.3. diff --git a/configure b/configure index 8b4e544..3f8459d 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 52455 . +# From configure.in Revision: 52457 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for python 2.5. # @@ -1555,6 +1555,11 @@ case $ac_sys_system/$ac_sys_release in # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish. OpenBSD/2.* | OpenBSD/3.[0123456789] | OpenBSD/4.[0]) define_xopen_source=no;; + # Defining _XOPEN_SOURCE on NetBSD version prior to the introduction of + # _NETBSD_SOURCE disables certain features (eg. setgroups). Reported by + # Marc Recht + NetBSD/1.5 | NetBSD/1.5.* | NetBSD/1.6 | NetBSD/1.6.* | NetBSD/1.6A-S) + define_xopen_source=no;; # On Solaris 2.6, sys/wait.h is inconsistent in the usage # of union __?sigval. Reported by Stuart Bishop. SunOS/5.6) diff --git a/configure.in b/configure.in index cd9161b..9d446c6 100644 --- a/configure.in +++ b/configure.in @@ -203,6 +203,11 @@ case $ac_sys_system/$ac_sys_release in # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish. OpenBSD/2.* | OpenBSD/3.@<:@0123456789@:>@ | OpenBSD/4.@<:@0@:>@) define_xopen_source=no;; + # Defining _XOPEN_SOURCE on NetBSD version prior to the introduction of + # _NETBSD_SOURCE disables certain features (eg. setgroups). Reported by + # Marc Recht + NetBSD/1.5 | NetBSD/1.5.* | NetBSD/1.6 | NetBSD/1.6.* | NetBSD/1.6[A-S]) + define_xopen_source=no;; # On Solaris 2.6, sys/wait.h is inconsistent in the usage # of union __?sigval. Reported by Stuart Bishop. SunOS/5.6) -- cgit v0.12 From 2286441a815b3dc2d9f5fa4e71c3d38875e9b463 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 26 Nov 2006 19:27:51 +0000 Subject: Bug #1603321: make pstats.Stats accept Unicode file paths. (backport from rev. 52845) --- Lib/pstats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pstats.py b/Lib/pstats.py index 4e94b0c..bdbb27e 100644 --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -116,7 +116,7 @@ class Stats: def load_stats(self, arg): if not arg: self.stats = {} - elif type(arg) == type(""): + elif isinstance(arg, basestring): f = open(arg, 'rb') self.stats = marshal.load(f) f.close() -- cgit v0.12 From 425e2d15c5b50e49e669a7a8a7316c4de21bccd9 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 27 Nov 2006 18:46:47 +0000 Subject: Bug #1603789: grammatical error in Tkinter docs. (backport from rev. 52850) --- Doc/lib/tkinter.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/tkinter.tex b/Doc/lib/tkinter.tex index db52cbd..20b2373 100644 --- a/Doc/lib/tkinter.tex +++ b/Doc/lib/tkinter.tex @@ -318,7 +318,7 @@ the name of a widget. \item[\var{options}] configure the widget's appearance and in some cases, its behavior. The options come in the form of a list of flags and values. -Flags are proceeded by a `-', like \UNIX{} shell command flags, and +Flags are preceded by a `-', like \UNIX{} shell command flags, and values are put in quotes if they are more than one word. \end{description} -- cgit v0.12 From 84a90cade58461822e7ee5bbb5e52aa6a415bd6f Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Tue, 28 Nov 2006 20:43:11 +0000 Subject: Fix #1563807: _ctypes built on AIX fails with ld ffi error. The contents of ffi_darwin.c must be compiled unless __APPLE__ is defined and __ppc__ is not. Backport from trunk. --- Misc/NEWS | 2 ++ Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 2d790f2..2e5cada 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -70,6 +70,8 @@ Core and builtins Extension Modules ----------------- +- Bug #1563807: _ctypes built on AIX fails with ld ffi error. + - Bug #1598620: A ctypes Structure cannot contain itself. - Bug #1588217: don't parse "= " as a soft line break in binascii's diff --git a/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c b/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c index 1595b00..55af70c 100644 --- a/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c +++ b/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c @@ -1,4 +1,4 @@ -#ifdef __ppc__ +#if !(defined(__APPLE__) && !defined(__ppc__)) /* ----------------------------------------------------------------------- ffi.c - Copyright (c) 1998 Geoffrey Keating -- cgit v0.12 From 1bc1ab23d3969b792e5861559e023baeec44dfd6 Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Wed, 29 Nov 2006 22:07:38 +0000 Subject: Backport of r52862. --- Python/ceval.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 73e8dee..7884051 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4046,8 +4046,10 @@ import_all_from(PyObject *locals, PyObject *v) value = PyObject_GetAttr(v, name); if (value == NULL) err = -1; - else + else if (PyDict_CheckExact(locals)) err = PyDict_SetItem(locals, name, value); + else + err = PyObject_SetItem(locals, name, value); Py_DECREF(name); Py_XDECREF(value); if (err != 0) -- cgit v0.12 From 1c305dbf978021b4609b43338fc037b36cc1ed38 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 2 Dec 2006 01:57:21 +0000 Subject: Fix nit in comment. --- Lib/Queue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/Queue.py b/Lib/Queue.py index 0f80584..79b0abf 100644 --- a/Lib/Queue.py +++ b/Lib/Queue.py @@ -26,7 +26,7 @@ class Queue: self._init(maxsize) # mutex must be held whenever the queue is mutating. All methods # that acquire mutex must release it before returning. mutex - # is shared between the two conditions, so acquiring and + # is shared between the three conditions, so acquiring and # releasing the conditions also acquires and releases mutex. self.mutex = threading.Lock() # Notify not_empty whenever an item is added to the queue; a -- cgit v0.12 From 95b744cea98be482c44fed4ff3a3e48bf910410c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 3 Dec 2006 11:24:00 +0000 Subject: Patch #1544279: Improve thread-safety of the socket module by moving the sock_addr_t storage out of the socket object. --- Misc/NEWS | 3 ++ Modules/socketmodule.c | 97 +++++++++++++++++++++++--------------------------- Modules/socketmodule.h | 1 - 3 files changed, 48 insertions(+), 53 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 2e5cada..f77b7ae 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -70,6 +70,9 @@ Core and builtins Extension Modules ----------------- +- Patch #1544279: Improve thread-safety of the socket module by moving + the sock_addr_t storage out of the socket object. + - Bug #1563807: _ctypes built on AIX fails with ld ffi error. - Bug #1598620: A ctypes Structure cannot contain itself. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index f03b34c..c9f0388 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -364,19 +364,16 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); #define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM #define sockaddr_l2 sockaddr_l2cap #define sockaddr_rc sockaddr_rfcomm -#define _BT_SOCKADDR_MEMB(s, proto) &((s)->sock_addr) #define _BT_L2_MEMB(sa, memb) ((sa)->l2cap_##memb) #define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb) #elif defined(__NetBSD__) #define sockaddr_l2 sockaddr_bt #define sockaddr_rc sockaddr_bt #define sockaddr_sco sockaddr_bt -#define _BT_SOCKADDR_MEMB(s, proto) &((s)->sock_addr) #define _BT_L2_MEMB(sa, memb) ((sa)->bt_##memb) #define _BT_RC_MEMB(sa, memb) ((sa)->bt_##memb) #define _BT_SCO_MEMB(sa, memb) ((sa)->bt_##memb) #else -#define _BT_SOCKADDR_MEMB(s, proto) (&((s)->sock_addr).bt_##proto) #define _BT_L2_MEMB(sa, memb) ((sa)->l2_##memb) #define _BT_RC_MEMB(sa, memb) ((sa)->rc_##memb) #define _BT_SCO_MEMB(sa, memb) ((sa)->sco_##memb) @@ -388,6 +385,8 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); #define SEGMENT_SIZE (32 * 1024 -1) #endif +#define SAS2SA(x) ((struct sockaddr *)(x)) + /* * Constants for getnameinfo() */ @@ -1174,7 +1173,7 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto) static int getsockaddrarg(PySocketSockObject *s, PyObject *args, - struct sockaddr **addr_ret, int *len_ret) + struct sockaddr *addr_ret, int *len_ret) { switch (s->sock_family) { @@ -1184,9 +1183,10 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, struct sockaddr_un* addr; char *path; int len; - addr = (struct sockaddr_un*)&(s->sock_addr).un; if (!PyArg_Parse(args, "t#", &path, &len)) return 0; + + addr = (struct sockaddr_un*)addr_ret; #ifdef linux if (len > 0 && path[0] == 0) { /* Linux abstract namespace extension */ @@ -1209,7 +1209,6 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, } addr->sun_family = s->sock_family; memcpy(addr->sun_path, path, len); - *addr_ret = (struct sockaddr *) addr; #if defined(PYOS_OS2) *len_ret = sizeof(*addr); #else @@ -1224,7 +1223,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, { struct sockaddr_nl* addr; int pid, groups; - addr = (struct sockaddr_nl *)&(s->sock_addr).nl; + addr = (struct sockaddr_nl *)addr_ret; if (!PyTuple_Check(args)) { PyErr_Format( PyExc_TypeError, @@ -1238,7 +1237,6 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, addr->nl_family = AF_NETLINK; addr->nl_pid = pid; addr->nl_groups = groups; - *addr_ret = (struct sockaddr *) addr; *len_ret = sizeof(*addr); return 1; } @@ -1249,7 +1247,6 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, struct sockaddr_in* addr; char *host; int port, result; - addr=(struct sockaddr_in*)&(s->sock_addr).in; if (!PyTuple_Check(args)) { PyErr_Format( PyExc_TypeError, @@ -1261,6 +1258,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, if (!PyArg_ParseTuple(args, "eti:getsockaddrarg", "idna", &host, &port)) return 0; + addr=(struct sockaddr_in*)addr_ret; result = setipaddr(host, (struct sockaddr *)addr, sizeof(*addr), AF_INET); PyMem_Free(host); @@ -1268,7 +1266,6 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, return 0; addr->sin_family = AF_INET; addr->sin_port = htons((short)port); - *addr_ret = (struct sockaddr *) addr; *len_ret = sizeof *addr; return 1; } @@ -1279,7 +1276,6 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, struct sockaddr_in6* addr; char *host; int port, flowinfo, scope_id, result; - addr = (struct sockaddr_in6*)&(s->sock_addr).in6; flowinfo = scope_id = 0; if (!PyTuple_Check(args)) { PyErr_Format( @@ -1294,6 +1290,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, &scope_id)) { return 0; } + addr = (struct sockaddr_in6*)addr_ret; result = setipaddr(host, (struct sockaddr *)addr, sizeof(*addr), AF_INET6); PyMem_Free(host); @@ -1303,7 +1300,6 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, addr->sin6_port = htons((short)port); addr->sin6_flowinfo = flowinfo; addr->sin6_scope_id = scope_id; - *addr_ret = (struct sockaddr *) addr; *len_ret = sizeof *addr; return 1; } @@ -1315,9 +1311,10 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, switch (s->sock_proto) { case BTPROTO_L2CAP: { - struct sockaddr_l2 *addr = (struct sockaddr_l2 *) _BT_SOCKADDR_MEMB(s, l2); + struct sockaddr_l2 *addr; char *straddr; + addr = (struct sockaddr_l2 *)addr_ret; _BT_L2_MEMB(addr, family) = AF_BLUETOOTH; if (!PyArg_ParseTuple(args, "si", &straddr, &_BT_L2_MEMB(addr, psm))) { @@ -1328,15 +1325,15 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, if (setbdaddr(straddr, &_BT_L2_MEMB(addr, bdaddr)) < 0) return 0; - *addr_ret = (struct sockaddr *) addr; *len_ret = sizeof *addr; return 1; } case BTPROTO_RFCOMM: { - struct sockaddr_rc *addr = (struct sockaddr_rc *) _BT_SOCKADDR_MEMB(s, rc); + struct sockaddr_rc *addr; char *straddr; + addr = (struct sockaddr_rc *)addr_ret; _BT_RC_MEMB(addr, family) = AF_BLUETOOTH; if (!PyArg_ParseTuple(args, "si", &straddr, &_BT_RC_MEMB(addr, channel))) { @@ -1347,16 +1344,16 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, if (setbdaddr(straddr, &_BT_RC_MEMB(addr, bdaddr)) < 0) return 0; - *addr_ret = (struct sockaddr *) addr; *len_ret = sizeof *addr; return 1; } #if !defined(__FreeBSD__) case BTPROTO_SCO: { - struct sockaddr_sco *addr = (struct sockaddr_sco *) _BT_SOCKADDR_MEMB(s, sco); + struct sockaddr_sco *addr; char *straddr; + addr = (struct sockaddr_sco *)addr_ret; _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH; straddr = PyString_AsString(args); if (straddr == NULL) { @@ -1367,7 +1364,6 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, if (setbdaddr(straddr, &_BT_SCO_MEMB(addr, bdaddr)) < 0) return 0; - *addr_ret = (struct sockaddr *) addr; *len_ret = sizeof *addr; return 1; } @@ -1409,22 +1405,21 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, s->errorhandler(); return 0; } - addr = &(s->sock_addr.ll); - addr->sll_family = AF_PACKET; - addr->sll_protocol = htons((short)protoNumber); - addr->sll_ifindex = ifr.ifr_ifindex; - addr->sll_pkttype = pkttype; - addr->sll_hatype = hatype; if (halen > 8) { PyErr_SetString(PyExc_ValueError, "Hardware address must be 8 bytes or less"); return 0; } + addr = (struct sockaddr_ll*)addr_ret; + addr->sll_family = AF_PACKET; + addr->sll_protocol = htons((short)protoNumber); + addr->sll_ifindex = ifr.ifr_ifindex; + addr->sll_pkttype = pkttype; + addr->sll_hatype = hatype; if (halen != 0) { memcpy(&addr->sll_addr, haddr, halen); } addr->sll_halen = halen; - *addr_ret = (struct sockaddr *) addr; *len_ret = sizeof *addr; return 1; } @@ -1551,8 +1546,7 @@ sock_accept(PySocketSockObject *s) Py_BEGIN_ALLOW_THREADS timeout = internal_select(s, 0); if (!timeout) - newfd = accept(s->sock_fd, (struct sockaddr *) &addrbuf, - &addrlen); + newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen); Py_END_ALLOW_THREADS if (timeout == 1) { @@ -1578,7 +1572,7 @@ sock_accept(PySocketSockObject *s) SOCKETCLOSE(newfd); goto finally; } - addr = makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf, + addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, s->sock_proto); if (addr == NULL) goto finally; @@ -1819,14 +1813,14 @@ string of that length; otherwise it is an integer."); static PyObject * sock_bind(PySocketSockObject *s, PyObject *addro) { - struct sockaddr *addr; + sock_addr_t addrbuf; int addrlen; int res; - if (!getsockaddrarg(s, addro, &addr, &addrlen)) + if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) return NULL; Py_BEGIN_ALLOW_THREADS - res = bind(s->sock_fd, addr, addrlen); + res = bind(s->sock_fd, SAS2SA(&addrbuf), addrlen); Py_END_ALLOW_THREADS if (res < 0) return s->errorhandler(); @@ -1952,16 +1946,16 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, static PyObject * sock_connect(PySocketSockObject *s, PyObject *addro) { - struct sockaddr *addr; + sock_addr_t addrbuf; int addrlen; int res; int timeout; - if (!getsockaddrarg(s, addro, &addr, &addrlen)) + if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) return NULL; Py_BEGIN_ALLOW_THREADS - res = internal_connect(s, addr, addrlen, &timeout); + res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout); Py_END_ALLOW_THREADS if (timeout == 1) { @@ -1986,16 +1980,16 @@ is a pair (host, port)."); static PyObject * sock_connect_ex(PySocketSockObject *s, PyObject *addro) { - struct sockaddr *addr; + sock_addr_t addrbuf; int addrlen; int res; int timeout; - if (!getsockaddrarg(s, addro, &addr, &addrlen)) + if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) return NULL; Py_BEGIN_ALLOW_THREADS - res = internal_connect(s, addr, addrlen, &timeout); + res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout); Py_END_ALLOW_THREADS /* Signals are not errors (though they may raise exceptions). Adapted @@ -2075,11 +2069,11 @@ sock_getsockname(PySocketSockObject *s) return NULL; memset(&addrbuf, 0, addrlen); Py_BEGIN_ALLOW_THREADS - res = getsockname(s->sock_fd, (struct sockaddr *) &addrbuf, &addrlen); + res = getsockname(s->sock_fd, SAS2SA(&addrbuf), &addrlen); Py_END_ALLOW_THREADS if (res < 0) return s->errorhandler(); - return makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf, addrlen, + return makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, s->sock_proto); } @@ -2104,11 +2098,11 @@ sock_getpeername(PySocketSockObject *s) return NULL; memset(&addrbuf, 0, addrlen); Py_BEGIN_ALLOW_THREADS - res = getpeername(s->sock_fd, (struct sockaddr *) &addrbuf, &addrlen); + res = getpeername(s->sock_fd, SAS2SA(&addrbuf), &addrlen); Py_END_ALLOW_THREADS if (res < 0) return s->errorhandler(); - return makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf, addrlen, + return makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, s->sock_proto); } @@ -2443,14 +2437,14 @@ sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags, #ifndef MS_WINDOWS #if defined(PYOS_OS2) && !defined(PYCC_GCC) n = recvfrom(s->sock_fd, cbuf, len, flags, - (struct sockaddr *) &addrbuf, &addrlen); + SAS2SA(&addrbuf), &addrlen); #else n = recvfrom(s->sock_fd, cbuf, len, flags, (void *) &addrbuf, &addrlen); #endif #else n = recvfrom(s->sock_fd, cbuf, len, flags, - (struct sockaddr *) &addrbuf, &addrlen); + SAS2SA(&addrbuf), &addrlen); #endif } Py_END_ALLOW_THREADS @@ -2464,7 +2458,7 @@ sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags, return -1; } - if (!(*addr = makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf, + if (!(*addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, s->sock_proto))) return -1; @@ -2664,7 +2658,7 @@ sock_sendto(PySocketSockObject *s, PyObject *args) { PyObject *addro; char *buf; - struct sockaddr *addr; + sock_addr_t addrbuf; int addrlen, len, n = -1, flags, timeout; flags = 0; @@ -2675,16 +2669,16 @@ sock_sendto(PySocketSockObject *s, PyObject *args) return NULL; } - if (!getsockaddrarg(s, addro, &addr, &addrlen)) - return NULL; - if (!IS_SELECTABLE(s)) return select_error(); + if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) + return NULL; + Py_BEGIN_ALLOW_THREADS timeout = internal_select(s, 1); if (!timeout) - n = sendto(s->sock_fd, buf, len, flags, addr, addrlen); + n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen); Py_END_ALLOW_THREADS if (timeout == 1) { @@ -2973,10 +2967,9 @@ socket_gethostbyname(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "s:gethostbyname", &name)) return NULL; - if (setipaddr(name, (struct sockaddr *)&addrbuf, sizeof(addrbuf), AF_INET) < 0) + if (setipaddr(name, SAS2SA(&addrbuf), sizeof(addrbuf), AF_INET) < 0) return NULL; - return makeipaddr((struct sockaddr *)&addrbuf, - sizeof(struct sockaddr_in)); + return makeipaddr(SAS2SA(&addrbuf), sizeof(struct sockaddr_in)); } PyDoc_STRVAR(gethostbyname_doc, diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h index ae38c86..84f2422 100644 --- a/Modules/socketmodule.h +++ b/Modules/socketmodule.h @@ -114,7 +114,6 @@ typedef struct { int sock_family; /* Address family, e.g., AF_INET */ int sock_type; /* Socket type, e.g., SOCK_STREAM */ int sock_proto; /* Protocol type, usually 0 */ - sock_addr_t sock_addr; /* Socket address */ PyObject *(*errorhandler)(void); /* Error handler; checks errno, returns NULL and sets a Python exception */ -- cgit v0.12 From fa713e18f6f7b3ef253fbd2c36a8814de1b3f607 Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Sun, 3 Dec 2006 17:13:54 +0000 Subject: - Fix build failure on kfreebsd and on the hurd. --- Lib/distutils/command/build_ext.py | 2 +- Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index 00f8a6b..2413829 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -186,7 +186,7 @@ class build_ext (Command): # for extensions under Cygwin and AtheOS Python's library directory must be # appended to library_dirs if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos' or \ - (sys.platform.startswith('linux') and + ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')) and sysconfig.get_config_var('Py_ENABLE_SHARED')): if string.find(sys.executable, sys.exec_prefix) != -1: # building third party extensions diff --git a/Misc/NEWS b/Misc/NEWS index f77b7ae..35960e0 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -214,6 +214,8 @@ Build - Patch #1576954: Update VC6 build directory; remove redundant files in VC7. +- Fix build failure on kfreebsd and on the hurd. + Windows ------- -- cgit v0.12 From 19d12d4cea1c235b040474a2178c34e090a3756b Mon Sep 17 00:00:00 2001 From: George Yoshida Date: Tue, 5 Dec 2006 05:40:57 +0000 Subject: Fix pickle doc typo Patch #1608758 (backport from r52917) --- Doc/lib/libpickle.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libpickle.tex b/Doc/lib/libpickle.tex index a8ab39e..3290641 100644 --- a/Doc/lib/libpickle.tex +++ b/Doc/lib/libpickle.tex @@ -519,7 +519,7 @@ as their value. The semantics of each element are: version of the object. The next element of the tuple will provide arguments for this callable, and later elements provide additional state information that will subsequently be used to fully reconstruct -the pickled date. +the pickled data. In the unpickling environment this object must be either a class, a callable registered as a ``safe constructor'' (see below), or it must -- cgit v0.12 From 25f58f6b5acb98b58e45714384f1549b61212bb1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 6 Dec 2006 22:21:23 +0000 Subject: Patch #1610437: fix a tarfile bug with long filename headers. (backport from rev. 52938) --- Lib/tarfile.py | 8 ++++++-- Lib/test/test_tarfile.py | 22 +++++++++++++--------- Misc/NEWS | 2 ++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index b5f9f30..1b8f140 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -857,7 +857,11 @@ class TarInfo(object): if self.name.endswith("/"): type = DIRTYPE - name = normpath(self.name) + if type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK): + # Prevent "././@LongLink" from being normalized. + name = self.name + else: + name = normpath(self.name) if type == DIRTYPE: # directories should end with '/' @@ -913,7 +917,7 @@ class TarInfo(object): ] buf += struct.pack("%ds" % BLOCKSIZE, "".join(parts)) - chksum = calc_chksums(buf)[0] + chksum = calc_chksums(buf[-BLOCKSIZE:])[0] buf = buf[:-364] + "%06o\0" % chksum + buf[-357:] self.buf = buf return buf diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index ee83cbe..2685d67 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -388,13 +388,6 @@ class WriteGNULongTest(unittest.TestCase): is tested as well. """ - def setUp(self): - self.tar = tarfile.open(tmpname(), "w") - self.tar.posix = False - - def tearDown(self): - self.tar.close() - def _length(self, s): blocks, remainder = divmod(len(s) + 1, 512) if remainder: @@ -423,12 +416,23 @@ class WriteGNULongTest(unittest.TestCase): tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE - self.tar.addfile(tarinfo) + tar = tarfile.open(tmpname(), "w") + tar.posix = False + tar.addfile(tarinfo) v1 = self._calc_size(name, link) - v2 = self.tar.offset + v2 = tar.offset self.assertEqual(v1, v2, "GNU longname/longlink creation failed") + tar.close() + + tar = tarfile.open(tmpname()) + member = tar.next() + self.failIf(member is None, "unable to read longname member") + self.assert_(tarinfo.name == member.name and \ + tarinfo.linkname == member.linkname, \ + "unable to read longname member") + def test_longname_1023(self): self._test(("longnam/" * 127) + "longnam") diff --git a/Misc/NEWS b/Misc/NEWS index 35960e0..c9ca095 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -110,6 +110,8 @@ Extension Modules Library ------- +- Patch #1610437: fix a tarfile bug with long filename headers. + - Patch #1472877: Fix Tix subwidget name resolution. - Patch #1594554: Always close a tkSimpleDialog on ok(), even -- cgit v0.12 From ec46940f3b1e848aba27be74ae65de534773b626 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 7 Dec 2006 09:30:11 +0000 Subject: RFE #1592899: mention string.maketrans() in docs for str.translate, remove reference to the old regex module in the former's doc. (backport from rev. 52951) --- Doc/lib/libstdtypes.tex | 3 +++ Doc/lib/libstring.tex | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex index a9fb19b..4046246 100644 --- a/Doc/lib/libstdtypes.tex +++ b/Doc/lib/libstdtypes.tex @@ -876,6 +876,9 @@ optional argument \var{deletechars} are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256. +You can use the \function{maketrans()} helper function in the +\refmodule{string} module to create a translation table. + For Unicode objects, the \method{translate()} method does not accept the optional \var{deletechars} argument. Instead, it returns a copy of the \var{s} where all characters have been mapped diff --git a/Doc/lib/libstring.tex b/Doc/lib/libstring.tex index 1828b2e..bc1649f 100644 --- a/Doc/lib/libstring.tex +++ b/Doc/lib/libstring.tex @@ -220,7 +220,7 @@ objects. They are not available as string methods. \begin{funcdesc}{maketrans}{from, to} Return a translation table suitable for passing to - \function{translate()} or \function{regex.compile()}, that will map + \function{translate()}, that will map each character in \var{from} into the character at the same position in \var{to}; \var{from} and \var{to} must have the same length. -- cgit v0.12 From 775ebe29a50d500e3a0710486bcf64574982b826 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 8 Dec 2006 18:12:24 +0000 Subject: Backport fixes to set objects: rev 52964 sf 1576657 KeyError unpacks tuple arguments rev 52963 sf 1456209 obscure resizing vulnerability rev 52962 redundant calls to PyObject_Hash() --- Lib/test/test_set.py | 11 ++++++++ Misc/NEWS | 10 ++++++- Objects/setobject.c | 80 ++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 89 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 0268be2..422cc41 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -293,6 +293,17 @@ class TestSet(TestJointOps): self.assert_(self.thetype(self.word) not in s) self.assertRaises(KeyError, self.s.remove, self.thetype(self.word)) + def test_remove_keyerror_unpacking(self): + # bug: www.python.org/sf/1576657 + for v1 in ['Q', (1,)]: + try: + self.s.remove(v1) + except KeyError, e: + v2 = e.args[0] + self.assertEqual(v1, v2) + else: + self.fail() + def test_discard(self): self.s.discard('a') self.assert_('a' not in self.s) diff --git a/Misc/NEWS b/Misc/NEWS index c9ca095..91e2bcf 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,12 +12,20 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1456209: In some obscure cases it was possible for a class with a + custom ``__eq__()`` method to confuse set internals when class instances + were used as a set's elements and the ``__eq__()`` method mutated the set. + +- Eliminated unnecessary repeated calls to hash() by set.intersection() and + set.symmetric_difference_update(). + - Bug #1591996: Correctly forward exception in instance_contains(). - Bug #1588287: fix invalid assertion for `1,2` in debug builds. - Bug #1576657: when setting a KeyError for a tuple key, make sure that - the tuple isn't used as the "exception arguments tuple". + the tuple isn't used as the "exception arguments tuple". Applied to + both sets and dictionaries. - Bug #1565514, SystemError not raised on too many nested blocks. diff --git a/Objects/setobject.c b/Objects/setobject.c index 9d72b33..d33fff9 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -10,6 +10,20 @@ #include "Python.h" #include "structmember.h" +/* Set a key error with the specified argument, wrapping it in a + * tuple automatically so that tuple keys are not unpacked as the + * exception arguments. */ +static void +set_key_error(PyObject *arg) +{ + PyObject *tup; + tup = PyTuple_Pack(1, arg); + if (!tup) + return; /* caller will expect error to be set anyway */ + PyErr_SetObject(PyExc_KeyError, tup); + Py_DECREF(tup); +} + /* This must be >= 1. */ #define PERTURB_SHIFT 5 @@ -185,7 +199,7 @@ set_lookkey_string(PySetObject *so, PyObject *key, register long hash) /* Internal routine to insert a new key into the table. -Used both by the internal resize routine and by the public insert routine. +Used by the public insert routine. Eats a reference to key. */ static int @@ -218,6 +232,35 @@ set_insert_key(register PySetObject *so, PyObject *key, long hash) } /* +Internal routine used by set_table_resize() to insert an item which is +known to be absent from the set. This routine also assumes that +the set contains no deleted entries. Besides the performance benefit, +using set_insert_clean() in set_table_resize() is dangerous (SF bug #1456209). +Note that no refcounts are changed by this routine; if needed, the caller +is responsible for incref'ing `key`. +*/ +static void +set_insert_clean(register PySetObject *so, PyObject *key, long hash) +{ + register size_t i; + register size_t perturb; + register size_t mask = (size_t)so->mask; + setentry *table = so->table; + register setentry *entry; + + i = hash & mask; + entry = &table[i]; + for (perturb = hash; entry->key != NULL; perturb >>= PERTURB_SHIFT) { + i = (i << 2) + i + perturb + 1; + entry = &table[i & mask]; + } + so->fill++; + entry->key = key; + entry->hash = hash; + so->used++; +} + +/* Restructure the table by allocating a new table and reinserting all keys again. When entries have been deleted, the new table may actually be smaller than the old one. @@ -298,11 +341,7 @@ set_table_resize(PySetObject *so, Py_ssize_t minused) } else { /* ACTIVE */ --i; - if(set_insert_key(so, entry->key, entry->hash) == -1) { - if (is_oldtable_malloced) - PyMem_DEL(oldtable); - return -1; - } + set_insert_clean(so, entry->key, entry->hash); } } @@ -1164,7 +1203,19 @@ set_intersection(PySetObject *so, PyObject *other) } while ((key = PyIter_Next(it)) != NULL) { - int rv = set_contains_key(so, key); + int rv; + setentry entry; + long hash = PyObject_Hash(key); + + if (hash == -1) { + Py_DECREF(it); + Py_DECREF(result); + Py_DECREF(key); + return NULL; + } + entry.hash = hash; + entry.key = key; + rv = set_contains_entry(so, &entry); if (rv == -1) { Py_DECREF(it); Py_DECREF(result); @@ -1172,7 +1223,7 @@ set_intersection(PySetObject *so, PyObject *other) return NULL; } if (rv) { - if (set_add_key(result, key) == -1) { + if (set_add_entry(result, &entry) == -1) { Py_DECREF(it); Py_DECREF(result); Py_DECREF(key); @@ -1383,11 +1434,18 @@ set_symmetric_difference_update(PySetObject *so, PyObject *other) PyObject *value; int rv; while (PyDict_Next(other, &pos, &key, &value)) { - rv = set_discard_key(so, key); + setentry an_entry; + long hash = PyObject_Hash(key); + + if (hash == -1) + return NULL; + an_entry.hash = hash; + an_entry.key = key; + rv = set_discard_entry(so, &an_entry); if (rv == -1) return NULL; if (rv == DISCARD_NOTFOUND) { - if (set_add_key(so, key) == -1) + if (set_add_entry(so, &an_entry) == -1) return NULL; } } @@ -1640,7 +1698,7 @@ set_remove(PySetObject *so, PyObject *key) Py_DECREF(tmpkey); return result; } else if (rv == DISCARD_NOTFOUND) { - PyErr_SetObject(PyExc_KeyError, key); + set_key_error(key); return NULL; } Py_RETURN_NONE; -- cgit v0.12 From db386544ed7b3c941a4c163d34c95c15f38db744 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Fri, 8 Dec 2006 20:44:19 +0000 Subject: Print the results of ctypes.util.find_library("c") and ctypes.util.find_library("m") so that we can see if it works on the buildbots. --- Lib/ctypes/test/test_loading.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py index 28c83fd4..1e7870b 100644 --- a/Lib/ctypes/test/test_loading.py +++ b/Lib/ctypes/test/test_loading.py @@ -14,8 +14,9 @@ elif sys.platform == "cygwin": else: libc_name = find_library("c") -if is_resource_enabled("printing"): - print "libc_name is", libc_name +if True or is_resource_enabled("printing"): + print >> sys.stderr, "\tfind_library('c') -> ", find_library('c') + print >> sys.stderr, "\tfind_library('m') -> ", find_library('m') class LoaderTest(unittest.TestCase): -- cgit v0.12 From ed8f294f43d61fd8e0d5c134c566d85adeadcdfc Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 8 Dec 2006 20:46:13 +0000 Subject: #1577756: svnversion doesn't react to LANG=C, use LC_ALL=C to force English output. (backport from rev. 52970) --- Makefile.pre.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index ce8710e..2ee077d 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -455,7 +455,7 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \ $(SIGNAL_OBJS) \ $(MODOBJS) \ $(srcdir)/Modules/getbuildinfo.c - $(CC) -c $(PY_CFLAGS) -DSVNVERSION=\"`LANG=C $(SVNVERSION)`\" -o $@ $(srcdir)/Modules/getbuildinfo.c + $(CC) -c $(PY_CFLAGS) -DSVNVERSION=\"`LC_ALL=C $(SVNVERSION)`\" -o $@ $(srcdir)/Modules/getbuildinfo.c Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile $(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \ -- cgit v0.12 From 2bcf0154d5412e0d03a30cbbe8a853c47ab6bfc5 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 9 Dec 2006 09:10:18 +0000 Subject: Patch #1608267: fix a race condition in os.makedirs() is the directory to be created is already there. (backport from rev. 52972) --- Lib/os.py | 11 ++++++++--- Misc/NEWS | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/os.py b/Lib/os.py index 2d1b29b..7d44dc4 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -25,6 +25,8 @@ and opendir), and leave all pathname manipulation to os.path import sys +from errno import ENOENT, ENOTDIR, EEXIST + _names = sys.builtin_module_names # Note: more names are added to __all__ later. @@ -160,7 +162,12 @@ def makedirs(name, mode=0777): if not tail: head, tail = path.split(head) if head and tail and not path.exists(head): - makedirs(head, mode) + try: + makedirs(head, mode) + except OSError, e: + # be happy if someone already created the path + if e.errno != EEXIST: + raise if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists return mkdir(name, mode) @@ -359,8 +366,6 @@ def execvpe(file, args, env): __all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"]) def _execvpe(file, args, env=None): - from errno import ENOENT, ENOTDIR - if env is not None: func = execve argrest = (args, env) diff --git a/Misc/NEWS b/Misc/NEWS index 91e2bcf..b568efd 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -118,6 +118,9 @@ Extension Modules Library ------- +- Patch #1608267: fix a race condition in os.makedirs() is the directory + to be created is already there. + - Patch #1610437: fix a tarfile bug with long filename headers. - Patch #1472877: Fix Tix subwidget name resolution. -- cgit v0.12 From f877b25008e1d3e10d4957e620261d6e101c6fdd Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Sat, 9 Dec 2006 12:13:02 +0000 Subject: - Fix the build of the library reference in info format. --- Doc/lib/libmsilib.tex | 4 ++-- Doc/tools/py2texi.el | 43 +++++++++++++++++++++++++++++++------------ Misc/NEWS | 2 ++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Doc/lib/libmsilib.tex b/Doc/lib/libmsilib.tex index 1e044f4..13d5556 100644 --- a/Doc/lib/libmsilib.tex +++ b/Doc/lib/libmsilib.tex @@ -344,8 +344,8 @@ the string inside the exception will contain more detail. \subsection{Features\label{features}} \begin{classdesc}{Feature}{database, id, title, desc, display\optional{, - level=1\optional{, parent\optional\{, directory\optional{, - attributes=0}}}} + level=1\optional{, parent\optional{, directory\optional{, + attributes=0}}}}} Add a new record to the \code{Feature} table, using the values \var{id}, \var{parent.id}, \var{title}, \var{desc}, \var{display}, diff --git a/Doc/tools/py2texi.el b/Doc/tools/py2texi.el index c3d8df0..404234f 100644 --- a/Doc/tools/py2texi.el +++ b/Doc/tools/py2texi.el @@ -1,5 +1,6 @@ ;;; py2texi.el -- Conversion of Python LaTeX documentation to Texinfo +;; Copyright (C) 2006 Jeroen Dekkers ;; Copyright (C) 1998, 1999, 2001, 2002 Milan Zamazal ;; Author: Milan Zamazal @@ -168,6 +169,7 @@ Otherwise a generated Info file name is used.") "@end table\n") ("productionlist" 0 "\n@table @code\n" "@end table\n") ("quotation" 0 "@quotation" "@end quotation") + ("quote" 0 "@quotation" "@end quotation") ("seealso" 0 "See also:\n@table @emph\n" "@end table\n") ("seealso*" 0 "@table @emph\n" "@end table\n") ("sloppypar" 0 "" "") @@ -246,11 +248,12 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("env" 1 "@code{\\1}") ("EOF" 0 "@code{EOF}") ("email" 1 "@email{\\1}") + ("em" 1 "@emph{\\1}") ("emph" 1 "@emph{\\1}") ("envvar" 1 "@env{\\1}") ("exception" 1 "@code{\\1}") ("exindex" 1 (progn (setq obindex t) "@obindex{\\1}")) - ("fi" 0 (concat "@end " last-if)) + ("fi" 0 (if (equal last-if "ifx") "" (concat "@end " last-if))) ("file" 1 "@file{\\1}") ("filenq" 1 "@file{\\1}") ("filevar" 1 "@file{@var{\\1}}") @@ -262,6 +265,7 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("grammartoken" 1 "@code{\\1}") ("guilabel" 1 "@strong{\\1}") ("hline" 0 "") + ("ifx" 0 (progn (setq last-if "ifx") "")) ("ifhtml" 0 (concat "@" (setq last-if "ifinfo"))) ("iftexi" 0 (concat "@" (setq last-if "ifinfo"))) ("index" 1 (progn (setq cindex t) "@cindex{\\1}")) @@ -284,6 +288,7 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("lineiii" 3 "@item \\1 @tab \\2 @tab \\3") ("lineiv" 4 "@item \\1 @tab \\2 @tab \\3 @tab \\4") ("linev" 5 "@item \\1 @tab \\2 @tab \\3 @tab \\4 @tab \\5") + ("locallinewidth" 0 "") ("localmoduletable" 0 "") ("longprogramopt" 1 "@option{--\\1}") ("macro" 1 "@code{@backslash{}\\1}") @@ -307,6 +312,7 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("moreargs" 0 "@dots{}") ("n" 0 "@backslash{}n") ("newcommand" 2 "") + ("newlength" 1 "") ("newsgroup" 1 "@samp{\\1}") ("nodename" 1 (save-excursion @@ -322,6 +328,7 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("opindex" 1 (progn (setq cindex t) "@cindex{\\1}")) ("option" 1 "@option{\\1}") ("optional" 1 "[\\1]") + ("paragraph" 1 "@subsubheading \\1") ("pep" 1 (progn (setq cindex t) "PEP@ \\1@cindex PEP \\1\n")) ("pi" 0 "pi") ("platform" 1 "") @@ -363,6 +370,7 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("seetitle" 1 "@cite{\\1}") ("seeurl" 2 "\n@table @url\n@item \\1\n\\2\n@end table\n") ("setindexsubitem" 1 (progn (setq cindex t) "@cindex \\1")) + ("setlength" 2 "") ("setreleaseinfo" 1 (progn (setq py2texi-releaseinfo ""))) ("setshortversion" 1 (progn (setq py2texi-python-short-version (match-string 1 string)) "")) @@ -382,8 +390,8 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("textasciicircum" 0 "^") ("textbackslash" 0 "@backslash{}") ("textbar" 0 "|") - ; Some common versions of Texinfo don't support @euro yet: - ; ("texteuro" 0 "@euro{}") + ("textbf" 1 "@strong{\\1}") + ("texteuro" 0 "@euro{}") ; Unfortunately, this alternate spelling doesn't actually apply to ; the usage found in Python Tutorial, which actually requires a ; Euro symbol to make sense, so this is commented out as well. @@ -394,6 +402,7 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("textrm" 1 "\\1") ("texttt" 1 "@code{\\1}") ("textunderscore" 0 "_") + ("tilde" 0 "~") ("title" 1 (progn (setq title (match-string 1 string)) "@settitle \\1")) ("today" 0 "@today{}") ("token" 1 "@code{\\1}") @@ -402,6 +411,7 @@ Both BEGIN and END are evaled. Moreover, you can reference arguments through ("u" 0 "@backslash{}u") ("ulink" 2 "\\1") ("UNIX" 0 "UNIX") + ("undefined" 0 "") ("unspecified" 0 "@dots{}") ("url" 1 "@url{\\1}") ("usepackage" 1 "") @@ -534,15 +544,20 @@ Each list item is of the form (COMMAND ARGNUM SUBSTITUTION) where: beg end) (py2texi-search-safe "\\\\begin{\\(verbatim\\|displaymath\\)}" - (replace-match "@example") - (setq beg (copy-marker (point) nil)) - (re-search-forward "\\\\end{\\(verbatim\\|displaymath\\)}") - (setq end (copy-marker (match-beginning 0) nil)) - (replace-match "@end example") - (py2texi-texinfo-escape beg end) - (put-text-property (- beg (length "@example")) - (+ end (length "@end example")) - 'py2texi-protected t)) + (when (save-excursion + ; Make sure we aren't looking at a commented out version + ; of a verbatim environment + (beginning-of-line) + (not (looking-at "%"))) + (replace-match "@example ") + (setq beg (copy-marker (point) nil)) + (re-search-forward "\\\\end{\\(verbatim\\|displaymath\\)}") + (setq end (copy-marker (match-beginning 0) nil)) + (replace-match "@end example") + (py2texi-texinfo-escape beg end) + (put-text-property (- beg (length "@example ")) + (+ end (length "@end example")) + 'py2texi-protected t))) (py2texi-search-safe "\\\\verb\\([^a-z]\\)" (setq delimiter (match-string 1)) (replace-match "@code{") @@ -883,6 +898,10 @@ Do not include .ind files." (defun py2texi-fix-braces () "Escape braces for Texinfo." + (py2texi-search "{@{}" + (replace-match "@{")) + (py2texi-search "{@}}" + (replace-match "@}")) (let (string) (py2texi-search "{" (unless (or (py2texi-protected) diff --git a/Misc/NEWS b/Misc/NEWS index b568efd..f9560e3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -229,6 +229,8 @@ Build - Fix build failure on kfreebsd and on the hurd. +- Fix the build of the library reference in info format. + Windows ------- -- cgit v0.12 From 9e2423ae8f6970ce95c6522e2efb8dedbbb96622 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 11 Dec 2006 07:56:43 +0000 Subject: Move errno imports back to individual functions. (backport from rev. 52996) --- Lib/os.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/os.py b/Lib/os.py index 7d44dc4..c8cc274 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -25,8 +25,6 @@ and opendir), and leave all pathname manipulation to os.path import sys -from errno import ENOENT, ENOTDIR, EEXIST - _names = sys.builtin_module_names # Note: more names are added to __all__ later. @@ -158,6 +156,7 @@ def makedirs(name, mode=0777): recursive. """ + from errno import EEXIST head, tail = path.split(name) if not tail: head, tail = path.split(head) @@ -366,6 +365,8 @@ def execvpe(file, args, env): __all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"]) def _execvpe(file, args, env=None): + from errno import ENOENT, ENOTDIR + if env is not None: func = execve argrest = (args, env) -- cgit v0.12 From 4d7ad63210e94b55021507efa07958563b0276b8 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 14 Dec 2006 08:41:39 +0000 Subject: Stripped whitespace from comma-separated values read from config file --- Lib/logging/config.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/logging/config.py b/Lib/logging/config.py index f14eb12..11d2b7a 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -110,7 +110,7 @@ def _create_formatters(cp): flist = string.split(flist, ",") formatters = {} for form in flist: - sectname = "formatter_%s" % form + sectname = "formatter_%s" % string.strip(form) opts = cp.options(sectname) if "format" in opts: fs = cp.get(sectname, "format", 1) @@ -139,7 +139,7 @@ def _install_handlers(cp, formatters): handlers = {} fixups = [] #for inter-handler references for hand in hlist: - sectname = "handler_%s" % hand + sectname = "handler_%s" % string.strip(hand) klass = cp.get(sectname, "class") opts = cp.options(sectname) if "formatter" in opts: @@ -176,6 +176,7 @@ def _install_loggers(cp, handlers): # configure the root first llist = cp.get("loggers", "keys") llist = string.split(llist, ",") + llist = map(lambda x: string.strip(x), llist) llist.remove("root") sectname = "logger_root" root = logging.root @@ -190,7 +191,7 @@ def _install_loggers(cp, handlers): if len(hlist): hlist = string.split(hlist, ",") for hand in hlist: - log.addHandler(handlers[hand]) + log.addHandler(handlers[string.strip(hand)]) #and now the others... #we don't want to lose the existing loggers, @@ -225,7 +226,7 @@ def _install_loggers(cp, handlers): if len(hlist): hlist = string.split(hlist, ",") for hand in hlist: - logger.addHandler(handlers[hand]) + logger.addHandler(handlers[string.strip(hand)]) #Disable any old loggers. There's no point deleting #them as other threads may continue to hold references -- cgit v0.12 From a75d31619c75854e45ad20918e4300efe7507767 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Thu, 14 Dec 2006 18:59:07 +0000 Subject: [Patch #1599256 from David Watson] check that os.fsync is available before using it --- Lib/mailbox.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 108d874..f9af494 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1887,7 +1887,8 @@ def _create_temporary(path): def _sync_flush(f): """Ensure changes to file f are physically on disk.""" f.flush() - os.fsync(f.fileno()) + if hasattr(os, 'fsync'): + os.fsync(f.fileno()) def _sync_close(f): """Close file f, ensuring all changes are physically on disk.""" -- cgit v0.12 From aa4135a45e4f01fa35c1b65825731a20bdb60d61 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Mon, 18 Dec 2006 17:13:10 +0000 Subject: [Bug #1618083] Add missing word; make a few grammar fixes --- Doc/lib/libsqlite3.tex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/lib/libsqlite3.tex b/Doc/lib/libsqlite3.tex index b8bdbdc..46e9800 100644 --- a/Doc/lib/libsqlite3.tex +++ b/Doc/lib/libsqlite3.tex @@ -187,12 +187,12 @@ int, long, float, str (UTF-8 encoded), unicode or buffer. \end{funcdesc} \begin{funcdesc}{complete_statement}{sql} -Returns \constant{True} if the string \var{sql} one or more complete SQL -statements terminated by semicolons. It does not verify if the SQL is -syntactically correct, only if there are no unclosed string literals and if the +Returns \constant{True} if the string \var{sql} contains one or more complete SQL +statements terminated by semicolons. It does not verify that the SQL is +syntactically correct, only that there are no unclosed string literals and the statement is terminated by a semicolon. -This can be used to build a shell for SQLite, like in the following example: +This can be used to build a shell for SQLite, as in the following example: \verbatiminput{sqlite3/complete_statement.py} \end{funcdesc} -- cgit v0.12 From 9333ce189f7d74109987c78f59d04fb74f78eda4 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Mon, 18 Dec 2006 19:26:13 +0000 Subject: [Patch #1615868 by Lars Gustaebel] Use Py_off_t to fix BZ2File.seek() for offsets > 2Gb --- Modules/bz2module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/bz2module.c b/Modules/bz2module.c index 27a3827..7a7d6cb 100644 --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -996,7 +996,7 @@ BZ2File_seek(BZ2FileObject *self, PyObject *args) char small_buffer[SMALLCHUNK]; char *buffer = small_buffer; size_t buffersize = SMALLCHUNK; - int bytesread = 0; + Py_off_t bytesread = 0; size_t readsize; int chunksize; int bzerror; -- cgit v0.12 From e6acc8718c863de31349ce7213e3bc76b81f4d32 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Mon, 18 Dec 2006 20:27:30 +0000 Subject: Add forgotten NEWS item for previous commit --- Misc/NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index f9560e3..8cb8ec8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -81,6 +81,8 @@ Extension Modules - Patch #1544279: Improve thread-safety of the socket module by moving the sock_addr_t storage out of the socket object. +- Patch #1615868: make bz2.BZFile.seek() work for offsets >2GiB. + - Bug #1563807: _ctypes built on AIX fails with ld ffi error. - Bug #1598620: A ctypes Structure cannot contain itself. -- cgit v0.12 From 0faf90acc43484c934e816bb675bca0007d31c17 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Tue, 19 Dec 2006 15:12:23 +0000 Subject: [Patch #1617413 from Dug Song] Fix HTTP Basic authentication via HTTPS --- Lib/urllib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/urllib.py b/Lib/urllib.py index 064632c..4a1fa64 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -405,8 +405,8 @@ class URLopener: h.putheader('Content-Length', '%d' % len(data)) else: h.putrequest('GET', selector) - if proxy_auth: h.putheader('Proxy-Authorization: Basic %s' % proxy_auth) - if auth: h.putheader('Authorization: Basic %s' % auth) + if proxy_auth: h.putheader('Proxy-Authorization', 'Basic %s' % proxy_auth) + if auth: h.putheader('Authorization', 'Basic %s' % auth) if realhost: h.putheader('Host', realhost) for args in self.addheaders: h.putheader(*args) h.endheaders() -- cgit v0.12 From fcb7513fc9034f1d40fbed311d0d06b30e57555c Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Tue, 19 Dec 2006 15:13:44 +0000 Subject: Add NEWS item --- Misc/NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 8cb8ec8..c1a5052 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -197,6 +197,9 @@ Library - Patch #1574068: fix urllib/urllib2 to not insert line breaks when HTTP authentication data was very long. +- Patch #1617413: fix urllib's support for HTTP Basic authentication via HTTPS + (patch by Dug Song). + - Fix a bug in traceback.format_exception_only() that led to an error being raised when print_exc() was called without an exception set. In version 2.4, this printed "None", restored that behavior. -- cgit v0.12 From df6994db846be928da2b1e200ed2339eece89570 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Tue, 19 Dec 2006 15:19:14 +0000 Subject: [Patch #1600491 from Jim Jewett] Describe how to build help files on Windows --- Lib/pydoc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 0fc624e..ce97517 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1737,6 +1737,9 @@ Here is a list of available topics. Enter any topic name to get more help. Sorry, topic and keyword documentation is not available because the Python HTML documentation files could not be found. If you have installed them, please set the environment variable PYTHONDOCS to indicate their location. + +On the Microsoft Windows operating system, the files can be built by +running "hh -decompile . PythonNN.chm" in the C:\PythonNN\Doc> directory. ''') return target = self.topics.get(topic, self.keywords.get(topic)) -- cgit v0.12 From e65f14fcc32bbc158d222408ec310a306714ec12 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Tue, 19 Dec 2006 18:31:22 +0000 Subject: Updated documentation for findCaller() to indicate that a 3-tuple is now returned, rather than a 2-tuple. --- Doc/lib/liblogging.tex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/lib/liblogging.tex b/Doc/lib/liblogging.tex index cc44294..c00c0d0 100644 --- a/Doc/lib/liblogging.tex +++ b/Doc/lib/liblogging.tex @@ -516,8 +516,10 @@ Removes the specified handler \var{hdlr} from this logger. \end{methoddesc} \begin{methoddesc}{findCaller}{} -Finds the caller's source filename and line number. Returns the filename -and line number as a 2-element tuple. +Finds the caller's source filename and line number. Returns the filename, +line number and function name as a 3-element tuple. +\versionchanged[The function name was added. In earlier versions, the +filename and line number were returned as a 2-element tuple.]{2.5} \end{methoddesc} \begin{methoddesc}{handle}{record} -- cgit v0.12 From 5425a673316af04bd1e449e45d2d9c03ee1cce25 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 20 Dec 2006 07:43:59 +0000 Subject: Bug #1590891: random.randrange don't return correct value for big number --- Lib/random.py | 2 +- Lib/test/test_random.py | 8 ++++++++ Misc/NEWS | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/random.py b/Lib/random.py index ae2d434..b80f1a1 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -205,7 +205,7 @@ class Random(_random.Random): raise ValueError, "empty range for randrange()" if n >= maxwidth: - return istart + self._randbelow(n) + return istart + istep*self._randbelow(n) return istart + istep*int(self.random() * n) def randint(self, a, b): diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index bba4c7c..6c32635 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -439,6 +439,14 @@ class MersenneTwister_TestBasicOps(TestBasicOps): self.assertEqual(k, numbits) # note the stronger assertion self.assert_(2**k > n > 2**(k-1)) # note the stronger assertion + def test_randrange_bug_1590891(self): + start = 1000000000000 + stop = -100000000000000000000 + step = -200 + x = self.gen.randrange(start, stop, step) + self.assert_(stop < x <= start) + self.assertEqual((x+stop)%step, 0) + _gammacoeff = (0.9999999999995183, 676.5203681218835, -1259.139216722289, 771.3234287757674, -176.6150291498386, 12.50734324009056, -0.1385710331296526, 0.9934937113930748e-05, 0.1659470187408462e-06) diff --git a/Misc/NEWS b/Misc/NEWS index c1a5052..93e9d0a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1590891: random.randrange don't return correct value for big number + - Bug #1456209: In some obscure cases it was possible for a class with a custom ``__eq__()`` method to confuse set internals when class instances were used as a set's elements and the ``__eq__()`` method mutated the set. -- cgit v0.12 From 96e60652fab99724189dea2af2dbfa7751723835 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Wed, 20 Dec 2006 19:58:18 +0000 Subject: Two grammar fixes --- Doc/lib/liburlparse.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/lib/liburlparse.tex b/Doc/lib/liburlparse.tex index 8603605..0473aed 100644 --- a/Doc/lib/liburlparse.tex +++ b/Doc/lib/liburlparse.tex @@ -89,7 +89,7 @@ information on the result object. \begin{funcdesc}{urlunparse}{parts} Construct a URL from a tuple as returned by \code{urlparse()}. -The \var{parts} argument be any six-item iterable. +The \var{parts} argument can be any six-item iterable. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had unnecessary delimiters (for example, a ? with an empty query; the RFC states that these are equivalent). @@ -133,7 +133,7 @@ information on the result object. \begin{funcdesc}{urlunsplit}{parts} Combine the elements of a tuple as returned by \function{urlsplit()} into a complete URL as a string. -The \var{parts} argument be any five-item iterable. +The \var{parts} argument can be any five-item iterable. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had unnecessary delimiters (for example, a ? with an empty query; the RFC states that these are equivalent). -- cgit v0.12 From 2a927915cbfff5f8b17933c4cb37bfdb74111c01 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Wed, 20 Dec 2006 20:15:08 +0000 Subject: Backport doc changes from rev. 53112, 53115: use 'iterable' in various places instead of 'sequence'. --- Doc/lib/libfuncs.tex | 86 ++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/Doc/lib/libfuncs.tex b/Doc/lib/libfuncs.tex index dc52915..26bffcc 100644 --- a/Doc/lib/libfuncs.tex +++ b/Doc/lib/libfuncs.tex @@ -237,11 +237,11 @@ class C: \code{del \var{x}.\var{foobar}}. \end{funcdesc} -\begin{funcdesc}{dict}{\optional{mapping-or-sequence}} +\begin{funcdesc}{dict}{\optional{arg}} Return a new dictionary initialized from an optional positional argument or from a set of keyword arguments. If no arguments are given, return a new empty dictionary. - If the positional argument is a mapping object, return a dictionary + If the positional argument \var{arg} is a mapping object, return a dictionary mapping the same keys to the same values as does the mapping object. Otherwise the positional argument must be a sequence, a container that supports iteration, or an iterator object. The elements of the argument @@ -414,18 +414,18 @@ class C: \versionadded{2.2} \end{funcdesc} -\begin{funcdesc}{filter}{function, list} - Construct a list from those elements of \var{list} for which - \var{function} returns true. \var{list} may be either a sequence, a - container which supports iteration, or an iterator, If \var{list} +\begin{funcdesc}{filter}{function, iterable} + Construct a list from those elements of \var{iterable} for which + \var{function} returns true. \var{iterable} may be either a sequence, a + container which supports iteration, or an iterator, If \var{iterable} is a string or a tuple, the result also has that type; otherwise it is always a list. If \var{function} is \code{None}, the identity function is assumed, that is, all elements of - \var{list} that are false are removed. + \var{iterable} that are false are removed. - Note that \code{filter(function, \var{list})} is equivalent to - \code{[item for item in \var{list} if function(item)]} if function is - not \code{None} and \code{[item for item in \var{list} if item]} if + Note that \code{filter(function, \var{iterable})} is equivalent to + \code{[item for item in \var{iterable} if function(item)]} if function is + not \code{None} and \code{[item for item in \var{iterable} if item]} if function is \code{None}. \end{funcdesc} @@ -591,12 +591,12 @@ class C: may be a sequence (string, tuple or list) or a mapping (dictionary). \end{funcdesc} -\begin{funcdesc}{list}{\optional{sequence}} +\begin{funcdesc}{list}{\optional{iterable}} Return a list whose items are the same and in the same order as - \var{sequence}'s items. \var{sequence} may be either a sequence, a + \var{iterable}'s items. \var{iterable} may be either a sequence, a container that supports iteration, or an iterator object. If - \var{sequence} is already a list, a copy is made and returned, - similar to \code{\var{sequence}[:]}. For instance, + \var{iterable} is already a list, a copy is made and returned, + similar to \code{\var{iterable}[:]}. For instance, \code{list('abc')} returns \code{['a', 'b', 'c']} and \code{list( (1, 2, 3) )} returns \code{[1, 2, 3]}. If no argument is given, returns a new empty list, \code{[]}. @@ -622,22 +622,22 @@ class C: are given, returns \code{0L}. \end{funcdesc} -\begin{funcdesc}{map}{function, list, ...} - Apply \var{function} to every item of \var{list} and return a list - of the results. If additional \var{list} arguments are passed, +\begin{funcdesc}{map}{function, iterable, ...} + Apply \var{function} to every item of \var{iterable} and return a list + of the results. If additional \var{iterable} arguments are passed, \var{function} must take that many arguments and is applied to the - items of all lists in parallel; if a list is shorter than another it + items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with \code{None} items. If \var{function} is \code{None}, the identity function is assumed; if there are - multiple list arguments, \function{map()} returns a list consisting - of tuples containing the corresponding items from all lists (a kind - of transpose operation). The \var{list} arguments may be any kind - of sequence; the result is always a list. + multiple arguments, \function{map()} returns a list consisting + of tuples containing the corresponding items from all iterables (a kind + of transpose operation). The \var{iterable} arguments may be a sequence + or any iterable object; the result is always a list. \end{funcdesc} -\begin{funcdesc}{max}{s\optional{, args...}\optional{key}} - With a single argument \var{s}, return the largest item of a - non-empty sequence (such as a string, tuple or list). With more +\begin{funcdesc}{max}{iterable\optional{, args...}\optional{key}} + With a single argument \var{iterable}, return the largest item of a + non-empty iterable (such as a string, tuple or list). With more than one argument, return the largest of the arguments. The optional \var{key} argument specifies a one-argument ordering @@ -647,16 +647,16 @@ class C: \versionchanged[Added support for the optional \var{key} argument]{2.5} \end{funcdesc} -\begin{funcdesc}{min}{s\optional{, args...}\optional{key}} - With a single argument \var{s}, return the smallest item of a - non-empty sequence (such as a string, tuple or list). With more +\begin{funcdesc}{min}{iterable\optional{, args...}\optional{key}} + With a single argument \var{iterable}, return the smallest item of a + non-empty iterable (such as a string, tuple or list). With more than one argument, return the smallest of the arguments. The optional \var{key} argument specifies a one-argument ordering function like that used for \method{list.sort()}. The \var{key} argument, if supplied, must be in keyword form (for example, \samp{min(a,b,c,key=func)}). - \versionchanged[Added support for the optional \var{key} argument]{2.5} + \versionchanged[Added support for the optional \var{key} argument]{2.5} \end{funcdesc} \begin{funcdesc}{object}{} @@ -871,17 +871,17 @@ class Parrot(object): line editing and history features. \end{funcdesc} -\begin{funcdesc}{reduce}{function, sequence\optional{, initializer}} +\begin{funcdesc}{reduce}{function, iterable\optional{, initializer}} Apply \var{function} of two arguments cumulatively to the items of - \var{sequence}, from left to right, so as to reduce the sequence to + \var{iterable}, from left to right, so as to reduce the iterable to a single value. For example, \code{reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])} calculates \code{((((1+2)+3)+4)+5)}. The left argument, \var{x}, is the accumulated value and the right argument, \var{y}, - is the update value from the \var{sequence}. If the optional + is the update value from the \var{iterable}. If the optional \var{initializer} is present, it is placed before the items of the - sequence in the calculation, and serves as a default when the - sequence is empty. If \var{initializer} is not given and - \var{sequence} contains only one item, the first item is returned. + iterable in the calculation, and serves as a default when the + iterable is empty. If \var{initializer} is not given and + \var{iterable} contains only one item, the first item is returned. \end{funcdesc} \begin{funcdesc}{reload}{module} @@ -1087,11 +1087,11 @@ class C: string, \code{''}. \end{funcdesc} -\begin{funcdesc}{sum}{sequence\optional{, start}} - Sums \var{start} and the items of a \var{sequence}, from left to - right, and returns the total. \var{start} defaults to \code{0}. - The \var{sequence}'s items are normally numbers, and are not allowed - to be strings. The fast, correct way to concatenate sequence of +\begin{funcdesc}{sum}{iterable\optional{, start}} + Sums \var{start} and the items of an \var{iterable} from left to + right and returns the total. \var{start} defaults to \code{0}. + The \var{iterable}'s items are normally numbers, and are not allowed + to be strings. The fast, correct way to concatenate a sequence of strings is by calling \code{''.join(\var{sequence})}. Note that \code{sum(range(\var{n}), \var{m})} is equivalent to \code{reduce(operator.add, range(\var{n}), \var{m})} @@ -1121,11 +1121,11 @@ class C(B): \versionadded{2.2} \end{funcdesc} -\begin{funcdesc}{tuple}{\optional{sequence}} +\begin{funcdesc}{tuple}{\optional{iterable}} Return a tuple whose items are the same and in the same order as - \var{sequence}'s items. \var{sequence} may be a sequence, a + \var{iterable}'s items. \var{iterable} may be a sequence, a container that supports iteration, or an iterator object. - If \var{sequence} is already a tuple, it + If \var{iterable} is already a tuple, it is returned unchanged. For instance, \code{tuple('abc')} returns \code{('a', 'b', 'c')} and \code{tuple([1, 2, 3])} returns \code{(1, 2, 3)}. If no argument is given, returns a new empty -- cgit v0.12 From a9b9ae46782b8d8c4b4f07a1efff82c8f52703ec Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Wed, 20 Dec 2006 20:20:56 +0000 Subject: [Bug #1619680] in_dll() arguments are documented in the wrong order --- Doc/lib/libctypes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libctypes.tex b/Doc/lib/libctypes.tex index c0e2310..a7c2459 100755 --- a/Doc/lib/libctypes.tex +++ b/Doc/lib/libctypes.tex @@ -2085,7 +2085,7 @@ classmethod, normally it returns \code{obj} if that is an instance of the type. Some types accept other objects as well. \end{methoddesc} -\begin{methoddesc}{in_dll}{name, library} +\begin{methoddesc}{in_dll}{library, name} This method returns a ctypes type instance exported by a shared library. \var{name} is the name of the symbol that exports the data, \code{library} is the loaded shared library. -- cgit v0.12 From 3bffd289b99a9673cb11b84a6eaf5ae4754904ab Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Thu, 21 Dec 2006 13:41:46 +0000 Subject: Mention the os.SEEK_* constants --- Doc/lib/libbz2.tex | 8 ++++---- Doc/lib/libmmap.tex | 5 +++-- Doc/lib/libstdtypes.tex | 9 ++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Doc/lib/libbz2.tex b/Doc/lib/libbz2.tex index f40b66f..fe0e3af 100644 --- a/Doc/lib/libbz2.tex +++ b/Doc/lib/libbz2.tex @@ -90,10 +90,10 @@ performance optimizations previously implemented in the \begin{methoddesc}[BZ2File]{seek}{offset\optional{, whence}} Move to new file position. Argument \var{offset} is a byte count. Optional -argument \var{whence} defaults to \code{0} (offset from start of file, -offset should be \code{>= 0}); other values are \code{1} (move relative to -current position, positive or negative), and \code{2} (move relative to end -of file, usually negative, although many platforms allow seeking beyond +argument \var{whence} defaults to \code{os.SEEK_SET} or \code{0} (offset from start of file; +offset should be \code{>= 0}); other values are \code{os.SEEK_CUR} or \code{1} (move relative to +current position; offset can be positive or negative), and \code{os.SEEK_END} or \code{2} (move relative to end +of file; offset is usually negative, although many platforms allow seeking beyond the end of a file). Note that seeking of bz2 files is emulated, and depending on the parameters diff --git a/Doc/lib/libmmap.tex b/Doc/lib/libmmap.tex index 3dca40f..3763d4f 100644 --- a/Doc/lib/libmmap.tex +++ b/Doc/lib/libmmap.tex @@ -140,8 +140,9 @@ Memory-mapped file objects support the following methods: \begin{methoddesc}{seek}{pos\optional{, whence}} Set the file's current position. \var{whence} argument is optional - and defaults to \code{0} (absolute file positioning); other values - are \code{1} (seek relative to the current position) and \code{2} + and defaults to \code{os.SEEK_SET} or \code{0} (absolute file + positioning); other values are \code{os.SEEK_CUR} or \code{1} (seek + relative to the current position) and \code{os.SEEK_END} or \code{2} (seek relative to the file's end). \end{methoddesc} diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex index 4046246..802d08a 100644 --- a/Doc/lib/libstdtypes.tex +++ b/Doc/lib/libstdtypes.tex @@ -1678,9 +1678,12 @@ flush the read-ahead buffer. \begin{methoddesc}[file]{seek}{offset\optional{, whence}} Set the file's current position, like \code{stdio}'s \cfunction{fseek()}. - The \var{whence} argument is optional and defaults to \code{0} - (absolute file positioning); other values are \code{1} (seek - relative to the current position) and \code{2} (seek relative to the + The \var{whence} argument is optional and defaults to + \code{os.SEEK_SET} or \code{0} + (absolute file positioning); other values are \code{os.SEEK_CUR} or \code{1} + (seek + relative to the current position) and \code{os.SEEK_END} or \code{2} + (seek relative to the file's end). There is no return value. Note that if the file is opened for appending (mode \code{'a'} or \code{'a+'}), any \method{seek()} operations will be undone at the next write. If the -- cgit v0.12 From 28cfe299be2c75343c9d4dae2dfe11a4124f7908 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Thu, 21 Dec 2006 18:31:36 +0000 Subject: Fix wrong markup of an argument in a method signature. Backported from trunk. --- Doc/lib/libctypes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libctypes.tex b/Doc/lib/libctypes.tex index a7c2459..2f880f2 100755 --- a/Doc/lib/libctypes.tex +++ b/Doc/lib/libctypes.tex @@ -2088,7 +2088,7 @@ the type. Some types accept other objects as well. \begin{methoddesc}{in_dll}{library, name} This method returns a ctypes type instance exported by a shared library. \var{name} is the name of the symbol that exports the data, -\code{library} is the loaded shared library. +\var{library} is the loaded shared library. \end{methoddesc} Common instance variables of ctypes data types: -- cgit v0.12 From bbad84b41aa73a3cf4be1fe41ca5fde3814af9ca Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 22 Dec 2006 13:28:43 +0000 Subject: [Bug #737202; fix from Titus Brown] Make CGIHTTPServer work for scripts in sub-directories --- Lib/CGIHTTPServer.py | 19 +++++++++++++++++++ Misc/NEWS | 3 +++ 2 files changed, 22 insertions(+) diff --git a/Lib/CGIHTTPServer.py b/Lib/CGIHTTPServer.py index 7a5c819..c119c9a 100644 --- a/Lib/CGIHTTPServer.py +++ b/Lib/CGIHTTPServer.py @@ -105,17 +105,36 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def run_cgi(self): """Execute a CGI script.""" + path = self.path dir, rest = self.cgi_info + + i = path.find('/', len(dir) + 1) + while i >= 0: + nextdir = path[:i] + nextrest = path[i+1:] + + scriptdir = self.translate_path(nextdir) + if os.path.isdir(scriptdir): + dir, rest = nextdir, nextrest + i = path.find('/', len(dir) + 1) + else: + break + + # find an explicit query string, if present. i = rest.rfind('?') if i >= 0: rest, query = rest[:i], rest[i+1:] else: query = '' + + # dissect the part after the directory name into a script name & + # a possible additional path, to be stored in PATH_INFO. i = rest.find('/') if i >= 0: script, rest = rest[:i], rest[i:] else: script, rest = rest, '' + scriptname = dir + '/' + script scriptfile = self.translate_path(scriptname) if not os.path.exists(scriptfile): diff --git a/Misc/NEWS b/Misc/NEWS index 93e9d0a..dca49c1 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -122,6 +122,9 @@ Extension Modules Library ------- +- Bug #737202: Make CGIHTTPServer work for scripts in subdirectories. + Fix by Titus Brown. + - Patch #1608267: fix a race condition in os.makedirs() is the directory to be created is already there. -- cgit v0.12 From 60775f29de0e6107a46f668144cb1c133d6e5147 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 22 Dec 2006 19:08:41 +0000 Subject: [Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work. --- Lib/SimpleHTTPServer.py | 6 ++++++ Misc/NEWS | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Lib/SimpleHTTPServer.py b/Lib/SimpleHTTPServer.py index fae551a..86c669e 100644 --- a/Lib/SimpleHTTPServer.py +++ b/Lib/SimpleHTTPServer.py @@ -66,6 +66,12 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): path = self.translate_path(self.path) f = None if os.path.isdir(path): + if not self.path.endswith('/'): + # redirect browser - doing basically what apache does + self.send_response(301) + self.send_header("Location", self.path + "/") + self.end_headers() + return None for index in "index.html", "index.htm": index = os.path.join(path, index) if os.path.exists(index): diff --git a/Misc/NEWS b/Misc/NEWS index dca49c1..897346b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -125,6 +125,10 @@ Library - Bug #737202: Make CGIHTTPServer work for scripts in subdirectories. Fix by Titus Brown. +- Patch #827559: Make SimpleHTTPServer redirect when a directory URL + is missing the trailing slash, so that relative links work correctly. + Patch by Chris Gonnerman. + - Patch #1608267: fix a race condition in os.makedirs() is the directory to be created is already there. -- cgit v0.12 From aedb92e59c2f4c3c33fbb33d5dc4afefe344620c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gust=C3=A4bel?= Date: Sat, 23 Dec 2006 16:51:47 +0000 Subject: Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell() work correctly together with readline(). (backport from rev. 53153) --- Lib/tarfile.py | 259 ++++++++++++++++++++++++++++------------------- Lib/test/test_tarfile.py | 12 ++- Misc/NEWS | 3 + 3 files changed, 167 insertions(+), 107 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 1b8f140..cffde45 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -622,140 +622,194 @@ class _BZ2Proxy(object): #------------------------ # Extraction file object #------------------------ -class ExFileObject(object): - """File-like object for reading an archive member. - Is returned by TarFile.extractfile(). Support for - sparse files included. +class _FileInFile(object): + """A thin wrapper around an existing file object that + provides a part of its data as an individual file + object. """ - def __init__(self, tarfile, tarinfo): - self.fileobj = tarfile.fileobj - self.name = tarinfo.name - self.mode = "r" - self.closed = False - self.offset = tarinfo.offset_data - self.size = tarinfo.size - self.pos = 0L - self.linebuffer = "" - if tarinfo.issparse(): - self.sparse = tarinfo.sparse - self.read = self._readsparse - else: - self.read = self._readnormal + def __init__(self, fileobj, offset, size, sparse=None): + self.fileobj = fileobj + self.offset = offset + self.size = size + self.sparse = sparse + self.position = 0 - def __read(self, size): - """Overloadable read method. + def tell(self): + """Return the current file position. """ - return self.fileobj.read(size) + return self.position - def readline(self, size=-1): - """Read a line with approx. size. If size is negative, - read a whole line. readline() and read() must not - be mixed up (!). + def seek(self, position): + """Seek to a position in the file. """ - if size < 0: - size = sys.maxint + self.position = position - nl = self.linebuffer.find("\n") - if nl >= 0: - nl = min(nl, size) + def read(self, size=None): + """Read data from the file. + """ + if size is None: + size = self.size - self.position else: - size -= len(self.linebuffer) - while (nl < 0 and size > 0): - buf = self.read(min(size, 100)) - if not buf: - break - self.linebuffer += buf - size -= len(buf) - nl = self.linebuffer.find("\n") - if nl == -1: - s = self.linebuffer - self.linebuffer = "" - return s - buf = self.linebuffer[:nl] - self.linebuffer = self.linebuffer[nl + 1:] - while buf[-1:] == "\r": - buf = buf[:-1] - return buf + "\n" + size = min(size, self.size - self.position) - def readlines(self): - """Return a list with all (following) lines. - """ - result = [] - while True: - line = self.readline() - if not line: break - result.append(line) - return result + if self.sparse is None: + return self.readnormal(size) + else: + return self.readsparse(size) - def _readnormal(self, size=None): + def readnormal(self, size): """Read operation for regular files. """ - if self.closed: - raise ValueError("file is closed") - self.fileobj.seek(self.offset + self.pos) - bytesleft = self.size - self.pos - if size is None: - bytestoread = bytesleft - else: - bytestoread = min(size, bytesleft) - self.pos += bytestoread - return self.__read(bytestoread) + self.fileobj.seek(self.offset + self.position) + self.position += size + return self.fileobj.read(size) - def _readsparse(self, size=None): + def readsparse(self, size): """Read operation for sparse files. """ - if self.closed: - raise ValueError("file is closed") - - if size is None: - size = self.size - self.pos - data = [] while size > 0: - buf = self._readsparsesection(size) + buf = self.readsparsesection(size) if not buf: break size -= len(buf) data.append(buf) return "".join(data) - def _readsparsesection(self, size): + def readsparsesection(self, size): """Read a single section of a sparse file. """ - section = self.sparse.find(self.pos) + section = self.sparse.find(self.position) if section is None: return "" - toread = min(size, section.offset + section.size - self.pos) + size = min(size, section.offset + section.size - self.position) + if isinstance(section, _data): - realpos = section.realpos + self.pos - section.offset - self.pos += toread + realpos = section.realpos + self.position - section.offset self.fileobj.seek(self.offset + realpos) - return self.__read(toread) + self.position += size + return self.fileobj.read(size) else: - self.pos += toread - return NUL * toread + self.position += size + return NUL * size +#class _FileInFile + + +class ExFileObject(object): + """File-like object for reading an archive member. + Is returned by TarFile.extractfile(). + """ + blocksize = 1024 + + def __init__(self, tarfile, tarinfo): + self.fileobj = _FileInFile(tarfile.fileobj, + tarinfo.offset_data, + tarinfo.size, + getattr(tarinfo, "sparse", None)) + self.name = tarinfo.name + self.mode = "r" + self.closed = False + self.size = tarinfo.size + + self.position = 0 + self.buffer = "" + + def read(self, size=None): + """Read at most size bytes from the file. If size is not + present or None, read all data until EOF is reached. + """ + if self.closed: + raise ValueError("I/O operation on closed file") + + buf = "" + if self.buffer: + if size is None: + buf = self.buffer + self.buffer = "" + else: + buf = self.buffer[:size] + self.buffer = self.buffer[size:] + + if size is None: + buf += self.fileobj.read() + else: + buf += self.fileobj.read(size - len(buf)) + + self.position += len(buf) + return buf + + def readline(self, size=-1): + """Read one entire line from the file. If size is present + and non-negative, return a string with at most that + size, which may be an incomplete line. + """ + if self.closed: + raise ValueError("I/O operation on closed file") + + if "\n" in self.buffer: + pos = self.buffer.find("\n") + 1 + else: + buffers = [self.buffer] + while True: + buf = self.fileobj.read(self.blocksize) + buffers.append(buf) + if not buf or "\n" in buf: + self.buffer = "".join(buffers) + pos = self.buffer.find("\n") + 1 + if pos == 0: + # no newline found. + pos = len(self.buffer) + break + + if size != -1: + pos = min(size, pos) + + buf = self.buffer[:pos] + self.buffer = self.buffer[pos:] + self.position += len(buf) + return buf + + def readlines(self): + """Return a list with all remaining lines. + """ + result = [] + while True: + line = self.readline() + if not line: break + result.append(line) + return result def tell(self): """Return the current file position. """ - return self.pos + if self.closed: + raise ValueError("I/O operation on closed file") + + return self.position - def seek(self, pos, whence=0): + def seek(self, pos, whence=os.SEEK_SET): """Seek to a position in the file. """ - self.linebuffer = "" - if whence == 0: - self.pos = min(max(pos, 0), self.size) - if whence == 1: + if self.closed: + raise ValueError("I/O operation on closed file") + + if whence == os.SEEK_SET: + self.position = min(max(pos, 0), self.size) + elif whence == os.SEEK_CUR: if pos < 0: - self.pos = max(self.pos + pos, 0) + self.position = max(self.position + pos, 0) else: - self.pos = min(self.pos + pos, self.size) - if whence == 2: - self.pos = max(min(self.size + pos, self.size), 0) + self.position = min(self.position + pos, self.size) + elif whence == os.SEEK_END: + self.position = max(min(self.size + pos, self.size), 0) + else: + raise ValueError("Invalid argument") + + self.buffer = "" + self.fileobj.seek(self.position) def close(self): """Close the file object. @@ -763,20 +817,13 @@ class ExFileObject(object): self.closed = True def __iter__(self): - """Get an iterator over the file object. - """ - if self.closed: - raise ValueError("I/O operation on closed file") - return self - - def next(self): - """Get the next item from the file iterator. + """Get an iterator over the file's lines. """ - result = self.readline() - if not result: - raise StopIteration - return result - + while True: + line = self.readline() + if not line: + break + yield line #class ExFileObject #------------------ diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 2685d67..f229fa5 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -110,7 +110,7 @@ class ReadTest(BaseTest): """Test seek() method of _FileObject, incl. random reading. """ if self.sep != "|": - filename = "0-REGTYPE" + filename = "0-REGTYPE-TEXT" self.tar.extract(filename, dirname()) f = open(os.path.join(dirname(), filename), "rb") data = f.read() @@ -149,6 +149,16 @@ class ReadTest(BaseTest): s2 = fobj.readlines() self.assert_(s1 == s2, "readlines() after seek failed") + fobj.seek(0) + self.assert_(len(fobj.readline()) == fobj.tell(), + "tell() after readline() failed") + fobj.seek(512) + self.assert_(len(fobj.readline()) + 512 == fobj.tell(), + "tell() after seek() and readline() failed") + fobj.seek(0) + line = fobj.readline() + self.assert_(fobj.read() == data[len(line):], + "read() after readline() failed") fobj.close() def test_old_dirtype(self): diff --git a/Misc/NEWS b/Misc/NEWS index 897346b..f8fc7a7 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -620,6 +620,9 @@ Core and builtins Library ------- +- Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell() + work correctly together with readline(). + - Correction of patch #1455898: In the mbcs decoder, set final=False for stream decoder, but final=True for the decode function. -- cgit v0.12 From 12e087a1b12dd09f24875b39db2f4e7a5034899e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gust=C3=A4bel?= Date: Sat, 23 Dec 2006 18:13:57 +0000 Subject: Patch #1262036: Prevent TarFiles from being added to themselves under certain conditions. (backport from rev. 53155) Moved message from my previous change to the right place in Misc/NEWS. --- Lib/tarfile.py | 33 ++++++--------------------------- Lib/test/test_tarfile.py | 14 ++++++++++++++ Misc/NEWS | 9 ++++++--- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index cffde45..4a41d9f 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1044,7 +1044,7 @@ class TarFile(object): can be determined, `mode' is overridden by `fileobj's mode. `fileobj' is not closed, when TarFile is closed. """ - self.name = name + self.name = os.path.abspath(name) if len(mode) > 1 or mode not in "raw": raise ValueError("mode must be 'r', 'a' or 'w'") @@ -1056,7 +1056,7 @@ class TarFile(object): self._extfileobj = False else: if self.name is None and hasattr(fileobj, "name"): - self.name = fileobj.name + self.name = os.path.abspath(fileobj.name) if hasattr(fileobj, "mode"): self.mode = fileobj.mode self._extfileobj = True @@ -1192,24 +1192,12 @@ class TarFile(object): except (ImportError, AttributeError): raise CompressionError("gzip module is not available") - pre, ext = os.path.splitext(name) - pre = os.path.basename(pre) - if ext == ".tgz": - ext = ".tar" - if ext == ".gz": - ext = "" - tarname = pre + ext - if fileobj is None: fileobj = file(name, mode + "b") - if mode != "r": - name = tarname - try: - t = cls.taropen(tarname, mode, - gzip.GzipFile(name, mode, compresslevel, fileobj) - ) + t = cls.taropen(name, mode, + gzip.GzipFile(name, mode, compresslevel, fileobj)) except IOError: raise ReadError("not a gzip file") t._extfileobj = False @@ -1228,21 +1216,13 @@ class TarFile(object): except ImportError: raise CompressionError("bz2 module is not available") - pre, ext = os.path.splitext(name) - pre = os.path.basename(pre) - if ext == ".tbz2": - ext = ".tar" - if ext == ".bz2": - ext = "" - tarname = pre + ext - if fileobj is not None: fileobj = _BZ2Proxy(fileobj, mode) else: fileobj = bz2.BZ2File(name, mode, compresslevel=compresslevel) try: - t = cls.taropen(tarname, mode, fileobj) + t = cls.taropen(name, mode, fileobj) except IOError: raise ReadError("not a bzip2 file") t._extfileobj = False @@ -1447,8 +1427,7 @@ class TarFile(object): arcname = name # Skip if somebody tries to archive the archive... - if self.name is not None \ - and os.path.abspath(name) == os.path.abspath(self.name): + if self.name is not None and os.path.abspath(name) == self.name: self._dbg(2, "tarfile: Skipped %r" % name) return diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index f229fa5..fbcd191 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -290,6 +290,20 @@ class WriteTest(BaseTest): else: self.dst.addfile(tarinfo, f) + def test_add_self(self): + dstname = os.path.abspath(self.dstname) + + self.assertEqual(self.dst.name, dstname, "archive name must be absolute") + + self.dst.add(dstname) + self.assertEqual(self.dst.getnames(), [], "added the archive to itself") + + cwd = os.getcwd() + os.chdir(dirname()) + self.dst.add(dstname) + os.chdir(cwd) + self.assertEqual(self.dst.getnames(), [], "added the archive to itself") + class Write100Test(BaseTest): # The name field in a tar header stores strings of at most 100 chars. diff --git a/Misc/NEWS b/Misc/NEWS index f8fc7a7..205ea40 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -122,6 +122,12 @@ Extension Modules Library ------- +- Patch #1262036: Prevent TarFiles from being added to themselves under + certain conditions. + +- Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell() + work correctly together with readline(). + - Bug #737202: Make CGIHTTPServer work for scripts in subdirectories. Fix by Titus Brown. @@ -620,9 +626,6 @@ Core and builtins Library ------- -- Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell() - work correctly together with readline(). - - Correction of patch #1455898: In the mbcs decoder, set final=False for stream decoder, but final=True for the decode function. -- cgit v0.12 From f9a2c63c79f51540e261854679eeb15d873f7dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gust=C3=A4bel?= Date: Wed, 27 Dec 2006 10:36:58 +0000 Subject: Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument. Backport from rev. 53161. --- Lib/tarfile.py | 4 ++++ Lib/test/test_tarfile.py | 10 ++++++++++ Misc/NEWS | 2 ++ 3 files changed, 16 insertions(+) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 4a41d9f..4c7dadb 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1133,9 +1133,13 @@ class TarFile(object): # Find out which *open() is appropriate for opening the file. for comptype in cls.OPEN_METH: func = getattr(cls, cls.OPEN_METH[comptype]) + if fileobj is not None: + saved_pos = fileobj.tell() try: return func(name, "r", fileobj) except (ReadError, CompressionError): + if fileobj is not None: + fileobj.seek(saved_pos) continue raise ReadError("file could not be opened successfully") diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index fbcd191..692d72a 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -625,6 +625,15 @@ class FileModeTest(unittest.TestCase): self.assertEqual(tarfile.filemode(0755), '-rwxr-xr-x') self.assertEqual(tarfile.filemode(07111), '---s--s--t') +class OpenFileobjTest(BaseTest): + # Test for SF bug #1496501. + + def test_opener(self): + fobj = StringIO.StringIO("foo\n") + try: + tarfile.open("", "r", fileobj=fobj) + except tarfile.ReadError: + self.assertEqual(fobj.tell(), 0, "fileobj's position has moved") if bz2: # Bzip2 TestCases @@ -670,6 +679,7 @@ def test_main(): tests = [ FileModeTest, + OpenFileobjTest, ReadTest, ReadStreamTest, ReadDetectTest, diff --git a/Misc/NEWS b/Misc/NEWS index 205ea40..9acc771 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -122,6 +122,8 @@ Extension Modules Library ------- +- Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument. + - Patch #1262036: Prevent TarFiles from being added to themselves under certain conditions. -- cgit v0.12 From 0c40ca6eb8f7331e7060f60a1db639e38e4d0403 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Thu, 28 Dec 2006 04:39:54 +0000 Subject: Remove a stray (old) macro name left around (I guess) --- Doc/api/newtypes.tex | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/api/newtypes.tex b/Doc/api/newtypes.tex index 43d2f88..e5c5aac 100644 --- a/Doc/api/newtypes.tex +++ b/Doc/api/newtypes.tex @@ -103,8 +103,6 @@ defining new object types. the value for the \var{methods} argument]{2.3} \end{cfuncdesc} -DL_IMPORT - \begin{cvardesc}{PyObject}{_Py_NoneStruct} Object which is visible in Python as \code{None}. This should only be accessed using the \code{Py_None} macro, which evaluates to a -- cgit v0.12 From e38ecee5c3c6ea0f0eba2dfe49c110279626b5e0 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Fri, 29 Dec 2006 03:01:06 +0000 Subject: SF bug #1623890, fix argument name in docstring --- Lib/subprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 5d79ea6..9816122 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -166,7 +166,7 @@ wait() communicate(input=None) Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to - terminate. The optional stdin argument should be a string to be + terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child. -- cgit v0.12 From 04e820443b78edebc986212e74291daba2480a12 Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Fri, 29 Dec 2006 14:42:17 +0000 Subject: Backport trunk checkin r51565: Fix SF bug #1545837: array.array borks on deepcopy. array.__deepcopy__() needs to take an argument, even if it doesn't actually use it. --- Lib/test/test_array.py | 7 +++++++ Misc/ACKS | 1 + Modules/arraymodule.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 62361fc..06f13cd 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -85,6 +85,13 @@ class BaseTest(unittest.TestCase): self.assertNotEqual(id(a), id(b)) self.assertEqual(a, b) + def test_deepcopy(self): + import copy + a = array.array(self.typecode, self.example) + b = copy.deepcopy(a) + self.assertNotEqual(id(a), id(b)) + self.assertEqual(a, b) + def test_pickle(self): for protocol in (0, 1, 2): a = array.array(self.typecode, self.example) diff --git a/Misc/ACKS b/Misc/ACKS index 2efbd05..7524bae 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -242,6 +242,7 @@ Dag Gruneau Michael Guravage Lars Gustäbel Barry Haddow +Václav Haisman Paul ten Hagen Rasmus Hahn Peter Haight diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index efa7835..9de14fd 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1495,7 +1495,7 @@ PyMethodDef array_methods[] = { copy_doc}, {"count", (PyCFunction)array_count, METH_O, count_doc}, - {"__deepcopy__",(PyCFunction)array_copy, METH_NOARGS, + {"__deepcopy__",(PyCFunction)array_copy, METH_O, copy_doc}, {"extend", (PyCFunction)array_extend, METH_O, extend_doc}, -- cgit v0.12 From 9cdf70399f9d61434741f1efb3eff01bfa26f656 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 29 Dec 2006 18:49:13 +0000 Subject: For sets with cyclical reprs, emit '...' instead of recursing. --- Lib/test/test_set.py | 26 ++++++++++++++++++++++++++ Misc/NEWS | 3 +++ Objects/setobject.c | 28 ++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 422cc41..dedd1fb 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -21,6 +21,11 @@ class BadCmp: def __cmp__(self, other): raise RuntimeError +class ReprWrapper: + 'Used to test self-referential repr() calls' + def __repr__(self): + return repr(self.value) + class TestJointOps(unittest.TestCase): # Tests common to both set and frozenset @@ -244,6 +249,27 @@ class TestJointOps(unittest.TestCase): self.assertRaises(RuntimeError, s.discard, BadCmp()) self.assertRaises(RuntimeError, s.remove, BadCmp()) + def test_cyclical_repr(self): + w = ReprWrapper() + s = self.thetype([w]) + w.value = s + name = repr(s).partition('(')[0] # strip class name from repr string + self.assertEqual(repr(s), '%s([%s(...)])' % (name, name)) + + def test_cyclical_print(self): + w = ReprWrapper() + s = self.thetype([w]) + w.value = s + try: + fo = open(test_support.TESTFN, "wb") + print >> fo, s, + fo.close() + fo = open(test_support.TESTFN, "rb") + self.assertEqual(fo.read(), repr(s)) + finally: + fo.close() + os.remove(test_support.TESTFN) + class TestSet(TestJointOps): thetype = set diff --git a/Misc/NEWS b/Misc/NEWS index 9acc771..7ab30ed 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -18,6 +18,9 @@ Core and builtins custom ``__eq__()`` method to confuse set internals when class instances were used as a set's elements and the ``__eq__()`` method mutated the set. +- The repr for self-referential sets and fronzensets now shows "..." instead + of falling into infinite recursion. + - Eliminated unnecessary repeated calls to hash() by set.intersection() and set.symmetric_difference_update(). diff --git a/Objects/setobject.c b/Objects/setobject.c index d33fff9..507a07b 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -572,34 +572,54 @@ set_tp_print(PySetObject *so, FILE *fp, int flags) Py_ssize_t pos=0; char *emit = ""; /* No separator emitted on first pass */ char *separator = ", "; + int status = Py_ReprEnter((PyObject*)so); + + if (status != 0) { + if (status < 0) + return status; + fprintf(fp, "%s(...)", so->ob_type->tp_name); + return 0; + } fprintf(fp, "%s([", so->ob_type->tp_name); while (set_next(so, &pos, &entry)) { fputs(emit, fp); emit = separator; - if (PyObject_Print(entry->key, fp, 0) != 0) + if (PyObject_Print(entry->key, fp, 0) != 0) { + Py_ReprLeave((PyObject*)so); return -1; + } } fputs("])", fp); + Py_ReprLeave((PyObject*)so); return 0; } static PyObject * set_repr(PySetObject *so) { - PyObject *keys, *result, *listrepr; + PyObject *keys, *result=NULL, *listrepr; + int status = Py_ReprEnter((PyObject*)so); + + if (status != 0) { + if (status < 0) + return NULL; + return PyString_FromFormat("%s(...)", so->ob_type->tp_name); + } keys = PySequence_List((PyObject *)so); if (keys == NULL) - return NULL; + goto done; listrepr = PyObject_Repr(keys); Py_DECREF(keys); if (listrepr == NULL) - return NULL; + goto done; result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name, PyString_AS_STRING(listrepr)); Py_DECREF(listrepr); +done: + Py_ReprLeave((PyObject*)so); return result; } -- cgit v0.12 From d0f672935607df950d01b3e213bb84496b7c65eb Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Thu, 4 Jan 2007 06:26:22 +0000 Subject: SF #1627373, fix typo in CarbonEvt. --- Doc/mac/toolbox.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/mac/toolbox.tex b/Doc/mac/toolbox.tex index 9fbcb84..e7ce24f 100644 --- a/Doc/mac/toolbox.tex +++ b/Doc/mac/toolbox.tex @@ -65,7 +65,7 @@ only partially. \modulesynopsis{Interface to the Component Manager.} \section{\module{Carbon.CarbonEvt} --- Carbon Event Manager} -\declaremodule{standard}{Carbon.CaronEvt} +\declaremodule{standard}{Carbon.CarbonEvt} \platform{Mac} \modulesynopsis{Interface to the Carbon Event Manager.} -- cgit v0.12 From ca516d21abf7d5c8857868744a58e6de85f4f103 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 4 Jan 2007 17:53:16 +0000 Subject: Fix stability of heapq's nlargest() and nsmallest(). --- Lib/heapq.py | 8 ++------ Lib/test/test_heapq.py | 24 ++++++++++++------------ Misc/NEWS | 2 ++ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Lib/heapq.py b/Lib/heapq.py index 04725cd..753c3b7 100644 --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -130,7 +130,7 @@ __all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'nlargest', 'nsmallest'] from itertools import islice, repeat, count, imap, izip, tee -from operator import itemgetter +from operator import itemgetter, neg import bisect def heappush(heap, item): @@ -315,8 +315,6 @@ def nsmallest(n, iterable, key=None): Equivalent to: sorted(iterable, key=key)[:n] """ - if key is None: - return _nsmallest(n, iterable) in1, in2 = tee(iterable) it = izip(imap(key, in1), count(), in2) # decorate result = _nsmallest(n, it) @@ -328,10 +326,8 @@ def nlargest(n, iterable, key=None): Equivalent to: sorted(iterable, key=key, reverse=True)[:n] """ - if key is None: - return _nlargest(n, iterable) in1, in2 = tee(iterable) - it = izip(imap(key, in1), count(), in2) # decorate + it = izip(imap(key, in1), imap(neg, count()), in2) # decorate result = _nlargest(n, it) return map(itemgetter(2), result) # undecorate diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index 2da4f8c..e9f2798 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -104,20 +104,20 @@ class TestHeap(unittest.TestCase): self.assertEqual(heap_sorted, sorted(data)) def test_nsmallest(self): - data = [random.randrange(2000) for i in range(1000)] - f = lambda x: x * 547 % 2000 - for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100): - self.assertEqual(nsmallest(n, data), sorted(data)[:n]) - self.assertEqual(nsmallest(n, data, key=f), - sorted(data, key=f)[:n]) + data = [(random.randrange(2000), i) for i in range(1000)] + for f in (None, lambda x: x[0] * 547 % 2000): + for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100): + self.assertEqual(nsmallest(n, data), sorted(data)[:n]) + self.assertEqual(nsmallest(n, data, key=f), + sorted(data, key=f)[:n]) def test_nlargest(self): - data = [random.randrange(2000) for i in range(1000)] - f = lambda x: x * 547 % 2000 - for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100): - self.assertEqual(nlargest(n, data), sorted(data, reverse=True)[:n]) - self.assertEqual(nlargest(n, data, key=f), - sorted(data, key=f, reverse=True)[:n]) + data = [(random.randrange(2000), i) for i in range(1000)] + for f in (None, lambda x: x[0] * 547 % 2000): + for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100): + self.assertEqual(nlargest(n, data), sorted(data, reverse=True)[:n]) + self.assertEqual(nlargest(n, data, key=f), + sorted(data, key=f, reverse=True)[:n]) #============================================================================== diff --git a/Misc/NEWS b/Misc/NEWS index 7ab30ed..aab3e43 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -125,6 +125,8 @@ Extension Modules Library ------- +- Fix sort stability in heapq.nlargest() and nsmallest(). + - Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument. - Patch #1262036: Prevent TarFiles from being added to themselves under -- cgit v0.12 From bea1c70144e4de97312e9d04dd4c90e549f79f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Thu, 4 Jan 2007 21:06:57 +0000 Subject: Bug #1566280: Explicitly invoke threading._shutdown from Py_Main, to avoid relying on atexit. --- Lib/threading.py | 10 +++++----- Misc/NEWS | 3 +++ Modules/main.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Lib/threading.py b/Lib/threading.py index 5655dde..fecd3cc 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -636,13 +636,11 @@ class _MainThread(Thread): _active_limbo_lock.acquire() _active[_get_ident()] = self _active_limbo_lock.release() - import atexit - atexit.register(self.__exitfunc) def _set_daemon(self): return False - def __exitfunc(self): + def _exitfunc(self): self._Thread__stop() t = _pickSomeNonDaemonThread() if t: @@ -715,9 +713,11 @@ def enumerate(): from thread import stack_size -# Create the main thread object +# Create the main thread object, +# and make it available for the interpreter +# (Py_Main) as threading._shutdown. -_MainThread() +_shutdown = _MainThread()._exitfunc # get thread-local implementation, either from the thread # module, or from the python fallback diff --git a/Misc/NEWS b/Misc/NEWS index aab3e43..74af3e4 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1566280: Explicitly invoke threading._shutdown from Py_Main, + to avoid relying on atexit. + - Bug #1590891: random.randrange don't return correct value for big number - Bug #1456209: In some obscure cases it was possible for a class with a diff --git a/Modules/main.c b/Modules/main.c index ac5f96e..83d567f 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -176,6 +176,33 @@ static int RunModule(char *module) return 0; } +/* Wait until threading._shutdown completes, provided + the threading module was imported in the first place. + The shutdown routine will wait until all non-daemon + "threading" threads have completed. */ +#include "abstract.h" +static void +WaitForThreadShutdown() +{ +#ifdef WITH_THREAD + PyObject *result; + PyThreadState *tstate = PyThreadState_GET(); + PyObject *threading = PyMapping_GetItemString(tstate->interp->modules, + "threading"); + if (threading == NULL) { + /* threading not imported */ + PyErr_Clear(); + return; + } + result = PyObject_CallMethod(threading, "_shutdown", ""); + if (result == NULL) + PyErr_WriteUnraisable(threading); + else + Py_DECREF(result); + Py_DECREF(threading); +#endif +} + /* Main program */ int @@ -513,6 +540,8 @@ Py_Main(int argc, char **argv) /* XXX */ sts = PyRun_AnyFileFlags(stdin, "", &cf) != 0; + WaitForThreadShutdown(); + Py_Finalize(); #ifdef RISCOS if (Py_RISCOSWimpFlag) -- cgit v0.12 From 1a050f5f52c88c28f7d00b5728e3ede548c8cb7e Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 5 Jan 2007 02:09:06 +0000 Subject: support linking the _bsddb extension module against BerkeleyDB 4.5 [backport of r53252] --- Doc/lib/libbsddb.tex | 2 +- Lib/bsddb/dbobj.py | 5 +++-- Lib/bsddb/test/test_1413192.py | 2 +- Misc/NEWS | 2 ++ Modules/_bsddb.c | 10 +++++++++- setup.py | 6 +++--- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Doc/lib/libbsddb.tex b/Doc/lib/libbsddb.tex index 85ea824..e9d7e21 100644 --- a/Doc/lib/libbsddb.tex +++ b/Doc/lib/libbsddb.tex @@ -16,7 +16,7 @@ serialize them somehow, typically using \function{marshal.dumps()} or \function{pickle.dumps()}. The \module{bsddb} module requires a Berkeley DB library version from -3.3 thru 4.4. +3.3 thru 4.5. \begin{seealso} \seeurl{http://pybsddb.sourceforge.net/} diff --git a/Lib/bsddb/dbobj.py b/Lib/bsddb/dbobj.py index 73a3010..b74ee72 100644 --- a/Lib/bsddb/dbobj.py +++ b/Lib/bsddb/dbobj.py @@ -55,8 +55,9 @@ class DBEnv: return apply(self._cobj.set_lg_max, args, kwargs) def set_lk_detect(self, *args, **kwargs): return apply(self._cobj.set_lk_detect, args, kwargs) - def set_lk_max(self, *args, **kwargs): - return apply(self._cobj.set_lk_max, args, kwargs) + if db.version() < (4,5): + def set_lk_max(self, *args, **kwargs): + return apply(self._cobj.set_lk_max, args, kwargs) def set_lk_max_locks(self, *args, **kwargs): return apply(self._cobj.set_lk_max_locks, args, kwargs) def set_lk_max_lockers(self, *args, **kwargs): diff --git a/Lib/bsddb/test/test_1413192.py b/Lib/bsddb/test/test_1413192.py index 3c13536..436f407 100644 --- a/Lib/bsddb/test/test_1413192.py +++ b/Lib/bsddb/test/test_1413192.py @@ -14,7 +14,7 @@ except ImportError: env_name = '.' env = db.DBEnv() -env.open(env_name, db.DB_CREATE | db.DB_INIT_TXN) +env.open(env_name, db.DB_CREATE | db.DB_INIT_TXN | db.DB_INIT_MPOOL) the_txn = env.txn_begin() map = db.DB(env) diff --git a/Misc/NEWS b/Misc/NEWS index 74af3e4..bf793a3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,8 @@ Extension Modules - Make regex engine raise MemoryError if allocating memory fails. +- Added support for linking the bsddb module against BerkeleyDB 4.5.x. + Library ------- diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index 8e343a6..9622c90 100644 --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -98,7 +98,7 @@ #error "eek! DBVER can't handle minor versions > 9" #endif -#define PY_BSDDB_VERSION "4.4.5.1" +#define PY_BSDDB_VERSION "4.4.5.2" static char *rcs_id = "$Id$"; @@ -4127,6 +4127,7 @@ DBEnv_set_lk_detect(DBEnvObject* self, PyObject* args) } +#if (DBVER < 45) static PyObject* DBEnv_set_lk_max(DBEnvObject* self, PyObject* args) { @@ -4142,6 +4143,7 @@ DBEnv_set_lk_max(DBEnvObject* self, PyObject* args) RETURN_IF_ERR(); RETURN_NONE(); } +#endif #if (DBVER >= 32) @@ -5231,7 +5233,9 @@ static PyMethodDef DBEnv_methods[] = { {"set_lg_regionmax",(PyCFunction)DBEnv_set_lg_regionmax, METH_VARARGS}, #endif {"set_lk_detect", (PyCFunction)DBEnv_set_lk_detect, METH_VARARGS}, +#if (DBVER < 45) {"set_lk_max", (PyCFunction)DBEnv_set_lk_max, METH_VARARGS}, +#endif #if (DBVER >= 32) {"set_lk_max_locks", (PyCFunction)DBEnv_set_lk_max_locks, METH_VARARGS}, {"set_lk_max_lockers", (PyCFunction)DBEnv_set_lk_max_lockers, METH_VARARGS}, @@ -5833,7 +5837,9 @@ DL_EXPORT(void) init_bsddb(void) ADD_INT(d, DB_AFTER); ADD_INT(d, DB_APPEND); ADD_INT(d, DB_BEFORE); +#if (DBVER < 45) ADD_INT(d, DB_CACHED_COUNTS); +#endif #if (DBVER >= 41) _addIntToDict(d, "DB_CHECKPOINT", 0); #else @@ -5868,7 +5874,9 @@ DL_EXPORT(void) init_bsddb(void) ADD_INT(d, DB_POSITION); ADD_INT(d, DB_PREV); ADD_INT(d, DB_PREV_NODUP); +#if (DBVER < 45) ADD_INT(d, DB_RECORDCOUNT); +#endif ADD_INT(d, DB_SET); ADD_INT(d, DB_SET_RANGE); ADD_INT(d, DB_SET_RECNO); diff --git a/setup.py b/setup.py index 5d71181..1e5e6e6 100644 --- a/setup.py +++ b/setup.py @@ -606,7 +606,7 @@ class PyBuildExt(build_ext): # a release. Most open source OSes come with one or more # versions of BerkeleyDB already installed. - max_db_ver = (4, 4) + max_db_ver = (4, 5) min_db_ver = (3, 3) db_setup_debug = False # verbose debug prints from this script? @@ -623,7 +623,7 @@ class PyBuildExt(build_ext): '/sw/include/db3', ] # 4.x minor number specific paths - for x in (0,1,2,3,4): + for x in (0,1,2,3,4,5): db_inc_paths.append('/usr/include/db4%d' % x) db_inc_paths.append('/usr/include/db4.%d' % x) db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x) @@ -631,7 +631,7 @@ class PyBuildExt(build_ext): db_inc_paths.append('/pkg/db-4.%d/include' % x) db_inc_paths.append('/opt/db-4.%d/include' % x) # 3.x minor number specific paths - for x in (2,3): + for x in (3,): db_inc_paths.append('/usr/include/db3%d' % x) db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x) db_inc_paths.append('/usr/local/include/db3%d' % x) -- cgit v0.12 From 7770f9f6d260548fbed4059c81a1727dc098e5b5 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Fri, 5 Jan 2007 05:28:50 +0000 Subject: Backport: Prevent crash on shutdown which can occur if we are finalizing and the module dict has been cleared already and some object raises a warning (like in a __del__). --- Misc/NEWS | 3 +++ Python/errors.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index bf793a3..76ed61e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Prevent seg fault on shutdown which could occur if an object + raised a warning. + - Bug #1566280: Explicitly invoke threading._shutdown from Py_Main, to avoid relying on atexit. diff --git a/Python/errors.c b/Python/errors.c index 66a734e..f31f025 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -640,7 +640,8 @@ PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level) if (warnings_module != NULL) { dict = PyModule_GetDict(warnings_module); - func = PyDict_GetItemString(dict, "warn"); + if (dict != NULL) + func = PyDict_GetItemString(dict, "warn"); } if (func == NULL) { PySys_WriteStderr("warning: %s\n", message); -- cgit v0.12 From a6e0f502ea99545385264fafb73c4134712c35be Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 5 Jan 2007 07:22:29 +0000 Subject: typo fix --- Doc/lib/libsimplexmlrpc.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libsimplexmlrpc.tex b/Doc/lib/libsimplexmlrpc.tex index 7a97861..6b45855 100644 --- a/Doc/lib/libsimplexmlrpc.tex +++ b/Doc/lib/libsimplexmlrpc.tex @@ -15,7 +15,7 @@ CGI environment, using \class{CGIXMLRPCRequestHandler}. \begin{classdesc}{SimpleXMLRPCServer}{addr\optional{, requestHandler\optional{, - logRequests\optional{allow_none\optional{, encoding}}}}} + logRequests\optional{, allow_none\optional{, encoding}}}}} Create a new server instance. This class provides methods for registration of functions that can be called by -- cgit v0.12 From 3b015c46a5f12322839512d54e15f51f5e10d3e4 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 5 Jan 2007 14:24:36 +0000 Subject: [Bug #1622533] Make docstrings raw strings because they contain control characters (\0, \1) --- Lib/StringIO.py | 2 +- Lib/difflib.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 1e5f254..232009f 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -137,7 +137,7 @@ class StringIO: return r def readline(self, length=None): - """Read one entire line from the file. + r"""Read one entire line from the file. A trailing newline character is kept in the string (but may be absent when a file ends with an incomplete line). If the size argument is diff --git a/Lib/difflib.py b/Lib/difflib.py index 3e28b18..d1c2931 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1311,7 +1311,7 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): def _mdiff(fromlines, tolines, context=None, linejunk=None, charjunk=IS_CHARACTER_JUNK): - """Returns generator yielding marked up from/to side by side differences. + r"""Returns generator yielding marked up from/to side by side differences. Arguments: fromlines -- list of text lines to compared to tolines -- cgit v0.12 -- cgit v0.12 -- cgit v0.12 -- cgit v0.12 -- cgit v0.12 From a7118d3a4aa7e2c0f1c7fbc441d39975344dfd33 Mon Sep 17 00:00:00 2001 From: Anthony Baxter Date: Sat, 6 Jan 2007 04:50:44 +0000 Subject: update to (c) years to include 2007 --- Doc/README | 2 +- LICENSE | 6 +++--- PC/python_nt.rc | 2 +- PCbuild/python20.wse | 4 ++-- PCbuild8/python20.wse | 4 ++-- Python/getcopyright.c | 2 +- README | 3 ++- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Doc/README b/Doc/README index 484fce6..a426ba2 100644 --- a/Doc/README +++ b/Doc/README @@ -229,7 +229,7 @@ The Python source is copyrighted, but you can freely use and copy it as long as you don't change or remove the copyright notice: ---------------------------------------------------------------------- -Copyright (c) 2000-2006 Python Software Foundation. +Copyright (c) 2000-2007 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. diff --git a/LICENSE b/LICENSE index 5affefc..0ae414c 100644 --- a/LICENSE +++ b/LICENSE @@ -88,9 +88,9 @@ license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright (c) -2001, 2002, 2003, 2004, 2005, 2006 Python Software Foundation; All Rights -Reserved" are retained in Python alone or in any derivative version -prepared by Licensee. +2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software Foundation; +All Rights Reserved" are retained in Python alone or in any derivative +version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates Python or any part thereof, and wants to make diff --git a/PC/python_nt.rc b/PC/python_nt.rc index a4e97fd..6fb73b6 100644 --- a/PC/python_nt.rc +++ b/PC/python_nt.rc @@ -61,7 +61,7 @@ BEGIN VALUE "FileDescription", "Python Core\0" VALUE "FileVersion", PYTHON_VERSION VALUE "InternalName", "Python DLL\0" - VALUE "LegalCopyright", "Copyright © 2001-2006 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0" + VALUE "LegalCopyright", "Copyright © 2001-2007 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0" VALUE "OriginalFilename", PYTHON_DLL_NAME "\0" VALUE "ProductName", "Python\0" VALUE "ProductVersion", PYTHON_VERSION diff --git a/PCbuild/python20.wse b/PCbuild/python20.wse index a62265a..fa11af4 100644 --- a/PCbuild/python20.wse +++ b/PCbuild/python20.wse @@ -24,8 +24,8 @@ item: Global Dialogs Version=8 Version File=2.4a1 Version Description=Python Programming Language - Version Copyright=©2001-2006 Python Software Foundation - Version Company=PythonLabs at Zope Corporation + Version Copyright=©2001-2007 Python Software Foundation + Version Company=Python Software Foundation Crystal Format=10111100101100000010001001001001 Step View=&All Variable Name1=_WISE_ diff --git a/PCbuild8/python20.wse b/PCbuild8/python20.wse index 33a3491..a8d9785 100644 --- a/PCbuild8/python20.wse +++ b/PCbuild8/python20.wse @@ -24,8 +24,8 @@ item: Global Dialogs Version=8 Version File=2.4a1 Version Description=Python Programming Language - Version Copyright=©2001-2006 Python Software Foundation - Version Company=PythonLabs at Zope Corporation + Version Copyright=©2001-2007 Python Software Foundation + Version Company=Python Software Foundation Crystal Format=10111100101100000010001001001001 Step View=&All Variable Name1=_WISE_ diff --git a/Python/getcopyright.c b/Python/getcopyright.c index 325aee5..c10aea4 100644 --- a/Python/getcopyright.c +++ b/Python/getcopyright.c @@ -4,7 +4,7 @@ static char cprt[] = "\ -Copyright (c) 2001-2006 Python Software Foundation.\n\ +Copyright (c) 2001-2007 Python Software Foundation.\n\ All Rights Reserved.\n\ \n\ Copyright (c) 2000 BeOpen.com.\n\ diff --git a/README b/README index 7e4c3aa..cc95ab5 100644 --- a/README +++ b/README @@ -1,7 +1,8 @@ This is Python version 2.5 ========================== -Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Python Software Foundation. +Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software +Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. -- cgit v0.12 From 6cdc34672ccf0e09d7b8b1a2c515159544bec6d4 Mon Sep 17 00:00:00 2001 From: Peter Astrand Date: Sun, 7 Jan 2007 09:00:11 +0000 Subject: Re-implemented fix for #1531862 once again, in a way that works with Python 2.2. Fixes bug #1603424. --- Lib/subprocess.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 9816122..abd790d 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1004,8 +1004,12 @@ class Popen(object): # Close pipe fds. Make sure we don't close the same # fd more than once, or standard fds. - for fd in set((p2cread, c2pwrite, errwrite))-set((0,1,2)): - if fd: os.close(fd) + if p2cread and p2cread not in (0,): + os.close(p2cread) + if c2pwrite and c2pwrite not in (p2cread, 1): + os.close(c2pwrite) + if errwrite and errwrite not in (p2cread, c2pwrite, 2): + os.close(errwrite) # Close all other fds, if asked for if close_fds: -- cgit v0.12 From 73fa6b58dd7b7febb1cb9e935e9c7f29cfa49b99 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 8 Jan 2007 09:36:17 +0000 Subject: Added relativeCreated to Formatter doc (has been in the system for a long time - was unaccountably left out of the docs and not noticed until now). Documentation clarified to mention optional parameters. Documentation omitted the additional parameter to LogRecord.__init__ which was added in 2.5. (See SF #1569622). --- Doc/lib/liblogging.tex | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Doc/lib/liblogging.tex b/Doc/lib/liblogging.tex index c00c0d0..b97854d 100644 --- a/Doc/lib/liblogging.tex +++ b/Doc/lib/liblogging.tex @@ -530,8 +530,8 @@ as those created locally. Logger-level filtering is applied using \method{filter()}. \end{methoddesc} -\begin{methoddesc}{makeRecord}{name, lvl, fn, lno, msg, args, exc_info, - func, extra} +\begin{methoddesc}{makeRecord}{name, lvl, fn, lno, msg, args, exc_info + \optional{, func, extra}} This is a factory method which can be overridden in subclasses to create specialized \class{LogRecord} instances. \versionchanged[\var{func} and \var{extra} were added]{2.5} @@ -1399,6 +1399,9 @@ Currently, the useful mapping keys in a \class{LogRecord} are: (if available).} \lineii{\%(created)f} {Time when the \class{LogRecord} was created (as returned by \function{time.time()}).} +\lineii{\%(relativeCreated)d} {Time in milliseconds when the LogRecord was + created, relative to the time the logging module was + loaded.} \lineii{\%(asctime)s} {Human-readable time when the \class{LogRecord} was created. By default this is of the form ``2003-07-08 16:49:45,896'' (the numbers after the @@ -1481,7 +1484,7 @@ source line where the logging call was made, and any exception information to be logged. \begin{classdesc}{LogRecord}{name, lvl, pathname, lineno, msg, args, - exc_info} + exc_info \optional{, func}} Returns an instance of \class{LogRecord} initialized with interesting information. The \var{name} is the logger name; \var{lvl} is the numeric level; \var{pathname} is the absolute pathname of the source @@ -1491,7 +1494,9 @@ user-supplied message (a format string); \var{args} is the tuple which, together with \var{msg}, makes up the user message; and \var{exc_info} is the exception tuple obtained by calling \function{sys.exc_info() }(or \constant{None}, if no exception information -is available). +is available). The \var{func} is the name of the function from which the +logging call was made. If not specified, it defaults to \var{None}. +\versionchanged[\var{func} was added]{2.5} \end{classdesc} \begin{methoddesc}{getMessage}{} -- cgit v0.12 From 977061142dc2a71d8a23ad18b3676d8240d9b757 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 8 Jan 2007 10:11:58 +0000 Subject: Backported change from trunk: Made SysLogHandler more resilient in the face of syslogd failures. --- Lib/logging/handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 3552950..4ef896e 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -586,11 +586,11 @@ class SysLogHandler(logging.Handler): self.address = address self.facility = facility if type(address) == types.StringType: - self._connect_unixsocket(address) self.unixsocket = 1 + self._connect_unixsocket(address) else: - self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.unixsocket = 0 + self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.formatter = None -- cgit v0.12 From f96725af8bf2a394b85104be13583ff091c6a634 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 8 Jan 2007 10:12:29 +0000 Subject: Backported changes from trunk: Made func argument in LogRecord.__init__ optional. Improved performance of _fixupChildren. --- Lib/logging/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index dc3400d..c727308 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -214,7 +214,7 @@ class LogRecord: information to be logged. """ def __init__(self, name, level, pathname, lineno, - msg, args, exc_info, func): + msg, args, exc_info, func=None): """ Initialize a logging record with interesting information. """ @@ -910,9 +910,12 @@ class Manager: Ensure that children of the placeholder ph are connected to the specified logger. """ - #for c in ph.loggers: + name = alogger.name + namelen = len(name) for c in ph.loggerMap.keys(): - if string.find(c.parent.name, alogger.name) <> 0: + #The if means ... if not c.parent.name.startswith(nm) + #if string.find(c.parent.name, nm) <> 0: + if c.parent.name[:namelen] != name: alogger.parent = c.parent c.parent = alogger -- cgit v0.12 From 5b44cbe6d8f9c07f6ec0da1134dc3b49ee81a4e3 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 8 Jan 2007 18:05:53 +0000 Subject: Fix zero-length corner case for iterating over a mutating deque. --- Lib/test/test_deque.py | 6 ++++++ Misc/NEWS | 3 +++ Modules/collectionsmodule.c | 5 ++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index a562922..35e1536 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -396,6 +396,12 @@ class TestVariousIteratorArgs(unittest.TestCase): d.pop() self.assertRaises(RuntimeError, it.next) + def test_runtime_error_on_empty_deque(self): + d = deque() + it = iter(d) + d.append(10) + self.assertRaises(RuntimeError, it.next) + class Deque(deque): pass diff --git a/Misc/NEWS b/Misc/NEWS index 76ed61e..4df89da 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -129,6 +129,9 @@ Extension Modules - Added support for linking the bsddb module against BerkeleyDB 4.5.x. +- Modifying an empty deque during iteration now raises RuntimeError + instead of StopIteration. + Library ------- diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index c1bd732..a0570cd 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -911,15 +911,14 @@ dequeiter_next(dequeiterobject *it) { PyObject *item; - if (it->counter == 0) - return NULL; - if (it->deque->state != it->state) { it->counter = 0; PyErr_SetString(PyExc_RuntimeError, "deque mutated during iteration"); return NULL; } + if (it->counter == 0) + return NULL; assert (!(it->b == it->deque->rightblock && it->index > it->deque->rightindex)); -- cgit v0.12 From 346085eb876df482956b66bf4c5aeb8e5a790af7 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Tue, 9 Jan 2007 19:52:31 +0000 Subject: Merged revisions 53316 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk/Lib/ctypes ........ r53316 | thomas.heller | 2007-01-09 20:19:33 +0100 (Di, 09 Jan 2007) | 4 lines Verify the sizes of the basic ctypes data types against the struct module. Backport from trunk. ........ --- Lib/ctypes/__init__.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index 61923b6..3a5c3b5 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -133,6 +133,18 @@ elif _os.name == "posix": from _ctypes import sizeof, byref, addressof, alignment, resize from _ctypes import _SimpleCData +def _check_size(typ, typecode=None): + # Check if sizeof(ctypes_type) against struct.calcsize. This + # should protect somewhat against a misconfigured libffi. + from struct import calcsize + if typecode is None: + # Most _type_ codes are the same as used in struct + typecode = typ._type_ + actual, required = sizeof(typ), calcsize(typecode) + if actual != required: + raise SystemError("sizeof(%s) wrong: %d instead of %d" % \ + (typ, actual, required)) + class py_object(_SimpleCData): _type_ = "O" def __repr__(self): @@ -140,18 +152,23 @@ class py_object(_SimpleCData): return super(py_object, self).__repr__() except ValueError: return "%s()" % type(self).__name__ +_check_size(py_object, "P") class c_short(_SimpleCData): _type_ = "h" +_check_size(c_short) class c_ushort(_SimpleCData): _type_ = "H" +_check_size(c_ushort) class c_long(_SimpleCData): _type_ = "l" +_check_size(c_long) class c_ulong(_SimpleCData): _type_ = "L" +_check_size(c_ulong) if _calcsize("i") == _calcsize("l"): # if int and long have the same size, make c_int an alias for c_long @@ -160,15 +177,19 @@ if _calcsize("i") == _calcsize("l"): else: class c_int(_SimpleCData): _type_ = "i" + _check_size(c_int) class c_uint(_SimpleCData): _type_ = "I" + _check_size(c_uint) class c_float(_SimpleCData): _type_ = "f" +_check_size(c_float) class c_double(_SimpleCData): _type_ = "d" +_check_size(c_double) if _calcsize("l") == _calcsize("q"): # if long and long long have the same size, make c_longlong an alias for c_long @@ -177,33 +198,40 @@ if _calcsize("l") == _calcsize("q"): else: class c_longlong(_SimpleCData): _type_ = "q" + _check_size(c_longlong) class c_ulonglong(_SimpleCData): _type_ = "Q" ## def from_param(cls, val): ## return ('d', float(val), val) ## from_param = classmethod(from_param) + _check_size(c_ulonglong) class c_ubyte(_SimpleCData): _type_ = "B" c_ubyte.__ctype_le__ = c_ubyte.__ctype_be__ = c_ubyte # backward compatibility: ##c_uchar = c_ubyte +_check_size(c_ubyte) class c_byte(_SimpleCData): _type_ = "b" c_byte.__ctype_le__ = c_byte.__ctype_be__ = c_byte +_check_size(c_byte) class c_char(_SimpleCData): _type_ = "c" c_char.__ctype_le__ = c_char.__ctype_be__ = c_char +_check_size(c_char) class c_char_p(_SimpleCData): _type_ = "z" +_check_size(c_char_p, "P") class c_void_p(_SimpleCData): _type_ = "P" c_voidp = c_void_p # backwards compatibility (to a bug) +_check_size(c_void_p) # This cache maps types to pointers to them. _pointer_type_cache = {} -- cgit v0.12 From 5131925034319a9ebaa21be0db37b5b75db3a697 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Wed, 10 Jan 2007 20:07:29 +0000 Subject: Change the ctypes version number to "1.0.2". --- Lib/ctypes/__init__.py | 2 +- Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index 3a5c3b5..4ebdb79 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -5,7 +5,7 @@ import os as _os, sys as _sys -__version__ = "1.0.1" +__version__ = "1.0.2" from _ctypes import Union, Structure, Array from _ctypes import _Pointer diff --git a/Misc/NEWS b/Misc/NEWS index 4df89da..87f1629 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -89,6 +89,8 @@ Core and builtins Extension Modules ----------------- +- The version number of the ctypes package was changed to "1.0.2". + - Patch #1544279: Improve thread-safety of the socket module by moving the sock_addr_t storage out of the socket object. -- cgit v0.12 From 3193763bdfc42c7ce5df86fe2327c6ff74d26209 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Wed, 10 Jan 2007 20:44:21 +0000 Subject: Must update the version number on the extension module as well. --- Modules/_ctypes/_ctypes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 4d57416..08977eb 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -4744,7 +4744,7 @@ init_ctypes(void) #endif PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); - PyModule_AddStringConstant(m, "__version__", "1.0.1"); + PyModule_AddStringConstant(m, "__version__", "1.0.2"); PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove)); PyModule_AddObject(m, "_memset_addr", PyLong_FromVoidPtr(memset)); -- cgit v0.12 From 1c3d0de47264e6bdfa296067294b7c66592f5a2f Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Thu, 11 Jan 2007 10:25:45 +0000 Subject: - Make the documentation match the code and the docstring --- Doc/lib/libsmtplib.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/lib/libsmtplib.tex b/Doc/lib/libsmtplib.tex index 2f87bc4..3d74dd8 100644 --- a/Doc/lib/libsmtplib.tex +++ b/Doc/lib/libsmtplib.tex @@ -173,7 +173,7 @@ or may raise the following exceptions: The server didn't reply properly to the \samp{HELO} greeting. \item[\exception{SMTPAuthenticationError}] The server didn't accept the username/password combination. - \item[\exception{SMTPError}] + \item[\exception{SMTPException}] No suitable authentication method was found. \end{description} \end{methoddesc} -- cgit v0.12 From 9e031c7c9dac1b087a38dbc3555bbbe56a8097fb Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Thu, 11 Jan 2007 11:42:43 +0000 Subject: - idle: Honor the "Cancel" action in the save dialog (Debian bug #299092). --- Lib/idlelib/EditorWindow.py | 2 +- Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index 6b8ab63..259c7f3 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -819,7 +819,7 @@ class EditorWindow(object): def close(self): reply = self.maybesave() - if reply != "cancel": + if str(reply) != "cancel": self._close() return reply diff --git a/Misc/NEWS b/Misc/NEWS index 87f1629..d24dd4d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -248,6 +248,8 @@ Tools/Demos - Patch #1552024: add decorator support to unparse.py demo script. +- idle: Honor the "Cancel" action in the save dialog (Debian bug #299092). + Tests ----- -- cgit v0.12 From 535989ecb68da1affc531e866d190bfdbd9fc5fc Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 11 Jan 2007 18:21:04 +0000 Subject: SF #1486663 -- Allow keyword args in subclasses of set() and frozenset(). --- Lib/test/test_set.py | 11 +++++++++++ Objects/setobject.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index dedd1fb..49bdec3 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -468,6 +468,16 @@ class SetSubclass(set): class TestSetSubclass(TestSet): thetype = SetSubclass +class SetSubclassWithKeywordArgs(set): + def __init__(self, iterable=[], newarg=None): + set.__init__(self, iterable) + +class TestSetSubclassWithKeywordArgs(TestSet): + + def test_keywords_in_subclass(self): + 'SF bug #1486663 -- this used to erroneously raise a TypeError' + SetSubclassWithKeywordArgs(newarg=1) + class TestFrozenSet(TestJointOps): thetype = frozenset @@ -1450,6 +1460,7 @@ def test_main(verbose=None): test_classes = ( TestSet, TestSetSubclass, + TestSetSubclassWithKeywordArgs, TestFrozenSet, TestFrozenSetSubclass, TestSetOfSets, diff --git a/Objects/setobject.c b/Objects/setobject.c index 507a07b..f038ee3 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1004,7 +1004,7 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *iterable = NULL, *result; - if (!_PyArg_NoKeywords("frozenset()", kwds)) + if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) @@ -1048,7 +1048,7 @@ PySet_Fini(void) static PyObject * set_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - if (!_PyArg_NoKeywords("set()", kwds)) + if (type == &PySet_Type && !_PyArg_NoKeywords("set()", kwds)) return NULL; return make_new_set(type, NULL); -- cgit v0.12 -- cgit v0.12 -- cgit v0.12 -- cgit v0.12 From 29794ecd43efc2c1b33da2c4e5064f0a1a654342 Mon Sep 17 00:00:00 2001 From: Peter Astrand Date: Sat, 13 Jan 2007 22:37:11 +0000 Subject: Fix for bug #1634343: allow specifying empty arguments on Windows --- Lib/subprocess.py | 2 +- Lib/test/test_subprocess.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index abd790d..eb1a735 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -499,7 +499,7 @@ def list2cmdline(seq): if result: result.append(' ') - needquote = (" " in arg) or ("\t" in arg) + needquote = (" " in arg) or ("\t" in arg) or arg == "" if needquote: result.append('"') diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 64f8d40..c2db6fa 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -430,6 +430,8 @@ class ProcessTestCase(unittest.TestCase): '"a\\\\b c" d e') self.assertEqual(subprocess.list2cmdline(['a\\\\b\\ c', 'd', 'e']), '"a\\\\b\\ c" d e') + self.assertEqual(subprocess.list2cmdline(['ab', '']), + 'ab ""') def test_poll(self): -- cgit v0.12 From 2a98c56c13fc9f284d4e7af27417053b2fb500e3 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Wed, 17 Jan 2007 09:53:03 +0000 Subject: Merged revisions 53466 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk/Modules/_ctypes ........ r53466 | thomas.heller | 2007-01-17 10:40:34 +0100 (Mi, 17 Jan 2007) | 2 lines Replace C++ comments with C comments. ........ --- Modules/_ctypes/_ctypes_test.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c index 7331d01..c10da0d 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -58,22 +58,25 @@ EXPORT(void) _testfunc_v(int a, int b, int *presult) EXPORT(int) _testfunc_i_bhilfd(signed char b, short h, int i, long l, float f, double d) { -// printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n", -// b, h, i, l, f, d); +/* printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n", + b, h, i, l, f, d); +*/ return (int)(b + h + i + l + f + d); } EXPORT(float) _testfunc_f_bhilfd(signed char b, short h, int i, long l, float f, double d) { -// printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n", -// b, h, i, l, f, d); +/* printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n", + b, h, i, l, f, d); +*/ return (float)(b + h + i + l + f + d); } EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f, double d) { -// printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", -// b, h, i, l, f, d); +/* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", + b, h, i, l, f, d); +*/ return (double)(b + h + i + l + f + d); } @@ -368,8 +371,9 @@ DL_EXPORT(int) unpack_bitfields(struct BITS *bits, char name) } PyMethodDef module_methods[] = { -// {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, -// {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, +/* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, + {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, +*/ {"func_si", py_func_si, METH_VARARGS}, {"func", py_func, METH_NOARGS}, { NULL, NULL, 0, NULL}, -- cgit v0.12 From 225755dc366db4e7fc084c3257d65825772c71a4 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Wed, 17 Jan 2007 19:53:24 +0000 Subject: Merged revisions 53402 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk/Lib/ctypes ........ r53402 | thomas.heller | 2007-01-12 21:17:34 +0100 (Fr, 12 Jan 2007) | 6 lines patch #1610795: BSD version of ctypes.util.find_library, by Martin Kammerhofer. Backported from trunk. ........ --- Lib/ctypes/util.py | 78 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 2ee2968..f713353 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -46,24 +46,17 @@ elif os.name == "posix": import re, tempfile, errno def _findLib_gcc(name): - expr = '[^\(\)\s]*lib%s\.[^\(\)\s]*' % name + expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) fdout, ccout = tempfile.mkstemp() os.close(fdout) - cmd = 'if type gcc &>/dev/null; then CC=gcc; else CC=cc; fi;' \ + cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; else CC=cc; fi;' \ '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name try: - fdout, outfile = tempfile.mkstemp() - os.close(fdout) - fd = os.popen(cmd) - trace = fd.read() - err = fd.close() + f = os.popen(cmd) + trace = f.read() + f.close() finally: try: - os.unlink(outfile) - except OSError, e: - if e.errno != errno.ENOENT: - raise - try: os.unlink(ccout) except OSError, e: if e.errno != errno.ENOENT: @@ -73,29 +66,58 @@ elif os.name == "posix": return None return res.group(0) - def _findLib_ld(name): - expr = '/[^\(\)\s]*lib%s\.[^\(\)\s]*' % name - res = re.search(expr, os.popen('/sbin/ldconfig -p 2>/dev/null').read()) - if not res: - # Hm, this works only for libs needed by the python executable. - cmd = 'ldd %s 2>/dev/null' % sys.executable - res = re.search(expr, os.popen(cmd).read()) - if not res: - return None - return res.group(0) - def _get_soname(f): + # assuming GNU binutils / ELF + if not f: + return None cmd = "objdump -p -j .dynamic 2>/dev/null " + f res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read()) if not res: return None return res.group(1) - def find_library(name): - lib = _findLib_ld(name) or _findLib_gcc(name) - if not lib: - return None - return _get_soname(lib) + if (sys.platform.startswith("freebsd") + or sys.platform.startswith("openbsd") + or sys.platform.startswith("dragonfly")): + + def _num_version(libname): + # "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ] + parts = libname.split(".") + nums = [] + try: + while parts: + nums.insert(0, int(parts.pop())) + except ValueError: + pass + return nums or [ sys.maxint ] + + def find_library(name): + ename = re.escape(name) + expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename) + res = re.findall(expr, + os.popen('/sbin/ldconfig -r 2>/dev/null').read()) + if not res: + return _get_soname(_findLib_gcc(name)) + res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y))) + return res[-1] + + else: + + def _findLib_ldconfig(name): + # XXX assuming GLIBC's ldconfig (with option -p) + expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) + res = re.search(expr, + os.popen('/sbin/ldconfig -p 2>/dev/null').read()) + if not res: + # Hm, this works only for libs needed by the python executable. + cmd = 'ldd %s 2>/dev/null' % sys.executable + res = re.search(expr, os.popen(cmd).read()) + if not res: + return None + return res.group(0) + + def find_library(name): + return _get_soname(_findLib_ldconfig(name) or _findLib_gcc(name)) ################################################################ # test code -- cgit v0.12 From dcb6eba83114c5523c47097d5b763ba389ce3ffc Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Wed, 17 Jan 2007 19:55:40 +0000 Subject: Bug #1610795: ctypes.util.find_library works now on BSD systems. --- Misc/NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index d24dd4d..cdee2af 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -138,6 +138,8 @@ Extension Modules Library ------- +- Bug #1610795: ctypes.util.find_library works now on BSD systems. + - Fix sort stability in heapq.nlargest() and nsmallest(). - Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument. -- cgit v0.12 From dfad614321080b6787aa29b055fea99a339a078b Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Wed, 17 Jan 2007 19:56:06 +0000 Subject: [Part of bug #1599254] Add suggestion to Mailbox docs to use Maildir, and warn user to lock/unlock mailboxes when modifying them --- Doc/lib/libmailbox.tex | 82 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/Doc/lib/libmailbox.tex b/Doc/lib/libmailbox.tex index 75ea7e1..961b050 100644 --- a/Doc/lib/libmailbox.tex +++ b/Doc/lib/libmailbox.tex @@ -25,22 +25,29 @@ Maildir, mbox, MH, Babyl, and MMDF. A mailbox, which may be inspected and modified. \end{classdesc*} +The \class{Mailbox} class defines an interface and +is not intended to be instantiated. Instead, format-specific +subclasses should inherit from \class{Mailbox} and your code +should instantiate a particular subclass. + The \class{Mailbox} interface is dictionary-like, with small keys -corresponding to messages. Keys are issued by the \class{Mailbox} instance -with which they will be used and are only meaningful to that \class{Mailbox} -instance. A key continues to identify a message even if the corresponding -message is modified, such as by replacing it with another message. Messages may -be added to a \class{Mailbox} instance using the set-like method -\method{add()} and removed using a \code{del} statement or the set-like methods -\method{remove()} and \method{discard()}. +corresponding to messages. Keys are issued by the \class{Mailbox} +instance with which they will be used and are only meaningful to that +\class{Mailbox} instance. A key continues to identify a message even +if the corresponding message is modified, such as by replacing it with +another message. + +Messages may be added to a \class{Mailbox} instance using the set-like +method \method{add()} and removed using a \code{del} statement or the +set-like methods \method{remove()} and \method{discard()}. \class{Mailbox} interface semantics differ from dictionary semantics in some -noteworthy ways. Each time a message is requested, a new representation -(typically a \class{Message} instance) is generated, based upon the current -state of the mailbox. Similarly, when a message is added to a \class{Mailbox} -instance, the provided message representation's contents are copied. In neither -case is a reference to the message representation kept by the \class{Mailbox} -instance. +noteworthy ways. Each time a message is requested, a new +representation (typically a \class{Message} instance) is generated +based upon the current state of the mailbox. Similarly, when a message +is added to a \class{Mailbox} instance, the provided message +representation's contents are copied. In neither case is a reference +to the message representation kept by the \class{Mailbox} instance. The default \class{Mailbox} iterator iterates over message representations, not keys as the default dictionary iterator does. Moreover, modification of a @@ -51,9 +58,14 @@ skipped, though using a key from an iterator may result in a \exception{KeyError} exception if the corresponding message is subsequently removed. -\class{Mailbox} itself is intended to define an interface and to be inherited -from by format-specific subclasses but is not intended to be instantiated. -Instead, you should instantiate a subclass. +Be very cautious when modifying mailboxes that might also be changed +by some other process. The safest mailbox format to use for such +tasks is Maildir; try to avoid using single-file formats such as mbox +for concurrent writing. If you're modifying a mailbox, no matter what +the format, you must lock it by calling the \method{lock()} and +\method{unlock()} methods before making any changes. Failing to lock +the mailbox runs the risk of losing data if some other process makes +changes to the mailbox while your Python code is running. \class{Mailbox} instances have the following methods: @@ -202,15 +214,16 @@ general it is incorrect for \var{arg} to be a \class{Mailbox} instance. \begin{methoddesc}{flush}{} Write any pending changes to the filesystem. For some \class{Mailbox} -subclasses, changes are always written immediately and this method does -nothing. +subclasses, changes are always written immediately and \method{flush()} does +nothing, but you should still make a habit of calling this method. \end{methoddesc} \begin{methoddesc}{lock}{} Acquire an exclusive advisory lock on the mailbox so that other processes know not to modify it. An \exception{ExternalClashError} is raised if the lock is not available. The particular locking mechanisms used depend upon the mailbox -format. +format. You should \emph{always} lock the mailbox before making any +modifications to its contents. \end{methoddesc} \begin{methoddesc}{unlock}{} @@ -1373,36 +1386,55 @@ of the format-specific information that can be converted: \begin{verbatim} import mailbox destination = mailbox.MH('~/Mail') +destination.lock() for message in mailbox.Babyl('~/RMAIL'): destination.add(MHMessage(message)) +destination.flush() +destination.unlock() \end{verbatim} -An example of sorting mail from numerous mailing lists, being careful to avoid -mail corruption due to concurrent modification by other programs, mail loss due -to interruption of the program, or premature termination due to malformed -messages in the mailbox: +This example sorts mail from several mailing lists into different +mailboxes, being careful to avoid mail corruption due to concurrent +modification by other programs, mail loss due to interruption of the +program, or premature termination due to malformed messages in the +mailbox: \begin{verbatim} import mailbox import email.Errors + list_names = ('python-list', 'python-dev', 'python-bugs') + boxes = dict((name, mailbox.mbox('~/email/%s' % name)) for name in list_names) -inbox = mailbox.Maildir('~/Maildir', None) +inbox = mailbox.Maildir('~/Maildir', factory=None) + for key in inbox.iterkeys(): try: message = inbox[key] except email.Errors.MessageParseError: continue # The message is malformed. Just leave it. + for name in list_names: list_id = message['list-id'] if list_id and name in list_id: + # Get mailbox to use box = boxes[name] + + # Write copy to disk before removing original. + # If there's a crash, you might duplicate a message, but + # that's better than losing a message completely. box.lock() box.add(message) - box.flush() # Write copy to disk before removing original. + box.flush() box.unlock() + + # Remove original message + inbox.lock() inbox.discard(key) + inbox.flush() + inbox.unlock() break # Found destination, so stop looking. + for box in boxes.itervalues(): box.close() \end{verbatim} -- cgit v0.12 From c3df1b1392e54e74bfc4c12d04e5b5d12558e9be Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 17 Jan 2007 21:09:07 +0000 Subject: Bug #1637967: missing //= operator in list. (backport from rev. 53475) --- Doc/ref/ref3.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/ref/ref3.tex b/Doc/ref/ref3.tex index 618dccd..7d36cbd 100644 --- a/Doc/ref/ref3.tex +++ b/Doc/ref/ref3.tex @@ -1999,8 +1999,8 @@ complicated). \methodline[numeric object]{__ixor__}{self, other} \methodline[numeric object]{__ior__}{self, other} These methods are called to implement the augmented arithmetic -operations (\code{+=}, \code{-=}, \code{*=}, \code{/=}, \code{\%=}, -\code{**=}, \code{<<=}, \code{>>=}, \code{\&=}, +operations (\code{+=}, \code{-=}, \code{*=}, \code{/=}, \code{//=}, +\code{\%=}, \code{**=}, \code{<<=}, \code{>>=}, \code{\&=}, \code{\textasciicircum=}, \code{|=}). These methods should attempt to do the operation in-place (modifying \var{self}) and return the result (which could be, but does not have to be, \var{self}). If a specific method -- cgit v0.12 From eb68188a0d79979d2b41ffaac25b5059a85fa1d1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 17 Jan 2007 21:20:01 +0000 Subject: Bug #1629125: fix wrong data type (int -> Py_ssize_t) in PyDict_Next docs. (backport from rev. 53477) --- Doc/api/concrete.tex | 4 ++-- Misc/NEWS | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Doc/api/concrete.tex b/Doc/api/concrete.tex index 97ef134..e1f3e9a 100644 --- a/Doc/api/concrete.tex +++ b/Doc/api/concrete.tex @@ -2082,7 +2082,7 @@ format. \begin{verbatim} PyObject *key, *value; -int pos = 0; +Py_ssize_t pos = 0; while (PyDict_Next(self->dict, &pos, &key, &value)) { /* do something interesting with the values... */ @@ -2097,7 +2097,7 @@ while (PyDict_Next(self->dict, &pos, &key, &value)) { \begin{verbatim} PyObject *key, *value; -int pos = 0; +Py_ssize_t pos = 0; while (PyDict_Next(self->dict, &pos, &key, &value)) { int i = PyInt_AS_LONG(value) + 1; diff --git a/Misc/NEWS b/Misc/NEWS index cdee2af..f277450 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -383,6 +383,9 @@ Tests Documentation ------------- +- Bug #1629125: fix wrong data type (int -> Py_ssize_t) in PyDict_Next + docs. + - Bug #1565919: document set types in the Language Reference. - Bug #1546052: cla