[Groonga-commit] groonga/groonga at 235b10f [master] mrb: define error classes

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Sep 12 22:42:13 JST 2014


Kouhei Sutou	2014-09-12 22:42:13 +0900 (Fri, 12 Sep 2014)

  New Revision: 235b10fa101111a83db52126e536ab7f140130ba
  https://github.com/groonga/groonga/commit/235b10fa101111a83db52126e536ab7f140130ba

  Message:
    mrb: define error classes
    
    anzu-query-replace-regexp is my friend. :-)

  Added files:
    lib/mrb/mrb_error.c
  Copied files:
    lib/mrb/mrb_error.h
      (from lib/mrb/mrb_ctx.h)
  Modified files:
    lib/ctx_impl_mrb.c
    lib/mrb/mrb_ctx.c
    lib/mrb/mrb_ctx.h
    lib/mrb/sources.am

  Modified: lib/ctx_impl_mrb.c (+2 -0)
===================================================================
--- lib/ctx_impl_mrb.c    2014-09-12 21:52:56 +0900 (657e95a)
+++ lib/ctx_impl_mrb.c    2014-09-12 22:42:13 +0900 (21531e4)
@@ -20,6 +20,7 @@
 #include "ctx_impl.h"
 
 #include "mrb.h"
+#include "mrb/mrb_error.h"
 #include "mrb/mrb_id.h"
 #include "mrb/mrb_operator.h"
 #include "mrb/mrb_ctx.h"
@@ -46,6 +47,7 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx)
 
   grn_mrb_load(ctx, "backtrace_entry.rb");
 
+  grn_mrb_error_init(ctx);
   grn_mrb_id_init(ctx);
   grn_mrb_operator_init(ctx);
   grn_mrb_ctx_init(ctx);

  Modified: lib/mrb/mrb_ctx.c (+465 -0)
===================================================================
--- lib/mrb/mrb_ctx.c    2014-09-12 21:52:56 +0900 (f9fbb42)
+++ lib/mrb/mrb_ctx.c    2014-09-12 22:42:13 +0900 (3f7bc36)
@@ -188,6 +188,471 @@ ctx_set_error_message(mrb_state *mrb, mrb_value self)
 }
 
 void
+grn_mrb_ctx_check(mrb_state *mrb)
+{
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
+  grn_mrb_data *data = &(ctx->impl->mrb);
+  struct RClass *module = data->module;
+  struct RClass *error_class;
+#define MESSAGE_SIZE 4096
+  char message[MESSAGE_SIZE];
+
+  switch (ctx->rc) {
+  case GRN_SUCCESS:
+    return;
+  case GRN_END_OF_DATA:
+    error_class = mrb_class_get_under(mrb, module, "EndOfData");
+    snprintf(message, MESSAGE_SIZE,
+             "end of data: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_UNKNOWN_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "UnknownError");
+    snprintf(message, MESSAGE_SIZE,
+             "unknown error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_OPERATION_NOT_PERMITTED:
+    error_class = mrb_class_get_under(mrb, module, "OperationNotPermitted");
+    snprintf(message, MESSAGE_SIZE,
+             "operation not permitted: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_SUCH_FILE_OR_DIRECTORY:
+    error_class = mrb_class_get_under(mrb, module, "NoSuchFileOrDirectory");
+    snprintf(message, MESSAGE_SIZE,
+             "no such file or directory: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_SUCH_PROCESS:
+    error_class = mrb_class_get_under(mrb, module, "NoSuchProcess");
+    snprintf(message, MESSAGE_SIZE,
+             "no such process: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_INTERRUPTED_FUNCTION_CALL:
+    error_class = mrb_class_get_under(mrb, module, "InterruptedFunctionCall");
+    snprintf(message, MESSAGE_SIZE,
+             "interrupted function call: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_INPUT_OUTPUT_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "InputOutputError");
+    snprintf(message, MESSAGE_SIZE,
+             "input output error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_SUCH_DEVICE_OR_ADDRESS:
+    error_class = mrb_class_get_under(mrb, module, "NoSuchDeviceOrAddress");
+    snprintf(message, MESSAGE_SIZE,
+             "no such device or address: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_ARG_LIST_TOO_LONG:
+    error_class = mrb_class_get_under(mrb, module, "ArgListTooLong");
+    snprintf(message, MESSAGE_SIZE,
+             "arg list too long: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_EXEC_FORMAT_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "ExecFormatError");
+    snprintf(message, MESSAGE_SIZE,
+             "exec format error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_BAD_FILE_DESCRIPTOR:
+    error_class = mrb_class_get_under(mrb, module, "BadFileDescriptor");
+    snprintf(message, MESSAGE_SIZE,
+             "bad file descriptor: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_CHILD_PROCESSES:
+    error_class = mrb_class_get_under(mrb, module, "NoChildProcesses");
+    snprintf(message, MESSAGE_SIZE,
+             "no child processes: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_RESOURCE_TEMPORARILY_UNAVAILABLE:
+    error_class = mrb_class_get_under(mrb, module,
+                                      "ResourceTemporarilyUnavailable");
+    snprintf(message, MESSAGE_SIZE,
+             "resource temporarily unavailable: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NOT_ENOUGH_SPACE:
+    error_class = mrb_class_get_under(mrb, module, "NotEnoughSpace");
+    snprintf(message, MESSAGE_SIZE,
+             "not enough space: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_PERMISSION_DENIED:
+    error_class = mrb_class_get_under(mrb, module, "PermissionDenied");
+    snprintf(message, MESSAGE_SIZE,
+             "permission denied: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_BAD_ADDRESS:
+    error_class = mrb_class_get_under(mrb, module, "BadAddress");
+    snprintf(message, MESSAGE_SIZE,
+             "bad address: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_RESOURCE_BUSY:
+    error_class = mrb_class_get_under(mrb, module, "ResourceBusy");
+    snprintf(message, MESSAGE_SIZE,
+             "resource busy: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_FILE_EXISTS:
+    error_class = mrb_class_get_under(mrb, module, "FileExists");
+    snprintf(message, MESSAGE_SIZE,
+             "file exists: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_IMPROPER_LINK:
+    error_class = mrb_class_get_under(mrb, module, "ImproperLink");
+    snprintf(message, MESSAGE_SIZE,
+             "improper link: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_SUCH_DEVICE:
+    error_class = mrb_class_get_under(mrb, module, "NoSuchDevice");
+    snprintf(message, MESSAGE_SIZE,
+             "no such device: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NOT_A_DIRECTORY:
+    error_class = mrb_class_get_under(mrb, module, "NotDirectory");
+    snprintf(message, MESSAGE_SIZE,
+             "not directory: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_IS_A_DIRECTORY:
+    error_class = mrb_class_get_under(mrb, module, "IsDirectory");
+    snprintf(message, MESSAGE_SIZE,
+             "is directory: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_INVALID_ARGUMENT:
+    error_class = mrb_class_get_under(mrb, module, "InvalidArgument");
+    snprintf(message, MESSAGE_SIZE,
+             "invalid argument: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOO_MANY_OPEN_FILES_IN_SYSTEM:
+    error_class = mrb_class_get_under(mrb, module, "TooManyOpenFilesInSystem");
+    snprintf(message, MESSAGE_SIZE,
+             "too many open files in system: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOO_MANY_OPEN_FILES:
+    error_class = mrb_class_get_under(mrb, module, "TooManyOpenFiles");
+    snprintf(message, MESSAGE_SIZE,
+             "too many open files: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_INAPPROPRIATE_I_O_CONTROL_OPERATION:
+    error_class = mrb_class_get_under(mrb, module,
+                                      "InappropriateIOControlOperation");
+    snprintf(message, MESSAGE_SIZE,
+             "inappropriate IO control operation: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_FILE_TOO_LARGE:
+    error_class = mrb_class_get_under(mrb, module, "FileTooLarge");
+    snprintf(message, MESSAGE_SIZE,
+             "file too large: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_SPACE_LEFT_ON_DEVICE:
+    error_class = mrb_class_get_under(mrb, module, "NoSpaceLeftOnDevice");
+    snprintf(message, MESSAGE_SIZE,
+             "no space left on device: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_INVALID_SEEK:
+    error_class = mrb_class_get_under(mrb, module, "InvalidSeek");
+    snprintf(message, MESSAGE_SIZE,
+             "invalid seek: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_READ_ONLY_FILE_SYSTEM:
+    error_class = mrb_class_get_under(mrb, module, "ReadOnlyFileSystem");
+    snprintf(message, MESSAGE_SIZE,
+             "read only file system: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOO_MANY_LINKS:
+    error_class = mrb_class_get_under(mrb, module, "TooManyLinks");
+    snprintf(message, MESSAGE_SIZE,
+             "too many links: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_BROKEN_PIPE:
+    error_class = mrb_class_get_under(mrb, module, "BrokenPipe");
+    snprintf(message, MESSAGE_SIZE,
+             "broken pipe: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_DOMAIN_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "DomainError");
+    snprintf(message, MESSAGE_SIZE,
+             "domain error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_RESULT_TOO_LARGE:
+    error_class = mrb_class_get_under(mrb, module, "ResultTooLarge");
+    snprintf(message, MESSAGE_SIZE,
+             "result too large: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_RESOURCE_DEADLOCK_AVOIDED:
+    error_class = mrb_class_get_under(mrb, module, "ResourceDeadlockAvoided");
+    snprintf(message, MESSAGE_SIZE,
+             "resource deadlock avoided: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_MEMORY_AVAILABLE:
+    error_class = mrb_class_get_under(mrb, module, "NoMemoryAvailable");
+    snprintf(message, MESSAGE_SIZE,
+             "no memory available: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_FILENAME_TOO_LONG:
+    error_class = mrb_class_get_under(mrb, module, "FilenameTooLong");
+    snprintf(message, MESSAGE_SIZE,
+             "filename too long: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_LOCKS_AVAILABLE:
+    error_class = mrb_class_get_under(mrb, module, "NoLocksAvailable");
+    snprintf(message, MESSAGE_SIZE,
+             "no locks available: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_FUNCTION_NOT_IMPLEMENTED:
+    error_class = mrb_class_get_under(mrb, module, "FunctionNotImplemented");
+    snprintf(message, MESSAGE_SIZE,
+             "function not implemented: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_DIRECTORY_NOT_EMPTY:
+    error_class = mrb_class_get_under(mrb, module, "DirectoryNotEmpty");
+    snprintf(message, MESSAGE_SIZE,
+             "directory not empty: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_ILLEGAL_BYTE_SEQUENCE:
+    error_class = mrb_class_get_under(mrb, module, "IllegalByteSequence");
+    snprintf(message, MESSAGE_SIZE,
+             "illegal byte sequence: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_SOCKET_NOT_INITIALIZED:
+    error_class = mrb_class_get_under(mrb, module, "SocketNotInitialized");
+    snprintf(message, MESSAGE_SIZE,
+             "socket not initialized: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_OPERATION_WOULD_BLOCK:
+    error_class = mrb_class_get_under(mrb, module, "OperationWouldBlock");
+    snprintf(message, MESSAGE_SIZE,
+             "operation would block: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_ADDRESS_IS_NOT_AVAILABLE:
+    error_class = mrb_class_get_under(mrb, module, "AddressIsNotAvailable");
+    snprintf(message, MESSAGE_SIZE,
+             "address is not available: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NETWORK_IS_DOWN:
+    error_class = mrb_class_get_under(mrb, module, "NetworkIsDown");
+    snprintf(message, MESSAGE_SIZE,
+             "network is down: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NO_BUFFER:
+    error_class = mrb_class_get_under(mrb, module, "NoBuffer");
+    snprintf(message, MESSAGE_SIZE,
+             "no buffer: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_SOCKET_IS_ALREADY_CONNECTED:
+    error_class = mrb_class_get_under(mrb, module, "SocketIsAlreadyConnected");
+    snprintf(message, MESSAGE_SIZE,
+             "socket is already connected: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_SOCKET_IS_NOT_CONNECTED:
+    error_class = mrb_class_get_under(mrb, module, "SocketIsNotConnected");
+    snprintf(message, MESSAGE_SIZE,
+             "socket is not connected: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_SOCKET_IS_ALREADY_SHUTDOWNED:
+    error_class = mrb_class_get_under(mrb, module, "SocketIsAlreadyShutdowned");
+    snprintf(message, MESSAGE_SIZE,
+             "socket is already shutdowned: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_OPERATION_TIMEOUT:
+    error_class = mrb_class_get_under(mrb, module, "OperationTimeout");
+    snprintf(message, MESSAGE_SIZE,
+             "operation timeout: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_CONNECTION_REFUSED:
+    error_class = mrb_class_get_under(mrb, module, "ConnectionRefused");
+    snprintf(message, MESSAGE_SIZE,
+             "connection refused: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_RANGE_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "RangeError");
+    snprintf(message, MESSAGE_SIZE,
+             "range error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOKENIZER_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "TokenizerError");
+    snprintf(message, MESSAGE_SIZE,
+             "tokenizer error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_FILE_CORRUPT:
+    error_class = mrb_class_get_under(mrb, module, "FileCorrupt");
+    snprintf(message, MESSAGE_SIZE,
+             "file corrupt: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_INVALID_FORMAT:
+    error_class = mrb_class_get_under(mrb, module, "InvalidFormat");
+    snprintf(message, MESSAGE_SIZE,
+             "invalid format: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_OBJECT_CORRUPT:
+    error_class = mrb_class_get_under(mrb, module, "ObjectCorrupt");
+    snprintf(message, MESSAGE_SIZE,
+             "object corrupt: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOO_MANY_SYMBOLIC_LINKS:
+    error_class = mrb_class_get_under(mrb, module, "TooManySymbolicLinks");
+    snprintf(message, MESSAGE_SIZE,
+             "too many symbolic links: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NOT_SOCKET:
+    error_class = mrb_class_get_under(mrb, module, "NotSocket");
+    snprintf(message, MESSAGE_SIZE,
+             "not socket: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_OPERATION_NOT_SUPPORTED:
+    error_class = mrb_class_get_under(mrb, module, "OperationNotSupported");
+    snprintf(message, MESSAGE_SIZE,
+             "operation not supported: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_ADDRESS_IS_IN_USE:
+    error_class = mrb_class_get_under(mrb, module, "AddressIsInUse");
+    snprintf(message, MESSAGE_SIZE,
+             "address is in use: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_ZLIB_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "ZlibError");
+    snprintf(message, MESSAGE_SIZE,
+             "zlib error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_LZO_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "LzoError");
+    snprintf(message, MESSAGE_SIZE,
+             "LZO error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_STACK_OVER_FLOW:
+    error_class = mrb_class_get_under(mrb, module, "StackOverFlow");
+    snprintf(message, MESSAGE_SIZE,
+             "stack over flow: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_SYNTAX_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "SyntaxError");
+    snprintf(message, MESSAGE_SIZE,
+             "syntax error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_RETRY_MAX:
+    error_class = mrb_class_get_under(mrb, module, "RetryMax");
+    snprintf(message, MESSAGE_SIZE,
+             "retry max: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_INCOMPATIBLE_FILE_FORMAT:
+    error_class = mrb_class_get_under(mrb, module, "IncompatibleFileFormat");
+    snprintf(message, MESSAGE_SIZE,
+             "incompatible file format: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_UPDATE_NOT_ALLOWED:
+    error_class = mrb_class_get_under(mrb, module, "UpdateNotAllowed");
+    snprintf(message, MESSAGE_SIZE,
+             "update not allowed: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOO_SMALL_OFFSET:
+    error_class = mrb_class_get_under(mrb, module, "TooSmallOffset");
+    snprintf(message, MESSAGE_SIZE,
+             "too small offset: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOO_LARGE_OFFSET:
+    error_class = mrb_class_get_under(mrb, module, "TooLargeOffset");
+    snprintf(message, MESSAGE_SIZE,
+             "too large offset: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_TOO_SMALL_LIMIT:
+    error_class = mrb_class_get_under(mrb, module, "TooSmallLimit");
+    snprintf(message, MESSAGE_SIZE,
+             "too small limit: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_CAS_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "CASError");
+    snprintf(message, MESSAGE_SIZE,
+             "CAS error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_UNSUPPORTED_COMMAND_VERSION:
+    error_class = mrb_class_get_under(mrb, module, "UnsupportedCommandVersion");
+    snprintf(message, MESSAGE_SIZE,
+             "unsupported command version: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  case GRN_NORMALIZER_ERROR:
+    error_class = mrb_class_get_under(mrb, module, "NormalizerError");
+    snprintf(message, MESSAGE_SIZE,
+             "normalizer error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  default:
+    error_class = mrb_class_get_under(mrb, module, "Error");
+    snprintf(message, MESSAGE_SIZE,
+             "unsupported error: <%s>(%d)",
+             ctx->errbuf, ctx->rc);
+    break;
+  }
+#undef MESSAGE_SIZE
+
+  mrb_raise(mrb, error_class, message);
+}
+
+void
 grn_mrb_ctx_init(grn_ctx *ctx)
 {
   grn_mrb_data *data = &(ctx->impl->mrb);

  Modified: lib/mrb/mrb_ctx.h (+1 -0)
===================================================================
--- lib/mrb/mrb_ctx.h    2014-09-12 21:52:56 +0900 (f620f94)
+++ lib/mrb/mrb_ctx.h    2014-09-12 22:42:13 +0900 (5916935)
@@ -26,6 +26,7 @@ extern "C" {
 #endif
 
 void grn_mrb_ctx_init(grn_ctx *ctx);
+void grn_mrb_ctx_check(mrb_state *mrb);
 
 #ifdef __cplusplus
 }

  Added: lib/mrb/mrb_error.c (+185 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_error.c    2014-09-12 22:42:13 +0900 (2f45cfc)
@@ -0,0 +1,185 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2014 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "../ctx_impl.h"
+
+#ifdef GRN_WITH_MRUBY
+#include <mruby.h>
+
+#include "../mrb.h"
+#include "mrb_error.h"
+
+void
+grn_mrb_error_init(grn_ctx *ctx)
+{
+  grn_mrb_data *data = &(ctx->impl->mrb);
+  mrb_state *mrb = data->state;
+  struct RClass *module = data->module;
+  struct RClass *error_class;
+
+  error_class = mrb_define_class_under(mrb, module, "Error",
+                                       mrb->eStandardError_class);
+
+  mrb_define_class_under(mrb, module, "EndOfData",
+                         error_class);
+  mrb_define_class_under(mrb, module, "UnknownError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "OperationNotPermitted",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoSuchFileOrDirectory",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoSuchProcess",
+                         error_class);
+  mrb_define_class_under(mrb, module, "InterruptedFunctionCall",
+                         error_class);
+  mrb_define_class_under(mrb, module, "InputOutputError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoSuchDeviceOrAddress",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ArgListTooLong",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ExecFormatError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "BadFileDescriptor",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoChildProcesses",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ResourceTemporarilyUnavailable",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NotEnoughSpace",
+                         error_class);
+  mrb_define_class_under(mrb, module, "PermissionDenied",
+                         error_class);
+  mrb_define_class_under(mrb, module, "BadAddress",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ResourceBusy",
+                         error_class);
+  mrb_define_class_under(mrb, module, "FileExists",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ImproperLink",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoSuchDevice",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NotDirectory",
+                         error_class);
+  mrb_define_class_under(mrb, module, "IsDirectory",
+                         error_class);
+  mrb_define_class_under(mrb, module, "InvalidArgument",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TooManyOpenFilesInSystem",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TooManyOpenFiles",
+                         error_class);
+  mrb_define_class_under(mrb, module, "InappropriateIOControlOperation",
+                         error_class);
+  mrb_define_class_under(mrb, module, "FileTooLarge",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoSpaceLeftOnDevice",
+                         error_class);
+  mrb_define_class_under(mrb, module, "InvalidSeek",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ReadOnlyFileSystem",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TooManyLinks",
+                         error_class);
+  mrb_define_class_under(mrb, module, "BrokenPipe",
+                         error_class);
+  mrb_define_class_under(mrb, module, "DomainError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ResultTooLarge",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ResourceDeadlockAvoided",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoMemoryAvailable",
+                         error_class);
+  mrb_define_class_under(mrb, module, "FilenameTooLong",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoLocksAvailable",
+                         error_class);
+  mrb_define_class_under(mrb, module, "FunctionNotImplemented",
+                         error_class);
+  mrb_define_class_under(mrb, module, "DirectoryNotEmpty",
+                         error_class);
+  mrb_define_class_under(mrb, module, "IllegalByteSequence",
+                         error_class);
+  mrb_define_class_under(mrb, module, "SocketNotInitialized",
+                         error_class);
+  mrb_define_class_under(mrb, module, "OperationWouldBlock",
+                         error_class);
+  mrb_define_class_under(mrb, module, "AddressIsNotAvailable",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NetworkIsDown",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NoBuffer",
+                         error_class);
+  mrb_define_class_under(mrb, module, "SocketIsAlreadyConnected",
+                         error_class);
+  mrb_define_class_under(mrb, module, "SocketIsNotConnected",
+                         error_class);
+  mrb_define_class_under(mrb, module, "SocketIsAlreadyShutdowned",
+                         error_class);
+  mrb_define_class_under(mrb, module, "OperationTimeout",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ConnectionRefused",
+                         error_class);
+  mrb_define_class_under(mrb, module, "RangeError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TokenizerError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "FileCorrupt",
+                         error_class);
+  mrb_define_class_under(mrb, module, "InvalidFormat",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ObjectCorrupt",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TooManySymbolicLinks",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NotSocket",
+                         error_class);
+  mrb_define_class_under(mrb, module, "OperationNotSupported",
+                         error_class);
+  mrb_define_class_under(mrb, module, "AddressIsInUse",
+                         error_class);
+  mrb_define_class_under(mrb, module, "ZlibError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "LzoError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "StackOverFlow",
+                         error_class);
+  mrb_define_class_under(mrb, module, "SyntaxError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "RetryMax",
+                         error_class);
+  mrb_define_class_under(mrb, module, "IncompatibleFileFormat",
+                         error_class);
+  mrb_define_class_under(mrb, module, "UpdateNotAllowed",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TooSmallOffset",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TooLargeOffset",
+                         error_class);
+  mrb_define_class_under(mrb, module, "TooSmallLimit",
+                         error_class);
+  mrb_define_class_under(mrb, module, "CASError",
+                         error_class);
+  mrb_define_class_under(mrb, module, "UnsupportedCommandVersion",
+                         error_class);
+  mrb_define_class_under(mrb, module, "NormalizerError",
+                         error_class);
+}
+#endif

  Copied: lib/mrb/mrb_error.h (+5 -5) 84%
===================================================================
--- lib/mrb/mrb_ctx.h    2014-09-12 21:52:56 +0900 (f620f94)
+++ lib/mrb/mrb_error.h    2014-09-12 22:42:13 +0900 (c59fabc)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2013 Brazil
+  Copyright(C) 2014 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -16,8 +16,8 @@
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-#ifndef GRN_MRB_CTX_H
-#define GRN_MRB_CTX_H
+#ifndef GRN_MRB_ERROR_H
+#define GRN_MRB_ERROR_H
 
 #include "../ctx.h"
 
@@ -25,10 +25,10 @@
 extern "C" {
 #endif
 
-void grn_mrb_ctx_init(grn_ctx *ctx);
+void grn_mrb_error_init(grn_ctx *ctx);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* GRN_MRB_CTX_H */
+#endif /* GRN_MRB_ERROR_H */

  Modified: lib/mrb/sources.am (+2 -0)
===================================================================
--- lib/mrb/sources.am    2014-09-12 21:52:56 +0900 (858b220)
+++ lib/mrb/sources.am    2014-09-12 22:42:13 +0900 (947607c)
@@ -9,6 +9,8 @@ libgrnmrb_la_SOURCES =				\
 	mrb_converter.h				\
 	mrb_ctx.c				\
 	mrb_ctx.h				\
+	mrb_error.c				\
+	mrb_error.h				\
 	mrb_expr.c				\
 	mrb_expr.h				\
 	mrb_fixed_size_column.c			\
-------------- next part --------------
HTML����������������������������...
Download 



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