Skip to content

Commit 3c16d93

Browse files
nobuyui-knk
authored andcommitted
Constify encoding type in universal parser
Fixed warning about discarding modifiers. ``` ../src/ruby_parser.c:677:48: warning: passing 'rb_encoding *' (aka 'const struct OnigEncodingTypeST *') to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] 677 | ast = rb_parser_compile(p, gets, ptr, len, enc, input, line); | ^~~ ../src/internal/parse.h:58:128: note: passing argument to parameter 'fname_enc' here 58 | rb_ast_t *rb_parser_compile(rb_parser_t *p, rb_parser_lex_gets_func *gets, const char *fname_ptr, long fname_len, rb_encoding *fname_enc, rb_parser_input_data input, int line); | ^ ```
1 parent b911d22 commit 3c16d93

File tree

4 files changed

+53
-51
lines changed

4 files changed

+53
-51
lines changed

internal/parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "internal/static_assert.h"
1414

1515
#ifdef UNIVERSAL_PARSER
16-
#define rb_encoding void
16+
#define rb_encoding const void
1717
#endif
1818

1919
struct rb_iseq_struct; /* in vm_core.h */

ruby_parser.c

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "vm_core.h"
3333
#include "symbol.h"
3434

35+
#define parser_encoding const void
36+
3537
static int
3638
is_ascii_string2(VALUE str)
3739
{
@@ -41,9 +43,9 @@ is_ascii_string2(VALUE str)
4143
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 6, 0)
4244
static VALUE
4345
syntax_error_append(VALUE exc, VALUE file, int line, int column,
44-
void *enc, const char *fmt, va_list args)
46+
parser_encoding *enc, const char *fmt, va_list args)
4547
{
46-
return rb_syntax_error_append(exc, file, line, column, (rb_encoding *)enc, fmt, args);
48+
return rb_syntax_error_append(exc, file, line, column, enc, fmt, args);
4749
}
4850

4951
static int
@@ -59,9 +61,9 @@ dvar_defined(ID id, const void *p)
5961
}
6062

6163
static int
62-
is_usascii_enc(void *enc)
64+
is_usascii_enc(parser_encoding *enc)
6365
{
64-
return rb_is_usascii_enc((rb_encoding *)enc);
66+
return rb_is_usascii_enc(enc);
6567
}
6668

6769
static int
@@ -83,21 +85,21 @@ is_notop_id2(ID id)
8385
}
8486

8587
static VALUE
86-
enc_str_new(const char *ptr, long len, void *enc)
88+
enc_str_new(const char *ptr, long len, parser_encoding *enc)
8789
{
88-
return rb_enc_str_new(ptr, len, (rb_encoding *)enc);
90+
return rb_enc_str_new(ptr, len, enc);
8991
}
9092

9193
static int
92-
enc_isalnum(OnigCodePoint c, void *enc)
94+
enc_isalnum(OnigCodePoint c, parser_encoding *enc)
9395
{
94-
return rb_enc_isalnum(c, (rb_encoding *)enc);
96+
return rb_enc_isalnum(c, enc);
9597
}
9698

9799
static int
98-
enc_precise_mbclen(const char *p, const char *e, void *enc)
100+
enc_precise_mbclen(const char *p, const char *e, parser_encoding *enc)
99101
{
100-
return rb_enc_precise_mbclen(p, e, (rb_encoding *)enc);
102+
return rb_enc_precise_mbclen(p, e, enc);
101103
}
102104

103105
static int
@@ -113,93 +115,93 @@ mbclen_charfound_len(int len)
113115
}
114116

115117
static const char *
116-
enc_name(void *enc)
118+
enc_name(parser_encoding *enc)
117119
{
118-
return rb_enc_name((rb_encoding *)enc);
120+
return rb_enc_name(enc);
119121
}
120122

121123
static char *
122-
enc_prev_char(const char *s, const char *p, const char *e, void *enc)
124+
enc_prev_char(const char *s, const char *p, const char *e, parser_encoding *enc)
123125
{
124-
return rb_enc_prev_char(s, p, e, (rb_encoding *)enc);
126+
return rb_enc_prev_char(s, p, e, enc);
125127
}
126128

127-
static void *
129+
static parser_encoding *
128130
enc_get(VALUE obj)
129131
{
130-
return (void *)rb_enc_get(obj);
132+
return rb_enc_get(obj);
131133
}
132134

133135
static int
134-
enc_asciicompat(void *enc)
136+
enc_asciicompat(parser_encoding *enc)
135137
{
136-
return rb_enc_asciicompat((rb_encoding *)enc);
138+
return rb_enc_asciicompat(enc);
137139
}
138140

139-
static void *
141+
static parser_encoding *
140142
utf8_encoding(void)
141143
{
142-
return (void *)rb_utf8_encoding();
144+
return rb_utf8_encoding();
143145
}
144146

145147
static VALUE
146-
enc_associate(VALUE obj, void *enc)
148+
enc_associate(VALUE obj, parser_encoding *enc)
147149
{
148-
return rb_enc_associate(obj, (rb_encoding *)enc);
150+
return rb_enc_associate(obj, enc);
149151
}
150152

151-
static void *
153+
static parser_encoding *
152154
ascii8bit_encoding(void)
153155
{
154-
return (void *)rb_ascii8bit_encoding();
156+
return rb_ascii8bit_encoding();
155157
}
156158

157159
static int
158-
enc_codelen(int c, void *enc)
160+
enc_codelen(int c, parser_encoding *enc)
159161
{
160-
return rb_enc_codelen(c, (rb_encoding *)enc);
162+
return rb_enc_codelen(c, enc);
161163
}
162164

163165
static int
164-
enc_mbcput(unsigned int c, void *buf, void *enc)
166+
enc_mbcput(unsigned int c, void *buf, parser_encoding *enc)
165167
{
166-
return rb_enc_mbcput(c, buf, (rb_encoding *)enc);
168+
return rb_enc_mbcput(c, buf, enc);
167169
}
168170

169171
static int
170-
enc_mbclen(const char *p, const char *e, void *enc)
172+
enc_mbclen(const char *p, const char *e, parser_encoding *enc)
171173
{
172-
return rb_enc_mbclen(p, e, (rb_encoding *)enc);
174+
return rb_enc_mbclen(p, e, enc);
173175
}
174176

175-
static void *
177+
static parser_encoding *
176178
enc_from_index(int idx)
177179
{
178-
return (void *)rb_enc_from_index(idx);
180+
return rb_enc_from_index(idx);
179181
}
180182

181183
static int
182-
enc_isspace(OnigCodePoint c, void *enc)
184+
enc_isspace(OnigCodePoint c, parser_encoding *enc)
183185
{
184-
return rb_enc_isspace(c, (rb_encoding *)enc);
186+
return rb_enc_isspace(c, enc);
185187
}
186188

187189
static ID
188-
intern3(const char *name, long len, void *enc)
190+
intern3(const char *name, long len, parser_encoding *enc)
189191
{
190-
return rb_intern3(name, len, (rb_encoding *)enc);
192+
return rb_intern3(name, len, enc);
191193
}
192194

193-
static void *
195+
static parser_encoding *
194196
usascii_encoding(void)
195197
{
196-
return (void *)rb_usascii_encoding();
198+
return rb_usascii_encoding();
197199
}
198200

199201
static int
200-
enc_symname_type(const char *name, long len, void *enc, unsigned int allowed_attrset)
202+
enc_symname_type(const char *name, long len, parser_encoding *enc, unsigned int allowed_attrset)
201203
{
202-
return rb_enc_symname_type(name, len, (rb_encoding *)enc, allowed_attrset);
204+
return rb_enc_symname_type(name, len, enc, allowed_attrset);
203205
}
204206

205207
typedef struct {
@@ -220,7 +222,7 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
220222
long len = name_end - name;
221223
const char *s = (const char *)name;
222224

223-
return rb_reg_named_capture_assign_iter_impl(p, s, len, (void *)enc, &arg->succ_block, loc);
225+
return rb_reg_named_capture_assign_iter_impl(p, s, len, enc, &arg->succ_block, loc);
224226
}
225227

226228
static NODE *
@@ -305,25 +307,25 @@ static_id2sym(ID id)
305307
}
306308

307309
static long
308-
str_coderange_scan_restartable(const char *s, const char *e, void *enc, int *cr)
310+
str_coderange_scan_restartable(const char *s, const char *e, parser_encoding *enc, int *cr)
309311
{
310-
return rb_str_coderange_scan_restartable(s, e, (rb_encoding *)enc, cr);
312+
return rb_str_coderange_scan_restartable(s, e, enc, cr);
311313
}
312314

313315
static int
314-
enc_mbminlen(void *enc)
316+
enc_mbminlen(parser_encoding *enc)
315317
{
316-
return rb_enc_mbminlen((rb_encoding *)enc);
318+
return rb_enc_mbminlen(enc);
317319
}
318320

319321
static bool
320-
enc_isascii(OnigCodePoint c, void *enc)
322+
enc_isascii(OnigCodePoint c, parser_encoding *enc)
321323
{
322-
return rb_enc_isascii(c, (rb_encoding *)enc);
324+
return rb_enc_isascii(c, enc);
323325
}
324326

325327
static OnigCodePoint
326-
enc_mbc_to_codepoint(const char *p, const char *e, void *enc)
328+
enc_mbc_to_codepoint(const char *p, const char *e, parser_encoding *enc)
327329
{
328330
const OnigUChar *up = RBIMPL_CAST((const OnigUChar *)p);
329331
const OnigUChar *ue = RBIMPL_CAST((const OnigUChar *)e);

rubyparser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#ifdef UNIVERSAL_PARSER
1111

12-
#define rb_encoding void
12+
#define rb_encoding const void
1313
#define OnigCodePoint unsigned int
1414
#include "parser_st.h"
1515
#ifndef RUBY_RUBY_H

universal_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#undef st_lookup
6060
#define st_lookup rb_parser_st_lookup
6161

62-
#define rb_encoding void
62+
#define rb_encoding const void
6363

6464
#undef xmalloc
6565
#define xmalloc p->config->malloc

0 commit comments

Comments
 (0)