static void mrb_fd_cloexec(mrb_state *mrb, int fd) { #if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) int flags, flags2; flags = fcntl(fd, F_GETFD); if (flags == -1) { mrb_bug(mrb, "mrb_fd_cloexec: fcntl(%S, F_GETFD) failed: %S", mrb_fixnum_value(fd), mrb_fixnum_value(errno)); } if (fd <= 2) { flags2 = flags & ~FD_CLOEXEC; /* Clear CLOEXEC for standard file descriptors: 0, 1, 2. */ } else { flags2 = flags | FD_CLOEXEC; /* Set CLOEXEC for non-standard file descriptors: 3, 4, 5, ... */ } if (flags != flags2) { if (fcntl(fd, F_SETFD, flags2) == -1) { mrb_bug(mrb, "mrb_fd_cloexec: fcntl(%S, F_SETFD, %S) failed: %S", mrb_fixnum_value(fd), mrb_fixnum_value(flags2), mrb_fixnum_value(errno)); } } #endif }
void mrb_bug_errno(const char *mesg, int errno_arg) { if (errno_arg == 0) mrb_bug("%s: errno == 0 (NOERROR)", mesg); else { const char *errno_str = mrb_strerrno(errno_arg); if (errno_str) mrb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str); else mrb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg); } }
static mrb_value mrb_enc_from_encoding_index(mrb_state *mrb, int idx) { mrb_value list, enc; if (mrb_nil_p(list = mrb_encoding_list)) { mrb_bug("mrb_enc_from_encoding_index(%d): no mrb_encoding_list", idx); } enc = mrb_ary_ref(mrb, list, idx);//mrb_ary_entry(list, idx); if (mrb_nil_p(enc)) { mrb_bug("mrb_enc_from_encoding_index(%d): not created yet", idx); } return enc; }
/* * code-seq: * struct.eql?(other) -> true or false * * Two structures are equal if they are the same object, or if all their * fields are equal (using <code>eql?</code>). */ static mrb_value mrb_struct_eql(mrb_state *mrb, mrb_value s) { mrb_value s2; mrb_value *ptr, *ptr2; mrb_int i, len; mrb_bool eql_p; mrb_get_args(mrb, "o", &s2); if (mrb_obj_equal(mrb, s, s2)) { eql_p = 1; } else if (strcmp(mrb_class_name(mrb, mrb_obj_class(mrb, s2)), "Struct") || mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) { eql_p = 0; } else if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) { mrb_bug(mrb, "inconsistent struct"); /* should never happen */ eql_p = 0; /* This substuture is just to suppress warnings. never called. */ } else { ptr = RSTRUCT_PTR(s); ptr2 = RSTRUCT_PTR(s2); len = RSTRUCT_LEN(s); eql_p = 1; for (i=0; i<len; i++) { if (!mrb_eql(mrb, ptr[i], ptr2[i])) { eql_p = 0; break; } } } return mrb_bool_value(eql_p); }
/* * code-seq: * struct.eql?(other) -> true or false * * Two structures are equal if they are the same object, or if all their * fields are equal (using <code>eql?</code>). */ static mrb_value mrb_struct_eql(mrb_state *mrb, mrb_value s) { mrb_value s2; mrb_value *ptr, *ptr2; mrb_int i, len; mrb_get_args(mrb, "o", &s2); if (mrb_obj_equal(mrb, s, s2)) { return mrb_true_value(); } if (mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) { return mrb_false_value(); } if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) { mrb_bug(mrb, "inconsistent struct"); /* should never happen */ } ptr = RSTRUCT_PTR(s); ptr2 = RSTRUCT_PTR(s2); len = RSTRUCT_LEN(s); for (i=0; i<len; i++) { if (!mrb_eql(mrb, ptr[i], ptr2[i])) { return mrb_false_value(); } } return mrb_true_value(); }
/* * code-seq: * struct.eql?(other) -> true or false * * Two structures are equal if they are the same object, or if all their * fields are equal (using <code>eql?</code>). */ static mrb_value mrb_struct_eql(mrb_state *mrb, mrb_value s) { mrb_value s2; mrb_get_args(mrb, "o", &s2); if (mrb_obj_equal(mrb, s, s2)) return mrb_true_value(); if (mrb_type(s2) != MRB_TT_STRUCT) return mrb_false_value(); if (mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) return mrb_false_value(); if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) { mrb_bug("inconsistent struct"); /* should never happen */ } return mrb_exec_recursive_paired(mrb, recursive_eql, s, s2, (void*)0); }