[前][次][番号順一覧][スレッド一覧]

ruby-changes:59528

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Fri, 27 Dec 2019 15:33:33 +0900 (JST)
Subject: [ruby-changes:59528] ec6f6b53d8 (master): internal/error.h rework

https://git.ruby-lang.org/ruby.git/commit/?id=ec6f6b53d8

From ec6f6b53d88b47570c3c2b83cefee2cfd7b72ce3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Tue, 3 Dec 2019 17:06:37 +0900
Subject: internal/error.h rework

Reduce macros for readability.  Also transplanted some part of
internal/file.h into here because the delcared functions are in fact
defined in error.c.

diff --git a/internal/error.h b/internal/error.h
index 5eddc76..6c645b2 100644
--- a/internal/error.h
+++ b/internal/error.h
@@ -9,8 +9,32 @@ https://github.com/ruby/ruby/blob/trunk/internal/error.h#L9
  *             modify this file, provided that  the conditions mentioned in the
  *             file COPYING are met.  Consult the file for details.
  */
+#include "ruby/config.h"
+#include <stdarg.h>             /* for va_list */
+#include "internal/stdbool.h"   /* for bool */
+#include "internal/string.h"    /* for rb_fstring_cstr */
+#include "ruby/encoding.h"      /* for rb_encoding */
+#include "ruby/intern.h"        /* for rb_exc_raise */
+#include "ruby/ruby.h"          /* for enum ruby_value_type */
+
+#undef Check_Type               /* in ruby/ruby.h */
+#define rb_raise_static(e, m) \
+    rb_raise_cstr_i((e), rb_str_new_static((m), rb_strlen_lit(m)))
+#ifdef RUBY_FUNCTION_NAME_STRING
+# define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
+# define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
+#else
+# define rb_sys_fail_path(path) rb_sys_fail_str(path)
+# define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path))
+#endif
 
 /* error.c */
+typedef enum {
+    RB_WARN_CATEGORY_NONE,
+    RB_WARN_CATEGORY_DEPRECATED,
+    RB_WARN_CATEGORY_EXPERIMENTAL,
+} rb_warning_category_t;
+
 extern VALUE rb_eEAGAIN;
 extern VALUE rb_eEWOULDBLOCK;
 extern VALUE rb_eEINPROGRESS;
@@ -19,54 +43,94 @@ NORETURN(void rb_async_bug_errno(const char *,int)); https://github.com/ruby/ruby/blob/trunk/internal/error.h#L43
 const char *rb_builtin_type_name(int t);
 const char *rb_builtin_class_name(VALUE x);
 PRINTF_ARGS(void rb_warn_deprecated(const char *fmt, const char *suggest, ...), 1, 3);
-#ifdef RUBY_ENCODING_H
 VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
 PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3);
 PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3);
 PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
-#endif
-
-typedef enum {
-    RB_WARN_CATEGORY_NONE,
-    RB_WARN_CATEGORY_DEPRECATED,
-    RB_WARN_CATEGORY_EXPERIMENTAL,
-} rb_warning_category_t;
 rb_warning_category_t rb_warning_category_from_name(VALUE category);
 bool rb_warning_category_enabled_p(rb_warning_category_t category);
-
-#define rb_raise_cstr(etype, mesg) \
-    rb_exc_raise(rb_exc_new_str(etype, rb_str_new_cstr(mesg)))
-#define rb_raise_static(etype, mesg) \
-    rb_exc_raise(rb_exc_new_str(etype, rb_str_new_static(mesg, rb_strlen_lit(mesg))))
-
 VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method);
-#define rb_name_err_raise_str(mesg, recv, name) \
-    rb_exc_raise(rb_name_err_new(mesg, recv, name))
-#define rb_name_err_raise(mesg, recv, name) \
-    rb_name_err_raise_str(rb_fstring_cstr(mesg), (recv), (name))
 VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv);
 VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name);
-#define rb_key_err_raise(mesg, recv, name) \
-    rb_exc_raise(rb_key_err_new(mesg, recv, name))
 PRINTF_ARGS(VALUE rb_warning_string(const char *fmt, ...), 1, 2);
 NORETURN(void rb_vraise(VALUE, const char *, va_list));
+NORETURN(static inline void rb_raise_cstr(VALUE etype, const char *mesg));
+NORETURN(static inline void rb_raise_cstr_i(VALUE etype, VALUE mesg));
+NORETURN(static inline void rb_name_err_raise_str(VALUE mesg, VALUE recv, VALUE name));
+NORETURN(static inline void rb_name_err_raise(const char *mesg, VALUE recv, VALUE name));
+NORETURN(static inline void rb_key_err_raise(VALUE mesg, VALUE recv, VALUE name));
+static inline void Check_Type(VALUE v, enum ruby_value_type t);
+static inline bool rb_typeddata_is_instance_of_inline(VALUE obj, const rb_data_type_t *data_type);
+#define rb_typeddata_is_instance_of rb_typeddata_is_instance_of_inline
 
 RUBY_SYMBOL_EXPORT_BEGIN
 /* error.c (export) */
 int rb_bug_reporter_add(void (*func)(FILE *, void *), void *data);
 NORETURN(void rb_unexpected_type(VALUE,int));
-#undef Check_Type
-#define Check_Type(v, t) \
-    (!RB_TYPE_P((VALUE)(v), (t)) || \
-     ((t) == RUBY_T_DATA && RTYPEDDATA_P(v)) ? \
-     rb_unexpected_type((VALUE)(v), (t)) : (void)0)
+#ifdef RUBY_FUNCTION_NAME_STRING
+NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
+NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path));
+#endif
+RUBY_SYMBOL_EXPORT_END
 
-static inline int
+static inline void
+rb_raise_cstr_i(VALUE etype, VALUE mesg)
+{
+    VALUE exc = rb_exc_new_str(etype, mesg);
+    rb_exc_raise(exc);
+}
+
+static inline void
+rb_raise_cstr(VALUE etype, const char *mesg)
+{
+    VALUE str = rb_str_new_cstr(mesg);
+    rb_raise_cstr_i(etype, str);
+}
+
+static inline void
+rb_name_err_raise_str(VALUE mesg, VALUE recv, VALUE name)
+{
+    VALUE exc = rb_name_err_new(mesg, recv, name);
+    rb_exc_raise(exc);
+}
+
+static inline void
+rb_name_err_raise(const char *mesg, VALUE recv, VALUE name)
+{
+    VALUE str = rb_fstring_cstr(mesg);
+    rb_name_err_raise_str(str, recv, name);
+}
+
+static inline void
+rb_key_err_raise(VALUE mesg, VALUE recv, VALUE name)
+{
+    VALUE exc = rb_key_err_new(mesg, recv, name);
+    rb_exc_raise(exc);
+}
+
+static inline void
+Check_Type(VALUE v, enum ruby_value_type t)
+{
+    if (! RB_TYPE_P(v, (int)t)) {
+        goto unexpected;
+    }
+    else if (t != T_DATA) {
+        return;
+    }
+    else if (! RTYPEDDATA_P(v)) {
+        goto unexpected;
+    }
+    else {
+        return;
+    }
+  unexpected:
+    rb_unexpected_type(v, t);
+}
+
+static inline bool
 rb_typeddata_is_instance_of_inline(VALUE obj, const rb_data_type_t *data_type)
 {
     return RB_TYPE_P(obj, T_DATA) && RTYPEDDATA_P(obj) && (RTYPEDDATA_TYPE(obj) == data_type);
 }
-#define rb_typeddata_is_instance_of rb_typeddata_is_instance_of_inline
-RUBY_SYMBOL_EXPORT_END
 
 #endif /* INTERNAL_ERROR_H */
diff --git a/internal/file.h b/internal/file.h
index f4a0794..0bbf50f 100644
--- a/internal/file.h
+++ b/internal/file.h
@@ -26,22 +26,6 @@ VALUE rb_get_path_check_to_string(VALUE); https://github.com/ruby/ruby/blob/trunk/internal/file.h#L26
 VALUE rb_get_path_check_convert(VALUE);
 int ruby_is_fd_loadable(int fd);
 
-#ifdef RUBY_FUNCTION_NAME_STRING
-# if defined __GNUC__ && __GNUC__ >= 4
-#   pragma GCC visibility push(default)
-# endif
-NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
-NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path));
-# if defined __GNUC__ && __GNUC__ >= 4
-#   pragma GCC visibility pop
-# endif
-# define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
-# define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
-#else
-# define rb_sys_fail_path(path) rb_sys_fail_str(path)
-# define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path))
-#endif
-
 RUBY_SYMBOL_EXPORT_BEGIN
 /* file.c (export) */
 #if defined HAVE_READLINK && defined RUBY_ENCODING_H
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]