pitchfork 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -226,7 +226,7 @@ static int is_chunked(VALUE v)
226
226
  return rb_funcall(cHttpParser, id_is_chunked_p, 1, v) != Qfalse;
227
227
  }
228
228
 
229
- static void write_value(struct http_parser *hp,
229
+ static void write_value(VALUE self, struct http_parser *hp,
230
230
  const char *buffer, const char *p)
231
231
  {
232
232
  VALUE f = find_common_field(PTR_TO(start.field), hp->s.field_len);
@@ -246,7 +246,7 @@ static void write_value(struct http_parser *hp,
246
246
  * rack env variable.
247
247
  */
248
248
  if (CONST_MEM_EQ("VERSION", field, flen)) {
249
- hp->cont = Qnil;
249
+ RB_OBJ_WRITE(self, &hp->cont, Qnil);
250
250
  return;
251
251
  }
252
252
  f = uncommon_field(field, flen);
@@ -298,16 +298,16 @@ static void write_value(struct http_parser *hp,
298
298
 
299
299
  e = rb_hash_aref(hp->env, f);
300
300
  if (NIL_P(e)) {
301
- hp->cont = rb_hash_aset(hp->env, f, v);
301
+ RB_OBJ_WRITE(self, &hp->cont, rb_hash_aset(hp->env, f, v));
302
302
  } else if (f == g_http_host) {
303
303
  /*
304
304
  * ignored, absolute URLs in REQUEST_URI take precedence over
305
305
  * the Host: header (ref: rfc 2616, section 5.2.1)
306
306
  */
307
- hp->cont = Qnil;
307
+ RB_OBJ_WRITE(self, &hp->cont, Qnil);
308
308
  } else {
309
309
  rb_str_buf_cat(e, ",", 1);
310
- hp->cont = rb_str_buf_append(e, v);
310
+ RB_OBJ_WRITE(self, &hp->cont, rb_str_buf_append(e, v));
311
311
  }
312
312
  }
313
313
 
@@ -354,7 +354,7 @@ static void http_parser_init(struct http_parser *hp)
354
354
 
355
355
  /** exec **/
356
356
  static void
357
- http_parser_execute(struct http_parser *hp, char *buffer, size_t len)
357
+ http_parser_execute(VALUE self, struct http_parser *hp, char *buffer, size_t len)
358
358
  {
359
359
  const char *p, *pe;
360
360
  int cs = hp->cs;
@@ -491,7 +491,7 @@ tr8:
491
491
  }
492
492
  }
493
493
  goto st5;
494
- tr41:
494
+ tr42:
495
495
  #line 317 "pitchfork_http.rl"
496
496
  {MARK(mark, p); }
497
497
  #line 346 "pitchfork_http.rl"
@@ -500,14 +500,14 @@ tr41:
500
500
  rb_hash_aset(hp->env, g_fragment, STR_NEW(mark, p));
501
501
  }
502
502
  goto st5;
503
- tr44:
503
+ tr45:
504
504
  #line 346 "pitchfork_http.rl"
505
505
  {
506
506
  VALIDATE_MAX_URI_LENGTH(LEN(mark, p), FRAGMENT);
507
507
  rb_hash_aset(hp->env, g_fragment, STR_NEW(mark, p));
508
508
  }
509
509
  goto st5;
510
- tr48:
510
+ tr49:
511
511
  #line 356 "pitchfork_http.rl"
512
512
  {
513
513
  VALUE val;
@@ -536,7 +536,7 @@ tr48:
536
536
  }
537
537
  }
538
538
  goto st5;
539
- tr54:
539
+ tr55:
540
540
  #line 350 "pitchfork_http.rl"
541
541
  {MARK(start.query, p); }
542
542
  #line 351 "pitchfork_http.rl"
@@ -561,7 +561,7 @@ tr54:
561
561
  }
562
562
  }
563
563
  goto st5;
564
- tr58:
564
+ tr59:
565
565
  #line 351 "pitchfork_http.rl"
566
566
  {
567
567
  VALIDATE_MAX_URI_LENGTH(LEN(start.query, p), QUERY_STRING);
@@ -663,25 +663,25 @@ tr18:
663
663
  #line 355 "pitchfork_http.rl"
664
664
  { http_version(hp, PTR_TO(mark), LEN(mark, p)); }
665
665
  goto st14;
666
- tr25:
666
+ tr26:
667
667
  #line 323 "pitchfork_http.rl"
668
668
  { MARK(mark, p); }
669
669
  #line 325 "pitchfork_http.rl"
670
670
  { write_cont_value(hp, buffer, p); }
671
671
  goto st14;
672
- tr30:
672
+ tr29:
673
673
  #line 325 "pitchfork_http.rl"
674
674
  { write_cont_value(hp, buffer, p); }
675
675
  goto st14;
676
- tr35:
676
+ tr36:
677
677
  #line 323 "pitchfork_http.rl"
678
678
  { MARK(mark, p); }
679
679
  #line 324 "pitchfork_http.rl"
680
- { write_value(hp, buffer, p); }
680
+ { write_value(self, hp, buffer, p); }
681
681
  goto st14;
682
682
  tr39:
683
683
  #line 324 "pitchfork_http.rl"
684
- { write_value(hp, buffer, p); }
684
+ { write_value(self, hp, buffer, p); }
685
685
  goto st14;
686
686
  st14:
687
687
  if ( ++p == pe )
@@ -715,7 +715,7 @@ case 14:
715
715
  } else
716
716
  goto tr23;
717
717
  goto st0;
718
- tr24:
718
+ tr25:
719
719
  #line 323 "pitchfork_http.rl"
720
720
  { MARK(mark, p); }
721
721
  goto st15;
@@ -725,67 +725,67 @@ st15:
725
725
  case 15:
726
726
  #line 727 "pitchfork_http.c"
727
727
  switch( (*p) ) {
728
- case 9: goto tr24;
729
- case 10: goto tr25;
730
- case 13: goto tr26;
731
- case 32: goto tr24;
728
+ case 9: goto tr25;
729
+ case 10: goto tr26;
730
+ case 13: goto tr27;
731
+ case 32: goto tr25;
732
+ case 127: goto st0;
733
+ }
734
+ if ( 0 <= (*p) && (*p) <= 31 )
735
+ goto st0;
736
+ goto tr24;
737
+ tr24:
738
+ #line 323 "pitchfork_http.rl"
739
+ { MARK(mark, p); }
740
+ goto st16;
741
+ st16:
742
+ if ( ++p == pe )
743
+ goto _test_eof16;
744
+ case 16:
745
+ #line 746 "pitchfork_http.c"
746
+ switch( (*p) ) {
747
+ case 10: goto tr29;
748
+ case 13: goto tr30;
732
749
  case 127: goto st0;
733
750
  }
734
- if ( (*p) <= 31 )
751
+ if ( (*p) > 8 ) {
752
+ if ( 11 <= (*p) && (*p) <= 31 )
753
+ goto st0;
754
+ } else if ( (*p) >= 0 )
735
755
  goto st0;
736
- goto tr27;
756
+ goto st16;
737
757
  tr19:
738
758
  #line 355 "pitchfork_http.rl"
739
759
  { http_version(hp, PTR_TO(mark), LEN(mark, p)); }
740
- goto st16;
741
- tr26:
760
+ goto st17;
761
+ tr27:
742
762
  #line 323 "pitchfork_http.rl"
743
763
  { MARK(mark, p); }
744
764
  #line 325 "pitchfork_http.rl"
745
765
  { write_cont_value(hp, buffer, p); }
746
- goto st16;
747
- tr31:
766
+ goto st17;
767
+ tr30:
748
768
  #line 325 "pitchfork_http.rl"
749
769
  { write_cont_value(hp, buffer, p); }
750
- goto st16;
751
- tr36:
770
+ goto st17;
771
+ tr37:
752
772
  #line 323 "pitchfork_http.rl"
753
773
  { MARK(mark, p); }
754
774
  #line 324 "pitchfork_http.rl"
755
- { write_value(hp, buffer, p); }
756
- goto st16;
775
+ { write_value(self, hp, buffer, p); }
776
+ goto st17;
757
777
  tr40:
758
778
  #line 324 "pitchfork_http.rl"
759
- { write_value(hp, buffer, p); }
760
- goto st16;
761
- st16:
762
- if ( ++p == pe )
763
- goto _test_eof16;
764
- case 16:
765
- #line 766 "pitchfork_http.c"
766
- if ( (*p) == 10 )
767
- goto st14;
768
- goto st0;
769
- tr27:
770
- #line 323 "pitchfork_http.rl"
771
- { MARK(mark, p); }
779
+ { write_value(self, hp, buffer, p); }
772
780
  goto st17;
773
781
  st17:
774
782
  if ( ++p == pe )
775
783
  goto _test_eof17;
776
784
  case 17:
777
- #line 778 "pitchfork_http.c"
778
- switch( (*p) ) {
779
- case 10: goto tr30;
780
- case 13: goto tr31;
781
- case 127: goto st0;
782
- }
783
- if ( (*p) > 8 ) {
784
- if ( 11 <= (*p) && (*p) <= 31 )
785
- goto st0;
786
- } else
787
- goto st0;
788
- goto st17;
785
+ #line 786 "pitchfork_http.c"
786
+ if ( (*p) == 10 )
787
+ goto st14;
788
+ goto st0;
789
789
  tr21:
790
790
  #line 371 "pitchfork_http.rl"
791
791
  {
@@ -844,7 +844,7 @@ tr104:
844
844
  goto post_exec;
845
845
  }
846
846
  goto st122;
847
- tr107:
847
+ tr108:
848
848
  #line 317 "pitchfork_http.rl"
849
849
  {MARK(mark, p); }
850
850
  #line 346 "pitchfork_http.rl"
@@ -872,7 +872,7 @@ tr107:
872
872
  goto post_exec;
873
873
  }
874
874
  goto st122;
875
- tr111:
875
+ tr112:
876
876
  #line 346 "pitchfork_http.rl"
877
877
  {
878
878
  VALIDATE_MAX_URI_LENGTH(LEN(mark, p), FRAGMENT);
@@ -898,7 +898,7 @@ tr111:
898
898
  goto post_exec;
899
899
  }
900
900
  goto st122;
901
- tr116:
901
+ tr117:
902
902
  #line 356 "pitchfork_http.rl"
903
903
  {
904
904
  VALUE val;
@@ -946,7 +946,7 @@ tr116:
946
946
  goto post_exec;
947
947
  }
948
948
  goto st122;
949
- tr123:
949
+ tr124:
950
950
  #line 350 "pitchfork_http.rl"
951
951
  {MARK(start.query, p); }
952
952
  #line 351 "pitchfork_http.rl"
@@ -990,7 +990,7 @@ tr123:
990
990
  goto post_exec;
991
991
  }
992
992
  goto st122;
993
- tr128:
993
+ tr129:
994
994
  #line 351 "pitchfork_http.rl"
995
995
  {
996
996
  VALIDATE_MAX_URI_LENGTH(LEN(start.query, p), QUERY_STRING);
@@ -1056,7 +1056,7 @@ tr105:
1056
1056
  }
1057
1057
  }
1058
1058
  goto st18;
1059
- tr108:
1059
+ tr109:
1060
1060
  #line 317 "pitchfork_http.rl"
1061
1061
  {MARK(mark, p); }
1062
1062
  #line 346 "pitchfork_http.rl"
@@ -1065,14 +1065,14 @@ tr108:
1065
1065
  rb_hash_aset(hp->env, g_fragment, STR_NEW(mark, p));
1066
1066
  }
1067
1067
  goto st18;
1068
- tr112:
1068
+ tr113:
1069
1069
  #line 346 "pitchfork_http.rl"
1070
1070
  {
1071
1071
  VALIDATE_MAX_URI_LENGTH(LEN(mark, p), FRAGMENT);
1072
1072
  rb_hash_aset(hp->env, g_fragment, STR_NEW(mark, p));
1073
1073
  }
1074
1074
  goto st18;
1075
- tr117:
1075
+ tr118:
1076
1076
  #line 356 "pitchfork_http.rl"
1077
1077
  {
1078
1078
  VALUE val;
@@ -1101,7 +1101,7 @@ tr117:
1101
1101
  }
1102
1102
  }
1103
1103
  goto st18;
1104
- tr124:
1104
+ tr125:
1105
1105
  #line 350 "pitchfork_http.rl"
1106
1106
  {MARK(start.query, p); }
1107
1107
  #line 351 "pitchfork_http.rl"
@@ -1126,7 +1126,7 @@ tr124:
1126
1126
  }
1127
1127
  }
1128
1128
  goto st18;
1129
- tr129:
1129
+ tr130:
1130
1130
  #line 351 "pitchfork_http.rl"
1131
1131
  {
1132
1132
  VALIDATE_MAX_URI_LENGTH(LEN(start.query, p), QUERY_STRING);
@@ -1196,7 +1196,7 @@ case 19:
1196
1196
  } else
1197
1197
  goto tr32;
1198
1198
  goto st0;
1199
- tr34:
1199
+ tr35:
1200
1200
  #line 323 "pitchfork_http.rl"
1201
1201
  { MARK(mark, p); }
1202
1202
  goto st20;
@@ -1210,16 +1210,16 @@ st20:
1210
1210
  case 20:
1211
1211
  #line 1212 "pitchfork_http.c"
1212
1212
  switch( (*p) ) {
1213
- case 9: goto tr34;
1214
- case 10: goto tr35;
1215
- case 13: goto tr36;
1216
- case 32: goto tr34;
1213
+ case 9: goto tr35;
1214
+ case 10: goto tr36;
1215
+ case 13: goto tr37;
1216
+ case 32: goto tr35;
1217
1217
  case 127: goto st0;
1218
1218
  }
1219
- if ( (*p) <= 31 )
1219
+ if ( 0 <= (*p) && (*p) <= 31 )
1220
1220
  goto st0;
1221
- goto tr37;
1222
- tr37:
1221
+ goto tr34;
1222
+ tr34:
1223
1223
  #line 323 "pitchfork_http.rl"
1224
1224
  { MARK(mark, p); }
1225
1225
  goto st21;
@@ -1236,7 +1236,7 @@ case 21:
1236
1236
  if ( (*p) > 8 ) {
1237
1237
  if ( 11 <= (*p) && (*p) <= 31 )
1238
1238
  goto st0;
1239
- } else
1239
+ } else if ( (*p) >= 0 )
1240
1240
  goto st0;
1241
1241
  goto st21;
1242
1242
  tr9:
@@ -1340,15 +1340,15 @@ st22:
1340
1340
  case 22:
1341
1341
  #line 1342 "pitchfork_http.c"
1342
1342
  switch( (*p) ) {
1343
- case 32: goto tr41;
1343
+ case 32: goto tr42;
1344
1344
  case 35: goto st0;
1345
1345
  case 37: goto tr43;
1346
1346
  case 127: goto st0;
1347
1347
  }
1348
- if ( (*p) <= 31 )
1348
+ if ( 0 <= (*p) && (*p) <= 31 )
1349
1349
  goto st0;
1350
- goto tr42;
1351
- tr42:
1350
+ goto tr41;
1351
+ tr41:
1352
1352
  #line 317 "pitchfork_http.rl"
1353
1353
  {MARK(mark, p); }
1354
1354
  goto st23;
@@ -1358,12 +1358,12 @@ st23:
1358
1358
  case 23:
1359
1359
  #line 1360 "pitchfork_http.c"
1360
1360
  switch( (*p) ) {
1361
- case 32: goto tr44;
1361
+ case 32: goto tr45;
1362
1362
  case 35: goto st0;
1363
1363
  case 37: goto st24;
1364
1364
  case 127: goto st0;
1365
1365
  }
1366
- if ( (*p) <= 31 )
1366
+ if ( 0 <= (*p) && (*p) <= 31 )
1367
1367
  goto st0;
1368
1368
  goto st23;
1369
1369
  tr43:
@@ -1413,13 +1413,13 @@ st26:
1413
1413
  case 26:
1414
1414
  #line 1415 "pitchfork_http.c"
1415
1415
  switch( (*p) ) {
1416
- case 32: goto tr48;
1416
+ case 32: goto tr49;
1417
1417
  case 35: goto tr50;
1418
1418
  case 37: goto st27;
1419
1419
  case 63: goto tr52;
1420
1420
  case 127: goto st0;
1421
1421
  }
1422
- if ( (*p) <= 31 )
1422
+ if ( 0 <= (*p) && (*p) <= 31 )
1423
1423
  goto st0;
1424
1424
  goto st26;
1425
1425
  st27:
@@ -1467,15 +1467,15 @@ st29:
1467
1467
  case 29:
1468
1468
  #line 1469 "pitchfork_http.c"
1469
1469
  switch( (*p) ) {
1470
- case 32: goto tr54;
1470
+ case 32: goto tr55;
1471
1471
  case 35: goto tr56;
1472
1472
  case 37: goto tr57;
1473
1473
  case 127: goto st0;
1474
1474
  }
1475
- if ( (*p) <= 31 )
1475
+ if ( 0 <= (*p) && (*p) <= 31 )
1476
1476
  goto st0;
1477
- goto tr55;
1478
- tr55:
1477
+ goto tr54;
1478
+ tr54:
1479
1479
  #line 350 "pitchfork_http.rl"
1480
1480
  {MARK(start.query, p); }
1481
1481
  goto st30;
@@ -1485,12 +1485,12 @@ st30:
1485
1485
  case 30:
1486
1486
  #line 1487 "pitchfork_http.c"
1487
1487
  switch( (*p) ) {
1488
- case 32: goto tr58;
1488
+ case 32: goto tr59;
1489
1489
  case 35: goto tr60;
1490
1490
  case 37: goto st31;
1491
1491
  case 127: goto st0;
1492
1492
  }
1493
- if ( (*p) <= 31 )
1493
+ if ( 0 <= (*p) && (*p) <= 31 )
1494
1494
  goto st0;
1495
1495
  goto st30;
1496
1496
  tr57:
@@ -1620,7 +1620,7 @@ case 39:
1620
1620
  if ( (*p) > 32 ) {
1621
1621
  if ( 34 <= (*p) && (*p) <= 35 )
1622
1622
  goto st0;
1623
- } else
1623
+ } else if ( (*p) >= 0 )
1624
1624
  goto st0;
1625
1625
  } else if ( (*p) > 57 ) {
1626
1626
  if ( (*p) < 65 ) {
@@ -1646,7 +1646,7 @@ case 40:
1646
1646
  case 127: goto st0;
1647
1647
  }
1648
1648
  if ( (*p) < 34 ) {
1649
- if ( (*p) <= 32 )
1649
+ if ( 0 <= (*p) && (*p) <= 32 )
1650
1650
  goto st0;
1651
1651
  } else if ( (*p) > 35 ) {
1652
1652
  if ( 62 <= (*p) && (*p) <= 63 )
@@ -1702,7 +1702,7 @@ case 43:
1702
1702
  if ( (*p) > 32 ) {
1703
1703
  if ( 34 <= (*p) && (*p) <= 35 )
1704
1704
  goto st0;
1705
- } else
1705
+ } else if ( (*p) >= 0 )
1706
1706
  goto st0;
1707
1707
  } else if ( (*p) > 57 ) {
1708
1708
  if ( (*p) < 65 ) {
@@ -1728,7 +1728,7 @@ case 44:
1728
1728
  case 127: goto st0;
1729
1729
  }
1730
1730
  if ( (*p) < 34 ) {
1731
- if ( (*p) <= 32 )
1731
+ if ( 0 <= (*p) && (*p) <= 32 )
1732
1732
  goto st0;
1733
1733
  } else if ( (*p) > 35 ) {
1734
1734
  if ( (*p) > 57 ) {
@@ -1759,7 +1759,7 @@ case 45:
1759
1759
  if ( (*p) > 32 ) {
1760
1760
  if ( 34 <= (*p) && (*p) <= 35 )
1761
1761
  goto st0;
1762
- } else
1762
+ } else if ( (*p) >= 0 )
1763
1763
  goto st0;
1764
1764
  } else if ( (*p) > 58 ) {
1765
1765
  if ( (*p) < 65 ) {
@@ -1789,7 +1789,7 @@ case 46:
1789
1789
  if ( (*p) > 32 ) {
1790
1790
  if ( 34 <= (*p) && (*p) <= 35 )
1791
1791
  goto st0;
1792
- } else
1792
+ } else if ( (*p) >= 0 )
1793
1793
  goto st0;
1794
1794
  } else if ( (*p) > 58 ) {
1795
1795
  if ( (*p) < 65 ) {
@@ -1816,7 +1816,7 @@ case 47:
1816
1816
  case 127: goto st0;
1817
1817
  }
1818
1818
  if ( (*p) < 34 ) {
1819
- if ( (*p) <= 32 )
1819
+ if ( 0 <= (*p) && (*p) <= 32 )
1820
1820
  goto st0;
1821
1821
  } else if ( (*p) > 35 ) {
1822
1822
  if ( 62 <= (*p) && (*p) <= 63 )
@@ -2571,17 +2571,17 @@ st73:
2571
2571
  case 73:
2572
2572
  #line 2573 "pitchfork_http.c"
2573
2573
  switch( (*p) ) {
2574
- case 10: goto tr107;
2575
- case 13: goto tr108;
2576
- case 32: goto tr41;
2574
+ case 10: goto tr108;
2575
+ case 13: goto tr109;
2576
+ case 32: goto tr42;
2577
2577
  case 35: goto st0;
2578
2578
  case 37: goto tr110;
2579
2579
  case 127: goto st0;
2580
2580
  }
2581
- if ( (*p) <= 31 )
2581
+ if ( 0 <= (*p) && (*p) <= 31 )
2582
2582
  goto st0;
2583
- goto tr109;
2584
- tr109:
2583
+ goto tr107;
2584
+ tr107:
2585
2585
  #line 317 "pitchfork_http.rl"
2586
2586
  {MARK(mark, p); }
2587
2587
  goto st74;
@@ -2591,14 +2591,14 @@ st74:
2591
2591
  case 74:
2592
2592
  #line 2593 "pitchfork_http.c"
2593
2593
  switch( (*p) ) {
2594
- case 10: goto tr111;
2595
- case 13: goto tr112;
2596
- case 32: goto tr44;
2594
+ case 10: goto tr112;
2595
+ case 13: goto tr113;
2596
+ case 32: goto tr45;
2597
2597
  case 35: goto st0;
2598
2598
  case 37: goto st75;
2599
2599
  case 127: goto st0;
2600
2600
  }
2601
- if ( (*p) <= 31 )
2601
+ if ( 0 <= (*p) && (*p) <= 31 )
2602
2602
  goto st0;
2603
2603
  goto st74;
2604
2604
  tr110:
@@ -2648,15 +2648,15 @@ st77:
2648
2648
  case 77:
2649
2649
  #line 2650 "pitchfork_http.c"
2650
2650
  switch( (*p) ) {
2651
- case 10: goto tr116;
2652
- case 13: goto tr117;
2653
- case 32: goto tr48;
2651
+ case 10: goto tr117;
2652
+ case 13: goto tr118;
2653
+ case 32: goto tr49;
2654
2654
  case 35: goto tr119;
2655
2655
  case 37: goto st78;
2656
2656
  case 63: goto tr121;
2657
2657
  case 127: goto st0;
2658
2658
  }
2659
- if ( (*p) <= 31 )
2659
+ if ( 0 <= (*p) && (*p) <= 31 )
2660
2660
  goto st0;
2661
2661
  goto st77;
2662
2662
  st78:
@@ -2704,17 +2704,17 @@ st80:
2704
2704
  case 80:
2705
2705
  #line 2706 "pitchfork_http.c"
2706
2706
  switch( (*p) ) {
2707
- case 10: goto tr123;
2708
- case 13: goto tr124;
2709
- case 32: goto tr54;
2707
+ case 10: goto tr124;
2708
+ case 13: goto tr125;
2709
+ case 32: goto tr55;
2710
2710
  case 35: goto tr126;
2711
2711
  case 37: goto tr127;
2712
2712
  case 127: goto st0;
2713
2713
  }
2714
- if ( (*p) <= 31 )
2714
+ if ( 0 <= (*p) && (*p) <= 31 )
2715
2715
  goto st0;
2716
- goto tr125;
2717
- tr125:
2716
+ goto tr123;
2717
+ tr123:
2718
2718
  #line 350 "pitchfork_http.rl"
2719
2719
  {MARK(start.query, p); }
2720
2720
  goto st81;
@@ -2724,14 +2724,14 @@ st81:
2724
2724
  case 81:
2725
2725
  #line 2726 "pitchfork_http.c"
2726
2726
  switch( (*p) ) {
2727
- case 10: goto tr128;
2728
- case 13: goto tr129;
2729
- case 32: goto tr58;
2727
+ case 10: goto tr129;
2728
+ case 13: goto tr130;
2729
+ case 32: goto tr59;
2730
2730
  case 35: goto tr131;
2731
2731
  case 37: goto st82;
2732
2732
  case 127: goto st0;
2733
2733
  }
2734
- if ( (*p) <= 31 )
2734
+ if ( 0 <= (*p) && (*p) <= 31 )
2735
2735
  goto st0;
2736
2736
  goto st81;
2737
2737
  tr127:
@@ -2861,7 +2861,7 @@ case 90:
2861
2861
  if ( (*p) > 32 ) {
2862
2862
  if ( 34 <= (*p) && (*p) <= 35 )
2863
2863
  goto st0;
2864
- } else
2864
+ } else if ( (*p) >= 0 )
2865
2865
  goto st0;
2866
2866
  } else if ( (*p) > 57 ) {
2867
2867
  if ( (*p) < 65 ) {
@@ -2887,7 +2887,7 @@ case 91:
2887
2887
  case 127: goto st0;
2888
2888
  }
2889
2889
  if ( (*p) < 34 ) {
2890
- if ( (*p) <= 32 )
2890
+ if ( 0 <= (*p) && (*p) <= 32 )
2891
2891
  goto st0;
2892
2892
  } else if ( (*p) > 35 ) {
2893
2893
  if ( 62 <= (*p) && (*p) <= 63 )
@@ -2943,7 +2943,7 @@ case 94:
2943
2943
  if ( (*p) > 32 ) {
2944
2944
  if ( 34 <= (*p) && (*p) <= 35 )
2945
2945
  goto st0;
2946
- } else
2946
+ } else if ( (*p) >= 0 )
2947
2947
  goto st0;
2948
2948
  } else if ( (*p) > 57 ) {
2949
2949
  if ( (*p) < 65 ) {
@@ -2969,7 +2969,7 @@ case 95:
2969
2969
  case 127: goto st0;
2970
2970
  }
2971
2971
  if ( (*p) < 34 ) {
2972
- if ( (*p) <= 32 )
2972
+ if ( 0 <= (*p) && (*p) <= 32 )
2973
2973
  goto st0;
2974
2974
  } else if ( (*p) > 35 ) {
2975
2975
  if ( (*p) > 57 ) {
@@ -3000,7 +3000,7 @@ case 96:
3000
3000
  if ( (*p) > 32 ) {
3001
3001
  if ( 34 <= (*p) && (*p) <= 35 )
3002
3002
  goto st0;
3003
- } else
3003
+ } else if ( (*p) >= 0 )
3004
3004
  goto st0;
3005
3005
  } else if ( (*p) > 58 ) {
3006
3006
  if ( (*p) < 65 ) {
@@ -3030,7 +3030,7 @@ case 97:
3030
3030
  if ( (*p) > 32 ) {
3031
3031
  if ( 34 <= (*p) && (*p) <= 35 )
3032
3032
  goto st0;
3033
- } else
3033
+ } else if ( (*p) >= 0 )
3034
3034
  goto st0;
3035
3035
  } else if ( (*p) > 58 ) {
3036
3036
  if ( (*p) < 65 ) {
@@ -3057,7 +3057,7 @@ case 98:
3057
3057
  case 127: goto st0;
3058
3058
  }
3059
3059
  if ( (*p) < 34 ) {
3060
- if ( (*p) <= 32 )
3060
+ if ( 0 <= (*p) && (*p) <= 32 )
3061
3061
  goto st0;
3062
3062
  } else if ( (*p) > 35 ) {
3063
3063
  if ( 62 <= (*p) && (*p) <= 63 )
@@ -3404,25 +3404,25 @@ case 113:
3404
3404
  } else
3405
3405
  goto st113;
3406
3406
  goto st0;
3407
- tr171:
3407
+ tr172:
3408
3408
  #line 323 "pitchfork_http.rl"
3409
3409
  { MARK(mark, p); }
3410
3410
  #line 325 "pitchfork_http.rl"
3411
3411
  { write_cont_value(hp, buffer, p); }
3412
3412
  goto st114;
3413
- tr176:
3413
+ tr175:
3414
3414
  #line 325 "pitchfork_http.rl"
3415
3415
  { write_cont_value(hp, buffer, p); }
3416
3416
  goto st114;
3417
- tr181:
3417
+ tr182:
3418
3418
  #line 323 "pitchfork_http.rl"
3419
3419
  { MARK(mark, p); }
3420
3420
  #line 324 "pitchfork_http.rl"
3421
- { write_value(hp, buffer, p); }
3421
+ { write_value(self, hp, buffer, p); }
3422
3422
  goto st114;
3423
3423
  tr185:
3424
3424
  #line 324 "pitchfork_http.rl"
3425
- { write_value(hp, buffer, p); }
3425
+ { write_value(self, hp, buffer, p); }
3426
3426
  goto st114;
3427
3427
  st114:
3428
3428
  if ( ++p == pe )
@@ -3456,7 +3456,7 @@ case 114:
3456
3456
  } else
3457
3457
  goto tr169;
3458
3458
  goto st0;
3459
- tr170:
3459
+ tr171:
3460
3460
  #line 323 "pitchfork_http.rl"
3461
3461
  { MARK(mark, p); }
3462
3462
  goto st115;
@@ -3466,63 +3466,63 @@ st115:
3466
3466
  case 115:
3467
3467
  #line 3468 "pitchfork_http.c"
3468
3468
  switch( (*p) ) {
3469
- case 9: goto tr170;
3470
- case 10: goto tr171;
3471
- case 13: goto tr172;
3472
- case 32: goto tr170;
3469
+ case 9: goto tr171;
3470
+ case 10: goto tr172;
3471
+ case 13: goto tr173;
3472
+ case 32: goto tr171;
3473
3473
  case 127: goto st0;
3474
3474
  }
3475
- if ( (*p) <= 31 )
3475
+ if ( 0 <= (*p) && (*p) <= 31 )
3476
3476
  goto st0;
3477
- goto tr173;
3478
- tr172:
3477
+ goto tr170;
3478
+ tr170:
3479
+ #line 323 "pitchfork_http.rl"
3480
+ { MARK(mark, p); }
3481
+ goto st116;
3482
+ st116:
3483
+ if ( ++p == pe )
3484
+ goto _test_eof116;
3485
+ case 116:
3486
+ #line 3487 "pitchfork_http.c"
3487
+ switch( (*p) ) {
3488
+ case 10: goto tr175;
3489
+ case 13: goto tr176;
3490
+ case 127: goto st0;
3491
+ }
3492
+ if ( (*p) > 8 ) {
3493
+ if ( 11 <= (*p) && (*p) <= 31 )
3494
+ goto st0;
3495
+ } else if ( (*p) >= 0 )
3496
+ goto st0;
3497
+ goto st116;
3498
+ tr173:
3479
3499
  #line 323 "pitchfork_http.rl"
3480
3500
  { MARK(mark, p); }
3481
3501
  #line 325 "pitchfork_http.rl"
3482
3502
  { write_cont_value(hp, buffer, p); }
3483
- goto st116;
3484
- tr177:
3503
+ goto st117;
3504
+ tr176:
3485
3505
  #line 325 "pitchfork_http.rl"
3486
3506
  { write_cont_value(hp, buffer, p); }
3487
- goto st116;
3488
- tr182:
3507
+ goto st117;
3508
+ tr183:
3489
3509
  #line 323 "pitchfork_http.rl"
3490
3510
  { MARK(mark, p); }
3491
3511
  #line 324 "pitchfork_http.rl"
3492
- { write_value(hp, buffer, p); }
3493
- goto st116;
3512
+ { write_value(self, hp, buffer, p); }
3513
+ goto st117;
3494
3514
  tr186:
3495
3515
  #line 324 "pitchfork_http.rl"
3496
- { write_value(hp, buffer, p); }
3497
- goto st116;
3498
- st116:
3499
- if ( ++p == pe )
3500
- goto _test_eof116;
3501
- case 116:
3502
- #line 3503 "pitchfork_http.c"
3503
- if ( (*p) == 10 )
3504
- goto st114;
3505
- goto st0;
3506
- tr173:
3507
- #line 323 "pitchfork_http.rl"
3508
- { MARK(mark, p); }
3516
+ { write_value(self, hp, buffer, p); }
3509
3517
  goto st117;
3510
3518
  st117:
3511
3519
  if ( ++p == pe )
3512
3520
  goto _test_eof117;
3513
3521
  case 117:
3514
- #line 3515 "pitchfork_http.c"
3515
- switch( (*p) ) {
3516
- case 10: goto tr176;
3517
- case 13: goto tr177;
3518
- case 127: goto st0;
3519
- }
3520
- if ( (*p) > 8 ) {
3521
- if ( 11 <= (*p) && (*p) <= 31 )
3522
- goto st0;
3523
- } else
3524
- goto st0;
3525
- goto st117;
3522
+ #line 3523 "pitchfork_http.c"
3523
+ if ( (*p) == 10 )
3524
+ goto st114;
3525
+ goto st0;
3526
3526
  tr167:
3527
3527
  #line 390 "pitchfork_http.rl"
3528
3528
  {
@@ -3582,7 +3582,7 @@ case 119:
3582
3582
  } else
3583
3583
  goto tr178;
3584
3584
  goto st0;
3585
- tr180:
3585
+ tr181:
3586
3586
  #line 323 "pitchfork_http.rl"
3587
3587
  { MARK(mark, p); }
3588
3588
  goto st120;
@@ -3596,16 +3596,16 @@ st120:
3596
3596
  case 120:
3597
3597
  #line 3598 "pitchfork_http.c"
3598
3598
  switch( (*p) ) {
3599
- case 9: goto tr180;
3600
- case 10: goto tr181;
3601
- case 13: goto tr182;
3602
- case 32: goto tr180;
3599
+ case 9: goto tr181;
3600
+ case 10: goto tr182;
3601
+ case 13: goto tr183;
3602
+ case 32: goto tr181;
3603
3603
  case 127: goto st0;
3604
3604
  }
3605
- if ( (*p) <= 31 )
3605
+ if ( 0 <= (*p) && (*p) <= 31 )
3606
3606
  goto st0;
3607
- goto tr183;
3608
- tr183:
3607
+ goto tr180;
3608
+ tr180:
3609
3609
  #line 323 "pitchfork_http.rl"
3610
3610
  { MARK(mark, p); }
3611
3611
  goto st121;
@@ -3622,7 +3622,7 @@ case 121:
3622
3622
  if ( (*p) > 8 ) {
3623
3623
  if ( 11 <= (*p) && (*p) <= 31 )
3624
3624
  goto st0;
3625
- } else
3625
+ } else if ( (*p) >= 0 )
3626
3626
  goto st0;
3627
3627
  goto st121;
3628
3628
  }
@@ -3779,9 +3779,13 @@ static size_t hp_memsize(const void *ptr)
3779
3779
  }
3780
3780
 
3781
3781
  static const rb_data_type_t hp_type = {
3782
- "pitchfork_http",
3783
- { hp_mark, RUBY_TYPED_DEFAULT_FREE, hp_memsize, /* reserved */ },
3784
- /* parent, data, [ flags ] */
3782
+ .wrap_struct_name = "pitchfork_http_parser",
3783
+ .function = {
3784
+ .dmark = hp_mark,
3785
+ .dfree = RUBY_TYPED_DEFAULT_FREE,
3786
+ .dsize = hp_memsize,
3787
+ },
3788
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
3785
3789
  };
3786
3790
 
3787
3791
  static struct http_parser *data_get(VALUE self)
@@ -3912,8 +3916,8 @@ static VALUE HttpParser_init(VALUE self)
3912
3916
  struct http_parser *hp = data_get(self);
3913
3917
 
3914
3918
  http_parser_init(hp);
3915
- hp->buf = rb_str_new(NULL, 0);
3916
- hp->env = rb_hash_new();
3919
+ RB_OBJ_WRITE(self, &hp->buf, rb_str_new(NULL, 0));
3920
+ RB_OBJ_WRITE(self, &hp->env, rb_hash_new());
3917
3921
 
3918
3922
  return self;
3919
3923
  }
@@ -3994,7 +3998,7 @@ static VALUE HttpParser_parse(VALUE self)
3994
3998
  if (HP_FL_TEST(hp, TO_CLEAR))
3995
3999
  HttpParser_clear(self);
3996
4000
 
3997
- http_parser_execute(hp, RSTRING_PTR(data), RSTRING_LEN(data));
4001
+ http_parser_execute(self, hp, RSTRING_PTR(data), RSTRING_LEN(data));
3998
4002
  if (hp->offset > MAX_HEADER_LEN)
3999
4003
  parser_raise(e413, "HTTP header is too large");
4000
4004
 
@@ -4050,8 +4054,8 @@ static VALUE HttpParser_headers(VALUE self, VALUE env, VALUE buf)
4050
4054
  {
4051
4055
  struct http_parser *hp = data_get(self);
4052
4056
 
4053
- hp->env = env;
4054
- hp->buf = buf;
4057
+ RB_OBJ_WRITE(self, &hp->buf, buf);
4058
+ RB_OBJ_WRITE(self, &hp->env, env);
4055
4059
 
4056
4060
  return HttpParser_parse(self);
4057
4061
  }
@@ -4179,9 +4183,9 @@ static VALUE HttpParser_filter_body(VALUE self, VALUE dst, VALUE src)
4179
4183
  rb_str_resize(dst, srclen); /* we can never copy more than srclen bytes */
4180
4184
 
4181
4185
  hp->s.dest_offset = 0;
4182
- hp->cont = dst;
4183
- hp->buf = src;
4184
- http_parser_execute(hp, srcptr, srclen);
4186
+ RB_OBJ_WRITE(self, &hp->cont, dst);
4187
+ RB_OBJ_WRITE(self, &hp->buf, src);
4188
+ http_parser_execute(self, hp, srcptr, srclen);
4185
4189
  if (hp->cs == http_parser_error)
4186
4190
  parser_raise(eHttpParserError, "Invalid HTTP format, parsing fails.");
4187
4191
 
@@ -4211,7 +4215,7 @@ static VALUE HttpParser_filter_body(VALUE self, VALUE dst, VALUE src)
4211
4215
  * This causes copy-on-write behavior to be triggered anyways
4212
4216
  * when the +src+ buffer is modified (when reading off the socket).
4213
4217
  */
4214
- hp->buf = src;
4218
+ RB_OBJ_WRITE(self, &hp->buf, src);
4215
4219
  memcpy(RSTRING_PTR(dst), srcptr, nr);
4216
4220
  hp->len.content -= nr;
4217
4221
  if (hp->len.content == 0) {