Skip to content

Commit

Permalink
Make STRINGIO_VERSION uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Nov 4, 2023
1 parent fd9051d commit 4400bf3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 4 additions & 1 deletion ext/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ static class StringIOData {
}
StringIOData ptr;

private static final String
STRINGIO_VERSION = "3.0.9";

private static final int STRIO_READABLE = ObjectFlags.registry.newFlag(StringIO.class);
private static final int STRIO_WRITABLE = ObjectFlags.registry.newFlag(StringIO.class);
private static final int STRIO_READWRITE = (STRIO_READABLE | STRIO_WRITABLE);
Expand All @@ -83,7 +86,7 @@ public static RubyClass createStringIOClass(final Ruby runtime) {
RubyClass stringIOClass = runtime.defineClass(
"StringIO", runtime.getObject(), StringIO::new);

RubyString version = RubyString.newString(runtime, "3.0.9");
RubyString version = RubyString.newString(runtime, STRINGIO_VERSION);
stringIOClass.defineConstant("VERSION", version);

stringIOClass.defineAnnotatedMethods(StringIO.class);
Expand Down
3 changes: 2 additions & 1 deletion ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
**********************************************************************/

#define STRINGIO_VERSION "3.0.9"
static const char *const
STRINGIO_VERSION = "3.0.9";

#include "ruby.h"
#include "ruby/io.h"
Expand Down
14 changes: 7 additions & 7 deletions rakelib/version.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ class << (helper = Bundler::GemHelper.instance)
C_SOURCE_PATH = "ext/stringio/stringio.c"
JAVA_SOURCE_PATH = "ext/java/org/jruby/ext/stringio/StringIO.java"
def update_source_version
c_source = File.read(C_SOURCE_PATH)
c_source.sub!(/^#define\s+STRINGIO_VERSION\s+\K".*"/) {version.to_s.dump}
File.write(C_SOURCE_PATH, c_source)

java_source = File.read(JAVA_SOURCE_PATH)
java_source.sub!(/version = RubyString\.newString\(runtime, \K".*"/) {version.to_s.dump}
File.write(JAVA_SOURCE_PATH, java_source)
v = version.to_s
[C_SOURCE_PATH, JAVA_SOURCE_PATH].each do |path|
source = File.read(path)
if source.sub!(/^\s*STRINGIO_VERSION\s*=\s*"\K.*(?=")/) {break if $& == v; v}
File.write(path, source)
end
end
end

def commit_bump
Expand Down
2 changes: 1 addition & 1 deletion stringio.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
source_version = ["", "ext/stringio/"].find do |dir|
begin
break File.open(File.join(__dir__, "#{dir}stringio.c")) {|f|
f.gets("\n#define STRINGIO_VERSION ")
f.gets("\nSTRINGIO_VERSION ")
f.gets[/\s*"(.+)"/, 1]
}
rescue Errno::ENOENT
Expand Down

0 comments on commit 4400bf3

Please sign in to comment.