Skip to content

Commit 5ed8cf7

Browse files
authored
Merge pull request #469 from nobu/fix-ragel-warnings
parser: fix warnings against code generated by ragel
2 parents 127f0e2 + e2ad91f commit 5ed8cf7

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ else
282282
end
283283
src = File.read("parser.c").gsub(/[ \t]+$/, '')
284284
src.gsub!(/^static const int (JSON_.*=.*);$/, 'enum {\1};')
285-
src.gsub!(/0 <= \(\*p\) && \(\*p\) <= 31/, "0 <= (signed char)(*p) && (*p) <= 31")
285+
src.gsub!(/^(static const char) (_JSON(?:_\w+)?_nfa_\w+)(?=\[\] =)/, '\1 MAYBE_UNUSED(\2)')
286+
src.gsub!(/0 <= ([\( ]+\*[\( ]*p\)+) && \1 <= 31/, "0 <= (signed char)(*(p)) && (*(p)) <= 31")
286287
src[0, 0] = "/* This file is automatically generated from parser.rl by using ragel */"
287288
File.open("parser.c", "w") {|f| f.print src}
288289
end

ext/json/ext/parser/parser.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,22 @@ enum {JSON_object_error = 0};
109109

110110
enum {JSON_object_en_main = 1};
111111

112-
static const char _JSON_object_nfa_targs[] = {
112+
static const char MAYBE_UNUSED(_JSON_object_nfa_targs)[] = {
113113
0, 0
114114
};
115115

116-
static const char _JSON_object_nfa_offsets[] = {
116+
static const char MAYBE_UNUSED(_JSON_object_nfa_offsets)[] = {
117117
0, 0, 0, 0, 0, 0, 0, 0,
118118
0, 0, 0, 0, 0, 0, 0, 0,
119119
0, 0, 0, 0, 0, 0, 0, 0,
120120
0, 0, 0, 0, 0
121121
};
122122

123-
static const char _JSON_object_nfa_push_actions[] = {
123+
static const char MAYBE_UNUSED(_JSON_object_nfa_push_actions)[] = {
124124
0, 0
125125
};
126126

127-
static const char _JSON_object_nfa_pop_trans[] = {
127+
static const char MAYBE_UNUSED(_JSON_object_nfa_pop_trans)[] = {
128128
0, 0
129129
};
130130

@@ -767,22 +767,22 @@ enum {JSON_value_error = 0};
767767

768768
enum {JSON_value_en_main = 1};
769769

770-
static const char _JSON_value_nfa_targs[] = {
770+
static const char MAYBE_UNUSED(_JSON_value_nfa_targs)[] = {
771771
0, 0
772772
};
773773

774-
static const char _JSON_value_nfa_offsets[] = {
774+
static const char MAYBE_UNUSED(_JSON_value_nfa_offsets)[] = {
775775
0, 0, 0, 0, 0, 0, 0, 0,
776776
0, 0, 0, 0, 0, 0, 0, 0,
777777
0, 0, 0, 0, 0, 0, 0, 0,
778778
0, 0, 0, 0, 0, 0, 0
779779
};
780780

781-
static const char _JSON_value_nfa_push_actions[] = {
781+
static const char MAYBE_UNUSED(_JSON_value_nfa_push_actions)[] = {
782782
0, 0
783783
};
784784

785-
static const char _JSON_value_nfa_pop_trans[] = {
785+
static const char MAYBE_UNUSED(_JSON_value_nfa_pop_trans)[] = {
786786
0, 0
787787
};
788788

@@ -1429,19 +1429,19 @@ enum {JSON_integer_error = 0};
14291429

14301430
enum {JSON_integer_en_main = 1};
14311431

1432-
static const char _JSON_integer_nfa_targs[] = {
1432+
static const char MAYBE_UNUSED(_JSON_integer_nfa_targs)[] = {
14331433
0, 0
14341434
};
14351435

1436-
static const char _JSON_integer_nfa_offsets[] = {
1436+
static const char MAYBE_UNUSED(_JSON_integer_nfa_offsets)[] = {
14371437
0, 0, 0, 0, 0, 0, 0
14381438
};
14391439

1440-
static const char _JSON_integer_nfa_push_actions[] = {
1440+
static const char MAYBE_UNUSED(_JSON_integer_nfa_push_actions)[] = {
14411441
0, 0
14421442
};
14431443

1444-
static const char _JSON_integer_nfa_pop_trans[] = {
1444+
static const char MAYBE_UNUSED(_JSON_integer_nfa_pop_trans)[] = {
14451445
0, 0
14461446
};
14471447

@@ -1582,20 +1582,20 @@ enum {JSON_float_error = 0};
15821582

15831583
enum {JSON_float_en_main = 1};
15841584

1585-
static const char _JSON_float_nfa_targs[] = {
1585+
static const char MAYBE_UNUSED(_JSON_float_nfa_targs)[] = {
15861586
0, 0
15871587
};
15881588

1589-
static const char _JSON_float_nfa_offsets[] = {
1589+
static const char MAYBE_UNUSED(_JSON_float_nfa_offsets)[] = {
15901590
0, 0, 0, 0, 0, 0, 0, 0,
15911591
0, 0, 0, 0
15921592
};
15931593

1594-
static const char _JSON_float_nfa_push_actions[] = {
1594+
static const char MAYBE_UNUSED(_JSON_float_nfa_push_actions)[] = {
15951595
0, 0
15961596
};
15971597

1598-
static const char _JSON_float_nfa_pop_trans[] = {
1598+
static const char MAYBE_UNUSED(_JSON_float_nfa_pop_trans)[] = {
15991599
0, 0
16001600
};
16011601

@@ -1893,21 +1893,21 @@ enum {JSON_array_error = 0};
18931893

18941894
enum {JSON_array_en_main = 1};
18951895

1896-
static const char _JSON_array_nfa_targs[] = {
1896+
static const char MAYBE_UNUSED(_JSON_array_nfa_targs)[] = {
18971897
0, 0
18981898
};
18991899

1900-
static const char _JSON_array_nfa_offsets[] = {
1900+
static const char MAYBE_UNUSED(_JSON_array_nfa_offsets)[] = {
19011901
0, 0, 0, 0, 0, 0, 0, 0,
19021902
0, 0, 0, 0, 0, 0, 0, 0,
19031903
0, 0, 0
19041904
};
19051905

1906-
static const char _JSON_array_nfa_push_actions[] = {
1906+
static const char MAYBE_UNUSED(_JSON_array_nfa_push_actions)[] = {
19071907
0, 0
19081908
};
19091909

1910-
static const char _JSON_array_nfa_pop_trans[] = {
1910+
static const char MAYBE_UNUSED(_JSON_array_nfa_pop_trans)[] = {
19111911
0, 0
19121912
};
19131913

@@ -2498,20 +2498,20 @@ enum {JSON_string_error = 0};
24982498

24992499
enum {JSON_string_en_main = 1};
25002500

2501-
static const char _JSON_string_nfa_targs[] = {
2501+
static const char MAYBE_UNUSED(_JSON_string_nfa_targs)[] = {
25022502
0, 0
25032503
};
25042504

2505-
static const char _JSON_string_nfa_offsets[] = {
2505+
static const char MAYBE_UNUSED(_JSON_string_nfa_offsets)[] = {
25062506
0, 0, 0, 0, 0, 0, 0, 0,
25072507
0, 0
25082508
};
25092509

2510-
static const char _JSON_string_nfa_push_actions[] = {
2510+
static const char MAYBE_UNUSED(_JSON_string_nfa_push_actions)[] = {
25112511
0, 0
25122512
};
25132513

2514-
static const char _JSON_string_nfa_pop_trans[] = {
2514+
static const char MAYBE_UNUSED(_JSON_string_nfa_pop_trans)[] = {
25152515
0, 0
25162516
};
25172517

@@ -2594,7 +2594,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
25942594
goto st3;
25952595
}
25962596
}
2597-
if ( 0 <= ( (*( p))) && ( (*( p))) <= 31 ) {
2597+
if ( 0 <= (signed char)(*(p)) && (*(p)) <= 31 ) {
25982598
goto st0;
25992599
}
26002600
{
@@ -2634,7 +2634,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
26342634
if ( ( (*( p))) == 117 ) {
26352635
goto st4;
26362636
}
2637-
if ( 0 <= ( (*( p))) && ( (*( p))) <= 31 ) {
2637+
if ( 0 <= (signed char)(*(p)) && (*(p)) <= 31 ) {
26382638
goto st0;
26392639
}
26402640
{
@@ -2924,20 +2924,20 @@ enum {JSON_error = 0};
29242924

29252925
enum {JSON_en_main = 1};
29262926

2927-
static const char _JSON_nfa_targs[] = {
2927+
static const char MAYBE_UNUSED(_JSON_nfa_targs)[] = {
29282928
0, 0
29292929
};
29302930

2931-
static const char _JSON_nfa_offsets[] = {
2931+
static const char MAYBE_UNUSED(_JSON_nfa_offsets)[] = {
29322932
0, 0, 0, 0, 0, 0, 0, 0,
29332933
0, 0, 0, 0
29342934
};
29352935

2936-
static const char _JSON_nfa_push_actions[] = {
2936+
static const char MAYBE_UNUSED(_JSON_nfa_push_actions)[] = {
29372937
0, 0
29382938
};
29392939

2940-
static const char _JSON_nfa_pop_trans[] = {
2940+
static const char MAYBE_UNUSED(_JSON_nfa_pop_trans)[] = {
29412941
0, 0
29422942
};
29432943

ext/json/ext/parser/parser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include "st.h"
1414
#endif
1515

16+
#ifndef MAYBE_UNUSED
17+
# define MAYBE_UNUSED(x) x
18+
#endif
19+
1620
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
1721

1822
/* unicode */

0 commit comments

Comments
 (0)