summaryrefslogtreecommitdiff
path: root/libre/ruby2.3/json-1.8.3-ruby-2.3.8-backports.patch
blob: 0696ca70b65737eea23de8dc237d323235b5bfdf (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
This is the complete set of patches applied to json-1.8.3 for the ruby
2.3.4 distribution (excluding changes to integrate the two build
systems together).

Some of these might look a little funny (like trunk@50661) because the
bulk of the patch made it upstream since it was originally applied,
but part of it didn't (in the case of trunk@50661, the tests added to
test for the fixed bug didn't make it in to 1.8.3).

 -- Luke Shumaker
    Parabola GNU/Linux-libre

commit e62b06bb43baf7486b3b1793274cb7cc15eae135
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Tue Jan 6 05:32:41 2015 +0000

    generic_object.rb: useless methods
    
    * ext/json/lib/json/generic_object.rb (JSON::GenericObject):
      remove useless overriding methods, [] and []=.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit c0ee6f2af98a8322e842bb2847492bfc56cb21b9)

diff --git a/lib/json/generic_object.rb b/lib/json/generic_object.rb
index 8b8fd53bef..3a14f0ea7d 100644
--- a/lib/json/generic_object.rb
+++ b/lib/json/generic_object.rb
@@ -47,14 +47,6 @@ module JSON
       table
     end
 
-    def [](name)
-      table[name.to_sym]
-    end
-
-    def []=(name, value)
-      __send__ "#{name}=", value
-    end
-
     def |(other)
       self.class[other.to_hash.merge(to_hash)]
     end

commit f1cd7efefbedd30bd78dc364873a9ea867e873f2
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Wed Feb 11 02:01:36 2015 +0000

    generator.c: fix infinite recursion
    
    * ext/json/generator/generator.c (generate_json): get rid of
      unnecessary recursive calls which can cause infinite recursion.
      T_STRING may not have rb_cString.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit e5c516c89a62839fd025ae112041ed9a5f06c9d0)

diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index 6300c64f39..a135e28348 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -871,7 +871,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
     } else {
         tmp = rb_funcall(obj, i_to_s, 0);
         Check_Type(tmp, T_STRING);
-        generate_json(buffer, Vstate, state, tmp);
+        generate_json_string(buffer, Vstate, state, tmp);
     }
 }
 
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb
index 8db0b7890b..1834290944 100755
--- a/tests/test_json_generate.rb
+++ b/tests/test_json_generate.rb
@@ -334,4 +334,14 @@ EOT
       assert_equal true, JSON.generate(["\xea"])
     end
   end
+
+  def test_string_subclass
+    s = Class.new(String) do
+      def to_s; self; end
+      undef to_json
+    end
+    assert_nothing_raised(SystemStackError) do
+      assert_equal '[""]', JSON.generate([s.new])
+    end
+  end
 end

commit 8033ba67b1ccae1fcb059c6f9be432fef21a86cc
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Sat Apr 18 06:18:37 2015 +0000

    parser.rl: use StringValue
    
    * ext/json/parser/parser.rl (cParser_initialize): use StringValue
      instead of direct rb_convert_type and remove duplicate
      conversion.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit 6583e5dbfacf0bb6052c8d9b5cfccb2ab0df4e81)

diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index 9c9d76ac3f..5927114250 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -1716,12 +1716,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
         json->object_class = Qnil;
         json->array_class = Qnil;
     }
-    source = rb_convert_type(source, T_STRING, "String", "to_str");
+    StringValue(source);
     if (!json->quirks_mode) {
-      source = convert_encoding(StringValue(source));
+	source = convert_encoding(source);
     }
     json->current_nesting = 0;
-    StringValue(source);
     json->len = RSTRING_LEN(source);
     json->source = RSTRING_PTR(source);;
     json->Vsource = source;
@@ -1729,7 +1728,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
 }
 
 
-#line 1733 "parser.c"
+#line 1732 "parser.c"
 enum {JSON_start = 1};
 enum {JSON_first_final = 10};
 enum {JSON_error = 0};
@@ -1737,7 +1736,7 @@ enum {JSON_error = 0};
 enum {JSON_en_main = 1};
 
 
-#line 740 "parser.rl"
+#line 739 "parser.rl"
 
 
 static VALUE cParser_parse_strict(VALUE self)
@@ -1748,16 +1747,16 @@ static VALUE cParser_parse_strict(VALUE self)
     GET_PARSER;
 
 
-#line 1752 "parser.c"
+#line 1751 "parser.c"
 	{
 	cs = JSON_start;
 	}
 
-#line 750 "parser.rl"
+#line 749 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1761 "parser.c"
+#line 1760 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1813,7 +1812,7 @@ case 5:
 		goto st1;
 	goto st5;
 tr3:
-#line 729 "parser.rl"
+#line 728 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1822,7 +1821,7 @@ tr3:
     }
 	goto st10;
 tr4:
-#line 722 "parser.rl"
+#line 721 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1834,7 +1833,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1838 "parser.c"
+#line 1837 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -1891,7 +1890,7 @@ case 9:
 	_out: {}
 	}
 
-#line 753 "parser.rl"
+#line 752 "parser.rl"
 
     if (cs >= JSON_first_final && p == pe) {
         return result;
@@ -1903,7 +1902,7 @@ case 9:
 
 
 
-#line 1907 "parser.c"
+#line 1906 "parser.c"
 enum {JSON_quirks_mode_start = 1};
 enum {JSON_quirks_mode_first_final = 10};
 enum {JSON_quirks_mode_error = 0};
@@ -1911,7 +1910,7 @@ enum {JSON_quirks_mode_error = 0};
 enum {JSON_quirks_mode_en_main = 1};
 
 
-#line 778 "parser.rl"
+#line 777 "parser.rl"
 
 
 static VALUE cParser_parse_quirks_mode(VALUE self)
@@ -1922,16 +1921,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
     GET_PARSER;
 
 
-#line 1926 "parser.c"
+#line 1925 "parser.c"
 	{
 	cs = JSON_quirks_mode_start;
 	}
 
-#line 788 "parser.rl"
+#line 787 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1935 "parser.c"
+#line 1934 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1965,7 +1964,7 @@ st0:
 cs = 0;
 	goto _out;
 tr2:
-#line 770 "parser.rl"
+#line 769 "parser.rl"
 	{
         char *np = JSON_parse_value(json, p, pe, &result);
         if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1975,7 +1974,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1979 "parser.c"
+#line 1978 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -2064,7 +2063,7 @@ case 9:
 	_out: {}
 	}
 
-#line 791 "parser.rl"
+#line 790 "parser.rl"
 
     if (cs >= JSON_quirks_mode_first_final && p == pe) {
         return result;
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 216ad26b20..de9c775001 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -700,12 +700,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
         json->object_class = Qnil;
         json->array_class = Qnil;
     }
-    source = rb_convert_type(source, T_STRING, "String", "to_str");
+    StringValue(source);
     if (!json->quirks_mode) {
-      source = convert_encoding(StringValue(source));
+	source = convert_encoding(source);
     }
     json->current_nesting = 0;
-    StringValue(source);
     json->len = RSTRING_LEN(source);
     json->source = RSTRING_PTR(source);;
     json->Vsource = source;

commit 2612a5b588d234535e9ed120d16b7afdd81756e4
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Sat Apr 18 06:18:50 2015 +0000

    parser.rl: use rb_encoding
    
    * ext/json/parser/parser.rl (convert_encoding): use rb_encoding
      functions to compare and convert encodings.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit f47dc0738a2e1b875ecdaa875298cfda70d1eaef)

diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index 5927114250..d334731e2a 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -3,6 +3,13 @@
 #include "../fbuffer/fbuffer.h"
 #include "parser.h"
 
+#ifdef HAVE_RB_ENC_RAISE
+# define EXC_ENCODING rb_utf8_encoding(),
+#else
+# define rb_enc_raise rb_raise
+# define EXC_ENCODING /* nothing */
+#endif
+
 /* unicode */
 
 static const char digit_values[256] = {
@@ -68,9 +75,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
 }
 
 #ifdef HAVE_RUBY_ENCODING_H
-static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
-    CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
-static ID i_encoding, i_encode;
+static rb_encoding *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
 #else
 static ID i_iconv;
 #endif
@@ -84,11 +89,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
           i_match_string, i_aset, i_aref, i_leftshift;
 
 
-#line 110 "parser.rl"
+#line 115 "parser.rl"
 
 
 
-#line 92 "parser.c"
+#line 97 "parser.c"
 enum {JSON_object_start = 1};
 enum {JSON_object_first_final = 27};
 enum {JSON_object_error = 0};
@@ -96,7 +101,7 @@ enum {JSON_object_error = 0};
 enum {JSON_object_en_main = 1};
 
 
-#line 151 "parser.rl"
+#line 156 "parser.rl"
 
 
 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -112,14 +117,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
     *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
 
 
-#line 116 "parser.c"
+#line 121 "parser.c"
 	{
 	cs = JSON_object_start;
 	}
 
-#line 166 "parser.rl"
+#line 171 "parser.rl"
 
-#line 123 "parser.c"
+#line 128 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -147,7 +152,7 @@ case 2:
 		goto st2;
 	goto st0;
 tr2:
-#line 133 "parser.rl"
+#line 138 "parser.rl"
 	{
         char *np;
         json->parsing_name = 1;
@@ -160,7 +165,7 @@ st3:
 	if ( ++p == pe )
 		goto _test_eof3;
 case 3:
-#line 164 "parser.c"
+#line 169 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st3;
 		case 32: goto st3;
@@ -227,7 +232,7 @@ case 8:
 		goto st8;
 	goto st0;
 tr11:
-#line 118 "parser.rl"
+#line 123 "parser.rl"
 	{
         VALUE v = Qnil;
         char *np = JSON_parse_value(json, p, pe, &v);
@@ -247,7 +252,7 @@ st9:
 	if ( ++p == pe )
 		goto _test_eof9;
 case 9:
-#line 251 "parser.c"
+#line 256 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st9;
 		case 32: goto st9;
@@ -336,14 +341,14 @@ case 18:
 		goto st9;
 	goto st18;
 tr4:
-#line 141 "parser.rl"
+#line 146 "parser.rl"
 	{ p--; {p++; cs = 27; goto _out;} }
 	goto st27;
 st27:
 	if ( ++p == pe )
 		goto _test_eof27;
 case 27:
-#line 347 "parser.c"
+#line 352 "parser.c"
 	goto st0;
 st19:
 	if ( ++p == pe )
@@ -441,7 +446,7 @@ case 26:
 	_out: {}
 	}
 
-#line 167 "parser.rl"
+#line 172 "parser.rl"
 
     if (cs >= JSON_object_first_final) {
         if (json->create_additions) {
@@ -466,7 +471,7 @@ case 26:
 
 
 
-#line 470 "parser.c"
+#line 475 "parser.c"
 enum {JSON_value_start = 1};
 enum {JSON_value_first_final = 21};
 enum {JSON_value_error = 0};
@@ -474,7 +479,7 @@ enum {JSON_value_error = 0};
 enum {JSON_value_en_main = 1};
 
 
-#line 271 "parser.rl"
+#line 276 "parser.rl"
 
 
 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -482,14 +487,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
     int cs = EVIL;
 
 
-#line 486 "parser.c"
+#line 491 "parser.c"
 	{
 	cs = JSON_value_start;
 	}
 
-#line 278 "parser.rl"
+#line 283 "parser.rl"
 
-#line 493 "parser.c"
+#line 498 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -514,14 +519,14 @@ st0:
 cs = 0;
 	goto _out;
 tr0:
-#line 219 "parser.rl"
+#line 224 "parser.rl"
 	{
         char *np = JSON_parse_string(json, p, pe, result);
         if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
     }
 	goto st21;
 tr2:
-#line 224 "parser.rl"
+#line 229 "parser.rl"
 	{
         char *np;
         if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
@@ -530,7 +535,7 @@ tr2:
                 {p = (( p + 10))-1;}
                 p--; {p++; cs = 21; goto _out;}
             } else {
-                rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+                rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
             }
         }
         np = JSON_parse_float(json, p, pe, result);
@@ -541,7 +546,7 @@ tr2:
     }
 	goto st21;
 tr5:
-#line 242 "parser.rl"
+#line 247 "parser.rl"
 	{
         char *np;
         json->current_nesting++;
@@ -551,7 +556,7 @@ tr5:
     }
 	goto st21;
 tr9:
-#line 250 "parser.rl"
+#line 255 "parser.rl"
 	{
         char *np;
         json->current_nesting++;
@@ -561,39 +566,39 @@ tr9:
     }
 	goto st21;
 tr16:
-#line 212 "parser.rl"
+#line 217 "parser.rl"
 	{
         if (json->allow_nan) {
             *result = CInfinity;
         } else {
-            rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
+            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
         }
     }
 	goto st21;
 tr18:
-#line 205 "parser.rl"
+#line 210 "parser.rl"
 	{
         if (json->allow_nan) {
             *result = CNaN;
         } else {
-            rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
+            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
         }
     }
 	goto st21;
 tr22:
-#line 199 "parser.rl"
+#line 204 "parser.rl"
 	{
         *result = Qfalse;
     }
 	goto st21;
 tr25:
-#line 196 "parser.rl"
+#line 201 "parser.rl"
 	{
         *result = Qnil;
     }
 	goto st21;
 tr28:
-#line 202 "parser.rl"
+#line 207 "parser.rl"
 	{
         *result = Qtrue;
     }
@@ -602,9 +607,9 @@ st21:
 	if ( ++p == pe )
 		goto _test_eof21;
 case 21:
-#line 258 "parser.rl"
+#line 263 "parser.rl"
 	{ p--; {p++; cs = 21; goto _out;} }
-#line 608 "parser.c"
+#line 613 "parser.c"
 	goto st0;
 st2:
 	if ( ++p == pe )
@@ -765,7 +770,7 @@ case 20:
 	_out: {}
 	}
 
-#line 279 "parser.rl"
+#line 284 "parser.rl"
 
     if (cs >= JSON_value_first_final) {
         return p;
@@ -775,7 +780,7 @@ case 20:
 }
 
 
-#line 779 "parser.c"
+#line 784 "parser.c"
 enum {JSON_integer_start = 1};
 enum {JSON_integer_first_final = 3};
 enum {JSON_integer_error = 0};
@@ -783,7 +788,7 @@ enum {JSON_integer_error = 0};
 enum {JSON_integer_en_main = 1};
 
 
-#line 295 "parser.rl"
+#line 300 "parser.rl"
 
 
 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -791,15 +796,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
     int cs = EVIL;
 
 
-#line 795 "parser.c"
+#line 800 "parser.c"
 	{
 	cs = JSON_integer_start;
 	}
 
-#line 302 "parser.rl"
+#line 307 "parser.rl"
     json->memo = p;
 
-#line 803 "parser.c"
+#line 808 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -833,14 +838,14 @@ case 3:
 		goto st0;
 	goto tr4;
 tr4:
-#line 292 "parser.rl"
+#line 297 "parser.rl"
 	{ p--; {p++; cs = 4; goto _out;} }
 	goto st4;
 st4:
 	if ( ++p == pe )
 		goto _test_eof4;
 case 4:
-#line 844 "parser.c"
+#line 849 "parser.c"
 	goto st0;
 st5:
 	if ( ++p == pe )
@@ -859,7 +864,7 @@ case 5:
 	_out: {}
 	}
 
-#line 304 "parser.rl"
+#line 309 "parser.rl"
 
     if (cs >= JSON_integer_first_final) {
         long len = p - json->memo;
@@ -874,7 +879,7 @@ case 5:
 }
 
 
-#line 878 "parser.c"
+#line 883 "parser.c"
 enum {JSON_float_start = 1};
 enum {JSON_float_first_final = 8};
 enum {JSON_float_error = 0};
@@ -882,7 +887,7 @@ enum {JSON_float_error = 0};
 enum {JSON_float_en_main = 1};
 
 
-#line 329 "parser.rl"
+#line 334 "parser.rl"
 
 
 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -890,15 +895,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
     int cs = EVIL;
 
 
-#line 894 "parser.c"
+#line 899 "parser.c"
 	{
 	cs = JSON_float_start;
 	}
 
-#line 336 "parser.rl"
+#line 341 "parser.rl"
     json->memo = p;
 
-#line 902 "parser.c"
+#line 907 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -956,14 +961,14 @@ case 8:
 		goto st0;
 	goto tr9;
 tr9:
-#line 323 "parser.rl"
+#line 328 "parser.rl"
 	{ p--; {p++; cs = 9; goto _out;} }
 	goto st9;
 st9:
 	if ( ++p == pe )
 		goto _test_eof9;
 case 9:
-#line 967 "parser.c"
+#line 972 "parser.c"
 	goto st0;
 st5:
 	if ( ++p == pe )
@@ -1024,7 +1029,7 @@ case 7:
 	_out: {}
 	}
 
-#line 338 "parser.rl"
+#line 343 "parser.rl"
 
     if (cs >= JSON_float_first_final) {
         long len = p - json->memo;
@@ -1040,7 +1045,7 @@ case 7:
 
 
 
-#line 1044 "parser.c"
+#line 1049 "parser.c"
 enum {JSON_array_start = 1};
 enum {JSON_array_first_final = 17};
 enum {JSON_array_error = 0};
@@ -1048,7 +1053,7 @@ enum {JSON_array_error = 0};
 enum {JSON_array_en_main = 1};
 
 
-#line 381 "parser.rl"
+#line 386 "parser.rl"
 
 
 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1062,14 +1067,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
     *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
 
 
-#line 1066 "parser.c"
+#line 1071 "parser.c"
 	{
 	cs = JSON_array_start;
 	}
 
-#line 394 "parser.rl"
+#line 399 "parser.rl"
 
-#line 1073 "parser.c"
+#line 1078 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1108,7 +1113,7 @@ case 2:
 		goto st2;
 	goto st0;
 tr2:
-#line 358 "parser.rl"
+#line 363 "parser.rl"
 	{
         VALUE v = Qnil;
         char *np = JSON_parse_value(json, p, pe, &v);
@@ -1128,7 +1133,7 @@ st3:
 	if ( ++p == pe )
 		goto _test_eof3;
 case 3:
-#line 1132 "parser.c"
+#line 1137 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st3;
 		case 32: goto st3;
@@ -1228,14 +1233,14 @@ case 12:
 		goto st3;
 	goto st12;
 tr4:
-#line 373 "parser.rl"
+#line 378 "parser.rl"
 	{ p--; {p++; cs = 17; goto _out;} }
 	goto st17;
 st17:
 	if ( ++p == pe )
 		goto _test_eof17;
 case 17:
-#line 1239 "parser.c"
+#line 1244 "parser.c"
 	goto st0;
 st13:
 	if ( ++p == pe )
@@ -1291,12 +1296,12 @@ case 16:
 	_out: {}
 	}
 
-#line 395 "parser.rl"
+#line 400 "parser.rl"
 
     if(cs >= JSON_array_first_final) {
         return p + 1;
     } else {
-        rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
         return NULL;
     }
 }
@@ -1372,7 +1377,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
 }
 
 
-#line 1376 "parser.c"
+#line 1381 "parser.c"
 enum {JSON_string_start = 1};
 enum {JSON_string_first_final = 8};
 enum {JSON_string_error = 0};
@@ -1380,7 +1385,7 @@ enum {JSON_string_error = 0};
 enum {JSON_string_en_main = 1};
 
 
-#line 494 "parser.rl"
+#line 499 "parser.rl"
 
 
 static int
@@ -1402,15 +1407,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
 
     *result = rb_str_buf_new(0);
 
-#line 1406 "parser.c"
+#line 1411 "parser.c"
 	{
 	cs = JSON_string_start;
 	}
 
-#line 515 "parser.rl"
+#line 520 "parser.rl"
     json->memo = p;
 
-#line 1414 "parser.c"
+#line 1419 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1435,7 +1440,7 @@ case 2:
 		goto st0;
 	goto st2;
 tr2:
-#line 480 "parser.rl"
+#line 485 "parser.rl"
 	{
         *result = json_string_unescape(*result, json->memo + 1, p);
         if (NIL_P(*result)) {
@@ -1446,14 +1451,14 @@ tr2:
             {p = (( p + 1))-1;}
         }
     }
-#line 491 "parser.rl"
+#line 496 "parser.rl"
 	{ p--; {p++; cs = 8; goto _out;} }
 	goto st8;
 st8:
 	if ( ++p == pe )
 		goto _test_eof8;
 case 8:
-#line 1457 "parser.c"
+#line 1462 "parser.c"
 	goto st0;
 st3:
 	if ( ++p == pe )
@@ -1529,7 +1534,7 @@ case 7:
 	_out: {}
 	}
 
-#line 517 "parser.rl"
+#line 522 "parser.rl"
 
     if (json->create_additions && RTEST(match_string = json->match_string)) {
           VALUE klass;
@@ -1573,22 +1578,22 @@ static VALUE convert_encoding(VALUE source)
     }
 #ifdef HAVE_RUBY_ENCODING_H
     {
-        VALUE encoding = rb_funcall(source, i_encoding, 0);
-        if (encoding == CEncoding_ASCII_8BIT) {
+        rb_encoding *enc = rb_enc_get(source);
+        if (enc == rb_ascii8bit_encoding()) {
             if (len >= 4 &&  ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
+                source = rb_str_conv_enc(source, UTF_32BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
+                source = rb_str_conv_enc(source, UTF_16BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
+                source = rb_str_conv_enc(source, UTF_32LE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
+                source = rb_str_conv_enc(source, UTF_16LE, rb_utf8_encoding());
             } else {
                 source = rb_str_dup(source);
                 FORCE_UTF8(source);
             }
         } else {
-            source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
+            source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
         }
     }
 #else
@@ -1728,7 +1733,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
 }
 
 
-#line 1732 "parser.c"
+#line 1737 "parser.c"
 enum {JSON_start = 1};
 enum {JSON_first_final = 10};
 enum {JSON_error = 0};
@@ -1736,7 +1741,7 @@ enum {JSON_error = 0};
 enum {JSON_en_main = 1};
 
 
-#line 739 "parser.rl"
+#line 744 "parser.rl"
 
 
 static VALUE cParser_parse_strict(VALUE self)
@@ -1747,16 +1752,16 @@ static VALUE cParser_parse_strict(VALUE self)
     GET_PARSER;
 
 
-#line 1751 "parser.c"
+#line 1756 "parser.c"
 	{
 	cs = JSON_start;
 	}
 
-#line 749 "parser.rl"
+#line 754 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1760 "parser.c"
+#line 1765 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1812,7 +1817,7 @@ case 5:
 		goto st1;
 	goto st5;
 tr3:
-#line 728 "parser.rl"
+#line 733 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1821,7 +1826,7 @@ tr3:
     }
 	goto st10;
 tr4:
-#line 721 "parser.rl"
+#line 726 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1833,7 +1838,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1837 "parser.c"
+#line 1842 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -1890,19 +1895,19 @@ case 9:
 	_out: {}
 	}
 
-#line 752 "parser.rl"
+#line 757 "parser.rl"
 
     if (cs >= JSON_first_final && p == pe) {
         return result;
     } else {
-        rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
         return Qnil;
     }
 }
 
 
 
-#line 1906 "parser.c"
+#line 1911 "parser.c"
 enum {JSON_quirks_mode_start = 1};
 enum {JSON_quirks_mode_first_final = 10};
 enum {JSON_quirks_mode_error = 0};
@@ -1910,7 +1915,7 @@ enum {JSON_quirks_mode_error = 0};
 enum {JSON_quirks_mode_en_main = 1};
 
 
-#line 777 "parser.rl"
+#line 782 "parser.rl"
 
 
 static VALUE cParser_parse_quirks_mode(VALUE self)
@@ -1921,16 +1926,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
     GET_PARSER;
 
 
-#line 1925 "parser.c"
+#line 1930 "parser.c"
 	{
 	cs = JSON_quirks_mode_start;
 	}
 
-#line 787 "parser.rl"
+#line 792 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1934 "parser.c"
+#line 1939 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1964,7 +1969,7 @@ st0:
 cs = 0;
 	goto _out;
 tr2:
-#line 769 "parser.rl"
+#line 774 "parser.rl"
 	{
         char *np = JSON_parse_value(json, p, pe, &result);
         if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1974,7 +1979,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1978 "parser.c"
+#line 1983 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -2063,12 +2068,12 @@ case 9:
 	_out: {}
 	}
 
-#line 790 "parser.rl"
+#line 795 "parser.rl"
 
     if (cs >= JSON_quirks_mode_first_final && p == pe) {
         return result;
     } else {
-        rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
         return Qnil;
     }
 }
@@ -2193,14 +2198,10 @@ void Init_parser(void)
     i_aref = rb_intern("[]");
     i_leftshift = rb_intern("<<");
 #ifdef HAVE_RUBY_ENCODING_H
-    CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
-    CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
-    CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
-    CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
-    CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
-    CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
-    i_encoding = rb_intern("encoding");
-    i_encode = rb_intern("encode");
+    UTF_16BE = rb_enc_find("utf-16be");
+    UTF_16LE = rb_enc_find("utf-16le");
+    UTF_32BE = rb_enc_find("utf-32be");
+    UTF_32LE = rb_enc_find("utf-32le");
 #else
     i_iconv = rb_intern("iconv");
 #endif
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index de9c775001..fd57a275bf 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -66,9 +66,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
 }
 
 #ifdef HAVE_RUBY_ENCODING_H
-static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
-    CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
-static ID i_encoding, i_encode;
+static rb_encoding *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
 #else
 static ID i_iconv;
 #endif
@@ -557,22 +555,22 @@ static VALUE convert_encoding(VALUE source)
     }
 #ifdef HAVE_RUBY_ENCODING_H
     {
-        VALUE encoding = rb_funcall(source, i_encoding, 0);
-        if (encoding == CEncoding_ASCII_8BIT) {
+        rb_encoding *enc = rb_enc_get(source);
+        if (enc == rb_ascii8bit_encoding()) {
             if (len >= 4 &&  ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
+                source = rb_str_conv_enc(source, UTF_32BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
+                source = rb_str_conv_enc(source, UTF_16BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
+                source = rb_str_conv_enc(source, UTF_32LE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
+                source = rb_str_conv_enc(source, UTF_16LE, rb_utf8_encoding());
             } else {
                 source = rb_str_dup(source);
                 FORCE_UTF8(source);
             }
         } else {
-            source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
+            source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
         }
     }
 #else
@@ -916,14 +914,10 @@ void Init_parser(void)
     i_aref = rb_intern("[]");
     i_leftshift = rb_intern("<<");
 #ifdef HAVE_RUBY_ENCODING_H
-    CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
-    CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
-    CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
-    CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
-    CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
-    CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
-    i_encoding = rb_intern("encoding");
-    i_encode = rb_intern("encode");
+    UTF_16BE = rb_enc_find("utf-16be");
+    UTF_16LE = rb_enc_find("utf-16le");
+    UTF_32BE = rb_enc_find("utf-32be");
+    UTF_32LE = rb_enc_find("utf-32le");
 #else
     i_iconv = rb_intern("iconv");
 #endif

commit c9d3b4b6f24aac4cf677256b10fb3c51ed283698
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Sat Apr 18 06:19:52 2015 +0000

    parser.rl: rb_enc_raise
    
    * ext/json/parser/parser.rl: raise with messages in UTF-8
      encoding.  [ruby-core:67386] [Bug #10705]
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit b38c0b7974854003a949a26f87bd7ff0e17113ef)

diff --git a/ext/json/ext/parser/extconf.rb b/ext/json/ext/parser/extconf.rb
index ae4f861c79..2addc53e7f 100644
--- a/ext/json/ext/parser/extconf.rb
+++ b/ext/json/ext/parser/extconf.rb
@@ -1,3 +1,5 @@
 require 'mkmf'
 
+have_func("rb_enc_raise", "ruby.h")
+
 create_makefile 'json/ext/parser'
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index d334731e2a..9d8cb54570 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -3,11 +3,26 @@
 #include "../fbuffer/fbuffer.h"
 #include "parser.h"
 
-#ifdef HAVE_RB_ENC_RAISE
-# define EXC_ENCODING rb_utf8_encoding(),
+#if defined HAVE_RUBY_ENCODING_H
+# define EXC_ENCODING UTF8,
+# ifndef HAVE_RB_ENC_RAISE
+static void
+enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
+{
+    va_list args;
+    VALUE mesg;
+
+    va_start(args, fmt);
+    mesg = rb_enc_vsprintf(enc, fmt, args);
+    va_end(args);
+
+    rb_exc_raise(rb_exc_new3(exc, mesg));
+}
+# endif
+# define rb_enc_raise enc_raise
 #else
-# define rb_enc_raise rb_raise
 # define EXC_ENCODING /* nothing */
+# define rb_enc_raise rb_raise
 #endif
 
 /* unicode */
@@ -75,7 +90,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
 }
 
 #ifdef HAVE_RUBY_ENCODING_H
-static rb_encoding *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
+static rb_encoding *UTF_8, *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
 #else
 static ID i_iconv;
 #endif
@@ -89,11 +104,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
           i_match_string, i_aset, i_aref, i_leftshift;
 
 
-#line 115 "parser.rl"
+#line 130 "parser.rl"
 
 
 
-#line 97 "parser.c"
+#line 112 "parser.c"
 enum {JSON_object_start = 1};
 enum {JSON_object_first_final = 27};
 enum {JSON_object_error = 0};
@@ -101,7 +116,7 @@ enum {JSON_object_error = 0};
 enum {JSON_object_en_main = 1};
 
 
-#line 156 "parser.rl"
+#line 171 "parser.rl"
 
 
 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -117,14 +132,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
     *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
 
 
-#line 121 "parser.c"
+#line 136 "parser.c"
 	{
 	cs = JSON_object_start;
 	}
 
-#line 171 "parser.rl"
+#line 186 "parser.rl"
 
-#line 128 "parser.c"
+#line 143 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -152,7 +167,7 @@ case 2:
 		goto st2;
 	goto st0;
 tr2:
-#line 138 "parser.rl"
+#line 153 "parser.rl"
 	{
         char *np;
         json->parsing_name = 1;
@@ -165,7 +180,7 @@ st3:
 	if ( ++p == pe )
 		goto _test_eof3;
 case 3:
-#line 169 "parser.c"
+#line 184 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st3;
 		case 32: goto st3;
@@ -232,7 +247,7 @@ case 8:
 		goto st8;
 	goto st0;
 tr11:
-#line 123 "parser.rl"
+#line 138 "parser.rl"
 	{
         VALUE v = Qnil;
         char *np = JSON_parse_value(json, p, pe, &v);
@@ -252,7 +267,7 @@ st9:
 	if ( ++p == pe )
 		goto _test_eof9;
 case 9:
-#line 256 "parser.c"
+#line 271 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st9;
 		case 32: goto st9;
@@ -341,14 +356,14 @@ case 18:
 		goto st9;
 	goto st18;
 tr4:
-#line 146 "parser.rl"
+#line 161 "parser.rl"
 	{ p--; {p++; cs = 27; goto _out;} }
 	goto st27;
 st27:
 	if ( ++p == pe )
 		goto _test_eof27;
 case 27:
-#line 352 "parser.c"
+#line 367 "parser.c"
 	goto st0;
 st19:
 	if ( ++p == pe )
@@ -446,7 +461,7 @@ case 26:
 	_out: {}
 	}
 
-#line 172 "parser.rl"
+#line 187 "parser.rl"
 
     if (cs >= JSON_object_first_final) {
         if (json->create_additions) {
@@ -471,7 +486,7 @@ case 26:
 
 
 
-#line 475 "parser.c"
+#line 490 "parser.c"
 enum {JSON_value_start = 1};
 enum {JSON_value_first_final = 21};
 enum {JSON_value_error = 0};
@@ -479,7 +494,7 @@ enum {JSON_value_error = 0};
 enum {JSON_value_en_main = 1};
 
 
-#line 276 "parser.rl"
+#line 291 "parser.rl"
 
 
 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -487,14 +502,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
     int cs = EVIL;
 
 
-#line 491 "parser.c"
+#line 506 "parser.c"
 	{
 	cs = JSON_value_start;
 	}
 
-#line 283 "parser.rl"
+#line 298 "parser.rl"
 
-#line 498 "parser.c"
+#line 513 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -519,14 +534,14 @@ st0:
 cs = 0;
 	goto _out;
 tr0:
-#line 224 "parser.rl"
+#line 239 "parser.rl"
 	{
         char *np = JSON_parse_string(json, p, pe, result);
         if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
     }
 	goto st21;
 tr2:
-#line 229 "parser.rl"
+#line 244 "parser.rl"
 	{
         char *np;
         if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
@@ -546,7 +561,7 @@ tr2:
     }
 	goto st21;
 tr5:
-#line 247 "parser.rl"
+#line 262 "parser.rl"
 	{
         char *np;
         json->current_nesting++;
@@ -556,7 +571,7 @@ tr5:
     }
 	goto st21;
 tr9:
-#line 255 "parser.rl"
+#line 270 "parser.rl"
 	{
         char *np;
         json->current_nesting++;
@@ -566,7 +581,7 @@ tr9:
     }
 	goto st21;
 tr16:
-#line 217 "parser.rl"
+#line 232 "parser.rl"
 	{
         if (json->allow_nan) {
             *result = CInfinity;
@@ -576,7 +591,7 @@ tr16:
     }
 	goto st21;
 tr18:
-#line 210 "parser.rl"
+#line 225 "parser.rl"
 	{
         if (json->allow_nan) {
             *result = CNaN;
@@ -586,19 +601,19 @@ tr18:
     }
 	goto st21;
 tr22:
-#line 204 "parser.rl"
+#line 219 "parser.rl"
 	{
         *result = Qfalse;
     }
 	goto st21;
 tr25:
-#line 201 "parser.rl"
+#line 216 "parser.rl"
 	{
         *result = Qnil;
     }
 	goto st21;
 tr28:
-#line 207 "parser.rl"
+#line 222 "parser.rl"
 	{
         *result = Qtrue;
     }
@@ -607,9 +622,9 @@ st21:
 	if ( ++p == pe )
 		goto _test_eof21;
 case 21:
-#line 263 "parser.rl"
+#line 278 "parser.rl"
 	{ p--; {p++; cs = 21; goto _out;} }
-#line 613 "parser.c"
+#line 628 "parser.c"
 	goto st0;
 st2:
 	if ( ++p == pe )
@@ -770,7 +785,7 @@ case 20:
 	_out: {}
 	}
 
-#line 284 "parser.rl"
+#line 299 "parser.rl"
 
     if (cs >= JSON_value_first_final) {
         return p;
@@ -780,7 +795,7 @@ case 20:
 }
 
 
-#line 784 "parser.c"
+#line 799 "parser.c"
 enum {JSON_integer_start = 1};
 enum {JSON_integer_first_final = 3};
 enum {JSON_integer_error = 0};
@@ -788,7 +803,7 @@ enum {JSON_integer_error = 0};
 enum {JSON_integer_en_main = 1};
 
 
-#line 300 "parser.rl"
+#line 315 "parser.rl"
 
 
 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -796,15 +811,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
     int cs = EVIL;
 
 
-#line 800 "parser.c"
+#line 815 "parser.c"
 	{
 	cs = JSON_integer_start;
 	}
 
-#line 307 "parser.rl"
+#line 322 "parser.rl"
     json->memo = p;
 
-#line 808 "parser.c"
+#line 823 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -838,14 +853,14 @@ case 3:
 		goto st0;
 	goto tr4;
 tr4:
-#line 297 "parser.rl"
+#line 312 "parser.rl"
 	{ p--; {p++; cs = 4; goto _out;} }
 	goto st4;
 st4:
 	if ( ++p == pe )
 		goto _test_eof4;
 case 4:
-#line 849 "parser.c"
+#line 864 "parser.c"
 	goto st0;
 st5:
 	if ( ++p == pe )
@@ -864,7 +879,7 @@ case 5:
 	_out: {}
 	}
 
-#line 309 "parser.rl"
+#line 324 "parser.rl"
 
     if (cs >= JSON_integer_first_final) {
         long len = p - json->memo;
@@ -879,7 +894,7 @@ case 5:
 }
 
 
-#line 883 "parser.c"
+#line 898 "parser.c"
 enum {JSON_float_start = 1};
 enum {JSON_float_first_final = 8};
 enum {JSON_float_error = 0};
@@ -887,7 +902,7 @@ enum {JSON_float_error = 0};
 enum {JSON_float_en_main = 1};
 
 
-#line 334 "parser.rl"
+#line 349 "parser.rl"
 
 
 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -895,15 +910,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
     int cs = EVIL;
 
 
-#line 899 "parser.c"
+#line 914 "parser.c"
 	{
 	cs = JSON_float_start;
 	}
 
-#line 341 "parser.rl"
+#line 356 "parser.rl"
     json->memo = p;
 
-#line 907 "parser.c"
+#line 922 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -961,14 +976,14 @@ case 8:
 		goto st0;
 	goto tr9;
 tr9:
-#line 328 "parser.rl"
+#line 343 "parser.rl"
 	{ p--; {p++; cs = 9; goto _out;} }
 	goto st9;
 st9:
 	if ( ++p == pe )
 		goto _test_eof9;
 case 9:
-#line 972 "parser.c"
+#line 987 "parser.c"
 	goto st0;
 st5:
 	if ( ++p == pe )
@@ -1029,7 +1044,7 @@ case 7:
 	_out: {}
 	}
 
-#line 343 "parser.rl"
+#line 358 "parser.rl"
 
     if (cs >= JSON_float_first_final) {
         long len = p - json->memo;
@@ -1045,7 +1060,7 @@ case 7:
 
 
 
-#line 1049 "parser.c"
+#line 1064 "parser.c"
 enum {JSON_array_start = 1};
 enum {JSON_array_first_final = 17};
 enum {JSON_array_error = 0};
@@ -1053,7 +1068,7 @@ enum {JSON_array_error = 0};
 enum {JSON_array_en_main = 1};
 
 
-#line 386 "parser.rl"
+#line 401 "parser.rl"
 
 
 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1067,14 +1082,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
     *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
 
 
-#line 1071 "parser.c"
+#line 1086 "parser.c"
 	{
 	cs = JSON_array_start;
 	}
 
-#line 399 "parser.rl"
+#line 414 "parser.rl"
 
-#line 1078 "parser.c"
+#line 1093 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1113,7 +1128,7 @@ case 2:
 		goto st2;
 	goto st0;
 tr2:
-#line 363 "parser.rl"
+#line 378 "parser.rl"
 	{
         VALUE v = Qnil;
         char *np = JSON_parse_value(json, p, pe, &v);
@@ -1133,7 +1148,7 @@ st3:
 	if ( ++p == pe )
 		goto _test_eof3;
 case 3:
-#line 1137 "parser.c"
+#line 1152 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st3;
 		case 32: goto st3;
@@ -1233,14 +1248,14 @@ case 12:
 		goto st3;
 	goto st12;
 tr4:
-#line 378 "parser.rl"
+#line 393 "parser.rl"
 	{ p--; {p++; cs = 17; goto _out;} }
 	goto st17;
 st17:
 	if ( ++p == pe )
 		goto _test_eof17;
 case 17:
-#line 1244 "parser.c"
+#line 1259 "parser.c"
 	goto st0;
 st13:
 	if ( ++p == pe )
@@ -1296,7 +1311,7 @@ case 16:
 	_out: {}
 	}
 
-#line 400 "parser.rl"
+#line 415 "parser.rl"
 
     if(cs >= JSON_array_first_final) {
         return p + 1;
@@ -1377,7 +1392,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
 }
 
 
-#line 1381 "parser.c"
+#line 1396 "parser.c"
 enum {JSON_string_start = 1};
 enum {JSON_string_first_final = 8};
 enum {JSON_string_error = 0};
@@ -1385,7 +1400,7 @@ enum {JSON_string_error = 0};
 enum {JSON_string_en_main = 1};
 
 
-#line 499 "parser.rl"
+#line 514 "parser.rl"
 
 
 static int
@@ -1407,15 +1422,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
 
     *result = rb_str_buf_new(0);
 
-#line 1411 "parser.c"
+#line 1426 "parser.c"
 	{
 	cs = JSON_string_start;
 	}
 
-#line 520 "parser.rl"
+#line 535 "parser.rl"
     json->memo = p;
 
-#line 1419 "parser.c"
+#line 1434 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1440,7 +1455,7 @@ case 2:
 		goto st0;
 	goto st2;
 tr2:
-#line 485 "parser.rl"
+#line 500 "parser.rl"
 	{
         *result = json_string_unescape(*result, json->memo + 1, p);
         if (NIL_P(*result)) {
@@ -1451,14 +1466,14 @@ tr2:
             {p = (( p + 1))-1;}
         }
     }
-#line 496 "parser.rl"
+#line 511 "parser.rl"
 	{ p--; {p++; cs = 8; goto _out;} }
 	goto st8;
 st8:
 	if ( ++p == pe )
 		goto _test_eof8;
 case 8:
-#line 1462 "parser.c"
+#line 1477 "parser.c"
 	goto st0;
 st3:
 	if ( ++p == pe )
@@ -1534,7 +1549,7 @@ case 7:
 	_out: {}
 	}
 
-#line 522 "parser.rl"
+#line 537 "parser.rl"
 
     if (json->create_additions && RTEST(match_string = json->match_string)) {
           VALUE klass;
@@ -1733,7 +1748,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
 }
 
 
-#line 1737 "parser.c"
+#line 1752 "parser.c"
 enum {JSON_start = 1};
 enum {JSON_first_final = 10};
 enum {JSON_error = 0};
@@ -1741,7 +1756,7 @@ enum {JSON_error = 0};
 enum {JSON_en_main = 1};
 
 
-#line 744 "parser.rl"
+#line 759 "parser.rl"
 
 
 static VALUE cParser_parse_strict(VALUE self)
@@ -1752,16 +1767,16 @@ static VALUE cParser_parse_strict(VALUE self)
     GET_PARSER;
 
 
-#line 1756 "parser.c"
+#line 1771 "parser.c"
 	{
 	cs = JSON_start;
 	}
 
-#line 754 "parser.rl"
+#line 769 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1765 "parser.c"
+#line 1780 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1817,7 +1832,7 @@ case 5:
 		goto st1;
 	goto st5;
 tr3:
-#line 733 "parser.rl"
+#line 748 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1826,7 +1841,7 @@ tr3:
     }
 	goto st10;
 tr4:
-#line 726 "parser.rl"
+#line 741 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1838,7 +1853,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1842 "parser.c"
+#line 1857 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -1895,7 +1910,7 @@ case 9:
 	_out: {}
 	}
 
-#line 757 "parser.rl"
+#line 772 "parser.rl"
 
     if (cs >= JSON_first_final && p == pe) {
         return result;
@@ -1907,7 +1922,7 @@ case 9:
 
 
 
-#line 1911 "parser.c"
+#line 1926 "parser.c"
 enum {JSON_quirks_mode_start = 1};
 enum {JSON_quirks_mode_first_final = 10};
 enum {JSON_quirks_mode_error = 0};
@@ -1915,7 +1930,7 @@ enum {JSON_quirks_mode_error = 0};
 enum {JSON_quirks_mode_en_main = 1};
 
 
-#line 782 "parser.rl"
+#line 797 "parser.rl"
 
 
 static VALUE cParser_parse_quirks_mode(VALUE self)
@@ -1926,16 +1941,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
     GET_PARSER;
 
 
-#line 1930 "parser.c"
+#line 1945 "parser.c"
 	{
 	cs = JSON_quirks_mode_start;
 	}
 
-#line 792 "parser.rl"
+#line 807 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1939 "parser.c"
+#line 1954 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1969,7 +1984,7 @@ st0:
 cs = 0;
 	goto _out;
 tr2:
-#line 774 "parser.rl"
+#line 789 "parser.rl"
 	{
         char *np = JSON_parse_value(json, p, pe, &result);
         if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1979,7 +1994,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1983 "parser.c"
+#line 1998 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -2068,7 +2083,7 @@ case 9:
 	_out: {}
 	}
 
-#line 795 "parser.rl"
+#line 810 "parser.rl"
 
     if (cs >= JSON_quirks_mode_first_final && p == pe) {
         return result;
@@ -2198,6 +2213,7 @@ void Init_parser(void)
     i_aref = rb_intern("[]");
     i_leftshift = rb_intern("<<");
 #ifdef HAVE_RUBY_ENCODING_H
+    UTF_8 = rb_utf8_encoding();
     UTF_16BE = rb_enc_find("utf-16be");
     UTF_16LE = rb_enc_find("utf-16le");
     UTF_32BE = rb_enc_find("utf-32be");
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index fd57a275bf..735fa8f350 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -1,6 +1,28 @@
 #include "../fbuffer/fbuffer.h"
 #include "parser.h"
 
+#if defined HAVE_RUBY_ENCODING_H
+# define EXC_ENCODING UTF8,
+# ifndef HAVE_RB_ENC_RAISE
+static void
+enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
+{
+    va_list args;
+    VALUE mesg;
+
+    va_start(args, fmt);
+    mesg = rb_enc_vsprintf(enc, fmt, args);
+    va_end(args);
+
+    rb_exc_raise(rb_exc_new3(exc, mesg));
+}
+# endif
+# define rb_enc_raise enc_raise
+#else
+# define EXC_ENCODING /* nothing */
+# define rb_enc_raise rb_raise
+#endif
+
 /* unicode */
 
 static const char digit_values[256] = {
@@ -66,7 +88,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
 }
 
 #ifdef HAVE_RUBY_ENCODING_H
-static rb_encoding *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
+static rb_encoding *UTF_8, *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
 #else
 static ID i_iconv;
 #endif
@@ -204,14 +226,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
         if (json->allow_nan) {
             *result = CNaN;
         } else {
-            rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
+            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
         }
     }
     action parse_infinity {
         if (json->allow_nan) {
             *result = CInfinity;
         } else {
-            rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
+            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
         }
     }
     action parse_string {
@@ -227,7 +249,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
                 fexec p + 10;
                 fhold; fbreak;
             } else {
-                rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+                rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
             }
         }
         np = JSON_parse_float(json, fpc, pe, result);
@@ -394,7 +416,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
     if(cs >= JSON_array_first_final) {
         return p + 1;
     } else {
-        rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
         return NULL;
     }
 }
@@ -751,7 +773,7 @@ static VALUE cParser_parse_strict(VALUE self)
     if (cs >= JSON_first_final && p == pe) {
         return result;
     } else {
-        rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
         return Qnil;
     }
 }
@@ -789,7 +811,7 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
     if (cs >= JSON_quirks_mode_first_final && p == pe) {
         return result;
     } else {
-        rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
         return Qnil;
     }
 }
@@ -914,6 +936,7 @@ void Init_parser(void)
     i_aref = rb_intern("[]");
     i_leftshift = rb_intern("<<");
 #ifdef HAVE_RUBY_ENCODING_H
+    UTF_8 = rb_utf8_encoding();
     UTF_16BE = rb_enc_find("utf-16be");
     UTF_16LE = rb_enc_find("utf-16le");
     UTF_32BE = rb_enc_find("utf-32be");
diff --git a/tests/test_json.rb b/tests/test_json.rb
index 7957773f23..46f000148f 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -550,4 +550,14 @@ EOT
     JSON::Parser.new(source)
     assert_equal Encoding::ASCII_8BIT, source.encoding
   end if defined?(Encoding::ASCII_8BIT)
+
+  def test_error_message_encoding
+    bug10705 = '[ruby-core:67386] [Bug #10705]'
+    json = "\"\xE2\x88\x9A\"".force_encoding(Encoding::UTF_8)
+    e = assert_raise(JSON::ParserError) {
+      JSON.parse(json)
+    }
+    assert_equal(Encoding::UTF_8, e.message.encoding, bug10705)
+    assert_include(e.message, json, bug10705)
+  end if defined?(Encoding::UTF_8)
 end

commit 45b835fec8adaf0aa1ce47fc2acfa3f61f06ca53
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Sat Apr 18 06:24:38 2015 +0000

    parser.rl: define enc_raise iff necessary
    
    * ext/json/parser/parser.rl (enc_raise): no needs if rb_enc_raise
      is available.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit 5c0df05b92de528a397d29fd9ca5dca534b4c930)

diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index 9d8cb54570..ae9be78ec2 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -4,7 +4,7 @@
 #include "parser.h"
 
 #if defined HAVE_RUBY_ENCODING_H
-# define EXC_ENCODING UTF8,
+# define EXC_ENCODING UTF_8,
 # ifndef HAVE_RB_ENC_RAISE
 static void
 enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
@@ -18,8 +18,8 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
 
     rb_exc_raise(rb_exc_new3(exc, mesg));
 }
+#   define rb_enc_raise enc_raise
 # endif
-# define rb_enc_raise enc_raise
 #else
 # define EXC_ENCODING /* nothing */
 # define rb_enc_raise rb_raise
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 735fa8f350..327e08cd81 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -2,7 +2,7 @@
 #include "parser.h"
 
 #if defined HAVE_RUBY_ENCODING_H
-# define EXC_ENCODING UTF8,
+# define EXC_ENCODING UTF_8,
 # ifndef HAVE_RB_ENC_RAISE
 static void
 enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
@@ -16,8 +16,8 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
 
     rb_exc_raise(rb_exc_new3(exc, mesg));
 }
+#   define rb_enc_raise enc_raise
 # endif
-# define rb_enc_raise enc_raise
 #else
 # define EXC_ENCODING /* nothing */
 # define rb_enc_raise rb_raise

commit 39feffc4fbb9047e9dee99bab90761f5aba28060
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Thu May 28 07:17:42 2015 +0000

    parser.rl: allocate structs with wrapper
    
    * ext/json/parser/parser.rl (cJSON_parser_s_allocate): allocate
      structs with making new wrapper objects and get rid of potential
      memory leak.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit cbf902fc3308290383c8c5e926bf684a23778719)

diff --git a/tests/test_json.rb b/tests/test_json.rb
index 46f000148f..96ba744478 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -560,4 +560,17 @@ EOT
     assert_equal(Encoding::UTF_8, e.message.encoding, bug10705)
     assert_include(e.message, json, bug10705)
   end if defined?(Encoding::UTF_8)
+
+  if EnvUtil.gc_stress_to_class?
+    def assert_no_memory_leak(code, *rest, **opt)
+      code = "8.times {20_000.times {begin #{code}; rescue NoMemoryError; end}; GC.start}"
+      super(["-rjson/ext/parser"],
+            "GC.add_stress_to_class(JSON::Ext::Parser); "\
+            "#{code}", code, *rest, rss: true, limit: 1.1, **opt)
+    end
+
+    def test_no_memory_leak_allocate
+      assert_no_memory_leak("JSON::Ext::Parser.allocate")
+    end
+  end
 end

commit a7b5c17a122a88e060676e74fc1925c5a703df03
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Thu May 28 07:17:55 2015 +0000

    generator.c: allocate structs with wrapper
    
    * ext/json/generator/generator.c (cState_s_allocate): allocate
      structs with making new wrapper objects and get rid of potential
      memory leak.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit 4d059bf9f5f10f3d3088de49fc87e5555db7770d)

diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb
index 1834290944..ce470db3c2 100755
--- a/tests/test_json_generate.rb
+++ b/tests/test_json_generate.rb
@@ -344,4 +344,17 @@ EOT
       assert_equal '[""]', JSON.generate([s.new])
     end
   end
+
+  if EnvUtil.gc_stress_to_class?
+    def assert_no_memory_leak(code, *rest, **opt)
+      code = "8.times {20_000.times {begin #{code}; rescue NoMemoryError; end}; GC.start}"
+      super(["-rjson/ext/generator"],
+            "GC.add_stress_to_class(JSON::Ext::Generator::State); "\
+            "#{code}", code, *rest, rss: true, limit: 1.1, **opt)
+    end
+
+    def test_no_memory_leak_allocate
+      assert_no_memory_leak("JSON::Ext::Generator::State.allocate")
+    end
+  end
 end

commit 73a2acda797178495ff3952c3b9293425b86f924
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Fri Sep 25 08:06:57 2015 +0000

    parser.rl: rb_scan_args
    
    * ext/json/parser/parser.rl (cParser_initialize): use ':' in
      rb_scan_args.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit f12fccbec58ca57cef61380e0eebed591ba847d8)

diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 327e08cd81..2fa0caee7a 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -570,7 +570,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
 
 static VALUE convert_encoding(VALUE source)
 {
-    char *ptr = RSTRING_PTR(source);
+    const char *ptr = RSTRING_PTR(source);
     long len = RSTRING_LEN(source);
     if (len < 2) {
         rb_raise(eParserError, "A JSON text must at least contain two octets!");
@@ -643,12 +643,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
     if (json->Vsource) {
         rb_raise(rb_eTypeError, "already initialized instance");
     }
+#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
+    rb_scan_args(argc, argv, "1:", &source, &opts);
+#else
     rb_scan_args(argc, argv, "11", &source, &opts);
+#endif
     if (!NIL_P(opts)) {
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
         opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
         if (NIL_P(opts)) {
             rb_raise(rb_eArgError, "opts needs to be like a hash");
         } else {
+#endif
             VALUE tmp = ID2SYM(i_max_nesting);
             if (option_given_p(opts, tmp)) {
                 VALUE max_nesting = rb_hash_aref(opts, tmp);
@@ -711,7 +717,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
             } else {
                 json->match_string = Qnil;
             }
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
         }
+#endif
     } else {
         json->max_nesting = 100;
         json->allow_nan = 0;

commit 4b429e42608ecca027435a2cb6f9c10afd3b5c89
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Fri Sep 25 08:08:58 2015 +0000

    parser.c: update
    
    * ext/json/parser/parser.c: update to r51946.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit 460152ea73f7eb55449329e77b141d50f8cabe01)

diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index ae9be78ec2..773605cf7c 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -1586,7 +1586,7 @@ case 7:
 
 static VALUE convert_encoding(VALUE source)
 {
-    char *ptr = RSTRING_PTR(source);
+    const char *ptr = RSTRING_PTR(source);
     long len = RSTRING_LEN(source);
     if (len < 2) {
         rb_raise(eParserError, "A JSON text must at least contain two octets!");
@@ -1659,12 +1659,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
     if (json->Vsource) {
         rb_raise(rb_eTypeError, "already initialized instance");
     }
+#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
+    rb_scan_args(argc, argv, "1:", &source, &opts);
+#else
     rb_scan_args(argc, argv, "11", &source, &opts);
+#endif
     if (!NIL_P(opts)) {
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
         opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
         if (NIL_P(opts)) {
             rb_raise(rb_eArgError, "opts needs to be like a hash");
         } else {
+#endif
             VALUE tmp = ID2SYM(i_max_nesting);
             if (option_given_p(opts, tmp)) {
                 VALUE max_nesting = rb_hash_aref(opts, tmp);
@@ -1727,7 +1733,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
             } else {
                 json->match_string = Qnil;
             }
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
         }
+#endif
     } else {
         json->max_nesting = 100;
         json->allow_nan = 0;
@@ -1748,7 +1756,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
 }
 
 
-#line 1752 "parser.c"
+#line 1760 "parser.c"
 enum {JSON_start = 1};
 enum {JSON_first_final = 10};
 enum {JSON_error = 0};
@@ -1756,7 +1764,7 @@ enum {JSON_error = 0};
 enum {JSON_en_main = 1};
 
 
-#line 759 "parser.rl"
+#line 767 "parser.rl"
 
 
 static VALUE cParser_parse_strict(VALUE self)
@@ -1767,16 +1775,16 @@ static VALUE cParser_parse_strict(VALUE self)
     GET_PARSER;
 
 
-#line 1771 "parser.c"
+#line 1779 "parser.c"
 	{
 	cs = JSON_start;
 	}
 
-#line 769 "parser.rl"
+#line 777 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1780 "parser.c"
+#line 1788 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1832,7 +1840,7 @@ case 5:
 		goto st1;
 	goto st5;
 tr3:
-#line 748 "parser.rl"
+#line 756 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1841,7 +1849,7 @@ tr3:
     }
 	goto st10;
 tr4:
-#line 741 "parser.rl"
+#line 749 "parser.rl"
 	{
         char *np;
         json->current_nesting = 1;
@@ -1853,7 +1861,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1857 "parser.c"
+#line 1865 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -1910,7 +1918,7 @@ case 9:
 	_out: {}
 	}
 
-#line 772 "parser.rl"
+#line 780 "parser.rl"
 
     if (cs >= JSON_first_final && p == pe) {
         return result;
@@ -1922,7 +1930,7 @@ case 9:
 
 
 
-#line 1926 "parser.c"
+#line 1934 "parser.c"
 enum {JSON_quirks_mode_start = 1};
 enum {JSON_quirks_mode_first_final = 10};
 enum {JSON_quirks_mode_error = 0};
@@ -1930,7 +1938,7 @@ enum {JSON_quirks_mode_error = 0};
 enum {JSON_quirks_mode_en_main = 1};
 
 
-#line 797 "parser.rl"
+#line 805 "parser.rl"
 
 
 static VALUE cParser_parse_quirks_mode(VALUE self)
@@ -1941,16 +1949,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
     GET_PARSER;
 
 
-#line 1945 "parser.c"
+#line 1953 "parser.c"
 	{
 	cs = JSON_quirks_mode_start;
 	}
 
-#line 807 "parser.rl"
+#line 815 "parser.rl"
     p = json->source;
     pe = p + json->len;
 
-#line 1954 "parser.c"
+#line 1962 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1984,7 +1992,7 @@ st0:
 cs = 0;
 	goto _out;
 tr2:
-#line 789 "parser.rl"
+#line 797 "parser.rl"
 	{
         char *np = JSON_parse_value(json, p, pe, &result);
         if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1994,7 +2002,7 @@ st10:
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1998 "parser.c"
+#line 2006 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -2083,7 +2091,7 @@ case 9:
 	_out: {}
 	}
 
-#line 810 "parser.rl"
+#line 818 "parser.rl"
 
     if (cs >= JSON_quirks_mode_first_final && p == pe) {
         return result;

commit 466bd2712d728a26b04b0ea4796aa664f23e006f
Author: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Fri Oct 30 04:37:13 2015 +0000

    use assert_raise
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit 068f312a7c642a1b6c358c17ef83421756568545)

diff --git a/tests/test_json.rb b/tests/test_json.rb
index 96ba744478..07287eed81 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -65,10 +65,10 @@ class TestJSON < Test::Unit::TestCase
     assert_equal([23], parse('[23]'))
     assert_equal([0.23], parse('[0.23]'))
     assert_equal([0.0], parse('[0e0]'))
-    assert_raises(JSON::ParserError) { parse('[+23.2]') }
-    assert_raises(JSON::ParserError) { parse('[+23]') }
-    assert_raises(JSON::ParserError) { parse('[.23]') }
-    assert_raises(JSON::ParserError) { parse('[023]') }
+    assert_raise(JSON::ParserError) { parse('[+23.2]') }
+    assert_raise(JSON::ParserError) { parse('[+23]') }
+    assert_raise(JSON::ParserError) { parse('[.23]') }
+    assert_raise(JSON::ParserError) { parse('[023]') }
     assert_equal_float [3.141], parse('[3.141]')
     assert_equal_float [-3.141], parse('[-3.141]')
     assert_equal_float [3.141], parse('[3141e-3]')
@@ -77,11 +77,11 @@ class TestJSON < Test::Unit::TestCase
     assert_equal_float [3.141], parse('[3141.0E-3]')
     assert_equal_float [-3.141], parse('[-3141.0e-3]')
     assert_equal_float [-3.141], parse('[-3141e-3]')
-    assert_raises(ParserError) { parse('[NaN]') }
+    assert_raise(ParserError) { parse('[NaN]') }
     assert parse('[NaN]', :allow_nan => true).first.nan?
-    assert_raises(ParserError) { parse('[Infinity]') }
+    assert_raise(ParserError) { parse('[Infinity]') }
     assert_equal [1.0/0], parse('[Infinity]', :allow_nan => true)
-    assert_raises(ParserError) { parse('[-Infinity]') }
+    assert_raise(ParserError) { parse('[-Infinity]') }
     assert_equal [-1.0/0], parse('[-Infinity]', :allow_nan => true)
     assert_equal([""], parse('[""]'))
     assert_equal(["foobar"], parse('["foobar"]'))
@@ -95,7 +95,7 @@ class TestJSON < Test::Unit::TestCase
     assert_equal({ "a" => nil }, parse('{"a":null}'))
     assert_equal({ "a" => false }, parse('{   "a"  :  false  }  '))
     assert_equal({ "a" => false }, parse('{"a":false}'))
-    assert_raises(JSON::ParserError) { parse('{false}') }
+    assert_raise(JSON::ParserError) { parse('{false}') }
     assert_equal({ "a" => true }, parse('{"a":true}'))
     assert_equal({ "a" => true }, parse('  { "a" :  true  }   '))
     assert_equal({ "a" => -23 }, parse('  {  "a"  :  -23  }  '))
@@ -380,7 +380,7 @@ EOT
                     *  comment */
 }
 EOT
-    assert_raises(ParserError) { parse(json) }
+    assert_raise(ParserError) { parse(json) }
     json = <<EOT
 {
   "key1":"value1"  /* multi line
@@ -389,7 +389,7 @@ EOT
                    and again, throw an Error */
 }
 EOT
-    assert_raises(ParserError) { parse(json) }
+    assert_raise(ParserError) { parse(json) }
     json = <<EOT
 {
   "key1":"value1"  /*/*/
@@ -425,32 +425,32 @@ EOT
   end
 
   def test_wrong_inputs
-    assert_raises(ParserError) { JSON.parse('"foo"') }
-    assert_raises(ParserError) { JSON.parse('123') }
-    assert_raises(ParserError) { JSON.parse('[] bla') }
-    assert_raises(ParserError) { JSON.parse('[] 1') }
-    assert_raises(ParserError) { JSON.parse('[] []') }
-    assert_raises(ParserError) { JSON.parse('[] {}') }
-    assert_raises(ParserError) { JSON.parse('{} []') }
-    assert_raises(ParserError) { JSON.parse('{} {}') }
-    assert_raises(ParserError) { JSON.parse('[NULL]') }
-    assert_raises(ParserError) { JSON.parse('[FALSE]') }
-    assert_raises(ParserError) { JSON.parse('[TRUE]') }
-    assert_raises(ParserError) { JSON.parse('[07]    ') }
-    assert_raises(ParserError) { JSON.parse('[0a]') }
-    assert_raises(ParserError) { JSON.parse('[1.]') }
-    assert_raises(ParserError) { JSON.parse('     ') }
+    assert_raise(ParserError) { JSON.parse('"foo"') }
+    assert_raise(ParserError) { JSON.parse('123') }
+    assert_raise(ParserError) { JSON.parse('[] bla') }
+    assert_raise(ParserError) { JSON.parse('[] 1') }
+    assert_raise(ParserError) { JSON.parse('[] []') }
+    assert_raise(ParserError) { JSON.parse('[] {}') }
+    assert_raise(ParserError) { JSON.parse('{} []') }
+    assert_raise(ParserError) { JSON.parse('{} {}') }
+    assert_raise(ParserError) { JSON.parse('[NULL]') }
+    assert_raise(ParserError) { JSON.parse('[FALSE]') }
+    assert_raise(ParserError) { JSON.parse('[TRUE]') }
+    assert_raise(ParserError) { JSON.parse('[07]    ') }
+    assert_raise(ParserError) { JSON.parse('[0a]') }
+    assert_raise(ParserError) { JSON.parse('[1.]') }
+    assert_raise(ParserError) { JSON.parse('     ') }
   end
 
   def test_nesting
-    assert_raises(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 }
-    assert_raises(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse }
+    assert_raise(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 }
+    assert_raise(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse }
     assert_equal [[]], JSON.parse('[[]]', :max_nesting => 2)
     too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
     too_deep_ary = eval too_deep
-    assert_raises(JSON::NestingError) { JSON.parse too_deep }
-    assert_raises(JSON::NestingError) { JSON.parser.new(too_deep).parse }
-    assert_raises(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 100 }
+    assert_raise(JSON::NestingError) { JSON.parse too_deep }
+    assert_raise(JSON::NestingError) { JSON.parser.new(too_deep).parse }
+    assert_raise(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 100 }
     ok = JSON.parse too_deep, :max_nesting => 101
     assert_equal too_deep_ary, ok
     ok = JSON.parse too_deep, :max_nesting => nil
@@ -459,10 +459,10 @@ EOT
     assert_equal too_deep_ary, ok
     ok = JSON.parse too_deep, :max_nesting => 0
     assert_equal too_deep_ary, ok
-    assert_raises(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 }
+    assert_raise(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 }
     assert_equal '[[]]', JSON.generate([[]], :max_nesting => 2)
-    assert_raises(JSON::NestingError) { JSON.generate too_deep_ary }
-    assert_raises(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 }
+    assert_raise(JSON::NestingError) { JSON.generate too_deep_ary }
+    assert_raise(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 }
     ok = JSON.generate too_deep_ary, :max_nesting => 101
     assert_equal too_deep, ok
     ok = JSON.generate too_deep_ary, :max_nesting => nil
@@ -505,8 +505,8 @@ EOT
     too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
     assert_equal too_deep, JSON.dump(eval(too_deep))
     assert_kind_of String, Marshal.dump(eval(too_deep))
-    assert_raises(ArgumentError) { JSON.dump(eval(too_deep), 100) }
-    assert_raises(ArgumentError) { Marshal.dump(eval(too_deep), 100) }
+    assert_raise(ArgumentError) { JSON.dump(eval(too_deep), 100) }
+    assert_raise(ArgumentError) { Marshal.dump(eval(too_deep), 100) }
     assert_equal too_deep, JSON.dump(eval(too_deep), 101)
     assert_kind_of String, Marshal.dump(eval(too_deep), 101)
     output = StringIO.new
diff --git a/tests/test_json_addition.rb b/tests/test_json_addition.rb
index a30f06addd..6034a183bd 100755
--- a/tests/test_json_addition.rb
+++ b/tests/test_json_addition.rb
@@ -112,7 +112,7 @@ class TestJSONAddition < Test::Unit::TestCase
     c = C.new
     assert !C.json_creatable?
     json = generate(c)
-    assert_raises(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) }
+    assert_raise(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) }
   end
 
   def test_raw_strings
@@ -151,7 +151,7 @@ class TestJSONAddition < Test::Unit::TestCase
     assert_equal s, JSON(JSON(s), :create_additions => true)
     struct = Struct.new :foo, :bar
     s = struct.new 4711, 'foot'
-    assert_raises(JSONError) { JSON(s) }
+    assert_raise(JSONError) { JSON(s) }
     begin
       raise TypeError, "test me"
     rescue TypeError => e
diff --git a/tests/test_json_encoding.rb b/tests/test_json_encoding.rb
index fa7d878920..13903cd266 100644
--- a/tests/test_json_encoding.rb
+++ b/tests/test_json_encoding.rb
@@ -59,7 +59,7 @@ class TestJSONEncoding < Test::Unit::TestCase
       assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true)
     else
       # XXX checking of correct utf8 data is not as strict (yet?) without :ascii_only
-      assert_raises(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) }
+      assert_raise(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) }
     end
   end
 end
diff --git a/tests/test_json_fixtures.rb b/tests/test_json_fixtures.rb
index 584dffdfdb..c861439573 100755
--- a/tests/test_json_fixtures.rb
+++ b/tests/test_json_fixtures.rb
@@ -26,7 +26,7 @@ class TestJSONFixtures < Test::Unit::TestCase
 
   def test_failing
     for name, source in @failed
-      assert_raises(JSON::ParserError, JSON::NestingError,
+      assert_raise(JSON::ParserError, JSON::NestingError,
         "Did not fail for fixture '#{name}': #{source.inspect}") do
         JSON.parse(source)
       end
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb
index ce470db3c2..5da0d2f4f0 100755
--- a/tests/test_json_generate.rb
+++ b/tests/test_json_generate.rb
@@ -123,12 +123,12 @@ EOT
     assert s[:check_circular?]
     h = { 1=>2 }
     h[3] = h
-    assert_raises(JSON::NestingError) {  generate(h) }
-    assert_raises(JSON::NestingError) {  generate(h, s) }
+    assert_raise(JSON::NestingError) {  generate(h) }
+    assert_raise(JSON::NestingError) {  generate(h, s) }
     s = JSON.state.new
     a = [ 1, 2 ]
     a << a
-    assert_raises(JSON::NestingError) {  generate(a, s) }
+    assert_raise(JSON::NestingError) {  generate(a, s) }
     assert s.check_circular?
     assert s[:check_circular?]
   end
@@ -185,34 +185,34 @@ EOT
   end
 
   def test_allow_nan
-    assert_raises(GeneratorError) { generate([JSON::NaN]) }
+    assert_raise(GeneratorError) { generate([JSON::NaN]) }
     assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
-    assert_raises(GeneratorError) { fast_generate([JSON::NaN]) }
-    assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) }
+    assert_raise(GeneratorError) { fast_generate([JSON::NaN]) }
+    assert_raise(GeneratorError) { pretty_generate([JSON::NaN]) }
     assert_equal "[\n  NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true)
-    assert_raises(GeneratorError) { generate([JSON::Infinity]) }
+    assert_raise(GeneratorError) { generate([JSON::Infinity]) }
     assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true)
-    assert_raises(GeneratorError) { fast_generate([JSON::Infinity]) }
-    assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) }
+    assert_raise(GeneratorError) { fast_generate([JSON::Infinity]) }
+    assert_raise(GeneratorError) { pretty_generate([JSON::Infinity]) }
     assert_equal "[\n  Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true)
-    assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) }
+    assert_raise(GeneratorError) { generate([JSON::MinusInfinity]) }
     assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true)
-    assert_raises(GeneratorError) { fast_generate([JSON::MinusInfinity]) }
-    assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
+    assert_raise(GeneratorError) { fast_generate([JSON::MinusInfinity]) }
+    assert_raise(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
     assert_equal "[\n  -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
   end
 
   def test_depth
     ary = []; ary << ary
     assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
-    assert_raises(JSON::NestingError) { JSON.generate(ary) }
+    assert_raise(JSON::NestingError) { JSON.generate(ary) }
     assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
     assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
-    assert_raises(JSON::NestingError) { JSON.pretty_generate(ary) }
+    assert_raise(JSON::NestingError) { JSON.pretty_generate(ary) }
     assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
     s = JSON.state.new
     assert_equal 0, s.depth
-    assert_raises(JSON::NestingError) { ary.to_json(s) }
+    assert_raise(JSON::NestingError) { ary.to_json(s) }
     assert_equal 100, s.depth
   end
 

commit ab8e1eda2385d418939a239189688aeddb6b7bde
Author: naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Wed Dec 16 05:07:31 2015 +0000

    Add frozen_string_literal: false for all files
    
    When you change this to true, you may need to add more tests.
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit 3e92b635fb5422207b7bbdc924e292e51e21f040)

diff --git a/tests/setup_variant.rb b/tests/setup_variant.rb
index 2dab184bc4..f7fb2a1d56 100644
--- a/tests/setup_variant.rb
+++ b/tests/setup_variant.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 case ENV['JSON']
 when 'pure'
   $:.unshift 'lib'
diff --git a/tests/test_json.rb b/tests/test_json.rb
index 07287eed81..8fe9459978 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # encoding: utf-8
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')
diff --git a/tests/test_json_addition.rb b/tests/test_json_addition.rb
index 6034a183bd..f2059312de 100755
--- a/tests/test_json_addition.rb
+++ b/tests/test_json_addition.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # -*- coding:utf-8 -*-
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')
diff --git a/tests/test_json_encoding.rb b/tests/test_json_encoding.rb
index 13903cd266..50fb4ea279 100644
--- a/tests/test_json_encoding.rb
+++ b/tests/test_json_encoding.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # encoding: utf-8
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')
diff --git a/tests/test_json_fixtures.rb b/tests/test_json_fixtures.rb
index c861439573..e192706d6b 100755
--- a/tests/test_json_fixtures.rb
+++ b/tests/test_json_fixtures.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # encoding: utf-8
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb
index 5da0d2f4f0..50895f6247 100755
--- a/tests/test_json_generate.rb
+++ b/tests/test_json_generate.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # encoding: utf-8
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')
diff --git a/tests/test_json_generic_object.rb b/tests/test_json_generic_object.rb
index c43c7762be..e04e1a1cb3 100644
--- a/tests/test_json_generic_object.rb
+++ b/tests/test_json_generic_object.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # encoding: utf-8
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')
diff --git a/tests/test_json_string_matching.rb b/tests/test_json_string_matching.rb
index c233df8c2c..6158231103 100644
--- a/tests/test_json_string_matching.rb
+++ b/tests/test_json_string_matching.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # encoding: utf-8
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')
diff --git a/tests/test_json_unicode.rb b/tests/test_json_unicode.rb
index 8352d5c6c6..16234f0491 100755
--- a/tests/test_json_unicode.rb
+++ b/tests/test_json_unicode.rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # encoding: utf-8
+# frozen_string_literal: false
 
 require 'test/unit'
 require File.join(File.dirname(__FILE__), 'setup_variant')

commit ee1844bffb1750448defa4c982f3aff240ff536a
Author: naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Wed Dec 16 05:31:54 2015 +0000

    handle ext/ as r53141
    
    g -L frozen_string_literal ext/**/*.rb|xargs ruby -Ka -e'ARGV.each{|fn|puts
    fn;open(fn,"r+"){|f|s=f.read.sub(/\A(#!.*\n)?(#.*coding.*\n)?/,"\\&#
    frozen_string_literal: false\n");f.rewind;f.write s}}'
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit c4fdfabcc8ea3f6186d1560f7756211fce125be3)

diff --git a/ext/json/ext/generator/extconf.rb b/ext/json/ext/generator/extconf.rb
index 8627c5f4bd..fd5c4a7f49 100644
--- a/ext/json/ext/generator/extconf.rb
+++ b/ext/json/ext/generator/extconf.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 require 'mkmf'
 
 $defs << "-DJSON_GENERATOR"
diff --git a/ext/json/ext/parser/extconf.rb b/ext/json/ext/parser/extconf.rb
index 2addc53e7f..f7360d46b2 100644
--- a/ext/json/ext/parser/extconf.rb
+++ b/ext/json/ext/parser/extconf.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 require 'mkmf'
 
 have_func("rb_enc_raise", "ruby.h")
diff --git a/ext/json/extconf.rb b/ext/json/extconf.rb
index 850798c643..ad1ef9ba82 100644
--- a/ext/json/extconf.rb
+++ b/ext/json/extconf.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 require 'mkmf'
 create_makefile('json')
 
diff --git a/lib/json.rb b/lib/json.rb
index 24aa385c91..61bb8fae0e 100644
--- a/lib/json.rb
+++ b/lib/json.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 require 'json/common'
 
 ##
diff --git a/lib/json/add/bigdecimal.rb b/lib/json/add/bigdecimal.rb
index 0ef69f12e0..a7646860a2 100644
--- a/lib/json/add/bigdecimal.rb
+++ b/lib/json/add/bigdecimal.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/complex.rb b/lib/json/add/complex.rb
index 2723f60103..cff40c1996 100644
--- a/lib/json/add/complex.rb
+++ b/lib/json/add/complex.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/core.rb b/lib/json/add/core.rb
index 77d9dc0b20..93b2bff424 100644
--- a/lib/json/add/core.rb
+++ b/lib/json/add/core.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 # This file requires the implementations of ruby core's custom objects for
 # serialisation/deserialisation.
 
diff --git a/lib/json/add/date.rb b/lib/json/add/date.rb
index 4288237db1..20f0e8dc77 100644
--- a/lib/json/add/date.rb
+++ b/lib/json/add/date.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/date_time.rb b/lib/json/add/date_time.rb
index 5ea42ea656..757d43c266 100644
--- a/lib/json/add/date_time.rb
+++ b/lib/json/add/date_time.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/exception.rb b/lib/json/add/exception.rb
index e6ad257abf..95379d97f5 100644
--- a/lib/json/add/exception.rb
+++ b/lib/json/add/exception.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/ostruct.rb b/lib/json/add/ostruct.rb
index da81e107a7..2fa1e88b93 100644
--- a/lib/json/add/ostruct.rb
+++ b/lib/json/add/ostruct.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/range.rb b/lib/json/add/range.rb
index e61e553cdb..4dd7ccf0eb 100644
--- a/lib/json/add/range.rb
+++ b/lib/json/add/range.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/rational.rb b/lib/json/add/rational.rb
index ee39c20e8d..e83a532775 100644
--- a/lib/json/add/rational.rb
+++ b/lib/json/add/rational.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/regexp.rb b/lib/json/add/regexp.rb
index 2fcbb6fb14..4bea64fb19 100644
--- a/lib/json/add/regexp.rb
+++ b/lib/json/add/regexp.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/struct.rb b/lib/json/add/struct.rb
index 6847cde99b..c9afe70770 100644
--- a/lib/json/add/struct.rb
+++ b/lib/json/add/struct.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/symbol.rb b/lib/json/add/symbol.rb
index 03dc9a56a5..831e5c6173 100644
--- a/lib/json/add/symbol.rb
+++ b/lib/json/add/symbol.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/add/time.rb b/lib/json/add/time.rb
index d9834677ac..18e57d7555 100644
--- a/lib/json/add/time.rb
+++ b/lib/json/add/time.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
diff --git a/lib/json/common.rb b/lib/json/common.rb
index f44184e138..020615fc1d 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 require 'json/version'
 require 'json/generic_object'
 
diff --git a/lib/json/ext.rb b/lib/json/ext.rb
index c5f813181d..2486f084cd 100644
--- a/lib/json/ext.rb
+++ b/lib/json/ext.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 if ENV['SIMPLECOV_COVERAGE'].to_i == 1
   require 'simplecov'
   SimpleCov.start do
diff --git a/lib/json/generic_object.rb b/lib/json/generic_object.rb
index 3a14f0ea7d..2241f6c7ce 100644
--- a/lib/json/generic_object.rb
+++ b/lib/json/generic_object.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 require 'ostruct'
 
 module JSON
diff --git a/lib/json/version.rb b/lib/json/version.rb
index 5a4013dbf6..b5748334b9 100644
--- a/lib/json/version.rb
+++ b/lib/json/version.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
 module JSON
   # JSON version
   VERSION         = '1.8.3'

commit 5af0d7c8ca76269f90f987cfa7db700ff968bc10
Author: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date:   Wed Aug 10 16:30:43 2016 +0000

    merge revision(s) 55380: [Backport #12255]
    
            * ext/json/lib/*.rb: Removed some comments. Because these are unnecessary
              class description. [ci skip][Bug #12255][ruby-core:74835]
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@55855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    (cherry picked from commit a3600fc3771818028f591969c2d3287fcecfa13c)

diff --git a/lib/json/add/date.rb b/lib/json/add/date.rb
index 20f0e8dc77..b58af76e10 100644
--- a/lib/json/add/date.rb
+++ b/lib/json/add/date.rb
@@ -4,7 +4,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
 end
 require 'date'
 
-# Date serialization/deserialization
 class Date
 
   # Deserializes JSON string by converting Julian year <tt>y</tt>, month
diff --git a/lib/json/add/date_time.rb b/lib/json/add/date_time.rb
index 757d43c266..f794eb3d7d 100644
--- a/lib/json/add/date_time.rb
+++ b/lib/json/add/date_time.rb
@@ -4,7 +4,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
 end
 require 'date'
 
-# DateTime serialization/deserialization
 class DateTime
 
   # Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
diff --git a/lib/json/add/exception.rb b/lib/json/add/exception.rb
index 95379d97f5..caac713c6a 100644
--- a/lib/json/add/exception.rb
+++ b/lib/json/add/exception.rb
@@ -3,7 +3,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
 
-# Exception serialization/deserialization
 class Exception
 
   # Deserializes JSON string by constructing new Exception object with message
diff --git a/lib/json/add/ostruct.rb b/lib/json/add/ostruct.rb
index 2fa1e88b93..1f9ce7b3b4 100644
--- a/lib/json/add/ostruct.rb
+++ b/lib/json/add/ostruct.rb
@@ -4,7 +4,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
 end
 require 'ostruct'
 
-# OpenStruct serialization/deserialization
 class OpenStruct
 
   # Deserializes JSON string by constructing new Struct object with values
diff --git a/lib/json/add/range.rb b/lib/json/add/range.rb
index 4dd7ccf0eb..3ef20150bf 100644
--- a/lib/json/add/range.rb
+++ b/lib/json/add/range.rb
@@ -3,7 +3,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
 
-# Range serialization/deserialization
 class Range
 
   # Deserializes JSON string by constructing new Range object with arguments
diff --git a/lib/json/add/regexp.rb b/lib/json/add/regexp.rb
index 4bea64fb19..41b260f307 100644
--- a/lib/json/add/regexp.rb
+++ b/lib/json/add/regexp.rb
@@ -3,7 +3,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
 
-# Regexp serialization/deserialization
 class Regexp
 
   # Deserializes JSON string by constructing new Regexp object with source
diff --git a/lib/json/add/struct.rb b/lib/json/add/struct.rb
index c9afe70770..d08d88237a 100644
--- a/lib/json/add/struct.rb
+++ b/lib/json/add/struct.rb
@@ -3,7 +3,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
 
-# Struct serialization/deserialization
 class Struct
 
   # Deserializes JSON string by constructing new Struct object with values
diff --git a/lib/json/add/symbol.rb b/lib/json/add/symbol.rb
index 831e5c6173..31b56a294f 100644
--- a/lib/json/add/symbol.rb
+++ b/lib/json/add/symbol.rb
@@ -3,7 +3,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
 
-# Symbol serialization/deserialization
 class Symbol
   # Returns a hash, that will be turned into a JSON object and represent this
   # object.
diff --git a/lib/json/add/time.rb b/lib/json/add/time.rb
index 18e57d7555..80b6434f17 100644
--- a/lib/json/add/time.rb
+++ b/lib/json/add/time.rb
@@ -3,7 +3,6 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
   require 'json'
 end
 
-# Time serialization/deserialization
 class Time
 
   # Deserializes JSON string by converting time since epoch to Time