diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c index 8400e96..5d787d0 100644 --- a/ext/cgi/escape/escape.c +++ b/ext/cgi/escape/escape.c @@ -1,14 +1,22 @@ #include "ruby.h" #include "ruby/encoding.h" +#include "ruby/util.h" #ifndef HAVE_RB_LEN_T typedef long rb_len_t; +typedef unsigned long rb_ulen_t; # define RB_LEN_MAX LONG_MAX #endif +#ifndef HAVE_RUBY_SCAN_DIGITS RUBY_EXTERN unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow); +#endif +#ifndef HAVE_RUBY_HEXDIGITS_0_ RUBY_EXTERN const char ruby_hexdigits[]; +#endif +#ifndef HAVE_RUBY_DIGIT36_TO_NUMBER_TABLE_0_ RUBY_EXTERN const signed char ruby_digit36_to_number_table[]; +#endif #define lower_hexdigits (ruby_hexdigits+0) #define upper_hexdigits (ruby_hexdigits+16) #define char_to_number(c) ruby_digit36_to_number_table[(unsigned char)(c)] @@ -99,7 +107,7 @@ optimized_unescape_html(VALUE str) cstr = RSTRING_PTR(str); for (i = 0; i < len; i++) { - unsigned long cc; + rb_ulen_t cc; char c = cstr[i]; if (c != '&') continue; plen = i - beg; diff --git a/ext/cgi/escape/extconf.rb b/ext/cgi/escape/extconf.rb index 73acd89..db4c5ca 100644 --- a/ext/cgi/escape/extconf.rb +++ b/ext/cgi/escape/extconf.rb @@ -3,5 +3,12 @@ if RUBY_ENGINE == 'truffleruby' File.write("Makefile", dummy_makefile($srcdir).join("")) else + if have_func(%[ruby_scan_digits()], "ruby/util.h") + $defs.pop # defined but no declaration + else + have_func(%[ruby_scan_digits("", 0, 0, NULL, NULL)], "ruby/util.h") + end + have_var(%[ruby_hexdigits[0]], "ruby/util.h") + have_var(%[ruby_digit36_to_number_table[0]], "ruby/util.h") create_makefile 'cgi/escape' end