[Groonga-commit] groonga/groonga at e792d71 [master] mrb: split rc check and raise phase

Back to archive index
Kouhei Sutou null+****@clear*****
Tue Dec 25 16:57:53 JST 2018


Kouhei Sutou	2018-12-25 16:57:53 +0900 (Tue, 25 Dec 2018)

  Revision: e792d71864d3af87bf2d679269b8f4d5d062cbe2
  https://github.com/groonga/groonga/commit/e792d71864d3af87bf2d679269b8f4d5d062cbe2

  Message:
    mrb: split rc check and raise phase
    
    We can run clean-up code after rc check.

  Modified files:
    lib/mrb/mrb_ctx.c
    lib/mrb/mrb_ctx.h

  Modified: lib/mrb/mrb_ctx.c (+19 -4)
===================================================================
--- lib/mrb/mrb_ctx.c    2018-12-25 15:58:21 +0900 (2546801ec)
+++ lib/mrb/mrb_ctx.c    2018-12-25 16:57:53 +0900 (5d8d04d59)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2013-2018 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -22,6 +23,7 @@
 #include <mruby.h>
 #include <mruby/class.h>
 #include <mruby/data.h>
+#include <mruby/error.h>
 #include <mruby/variable.h>
 #include <mruby/string.h>
 
@@ -288,8 +290,8 @@ ctx_is_opened(mrb_state *mrb, mrb_value self)
   return mrb_bool_value(grn_ctx_is_opened(ctx, mrb_id));
 }
 
-void
-grn_mrb_ctx_check(mrb_state *mrb)
+mrb_value
+grn_mrb_ctx_to_exception(mrb_state *mrb)
 {
   grn_ctx *ctx = (grn_ctx *)mrb->ud;
   grn_mrb_data *data = &(ctx->impl->mrb);
@@ -300,7 +302,7 @@ grn_mrb_ctx_check(mrb_state *mrb)
   const char *utf8_error_message;
 
   if (ctx->rc == GRN_SUCCESS) {
-    return;
+    return mrb_nil_value();
   }
 
   utf8_error_message = grn_encoding_convert_to_utf8(ctx, ctx->errbuf, -1, NULL);
@@ -802,7 +804,20 @@ grn_mrb_ctx_check(mrb_state *mrb)
   grn_encoding_converted_free(ctx, utf8_error_message);
 #undef MESSAGE_SIZE
 
-  mrb_raise(mrb, error_class, message);
+  return mrb_exc_new_str(mrb, error_class, mrb_str_new_cstr(mrb, message));
+}
+
+void
+grn_mrb_ctx_check(mrb_state *mrb)
+{
+  mrb_value mrb_exception;
+
+  mrb_exception = grn_mrb_ctx_to_exception(mrb);
+  if (mrb_nil_p(mrb_exception)) {
+    return;
+  }
+
+  mrb_exc_raise(mrb, mrb_exception);
 }
 
 void

  Modified: lib/mrb/mrb_ctx.h (+2 -0)
===================================================================
--- lib/mrb/mrb_ctx.h    2018-12-25 15:58:21 +0900 (b94128292)
+++ lib/mrb/mrb_ctx.h    2018-12-25 16:57:53 +0900 (452a0d732)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2013-2016 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -25,6 +26,7 @@ extern "C" {
 #endif
 
 void grn_mrb_ctx_init(grn_ctx *ctx);
+mrb_value grn_mrb_ctx_to_exception(mrb_state *mrb);
 void grn_mrb_ctx_check(mrb_state *mrb);
 
 #ifdef __cplusplus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181225/ff580286/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index