Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

marshal.c: io_needed

* marshal.c (io_needed): extract from marshal_dump and marshal_load.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 407e32746e1d1f77cf7d89e02fd4820f0f00a3a9 1 parent 0b0dea7
Nobuyoshi Nakada nobu authored

Showing 1 changed file with 11 additions and 5 deletions. Show diff stats Hide diff stats

  1. +11 5 marshal.c
16 marshal.c
@@ -865,6 +865,13 @@ clear_dump_arg(struct dump_arg *arg)
865 865 }
866 866 }
867 867
  868 +NORETURN(static inline void io_needed(void));
  869 +static inline void
  870 +io_needed(void)
  871 +{
  872 + rb_raise(rb_eTypeError, "instance of IO needed");
  873 +}
  874 +
868 875 /*
869 876 * call-seq:
870 877 * dump( obj [, anIO] , limit=-1 ) -> anIO
@@ -911,12 +918,12 @@ marshal_dump(int argc, VALUE *argv)
911 918 rb_scan_args(argc, argv, "12", &obj, &a1, &a2);
912 919 if (argc == 3) {
913 920 if (!NIL_P(a2)) limit = NUM2INT(a2);
914   - if (NIL_P(a1)) goto type_error;
  921 + if (NIL_P(a1)) io_needed();
915 922 port = a1;
916 923 }
917 924 else if (argc == 2) {
918 925 if (FIXNUM_P(a1)) limit = FIX2INT(a1);
919   - else if (NIL_P(a1)) goto type_error;
  926 + else if (NIL_P(a1)) io_needed();
920 927 else port = a1;
921 928 }
922 929 wrapper = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg);
@@ -929,8 +936,7 @@ marshal_dump(int argc, VALUE *argv)
929 936 arg->str = rb_str_buf_new(0);
930 937 if (!NIL_P(port)) {
931 938 if (!rb_respond_to(port, s_write)) {
932   - type_error:
933   - rb_raise(rb_eTypeError, "instance of IO needed");
  939 + io_needed();
934 940 }
935 941 arg->dest = port;
936 942 if (rb_respond_to(port, s_binmode)) {
@@ -1783,7 +1789,7 @@ marshal_load(int argc, VALUE *argv)
1783 1789 infection = (int)(FL_TAINT | FL_TEST(port, FL_UNTRUSTED));
1784 1790 }
1785 1791 else {
1786   - rb_raise(rb_eTypeError, "instance of IO needed");
  1792 + io_needed();
1787 1793 }
1788 1794 wrapper = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg);
1789 1795 arg->infection = infection;

0 comments on commit 407e327

Please sign in to comment.
Something went wrong with that request. Please try again.