Skip to content

Commit bdf1af3

Browse files
committed
build with latest jq and onigmo instead of oniguruma
oniguruma regular expressions captures are not working properly when linked with ruby
1 parent 9cf0314 commit bdf1af3

File tree

5 files changed

+89
-8
lines changed

5 files changed

+89
-8
lines changed

ext/extconf.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,28 @@ def using_system_libraries?
1212
require 'rubygems'
1313
require 'mini_portile2'
1414

15+
onig_recipe = MiniPortile.new('onigmo', '6.2.0')
16+
onig_recipe.files << 'https://github.com/k-takata/Onigmo/releases/download/Onigmo-6.2.0/onigmo-6.2.0.tar.gz'
17+
onig_recipe.configure_options = [
18+
'--disable-static',
19+
'--disable-maintainer-mode'
20+
]
21+
class << onig_recipe
22+
def configure
23+
execute('autoreconf', 'autoreconf -vfi')
24+
super
25+
end
26+
end
27+
onig_recipe.cook
28+
onig_recipe.activate
29+
$LIBPATH = ["#{onig_recipe.path}/lib"] | $LIBPATH # rubocop:disable Style/GlobalVars
30+
$CPPFLAGS << " -I#{onig_recipe.path}/include" # rubocop:disable Style/GlobalVars
31+
1532
recipe = MiniPortile.new('jq', '1.6')
16-
recipe.files = ['https://github.com/stedolan/jq/releases/download/jq-1.6/jq-1.6.tar.gz']
33+
recipe.files = ['https://github.com/stedolan/jq/archive/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8.tar.gz']
34+
recipe.patch_files << File.join(File.dirname(File.expand_path(__FILE__)), "jq-onigmo.patch")
1735
recipe.configure_options = [
18-
'--enable-shared',
36+
'--disable-static',
1937
'--disable-maintainer-mode'
2038
]
2139
class << recipe
@@ -27,7 +45,7 @@ def configure
2745
end
2846
recipe.cook
2947
recipe.activate
30-
$LIBPATH = ["#{recipe.path}/lib"] | $LIBPATH # rubocop:disable Style/GlobalVars
48+
$LIBPATH = ["#{onig_recipe.path}/lib", "#{recipe.path}/lib"] | $LIBPATH # rubocop:disable Style/GlobalVars
3149
$CPPFLAGS << " -I#{recipe.path}/include" # rubocop:disable Style/GlobalVars
3250
end
3351

ext/jq-onigmo.patch

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--- configure.ac
2+
+++ configure.ac
3+
@@ -270,10 +270,10 @@ AS_IF([test "x$with_oniguruma" != xno], [
4+
# check for ONIGURUMA library, either in /usr or where requested
5+
CFLAGS="$CFLAGS $onig_CFLAGS"
6+
LDFLAGS="$LDFLAGS $onig_LDFLAGS"
7+
- AC_CHECK_HEADER("oniguruma.h",
8+
- AC_CHECK_LIB([onig],[onig_version]))
9+
+ AC_CHECK_HEADER("onigmo.h",
10+
+ AC_CHECK_LIB([onigmo],[onig_version]))
11+
# handle check results
12+
- AS_IF([test "x$ac_cv_lib_onig_onig_version" != "xyes"], [
13+
+ AS_IF([test "x$ac_cv_lib_onigmo_onig_version" != "xyes"], [
14+
build_oniguruma=yes
15+
AC_MSG_NOTICE([Oniguruma was not found. Will use the packaged oniguruma.])
16+
])
17+
--- src/builtin.c
18+
+++ src/builtin.c
19+
@@ -29,8 +29,8 @@ void *alloca (size_t);
20+
#include <ctype.h>
21+
#include <limits.h>
22+
#include <math.h>
23+
-#ifdef HAVE_LIBONIG
24+
-#include <oniguruma.h>
25+
+#ifdef HAVE_LIBONIGMO
26+
+#include <onigmo.h>
27+
#endif
28+
#include <string.h>
29+
#include <time.h>
30+
@@ -801,7 +801,7 @@ static jv f_group_by_impl(jq_state *jq, jv input, jv keys) {
31+
}
32+
}
33+
34+
-#ifdef HAVE_LIBONIG
35+
+#ifdef HAVE_LIBONIGMO
36+
static int f_match_name_iter(const UChar* name, const UChar *name_end, int ngroups,
37+
int *groups, regex_t *reg, void *arg) {
38+
jv captures = *(jv*)arg;
39+
@@ -889,7 +889,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
40+
41+
onigret = onig_new(&reg, (const UChar*)jv_string_value(regex),
42+
(const UChar*)(jv_string_value(regex) + jv_string_length_bytes(jv_copy(regex))),
43+
- options, ONIG_ENCODING_UTF8, ONIG_SYNTAX_PERL_NG, &einfo);
44+
+ options, ONIG_ENCODING_UTF8, ONIG_SYNTAX_PERL58_NG, &einfo);
45+
if (onigret != ONIG_NORMAL) {
46+
UChar ebuf[ONIG_MAX_ERROR_MESSAGE_LEN];
47+
onig_error_code_to_str(ebuf, onigret, &einfo);
48+
@@ -1005,11 +1005,11 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
49+
jv_free(regex);
50+
return result;
51+
}
52+
-#else /* !HAVE_LIBONIG */
53+
+#else /* !HAVE_LIBONIGMO */
54+
static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
55+
- return jv_invalid_with_msg(jv_string("jq was compiled without ONIGURUMA regex library. match/test/sub and related functions are not available."));
56+
+ return jv_invalid_with_msg(jv_string("jq was compiled without ONIGMO regex library. match/test/sub and related functions are not available."));
57+
}
58+
-#endif /* HAVE_LIBONIG */
59+
+#endif /* HAVE_LIBONIGMO */
60+
61+
static jv minmax_by(jv values, jv keys, int is_min) {
62+
if (jv_get_kind(values) != JV_KIND_ARRAY)

ext/jq_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void jq_process(jq_state *jq, jv value, VALUE (*proc)(), int *status, VAL
9595
if (*status == 0) {
9696
rb_protect(proc, rb_str_new2(str), status);
9797
}
98+
jv_free(dumped);
9899
}
99100

100101
if (jv_invalid_has_msg(jv_copy(result))) {

lib/jq/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module JQ
4-
VERSION = '0.2.2'
4+
VERSION = '0.2.3'
55
end

ruby-jq.gemspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
2323
spec.add_dependency 'multi_json', '~> 1.15', '>= 1.10.0'
2424
spec.add_runtime_dependency 'mini_portile2', '~> 2.2', '>= 2.2.0'
2525

26-
spec.add_development_dependency 'rake', '~> 0'
27-
spec.add_development_dependency 'rake-compiler', '~> 0'
28-
spec.add_development_dependency 'rspec', '~> 0'
29-
spec.add_development_dependency 'rubocop', '~> 0'
26+
spec.add_development_dependency 'rake', '~> 0.9.6'
27+
spec.add_development_dependency 'rake-compiler', '~> 0.9.9'
28+
spec.add_development_dependency 'rspec', '~> 3.9.0'
29+
spec.add_development_dependency 'rubocop', '~> 0.93.1'
3030
end

0 commit comments

Comments
 (0)