Skip to content

Commit

Permalink
encoding.c: encoding check
Browse files Browse the repository at this point in the history
* encoding.c (enc_check_encoding): use is_data_encoding() to check
  type consistently.
* encoding.c (must_encoding): return rb_encoding* instead of encoding
  index.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jul 14, 2013
1 parent a7481aa commit 599076c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
Mon Jul 15 02:31:12 2013 Nobuyoshi Nakada <[email protected]>

* encoding.c (enc_check_encoding): use is_data_encoding() to check
type consistently.

* encoding.c (must_encoding): return rb_encoding* instead of encoding
index.

* encoding.c (enc_check_encoding): use is_data_encoding() to check
type consistently.

* encoding.c (must_encoding): return rb_encoding* instead of encoding
index.

Mon Jul 15 02:21:39 2013 Nobuyoshi Nakada <[email protected]>

* string.c (str_fill_term): consider old terminator length, and should
Expand Down
10 changes: 5 additions & 5 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,21 @@ check_encoding(rb_encoding *enc)
static int
enc_check_encoding(VALUE obj)
{
if (SPECIAL_CONST_P(obj) || !rb_typeddata_is_kind_of(obj, &encoding_data_type)) {
if (!is_data_encoding(obj)) {
return -1;
}
return check_encoding(RDATA(obj)->data);
}

static int
static rb_encoding *
must_encoding(VALUE enc)
{
int index = enc_check_encoding(enc);
if (index < 0) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding)",
rb_obj_classname(enc));
}
return index;
return DATA_PTR(enc);
}

static rb_encoding *
Expand Down Expand Up @@ -456,7 +456,7 @@ rb_encdb_dummy(const char *name)
static VALUE
enc_dummy_p(VALUE enc)
{
return ENC_DUMMY_P(enc_table.list[must_encoding(enc)].enc) ? Qtrue : Qfalse;
return ENC_DUMMY_P(must_encoding(enc)) ? Qtrue : Qfalse;
}

/*
Expand All @@ -472,7 +472,7 @@ enc_dummy_p(VALUE enc)
static VALUE
enc_ascii_compatible_p(VALUE enc)
{
return rb_enc_asciicompat(enc_table.list[must_encoding(enc)].enc) ? Qtrue : Qfalse;
return rb_enc_asciicompat(must_encoding(enc)) ? Qtrue : Qfalse;
}

/*
Expand Down

0 comments on commit 599076c

Please sign in to comment.