|
From 050295f856eced53f10d1b65174c71f026521beb Mon Sep 17 00:00:00 2001 |
|
From: Olivier El Mekki <[email protected]> |
|
Date: Sun, 9 Feb 2020 12:50:00 +0100 |
|
Subject: [PATCH] FIX makes elinks work with ruby-2.5 |
|
|
|
--- |
|
config/m4/ruby.m4 | 91 +++----------------------------------- |
|
src/scripting/ruby/core.c | 14 +++--- |
|
src/scripting/ruby/hooks.c | 10 ++--- |
|
3 files changed, 18 insertions(+), 97 deletions(-) |
|
|
|
diff --git a/config/m4/ruby.m4 b/config/m4/ruby.m4 |
|
index 39839206..e1618ad4 100644 |
|
--- a/config/m4/ruby.m4 |
|
+++ b/config/m4/ruby.m4 |
|
@@ -15,91 +15,12 @@ AC_ARG_WITH(ruby, |
|
[ --with-ruby enable Ruby support], |
|
[CONFIG_SCRIPTING_RUBY_WITHVAL="$withval"]) |
|
|
|
-if test "$CONFIG_SCRIPTING_RUBY_WITHVAL" != no; then |
|
- CONFIG_SCRIPTING_RUBY="yes" |
|
-fi |
|
- |
|
-AC_MSG_RESULT($CONFIG_SCRIPTING_RUBY) |
|
- |
|
-if test "$CONFIG_SCRIPTING_RUBY" = "yes"; then |
|
- if test -d "$CONFIG_SCRIPTING_RUBY_WITHVAL"; then |
|
- RUBY_PATH="$CONFIG_SCRIPTING_RUBY_WITHVAL:$PATH" |
|
- else |
|
- RUBY_PATH="$PATH" |
|
- fi |
|
- |
|
- AC_PATH_PROG(CONFIG_SCRIPTING_RUBY, ruby, no, $RUBY_PATH) |
|
- if test "$CONFIG_SCRIPTING_RUBY" != "no"; then |
|
- |
|
- AC_MSG_CHECKING(Ruby version) |
|
- if $CONFIG_SCRIPTING_RUBY -e 'exit((VERSION or RUBY_VERSION) >= "1.6.0")' >/dev/null 2>/dev/null; then |
|
- ruby_version=`$CONFIG_SCRIPTING_RUBY -e 'puts "#{VERSION rescue RUBY_VERSION}"'` |
|
- AC_MSG_RESULT($ruby_version) |
|
- |
|
- AC_MSG_CHECKING(for Ruby header files) |
|
- rubyhdrdir=`$CONFIG_SCRIPTING_RUBY -r mkmf -e 'print Config::CONFIG[["archdir"]] || $hdrdir' 2>/dev/null` |
|
- |
|
- if test "X$rubyhdrdir" != "X"; then |
|
- AC_MSG_RESULT($rubyhdrdir) |
|
- RUBY_CFLAGS="-I$rubyhdrdir" |
|
- rubylibs=`$CONFIG_SCRIPTING_RUBY -r rbconfig -e 'print Config::CONFIG[["LIBS"]]'` |
|
- |
|
- if test "X$rubylibs" != "X"; then |
|
- RUBY_LIBS="$rubylibs" |
|
- fi |
|
- |
|
- librubyarg=`$CONFIG_SCRIPTING_RUBY -r rbconfig -e 'print Config.expand(Config::CONFIG[["LIBRUBYARG"]])'` |
|
- |
|
- if test -f "$rubyhdrdir/$librubyarg"; then |
|
- librubyarg="$rubyhdrdir/$librubyarg" |
|
- |
|
- else |
|
- rubylibdir=`$CONFIG_SCRIPTING_RUBY -r rbconfig -e 'print Config.expand(Config::CONFIG[["libdir"]])'` |
|
- if test -f "$rubylibdir/$librubyarg"; then |
|
- librubyarg="$rubylibdir/$librubyarg" |
|
- elif test "$librubyarg" = "libruby.a"; then |
|
- dnl required on Mac OS 10.3 where libruby.a doesn't exist |
|
- librubyarg="-lruby" |
|
- else |
|
- librubyarg=`$CONFIG_SCRIPTING_RUBY -r rbconfig -e "print '$librubyarg'.gsub(/-L\./, %'-L#{Config.expand(Config::CONFIG[\"libdir\"])}')"` |
|
- fi |
|
- fi |
|
- |
|
- if test "X$librubyarg" != "X"; then |
|
- RUBY_LIBS="$librubyarg $RUBY_LIBS" |
|
- fi |
|
- |
|
- rubyldflags=`$CONFIG_SCRIPTING_RUBY -r rbconfig -e 'print Config::CONFIG[["LDFLAGS"]]'` |
|
- if test "X$rubyldflags" != "X"; then |
|
- LDFLAGS="$rubyldflags $LDFLAGS" |
|
- fi |
|
- |
|
- LIBS="$RUBY_LIBS $LIBS" |
|
- CFLAGS="$RUBY_CFLAGS $CFLAGS" |
|
- CPPFLAGS="$CPPFLAGS $RUBY_CFLAGS" |
|
- |
|
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <ruby.h>]], [[ruby_init();]])],[CONFIG_SCRIPTING_RUBY=yes],[CONFIG_SCRIPTING_RUBY=no]) |
|
- else |
|
- AC_MSG_RESULT([Ruby header files not found]) |
|
- fi |
|
- else |
|
- AC_MSG_RESULT(too old; need Ruby version 1.6.0 or later) |
|
- fi |
|
- fi |
|
-fi |
|
- |
|
EL_RESTORE_FLAGS |
|
|
|
-if test "$CONFIG_SCRIPTING_RUBY" != "yes"; then |
|
- if test -n "$CONFIG_SCRIPTING_RUBY_WITHVAL" && |
|
- test "$CONFIG_SCRIPTING_RUBY_WITHVAL" != no; then |
|
- AC_MSG_ERROR([Ruby not found]) |
|
- fi |
|
-else |
|
- EL_CONFIG(CONFIG_SCRIPTING_RUBY, [Ruby]) |
|
- |
|
- LIBS="$LIBS $RUBY_LIBS" |
|
- AC_SUBST(RUBY_CFLAGS) |
|
- AC_SUBST(RUBY_LIBS) |
|
-fi |
|
+EL_CONFIG(CONFIG_SCRIPTING_RUBY, [Ruby]) |
|
+PKG_CHECK_MODULES([RUBY], [ruby-2.5 >= 2.5]) |
|
+CFLAGS="$RUBY_CFLAGS" |
|
+LIBS="$LIBS $RUBY_LIBS" |
|
+AC_SUBST(RUBY_CFLAGS) |
|
+AC_SUBST(RUBY_LIBS) |
|
]) |
|
diff --git a/src/scripting/ruby/core.c b/src/scripting/ruby/core.c |
|
index 24b0b3dd..c45e704c 100644 |
|
--- a/src/scripting/ruby/core.c |
|
+++ b/src/scripting/ruby/core.c |
|
@@ -76,10 +76,10 @@ erb_report_error(struct session *ses, int error) |
|
break; |
|
case TAG_RAISE: |
|
case TAG_FATAL: |
|
- eclass = CLASS_OF(ruby_errinfo); |
|
- einfo = rb_obj_as_string(ruby_errinfo); |
|
+ eclass = CLASS_OF(rb_errinfo); |
|
+ einfo = rb_obj_as_string(rb_errinfo); |
|
|
|
- if (eclass == rb_eRuntimeError && RSTRING(einfo)->len == 0) { |
|
+ if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) { |
|
msg = "unhandled exception"; |
|
|
|
} else { |
|
@@ -88,7 +88,7 @@ erb_report_error(struct session *ses, int error) |
|
|
|
epath = rb_class_path(eclass); |
|
snprintf(buff, MAX_STR_LEN, "%s: %s", |
|
- RSTRING(epath)->ptr, RSTRING(einfo)->ptr); |
|
+ StringValuePtr(epath), StringValuePtr(einfo)); |
|
|
|
p = strchr((const char *)buff, '\n'); |
|
if (p) *p = '\0'; |
|
@@ -116,7 +116,7 @@ erb_module_message(VALUE self, VALUE str) |
|
struct terminal *term; |
|
|
|
str = rb_obj_as_string(str); |
|
- message = memacpy(RSTRING(str)->ptr, RSTRING(str)->len); |
|
+ message = memacpy(StringValuePtr(str), RSTRING_LEN(str)); |
|
if (!message) return Qnil; |
|
|
|
line_end = strchr((const char *)message, '\n'); |
|
@@ -165,8 +165,8 @@ erb_stdout_p(int argc, VALUE *argv, VALUE self) |
|
* the inspect() method, which adds quotes to the strings, so |
|
* gently ignore them. */ |
|
|
|
- ptr = RSTRING(substr)->ptr; |
|
- len = RSTRING(substr)->len; |
|
+ ptr = StringValuePtr(substr); |
|
+ len = RSTRING_LEN(substr); |
|
|
|
if (*ptr == '"') |
|
ptr++, len--; |
|
diff --git a/src/scripting/ruby/hooks.c b/src/scripting/ruby/hooks.c |
|
index 4b8ddb84..d7f92982 100644 |
|
--- a/src/scripting/ruby/hooks.c |
|
+++ b/src/scripting/ruby/hooks.c |
|
@@ -83,7 +83,7 @@ script_hook_goto_url(va_list ap, void *data) |
|
{ |
|
unsigned char *new_url; |
|
|
|
- new_url = memacpy(RSTRING(result)->ptr, RSTRING(result)->len); |
|
+ new_url = memacpy(StringValuePtr(result), RSTRING_LEN(result)); |
|
if (new_url) { |
|
mem_free_set(url, new_url); |
|
} |
|
@@ -126,7 +126,7 @@ script_hook_follow_url(va_list ap, void *data) |
|
{ |
|
unsigned char *new_url; |
|
|
|
- new_url = memacpy(RSTRING(result)->ptr, RSTRING(result)->len); |
|
+ new_url = memacpy(StringValuePtr(result), RSTRING_LEN(result)); |
|
if (new_url) { |
|
mem_free_set(url, new_url); |
|
} |
|
@@ -170,9 +170,9 @@ script_hook_pre_format_html(va_list ap, void *data) |
|
switch (rb_type(result)) { |
|
case T_STRING: |
|
{ |
|
- int len = RSTRING(result)->len; |
|
+ int len = RSTRING_LEN(result); |
|
|
|
- add_fragment(cached, 0, RSTRING(result)->ptr, len); |
|
+ add_fragment(cached, 0, StringValuePtr(result), len); |
|
normalize_cache_entry(cached, len); |
|
|
|
break; |
|
@@ -216,7 +216,7 @@ script_hook_get_proxy(va_list ap, void *data) |
|
{ |
|
unsigned char *proxy; |
|
|
|
- proxy = memacpy(RSTRING(result)->ptr, RSTRING(result)->len); |
|
+ proxy = memacpy(StringValuePtr(result), RSTRING_LEN(result)); |
|
if (proxy) { |
|
mem_free_set(new_proxy_url, proxy); |
|
} |
|
-- |
|
2.26.2 |
Note2: when launching elinks, an error while be thrown:
I've used this patch for months without issue, that error can be discarded.
Elinks startup time raises considerably when using ruby-2.5.