summaryrefslogtreecommitdiff
path: root/encoding.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-02 20:23:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-02 20:23:47 +0000
commitf2980e3e2050f21273bfc8412e83adef5f75b1f0 (patch)
tree567b8001811a2396a9746d9f2332dbeab08f158d /encoding.c
parentb875b4a6d9fd3a025bffc77c5c265e746614ee2d (diff)
encoding.h: constify rb_encoding
* include/ruby/encoding.h: constify `rb_encoding` itself, not only arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/encoding.c b/encoding.c
index 98d83e49d9..8e05b82f10 100644
--- a/encoding.c
+++ b/encoding.c
@@ -20,9 +20,11 @@
#undef rb_utf8_encindex
#undef rb_usascii_encindex
+typedef OnigEncodingType rb_raw_encoding;
+
#if defined __GNUC__ && __GNUC__ >= 4
#pragma GCC visibility push(default)
-int rb_enc_register(const char *name, const rb_encoding *encoding);
+int rb_enc_register(const char *name, rb_encoding *encoding);
void rb_enc_set_base(const char *name, const char *orig);
int rb_enc_set_dummy(int index);
void rb_encdb_declare(const char *name);
@@ -80,7 +82,7 @@ static const rb_data_type_t encoding_data_type = {
static VALUE
enc_new(rb_encoding *encoding)
{
- return TypedData_Wrap_Struct(rb_cEncoding, &encoding_data_type, encoding);
+ return TypedData_Wrap_Struct(rb_cEncoding, &encoding_data_type, (void *)encoding);
}
static VALUE
@@ -99,7 +101,7 @@ rb_enc_from_encoding_index(int idx)
}
VALUE
-rb_enc_from_encoding(const rb_encoding *encoding)
+rb_enc_from_encoding(rb_encoding *encoding)
{
int idx;
if (!encoding) return Qnil;
@@ -254,10 +256,10 @@ enc_table_expand(int newsize)
}
static int
-enc_register_at(int index, const char *name, const rb_encoding *base_encoding)
+enc_register_at(int index, const char *name, rb_encoding *base_encoding)
{
struct rb_encoding_entry *ent = &enc_table.list[index];
- rb_encoding *encoding;
+ rb_raw_encoding *encoding;
VALUE list;
if (!valid_encoding_name_p(name)) return -1;
@@ -267,18 +269,19 @@ enc_register_at(int index, const char *name, const rb_encoding *base_encoding)
else if (STRCASECMP(name, ent->name)) {
return -1;
}
- if (!ent->enc) {
- ent->enc = xmalloc(sizeof(rb_encoding));
+ encoding = (rb_raw_encoding *)ent->enc;
+ if (!encoding) {
+ encoding = xmalloc(sizeof(rb_encoding));
}
if (base_encoding) {
- *ent->enc = *base_encoding;
+ *encoding = *base_encoding;
}
else {
- memset(ent->enc, 0, sizeof(*ent->enc));
+ memset(encoding, 0, sizeof(*ent->enc));
}
- encoding = ent->enc;
encoding->name = name;
encoding->ruby_encoding_index = index;
+ ent->enc = encoding;
st_insert(enc_table.names, (st_data_t)name, (st_data_t)index);
list = rb_encoding_list;
if (list && NIL_P(rb_ary_entry(list, index))) {
@@ -289,7 +292,7 @@ enc_register_at(int index, const char *name, const rb_encoding *base_encoding)
}
static int
-enc_register(const char *name, const rb_encoding *encoding)
+enc_register(const char *name, rb_encoding *encoding)
{
int index = enc_table.count;
@@ -298,11 +301,11 @@ enc_register(const char *name, const rb_encoding *encoding)
return enc_register_at(index - 1, name, encoding);
}
-static void set_encoding_const(const char *, const rb_encoding *);
+static void set_encoding_const(const char *, rb_encoding *);
int rb_enc_registered(const char *name);
int
-rb_enc_register(const char *name, const rb_encoding *encoding)
+rb_enc_register(const char *name, rb_encoding *encoding)
{
int index = rb_enc_registered(name);
@@ -349,7 +352,7 @@ set_base_encoding(int index, rb_encoding *base)
rb_encoding *enc = enc_table.list[index].enc;
enc_table.list[index].base = base;
- if (rb_enc_dummy_p(base)) ENC_SET_DUMMY(enc);
+ if (rb_enc_dummy_p(base)) ENC_SET_DUMMY((rb_raw_encoding *)enc);
return enc;
}
@@ -373,7 +376,7 @@ rb_enc_set_dummy(int index)
{
rb_encoding *enc = enc_table.list[index].enc;
- ENC_SET_DUMMY(enc);
+ ENC_SET_DUMMY((rb_raw_encoding *)enc);
return index;
}
@@ -440,7 +443,7 @@ rb_define_dummy_encoding(const char *name)
int index = rb_enc_replicate(name, rb_ascii8bit_encoding());
rb_encoding *enc = enc_table.list[index].enc;
- ENC_SET_DUMMY(enc);
+ ENC_SET_DUMMY((rb_raw_encoding *)enc);
return index;
}
@@ -451,7 +454,7 @@ rb_encdb_dummy(const char *name)
rb_enc_registered(name));
rb_encoding *enc = enc_table.list[index].enc;
- ENC_SET_DUMMY(enc);
+ ENC_SET_DUMMY((rb_raw_encoding *)enc);
return index;
}
@@ -494,7 +497,7 @@ enc_ascii_compatible_p(VALUE enc)
* Returns 1 when the encoding is Unicode series other than UTF-7 else 0.
*/
int
-rb_enc_unicode_p(const rb_encoding *enc)
+rb_enc_unicode_p(rb_encoding *enc)
{
return ONIGENC_IS_UNICODE(enc);
}
@@ -554,7 +557,7 @@ rb_encdb_alias(const char *alias, const char *orig)
void
rb_encdb_set_unicode(int index)
{
- rb_enc_from_index(index)->flags |= ONIGENC_FLAG_UNICODE;
+ ((rb_raw_encoding *)rb_enc_from_index(index))->flags |= ONIGENC_FLAG_UNICODE;
}
extern rb_encoding OnigEncodingUTF_8;
@@ -672,7 +675,7 @@ enc_autoload(rb_encoding *enc)
}
i = enc->ruby_encoding_index;
enc_register_at(i & ENC_INDEX_MASK, rb_enc_name(enc), base);
- enc->ruby_encoding_index = i;
+ ((rb_raw_encoding *)enc)->ruby_encoding_index = i;
}
else {
i = load_encoding(rb_enc_name(enc));
@@ -825,7 +828,7 @@ rb_enc_associate_index(VALUE obj, int idx)
}
VALUE
-rb_enc_associate(VALUE obj, const rb_encoding *enc)
+rb_enc_associate(VALUE obj, rb_encoding *enc)
{
return rb_enc_associate_index(obj, rb_enc_to_index(enc));
}
@@ -939,13 +942,13 @@ rb_obj_encoding(VALUE obj)
}
int
-rb_enc_fast_mbclen(const char *p, const char *e, const rb_encoding *enc)
+rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc)
{
return ONIGENC_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
}
int
-rb_enc_mbclen(const char *p, const char *e, const rb_encoding *enc)
+rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
{
int n = ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
if (MBCLEN_CHARFOUND_P(n) && MBCLEN_CHARFOUND_LEN(n) <= e-p)
@@ -957,7 +960,7 @@ rb_enc_mbclen(const char *p, const char *e, const rb_encoding *enc)
}
int
-rb_enc_precise_mbclen(const char *p, const char *e, const rb_encoding *enc)
+rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
{
int n;
if (e <= p)
@@ -969,7 +972,7 @@ rb_enc_precise_mbclen(const char *p, const char *e, const rb_encoding *enc)
}
int
-rb_enc_ascget(const char *p, const char *e, int *len, const rb_encoding *enc)
+rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
{
unsigned int c, l;
if (e <= p)
@@ -992,7 +995,7 @@ rb_enc_ascget(const char *p, const char *e, int *len, const rb_encoding *enc)
}
unsigned int
-rb_enc_codepoint_len(const char *p, const char *e, int *len_p, const rb_encoding *enc)
+rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc)
{
int r;
if (e <= p)
@@ -1007,13 +1010,13 @@ rb_enc_codepoint_len(const char *p, const char *e, int *len_p, const rb_encoding
#undef rb_enc_codepoint
unsigned int
-rb_enc_codepoint(const char *p, const char *e, const rb_encoding *enc)
+rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc)
{
return rb_enc_codepoint_len(p, e, 0, enc);
}
int
-rb_enc_codelen(int c, const rb_encoding *enc)
+rb_enc_codelen(int c, rb_encoding *enc)
{
int n = ONIGENC_CODE_TO_MBCLEN(enc,c);
if (n == 0) {
@@ -1024,19 +1027,19 @@ rb_enc_codelen(int c, const rb_encoding *enc)
#undef rb_enc_code_to_mbclen
int
-rb_enc_code_to_mbclen(int code, const rb_encoding *enc)
+rb_enc_code_to_mbclen(int code, rb_encoding *enc)
{
return ONIGENC_CODE_TO_MBCLEN(enc, code);
}
int
-rb_enc_toupper(int c, const rb_encoding *enc)
+rb_enc_toupper(int c, rb_encoding *enc)
{
return (ONIGENC_IS_ASCII_CODE(c)?ONIGENC_ASCII_CODE_TO_UPPER_CASE(c):(c));
}
int
-rb_enc_tolower(int c, const rb_encoding *enc)
+rb_enc_tolower(int c, rb_encoding *enc)
{
return (ONIGENC_IS_ASCII_CODE(c)?ONIGENC_ASCII_CODE_TO_LOWER_CASE(c):(c));
}
@@ -1544,7 +1547,7 @@ VALUE
rb_locale_charmap(VALUE klass);
static void
-set_encoding_const(const char *name, const rb_encoding *enc)
+set_encoding_const(const char *name, rb_encoding *enc)
{
VALUE encoding = rb_enc_from_encoding(enc);
char *s = (char *)name;