Kouhei Sutou
null+****@clear*****
Tue Feb 3 11:40:28 JST 2015
Kouhei Sutou 2015-02-03 11:40:28 +0900 (Tue, 03 Feb 2015) New Revision: 095549e06f041e5f720fe932d56638c0b74d044e https://github.com/groonga/groonga/commit/095549e06f041e5f720fe932d56638c0b74d044e Message: mrb: bind error class and rc Modified files: lib/mrb/mrb_ctx.c lib/mrb/mrb_error.c lib/mrb/scripts/context.rb lib/mrb/scripts/context/rc.rb lib/mrb/scripts/error.rb lib/mrb/scripts/initialize/post.rb Modified: lib/mrb/mrb_ctx.c (+0 -4) =================================================================== --- lib/mrb/mrb_ctx.c 2015-02-03 11:02:55 +0900 (8f393bd) +++ lib/mrb/mrb_ctx.c 2015-02-03 11:40:28 +0900 (e975cdd) @@ -736,9 +736,5 @@ grn_mrb_ctx_init(grn_ctx *ctx) mrb_define_method(mrb, klass, "output", ctx_output, MRB_ARGS_REQ(1)); - - grn_mrb_load(ctx, "context/error_level.rb"); - grn_mrb_load(ctx, "context/rc.rb"); - grn_mrb_load(ctx, "context.rb"); } #endif Modified: lib/mrb/mrb_error.c (+82 -73) =================================================================== --- lib/mrb/mrb_error.c 2015-02-03 11:02:55 +0900 (39d34bf) +++ lib/mrb/mrb_error.c 2015-02-03 11:40:28 +0900 (a8ff994) @@ -31,155 +31,164 @@ grn_mrb_error_init(grn_ctx *ctx) mrb_state *mrb = data->state; struct RClass *module = data->module; struct RClass *error_class; + struct RClass *groonga_error_class; error_class = mrb_define_class_under(mrb, module, "Error", mrb->eStandardError_class); + groonga_error_class = mrb_define_class_under(mrb, module, "GroongaError", + error_class); mrb_define_class_under(mrb, module, "EndOfData", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "UnknownError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "OperationNotPermitted", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoSuchFileOrDirectory", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoSuchProcess", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "InterruptedFunctionCall", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "InputOutputError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoSuchDeviceOrAddress", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ArgListTooLong", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ExecFormatError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "BadFileDescriptor", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoChildProcesses", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ResourceTemporarilyUnavailable", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NotEnoughSpace", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "PermissionDenied", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "BadAddress", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ResourceBusy", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "FileExists", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ImproperLink", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoSuchDevice", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NotDirectory", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "IsDirectory", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "InvalidArgument", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TooManyOpenFilesInSystem", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TooManyOpenFiles", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "InappropriateIOControlOperation", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "FileTooLarge", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoSpaceLeftOnDevice", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "InvalidSeek", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ReadOnlyFileSystem", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TooManyLinks", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "BrokenPipe", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "DomainError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ResultTooLarge", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ResourceDeadlockAvoided", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoMemoryAvailable", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "FilenameTooLong", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoLocksAvailable", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "FunctionNotImplemented", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "DirectoryNotEmpty", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "IllegalByteSequence", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "SocketNotInitialized", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "OperationWouldBlock", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "AddressIsNotAvailable", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NetworkIsDown", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NoBuffer", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "SocketIsAlreadyConnected", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "SocketIsNotConnected", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "SocketIsAlreadyShutdowned", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "OperationTimeout", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ConnectionRefused", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "RangeError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TokenizerError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "FileCorrupt", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "InvalidFormat", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ObjectCorrupt", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TooManySymbolicLinks", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NotSocket", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "OperationNotSupported", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "AddressIsInUse", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "ZlibError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "Lz4Error", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "StackOverFlow", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "SyntaxError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "RetryMax", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "IncompatibleFileFormat", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "UpdateNotAllowed", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TooSmallOffset", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TooLargeOffset", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "TooSmallLimit", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "CASError", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "UnsupportedCommandVersion", - error_class); + groonga_error_class); mrb_define_class_under(mrb, module, "NormalizerError", - error_class); + groonga_error_class); + mrb_define_class_under(mrb, module, "TokenFilterError", + groonga_error_class); + mrb_define_class_under(mrb, module, "CommandError", + groonga_error_class); + mrb_define_class_under(mrb, module, "PluginError", + groonga_error_class); } #endif Modified: lib/mrb/scripts/context.rb (+3 -0) =================================================================== --- lib/mrb/scripts/context.rb 2015-02-03 11:02:55 +0900 (8ebe2c9) +++ lib/mrb/scripts/context.rb 2015-02-03 11:40:28 +0900 (e8056bd) @@ -1,3 +1,6 @@ +require "context/error_level" +require "context/rc" + module Groonga class Context def guard(fallback=nil) Modified: lib/mrb/scripts/context/rc.rb (+165 -78) =================================================================== --- lib/mrb/scripts/context/rc.rb 2015-02-03 11:02:55 +0900 (30dd312) +++ lib/mrb/scripts/context/rc.rb 2015-02-03 11:40:28 +0900 (9f2ff07) @@ -7,11 +7,17 @@ module Groonga def find(name) @@names[name] || UNKNOWN_ERROR end + + def register(name, code, error_class) + rc = new(name, code) + @@names[name] = rc + error_class.rc = rc if error_class + rc + end end attr_reader :name def initialize(name, code) - @@names[name] = self @name = name @code = code end @@ -20,83 +26,164 @@ module Groonga @code end - SUCCESS = new(:success, 0) - END_OF_DATA = new(:end_of_data, 1) - UNKNOWN_ERROR = new(:unknown_error, -1) - OPERATION_NOT_PERMITTED = new(:operation_not_permitted, -2) - NO_SUCH_FILE_OR_DIRECTORY = new(:no_such_file_or_directory, -3) - NO_SUCH_PROCESS = new(:no_such_process, -4) - INTERRUPTED_FUNCTION_CALL = new(:interrupted_function_call, -5) - INPUT_OUTPUT_ERROR = new(:input_output_error, -6) - NO_SUCH_DEVICE_OR_ADDRESS = new(:no_such_device_or_address, -7) - ARG_LIST_TOO_LONG = new(:arg_list_too_long, -8) - EXEC_FORMAT_ERROR = new(:exec_format_error, -9) - BAD_FILE_DESCRIPTOR = new(:bad_file_descriptor, -10) - NO_CHILD_PROCESSES = new(:no_child_processes, -11) - RESOURCE_TEMPORARILY_UNAVAILABLE = new(:resource_temporarily_unavailable, -12) - NOT_ENOUGH_SPACE = new(:not_enough_space, -13) - PERMISSION_DENIED = new(:permission_denied, -14) - BAD_ADDRESS = new(:bad_address, -15) - RESOURCE_BUSY = new(:resource_busy, -16) - FILE_EXISTS = new(:file_exists, -17) - IMPROPER_LINK = new(:improper_link, -18) - NO_SUCH_DEVICE = new(:no_such_device, -19) - NOT_A_DIRECTORY = new(:not_a_directory, -20) - IS_A_DIRECTORY = new(:is_a_directory, -21) - INVALID_ARGUMENT = new(:invalid_argument, -22) - TOO_MANY_OPEN_FILES_IN_SYSTEM = new(:too_many_open_files_in_system, -23) - TOO_MANY_OPEN_FILES = new(:too_many_open_files, -24) - INAPPROPRIATE_IO_CONTROL_OPERATION = new(:inappropriate_io_control_operation, -25) - FILE_TOO_LARGE = new(:file_too_large, -26) - NO_SPACE_LEFT_ON_DEVICE = new(:no_space_left_on_device, -27) - INVALID_SEEK = new(:invalid_seek, -28) - READ_ONLY_FILE_SYSTEM = new(:read_only_file_system, -29) - TOO_MANY_LINKS = new(:too_many_links, -30) - BROKEN_PIPE = new(:broken_pipe, -31) - DOMAIN_ERROR = new(:domain_error, -32) - RESULT_TOO_LARGE = new(:result_too_large, -33) - RESOURCE_DEADLOCK_AVOIDED = new(:resource_deadlock_avoided, -34) - NO_MEMORY_AVAILABLE = new(:no_memory_available, -35) - FILENAME_TOO_LONG = new(:filename_too_long, -36) - NO_LOCKS_AVAILABLE = new(:no_locks_available, -37) - FUNCTION_NOT_IMPLEMENTED = new(:function_not_implemented, -38) - DIRECTORY_NOT_EMPTY = new(:directory_not_empty, -39) - ILLEGAL_BYTE_SEQUENCE = new(:illegal_byte_sequence, -40) - SOCKET_NOT_INITIALIZED = new(:socket_not_initialized, -41) - OPERATION_WOULD_BLOCK = new(:operation_would_block, -42) - ADDRESS_IS_NOT_AVAILABLE = new(:address_is_not_available, -43) - NETWORK_IS_DOWN = new(:network_is_down, -44) - NO_BUFFER = new(:no_buffer, -45) - SOCKET_IS_ALREADY_CONNECTED = new(:socket_is_already_connected, -46) - SOCKET_IS_NOT_CONNECTED = new(:socket_is_not_connected, -47) - SOCKET_IS_ALREADY_SHUTDOWNED = new(:socket_is_already_shutdowned, -48) - OPERATION_TIMEOUT = new(:operation_timeout, -49) - CONNECTION_REFUSED = new(:connection_refused, -50) - RANGE_ERROR = new(:range_error, -51) - TOKENIZER_ERROR = new(:tokenizer_error, -52) - FILE_CORRUPT = new(:file_corrupt, -53) - INVALID_FORMAT = new(:invalid_format, -54) - OBJECT_CORRUPT = new(:object_corrupt, -55) - TOO_MANY_SYMBOLIC_LINKS = new(:too_many_symbolic_links, -56) - NOT_SOCKET = new(:not_socket, -57) - OPERATION_NOT_SUPPORTED = new(:operation_not_supported, -58) - ADDRESS_IS_IN_USE = new(:address_is_in_use, -59) - ZLIB_ERROR = new(:zlib_error, -60) - LZ4_ERROR = new(:lz4_error, -61) - STACK_OVER_FLOW = new(:stack_over_flow, -62) - SYNTAX_ERROR = new(:syntax_error, -63) - RETRY_MAX = new(:retry_max, -64) - INCOMPATIBLE_FILE_FORMAT = new(:incompatible_file_format, -65) - UPDATE_NOT_ALLOWED = new(:update_not_allowed, -66) - TOO_SMALL_OFFSET = new(:too_small_offset, -67) - TOO_LARGE_OFFSET = new(:too_large_offset, -68) - TOO_SMALL_LIMIT = new(:too_small_limit, -69) - CAS_ERROR = new(:cas_error, -70) - UNSUPPORTED_COMMAND_VERSION = new(:unsupported_command_version, -71) - NORMALIZER_ERROR = new(:normalizer_error, -72) - TOKEN_FILTER_ERROR = new(:token_filter, -73) - COMMAND_ERROR = new(:command_error, -74) - PLUGIN_ERROR = new(:plugin_error, -75) + SUCCESS = + register(:success, 0, nil) + END_OF_DATA = + register(:end_of_data, 1, EndOfData) + UNKNOWN_ERROR = + register(:unknown_error, -1, UnknownError) + OPERATION_NOT_PERMITTED = + register(:operation_not_permitted, -2, OperationNotPermitted) + NO_SUCH_FILE_OR_DIRECTORY = + register(:no_such_file_or_directory, -3, NoSuchFileOrDirectory) + NO_SUCH_PROCESS = + register(:no_such_process, -4, NoSuchProcess) + INTERRUPTED_FUNCTION_CALL = + register(:interrupted_function_call, -5, InterruptedFunctionCall) + INPUT_OUTPUT_ERROR = + register(:input_output_error, -6, InputOutputError) + NO_SUCH_DEVICE_OR_ADDRESS = + register(:no_such_device_or_address, -7, NoSuchDeviceOrAddress) + ARG_LIST_TOO_LONG = + register(:arg_list_too_long, -8, ArgListTooLong) + EXEC_FORMAT_ERROR = + register(:exec_format_error, -9, ExecFormatError) + BAD_FILE_DESCRIPTOR = + register(:bad_file_descriptor, -10, BadFileDescriptor) + NO_CHILD_PROCESSES = + register(:no_child_processes, -11, NoChildProcesses) + RESOURCE_TEMPORARILY_UNAVAILABLE = + register(:resource_temporarily_unavailable, -12, + ResourceTemporarilyUnavailable) + NOT_ENOUGH_SPACE = + register(:not_enough_space, -13, NotEnoughSpace) + PERMISSION_DENIED = + register(:permission_denied, -14, PermissionDenied) + BAD_ADDRESS = + register(:bad_address, -15, BadAddress) + RESOURCE_BUSY = + register(:resource_busy, -16, ResourceBusy) + FILE_EXISTS = + register(:file_exists, -17, FileExists) + IMPROPER_LINK = + register(:improper_link, -18, ImproperLink) + NO_SUCH_DEVICE = + register(:no_such_device, -19, NoSuchDevice) + NOT_DIRECTORY = + register(:not_directory, -20, NotDirectory) + IS_DIRECTORY = + register(:is_directory, -21, IsDirectory) + INVALID_ARGUMENT = + register(:invalid_argument, -22, InvalidArgument) + TOO_MANY_OPEN_FILES_IN_SYSTEM = + register(:too_many_open_files_in_system, -23, TooManyOpenFilesInSystem) + TOO_MANY_OPEN_FILES = + register(:too_many_open_files, -24, TooManyOpenFiles) + INAPPROPRIATE_IO_CONTROL_OPERATION = + register(:inappropriate_io_control_operation, -25, + InappropriateIOControlOperation) + FILE_TOO_LARGE = + register(:file_too_large, -26, FileTooLarge) + NO_SPACE_LEFT_ON_DEVICE = + register(:no_space_left_on_device, -27, NoSpaceLeftOnDevice) + INVALID_SEEK = + register(:invalid_seek, -28, InvalidSeek) + READ_ONLY_FILE_SYSTEM = + register(:read_only_file_system, -29, ReadOnlyFileSystem) + TOO_MANY_LINKS = + register(:too_many_links, -30, TooManyLinks) + BROKEN_PIPE = + register(:broken_pipe, -31, BrokenPipe) + DOMAIN_ERROR = + register(:domain_error, -32, DomainError) + RESULT_TOO_LARGE = + register(:result_too_large, -33, ResultTooLarge) + RESOURCE_DEADLOCK_AVOIDED = + register(:resource_deadlock_avoided, -34, ResourceDeadlockAvoided) + NO_MEMORY_AVAILABLE = + register(:no_memory_available, -35, NoMemoryAvailable) + FILENAME_TOO_LONG = + register(:filename_too_long, -36, FilenameTooLong) + NO_LOCKS_AVAILABLE = + register(:no_locks_available, -37, NoLocksAvailable) + FUNCTION_NOT_IMPLEMENTED = + register(:function_not_implemented, -38, FunctionNotImplemented) + DIRECTORY_NOT_EMPTY = + register(:directory_not_empty, -39, DirectoryNotEmpty) + ILLEGAL_BYTE_SEQUENCE = + register(:illegal_byte_sequence, -40, IllegalByteSequence) + SOCKET_NOT_INITIALIZED = + register(:socket_not_initialized, -41, SocketNotInitialized) + OPERATION_WOULD_BLOCK = + register(:operation_would_block, -42, OperationWouldBlock) + ADDRESS_IS_NOT_AVAILABLE = + register(:address_is_not_available, -43, AddressIsNotAvailable) + NETWORK_IS_DOWN = + register(:network_is_down, -44, NetworkIsDown) + NO_BUFFER = + register(:no_buffer, -45, NoBuffer) + SOCKET_IS_ALREADY_CONNECTED = + register(:socket_is_already_connected, -46, SocketIsAlreadyConnected) + SOCKET_IS_NOT_CONNECTED = + register(:socket_is_not_connected, -47, SocketIsNotConnected) + SOCKET_IS_ALREADY_SHUTDOWNED = + register(:socket_is_already_shutdowned, -48, SocketIsAlreadyShutdowned) + OPERATION_TIMEOUT = + register(:operation_timeout, -49, OperationTimeout) + CONNECTION_REFUSED = + register(:connection_refused, -50, ConnectionRefused) + RANGE_ERROR = + register(:range_error, -51, RangeError) + TOKENIZER_ERROR = + register(:tokenizer_error, -52, TokenizerError) + FILE_CORRUPT = + register(:file_corrupt, -53, FileCorrupt) + INVALID_FORMAT = + register(:invalid_format, -54, InvalidFormat) + OBJECT_CORRUPT = + register(:object_corrupt, -55, ObjectCorrupt) + TOO_MANY_SYMBOLIC_LINKS = + register(:too_many_symbolic_links, -56, TooManySymbolicLinks) + NOT_SOCKET = + register(:not_socket, -57, NotSocket) + OPERATION_NOT_SUPPORTED = + register(:operation_not_supported, -58, OperationNotSupported) + ADDRESS_IS_IN_USE = + register(:address_is_in_use, -59, AddressIsInUse) + ZLIB_ERROR = + register(:zlib_error, -60, ZlibError) + LZ4_ERROR = + register(:lz4_error, -61, Lz4Error) + STACK_OVER_FLOW = + register(:stack_over_flow, -62, StackOverFlow) + SYNTAX_ERROR = + register(:syntax_error, -63, SyntaxError) + RETRY_MAX = + register(:retry_max, -64, RetryMax) + INCOMPATIBLE_FILE_FORMAT = + register(:incompatible_file_format, -65, IncompatibleFileFormat) + UPDATE_NOT_ALLOWED = + register(:update_not_allowed, -66, UpdateNotAllowed) + TOO_SMALL_OFFSET = + register(:too_small_offset, -67, TooSmallOffset) + TOO_LARGE_OFFSET = + register(:too_large_offset, -68, TooLargeOffset) + TOO_SMALL_LIMIT = + register(:too_small_limit, -69, TooSmallLimit) + CAS_ERROR = + register(:cas_error, -70, CASError) + UNSUPPORTED_COMMAND_VERSION = + register(:unsupported_command_version, -71, UnsupportedCommandVersion) + NORMALIZER_ERROR = + register(:normalizer_error, -72, NormalizerError) + TOKEN_FILTER_ERROR = + register(:token_filter_error, -73, TokenFilterError) + COMMAND_ERROR = + register(:command_error, -74, CommandError) + PLUGIN_ERROR = + register(:plugin_error, -75, PluginError) + + GroongaError.rc = UNKNOWN_ERROR end end end Modified: lib/mrb/scripts/error.rb (+12 -0) =================================================================== --- lib/mrb/scripts/error.rb 2015-02-03 11:02:55 +0900 (576a89b) +++ lib/mrb/scripts/error.rb 2015-02-03 11:40:28 +0900 (e39c904) @@ -1,4 +1,16 @@ module Groonga + class GroongaError + class << self + def rc + @rc + end + + def rc=(rc) + @rc = rc + end + end + end + class ErrorMessage < Error end end Modified: lib/mrb/scripts/initialize/post.rb (+2 -0) =================================================================== --- lib/mrb/scripts/initialize/post.rb 2015-02-03 11:02:55 +0900 (b9ae0cb) +++ lib/mrb/scripts/initialize/post.rb 2015-02-03 11:40:28 +0900 (4b5e3d7) @@ -1,5 +1,7 @@ require "error" +require "context" + require "database" require "command" require "table_cursor" -------------- next part -------------- HTML����������������������������...Descargar