Kouhei Sutou
null+****@clear*****
Sun Mar 6 00:01:10 JST 2016
Kouhei Sutou 2016-03-06 00:01:10 +0900 (Sun, 06 Mar 2016) New Revision: e44f063f213747bb8b23e50718dbfd5d68d10d27 https://github.com/ranguba/rroonga/commit/e44f063f213747bb8b23e50718dbfd5d68d10d27 Message: Add Groonga.error_message Added files: test/test-error-message.rb Modified files: ext/groonga/rb-groonga.c Modified: ext/groonga/rb-groonga.c (+29 -0) =================================================================== --- ext/groonga/rb-groonga.c 2016-03-05 23:33:56 +0900 (2e9d26a) +++ ext/groonga/rb-groonga.c 2016-03-06 00:01:10 +0900 (1d99050) @@ -30,6 +30,34 @@ finish_groonga (VALUE data) debug("finish: done\n"); } +/* + * @overload error_message + * @return [String, nil] The process global error message. + * + * @since 6.0.0 + */ +static VALUE +rb_grn_s_get_error_message (VALUE klass) +{ + const char *message; + + message = grn_get_global_error_message(); + if (message[0] == '\0') { + return Qnil; + } else { + grn_encoding encoding = grn_get_default_encoding(); + return rb_enc_str_new_cstr(message, + rb_grn_encoding_to_ruby_encoding(encoding)); + } +} + +static void +rb_grn_init_error_message (VALUE mGrn) +{ + rb_define_singleton_method(mGrn, "error_message", + rb_grn_s_get_error_message, 0); +} + static void rb_grn_init_runtime_version (VALUE mGrn) { @@ -180,6 +208,7 @@ Init_groonga (void) mGrn = rb_define_module("Groonga"); + rb_grn_init_error_message(mGrn); rb_grn_init_exception(mGrn); rb_grn_rc_check(grn_init(), Qnil); Added: test/test-error-message.rb (+20 -0) 100644 =================================================================== --- /dev/null +++ test/test-error-message.rb 2016-03-06 00:01:10 +0900 (ebdbbe5) @@ -0,0 +1,20 @@ +# Copyright (C) 2016 Kouhei Sutou <kou �� clear-code.com> +# +# 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 + +class ErrorMessageTest < Test::Unit::TestCase + def test_nonexistent + assert_nil(Groonga.error_message) + end +end -------------- next part -------------- HTML����������������������������...Descargar