gettextpo 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ac67f013230155611dd5bd8f673a19eb8d84153dbc3240e3f0849a3a78ebf9d
4
- data.tar.gz: 5c3d1ac85ab300ccd98b798948448b64be26d1b69c055b0ec1e11c08641209d9
3
+ metadata.gz: 939f88fac034fa8ae14d06943e12163df3a34ca1797c625c7d5c6c591c18756b
4
+ data.tar.gz: 972a70b2e9f8c5c623e839a7e8c5d54e2b95cd62d1fe0d3f6c26fe4f3d53b429
5
5
  SHA512:
6
- metadata.gz: 5cd5653bdff4094cbf3b14f57ae30b224ae0a20b775cf072ef008bf851e8fce4f129c8ffeb9071d271223c70c78035d717d82d70f8f00f32d1a2fe5c2ffae4d3
7
- data.tar.gz: 77e26a94e04627ba399495819e25972b6dca2a9742e27e8c6ae9f5fff5032a3987f64e003707631c6a13ce38c4694a9d5a5692179a7e938d40023288d5965aa2
6
+ metadata.gz: 9d1f6fbf4c89921e78629b4f23b2f120671fb04db1dfcb09d73db5f28c6396d37f4bf792a9f69e034ce5ab077ac5c79b3d310beb0deb7707966be306065e8a2f
7
+ data.tar.gz: b9bdbc78813ad3e20c783e5a2745297624c7c629fc2b97a55081a5b7f904fa3be99df556dc0b6664199e4d71e2e4e02c0d59340129f6f273ff3ae2e8607de3ad
data/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ MRUBY_SRC=/path/to/mruby
2
+ DEVELOP_MRUBY=no
data/.envrc CHANGED
@@ -1,3 +1,18 @@
1
+ # Copyright (C) 2026 gemmaro
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
1
16
  use guix \
2
17
  clang \
3
18
  gcc-toolchain \
@@ -7,5 +22,17 @@ use guix \
7
22
  gettext \
8
23
  gdb
9
24
 
10
- path_add C_INCLUDE_PATH "$(ruby -e "puts RbConfig::CONFIG['rubyhdrdir']")"
11
- path_add C_INCLUDE_PATH "$(ruby -e "puts RbConfig::CONFIG['rubyarchhdrdir']")"
25
+ dotenv
26
+
27
+ if [ "$DEVELOP_MRUBY" != 'yes' ]
28
+ then
29
+ # CRuby
30
+ path_add C_INCLUDE_PATH "$(ruby -e "puts RbConfig::CONFIG['rubyhdrdir']")"
31
+ path_add C_INCLUDE_PATH "$(ruby -e "puts RbConfig::CONFIG['rubyarchhdrdir']")"
32
+ else
33
+ # mruby
34
+ env_vars_required MRUBY_SRC
35
+ path_add C_INCLUDE_PATH include
36
+ path_add C_INCLUDE_PATH "$MRUBY_SRC/include"
37
+ path_add C_INCLUDE_PATH "$MRUBY_SRC/build/host/include"
38
+ fi
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## CRuby version 0.1.2 and mruby version 0.1.0 - 2026-03-11
6
+
7
+ - Add mruby version.
8
+ - CRuby: Fix exception error 2 handling.
9
+
5
10
  ## 0.1.1 - 2026-03-09
6
11
 
7
12
  - Fix dangling pointer issue.
data/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  This is a Ruby library for the GNU gettext PO files. This is a C
4
4
  binding of the libgettextpo library, which is provided by the GNU
5
- gettext package. It is designed to promote Ruby's idiomatic coding
6
- style while avoiding memory leaks.
5
+ gettext package. The API of this gem is designed to promote Ruby's
6
+ idiomatic coding style while avoiding memory safety. Currently this
7
+ supports both CRuby and mruby.
7
8
 
8
9
  ## Installation
9
10
 
@@ -23,17 +24,22 @@ apt search libgettextpo
23
24
  # process PO files - shared library
24
25
  ```
25
26
 
26
- Install the gem and add to the application's `Gemfile` by executing:
27
+ For CRuby:
27
28
 
28
- ```bash
29
- bundle add gettextpo
30
- ```
29
+ * Install the gem and add to the application's `Gemfile` by executing:
31
30
 
32
- If Bundler is not being used to manage dependencies, install the gem by executing:
31
+ ```bash
32
+ bundle add gettextpo
33
+ ```
33
34
 
34
- ```bash
35
- gem install gettextpo
36
- ```
35
+ * If Bundler is not being used to manage dependencies, install the gem by executing:
36
+
37
+ ```bash
38
+ gem install gettextpo
39
+ ```
40
+
41
+ For mruby, modify `build_config.rb` as you like, set `MRUBY_SRC` to
42
+ mruby source repository, and run `./bin/compile` or `./bin/test`.
37
43
 
38
44
  ## Usage
39
45
 
@@ -56,14 +62,12 @@ end
56
62
  ```
57
63
 
58
64
  Please refer to the [API documentation][api] and test cases for
59
- details.
65
+ details. The mruby version has same API.
60
66
 
61
67
  [api]: https://gemmaro.github.io/ruby-gettextpo/
62
68
 
63
69
  ## Development
64
70
 
65
- `./bin/debug` to debug when segmentation fault.
66
-
67
71
  After checking out the repo, run `bin/setup` to install
68
72
  dependencies. Then, run `rake test` to run the tests. You can also run
69
73
  `bin/console` for an interactive prompt that will allow you to
@@ -75,6 +79,42 @@ install`. To release a new version, update the version number in
75
79
  create a git tag for the version, push git commits and the created
76
80
  tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
81
 
82
+ File structure:
83
+
84
+ ```text
85
+ bin : script ifles
86
+ build_config.rb : for mruby
87
+ * build_config.rb.lock
88
+ CHANGELOG.md
89
+ COPYING
90
+ * doc : generated by RDoc from CRuby sources
91
+ ext : for CRuby
92
+ Gemfile : for CRuby
93
+ gettextpo.gemspec : for CRuby
94
+ include : for mruby
95
+ lib : for CRuby
96
+ mrbgem.rake : for mruby
97
+ mrblib : for mruby
98
+ * pkg : generated by RubyGem
99
+ Rakefile : for CRuby
100
+ README.md
101
+ - sample.rb : for debug purpose especially with GDB
102
+ sig : for CRuby
103
+ src : for mruby
104
+ test : common test cases for both CRuby and mruby
105
+ test.cruby : CRuby specific tests
106
+ * tmp
107
+ - .env
108
+ .env.example
109
+ .envrc : Direnv config
110
+ .clang-format
111
+ .dir-locals.el : Emacs config
112
+ .gitignore
113
+
114
+ * generated files
115
+ - ignored by version control
116
+ ```
117
+
78
118
  ## Contributing
79
119
 
80
120
  Bug reports and pull requests are welcome on [Disroot][disroot].
data/Rakefile CHANGED
@@ -19,9 +19,9 @@ require "bundler/gem_tasks"
19
19
  require "rake/testtask"
20
20
 
21
21
  Rake::TestTask.new(:test) do |t|
22
- t.libs << "test"
22
+ t.libs << "test.cruby"
23
23
  t.libs << "lib"
24
- t.test_files = FileList["test/**/*_test.rb"]
24
+ t.test_files = FileList["test.cruby/**/*_test.rb"]
25
25
  end
26
26
 
27
27
  require "rake/extensiontask"
data/build_config.rb ADDED
@@ -0,0 +1,27 @@
1
+ # Copyright (C) 2026 gemmaro
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ MRuby::Build.new do |conf|
17
+ toolchain :gcc
18
+ conf.gem File.expand_path(File.dirname(__FILE__))
19
+ conf.linker.libraries << 'gettextpo'
20
+ conf.enable_test
21
+ conf.gem core: 'hal-posix-io'
22
+ conf.gem core: 'mruby-bin-mruby'
23
+ conf.gem core: 'mruby-bin-mirb'
24
+ conf.cc do |cc|
25
+ cc.flags << '-O0'
26
+ end
27
+ end
@@ -14,13 +14,6 @@
14
14
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
15
15
  */
16
16
 
17
- #include "gettextpo.h"
18
-
19
- VALUE rb_cMessage;
20
- VALUE rb_cMessageIterator;
21
- VALUE rb_cFilePos;
22
- VALUE rb_eError;
23
-
24
17
  /* FilePos, Message, and MessageIterator each hold a @file instance
25
18
  * variable (ivar) pointing to the GettextPO::File object that owns
26
19
  * the underlying po_file_t. This prevents the File object from being
@@ -30,6 +23,18 @@ VALUE rb_eError;
30
23
  * the parent object: File -> MessageIterator -> Message -> FilePos.
31
24
  */
32
25
 
26
+ #include "gettextpo.h"
27
+ #include <ruby/internal/core/rdata.h>
28
+ #include <ruby/internal/intern/variable.h>
29
+
30
+ #define ERROR \
31
+ rb_const_get (rb_const_get (rb_cObject, rb_intern ("GettextPO")), \
32
+ rb_intern ("Error"))
33
+
34
+ VALUE rb_cMessage;
35
+ VALUE rb_cMessageIterator;
36
+ VALUE rb_cFilePos;
37
+
33
38
  /* ********** error ********** */
34
39
 
35
40
  static struct
@@ -146,7 +151,7 @@ gettextpo_xerror2 (const int severity, const po_message_t message1,
146
151
  rb_str_new_cstr (message_text2));
147
152
  VALUE args = rb_ary_new ();
148
153
  rb_ary_push (args, kwargs);
149
- rb_proc_call_kw (*gettextpo_xerror_context.user_xerror, args,
154
+ rb_proc_call_kw (*gettextpo_xerror_context.user_xerror2, args,
150
155
  RB_PASS_KEYWORDS);
151
156
  if (severity == PO_SEVERITY_FATAL_ERROR)
152
157
  abort ();
@@ -415,7 +420,7 @@ gettextpo_po_message_m_format_set (int argc, VALUE *argv, VALUE self)
415
420
  bool opposite = !RB_UNDEF_P (kwargs_vals[0]) && RB_TEST (kwargs_vals[0]);
416
421
  bool remove = !RB_UNDEF_P (kwargs_vals[1]) && RB_TEST (kwargs_vals[1]);
417
422
  if (opposite && remove)
418
- rb_raise (rb_eError, "opposite and remove cannot be set at the same time");
423
+ rb_raise (ERROR, "opposite and remove cannot be set at the same time");
419
424
  po_message_set_format (DATA_PTR (self), StringValueCStr (format),
420
425
  opposite ? 0 : (remove ? -1 : 1));
421
426
  return Qnil;
@@ -514,7 +519,7 @@ gettextpo_po_message_m_check_all (int argc, VALUE *argv, VALUE self)
514
519
  po_message_check_all (DATA_PTR (self), DATA_PTR (iterator),
515
520
  &gettextpo_xerror_handler);
516
521
  if (gettextpo_xerror_context.error)
517
- rb_raise (rb_eError, "check all for message failed");
522
+ rb_raise (ERROR, "check all for message failed");
518
523
  return Qnil;
519
524
  }
520
525
 
@@ -540,7 +545,7 @@ gettextpo_po_message_m_check_format (int argc, VALUE *argv, VALUE self)
540
545
  gettextpo_xerror_context.user_xerror2 = &kwargs_vals[1];
541
546
  po_message_check_format (DATA_PTR (self), &gettextpo_xerror_handler);
542
547
  if (gettextpo_xerror_context.error)
543
- rb_raise (rb_eError, "check format for message failed");
548
+ rb_raise (ERROR, "check format for message failed");
544
549
  return Qnil;
545
550
  }
546
551
 
@@ -597,10 +602,12 @@ gettextpo_po_file_m_read (int argc, VALUE *argv, VALUE klass)
597
602
  gettextpo_xerror_context.user_xerror = &kwargs_vals[0];
598
603
  if (kwargs_vals[1] != Qundef)
599
604
  gettextpo_xerror_context.user_xerror2 = &kwargs_vals[1];
605
+ /* TODO: po_file_read can return NULL when not found? Also check
606
+ null at file free. */
600
607
  DATA_PTR (self)
601
608
  = po_file_read (StringValueCStr (filename), &gettextpo_xerror_handler);
602
609
  if (gettextpo_xerror_context.error)
603
- rb_raise (rb_eError, "failed to read");
610
+ rb_raise (ERROR, "failed to read");
604
611
  return self;
605
612
  }
606
613
 
@@ -626,7 +633,7 @@ gettextpo_po_file_m_write (int argc, VALUE *argv, VALUE self)
626
633
  po_file_write (DATA_PTR (self), StringValueCStr (filename),
627
634
  &gettextpo_xerror_handler);
628
635
  if (gettextpo_xerror_context.error)
629
- rb_raise (rb_eError, "failed to write");
636
+ rb_raise (ERROR, "failed to write");
630
637
  return Qnil;
631
638
  }
632
639
 
@@ -693,7 +700,7 @@ gettextpo_po_file_m_check_all (int argc, VALUE *argv, VALUE self)
693
700
  gettextpo_xerror_context.user_xerror2 = &kwargs_vals[1];
694
701
  po_file_check_all (DATA_PTR (self), &gettextpo_xerror_handler);
695
702
  if (gettextpo_xerror_context.error)
696
- rb_raise (rb_eError, "check all for file failed");
703
+ rb_raise (ERROR, "check all for file failed");
697
704
  return Qnil;
698
705
  }
699
706
 
@@ -961,6 +968,4 @@ Init_gettextpo (void)
961
968
  rb_define_method (rb_cFilePos, "file", gettextpo_po_filepos_m_file, 0);
962
969
  rb_define_method (rb_cFilePos, "start_line",
963
970
  gettextpo_po_filepos_m_start_line, 0);
964
- rb_eError
965
- = rb_define_class_under (rb_mGettextPO, "Error", rb_eStandardError);
966
971
  }
@@ -0,0 +1,24 @@
1
+ /* Copyright (C) 2026 gemmaro
2
+ *
3
+ * This program is free software: you can redistribute it and/or modify
4
+ * it under the terms of the GNU General Public License as published by
5
+ * the Free Software Foundation, either version 3 of the License, or
6
+ * (at your option) any later version.
7
+
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ */
16
+
17
+ #ifndef MRB_GETTEXTPO_H
18
+ #define MRB_GETTEXTPO_H
19
+
20
+ #include <mruby.h>
21
+
22
+ void mrb_gettextpo_gem_init(mrb_state *mrb);
23
+
24
+ #endif
@@ -19,5 +19,5 @@
19
19
 
20
20
  module GettextPO
21
21
  # Version of this gem.
22
- VERSION = "0.1.1"
22
+ VERSION = "0.1.2"
23
23
  end
data/lib/gettextpo.rb CHANGED
@@ -23,6 +23,10 @@ require_relative "gettextpo/gettextpo"
23
23
  #
24
24
  # == Error handling
25
25
  #
26
+ # There are two kinds of errors in this gem. The first is for
27
+ # exception handlings of libgettextpo. The second is regular error
28
+ # raising from this gem.
29
+ #
26
30
  # Some functions takes exception error handling paramters like
27
31
  # +xerror+ and +xerror2+. These parameters expect +Proc+ object which
28
32
  # takes several parameters. See also the description of
@@ -30,8 +34,11 @@ require_relative "gettextpo/gettextpo"
30
34
  # parameters is either SEVERITY_WARNING, SEVERITY_ERROR, or
31
35
  # SEVERITY_FATAL_ERROR.
32
36
  #
37
+ # This gem normally raises +GettextPO::Error+ object, except for the
38
+ # standard ones, +StopIteration+ for example.
39
+ #
33
40
  module GettextPO
34
- class Error < StandardError; end
41
+ class Error < StandardError; end # :nodoc:
35
42
 
36
43
  # This class doesn't provide the +new+ class method. Refre to
37
44
  # GettextPO::MessageIterator#next or
data/mrbgem.rake ADDED
@@ -0,0 +1,24 @@
1
+ # Copyright (C) 2026 gemmaro
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ MRuby::Gem::Specification.new('mruby-gettextpo') do |spec|
17
+ spec.license = 'GPL-3.0-or-later'
18
+ spec.authors = 'gemmaro'
19
+ spec.summary = 'GNU gettext PO parser for mruby'
20
+ spec.version = '0.1.0'
21
+ spec.homepage = 'https://git.disroot.org/gemmaro/ruby-gettextpo'
22
+ spec.linker.libraries << 'gettextpo'
23
+ spec.add_test_dependency 'mruby-io'
24
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright (C) 2026 gemmaro
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ module GettextPO
17
+ Error = Class.new(StandardError)
18
+
19
+ class File
20
+ class << self
21
+ # It seems that calling Proc with keyword arguments is not yet
22
+ # supported.
23
+ alias original_read read
24
+ def read(filename, xerror: nil, xerror2: nil)
25
+ original_read(filename,
26
+ xerror: xerror && Proc.new { |kwargs| xerror.(**kwargs) },
27
+ xerror2: xerror2 && Proc.new { |kwargs| xerror2.(**kwargs) })
28
+ end
29
+ end
30
+
31
+ # It seems that calling Proc with keyword arguments is not yet
32
+ # supported.
33
+ alias original_check_all check_all
34
+ def check_all(xerror: nil, xerror2: nil)
35
+ original_check_all(xerror: xerror && Proc.new { |kwargs| xerror.(**kwargs) },
36
+ xerror2: xerror2 && Proc.new { |kwargs| xerror2.(**kwargs) })
37
+ end
38
+ end
39
+
40
+ class MessageIterator
41
+ def self.new
42
+ raise NoMethodError,
43
+ "please use other methods instead, such as GettextPO::File#message_iterator"
44
+ end
45
+
46
+ def each # yields: message
47
+ while true
48
+ begin
49
+ yield self.next
50
+ rescue StopIteration
51
+ return self
52
+ end
53
+ end
54
+ end
55
+
56
+ include Enumerable
57
+ end
58
+
59
+ class Message
60
+ def self.new
61
+ raise NoMethodError,
62
+ "please use other methods instead, such as GettextPO::MessageIterator#next"
63
+ end
64
+
65
+ # It seems that calling Proc with keyword arguments is not yet
66
+ # supported.
67
+ alias original_check_all check_all
68
+ def check_all(iterator, xerror: nil, xerror2: nil)
69
+ original_check_all(iterator,
70
+ xerror: xerror && Proc.new { |kwargs| xerror.(**kwargs) },
71
+ xerror2: xerror2 && Proc.new { |kwargs| xerror2.(**kwargs) })
72
+ end
73
+
74
+ # It seems that calling Proc with keyword arguments is not yet
75
+ # supported.
76
+ alias original_check_format check_format
77
+ def check_format(xerror: nil, xerror2: nil)
78
+ original_check_format(xerror: xerror && Proc.new { |kwargs| xerror.(**kwargs) },
79
+ xerror2: xerror2 && Proc.new { |kwargs| xerror2.(**kwargs) })
80
+ end
81
+ end
82
+
83
+ class FilePos
84
+ def self.new
85
+ raise NoMethodError,
86
+ "please use other methods instead, such as GettextPO::Message#filepos"
87
+ end
88
+ end
89
+ end
data/mrblib/version.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Copyright (C) 2026 gemmaro
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module GettextPO
21
+ # Version of this gem.
22
+ VERSION = "0.1.0"
23
+ end