clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: Pat Allan <pat@freelancing-gods.com>
Cc: clogger-public@bogomips.org
Subject: Re: [PATCH] Update respond_to? calls for second argument.
Date: Sun, 21 May 2017 04:38:48 +0000
Message-ID: <20170521043848.GA25750@starla> (raw)
In-Reply-To: <D6ACA95E-0296-4CB7-9788-E5CB95291224@freelancing-gods.com>

Pat Allan <pat@freelancing-gods.com> wrote:
> Rack (since v2) has started explicitly listing the second
> (optional) argument for respond_to?, which matches the
> underlying Ruby spec. This patch fixes the calls in both C and
> Ruby approaches.

Thanks for noticing this!

> However, rb_respond_to only accepts a single argument -
> differing from the Ruby side of things - so perhaps this patch
> isn't quite perfect (and my C skills are very limited, so the
> whole thing could use a review).

No worries.  I think the following should work:

-----8<------
Subject: [PATCH] SQUASH/WIP - use rb_funcallv to handle second respond_to arg

While we're at it, avoid mixing declarations and code
in case there's still compiler compatibility problems.

(We will add a check for -Wdeclaration-after-statement support
 in a separate commit)
---
	Also pushed to the respond_to-priv branch at
	git://bogomips.org/clogger
	commit 7b3ed7c0bed876efe5298232a49f8542b8b340a0

 Do you think you can write a test?  No obligation, I can take
 care of it, too.  Thanks again!

 ext/clogger_ext/clogger.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index 622c98c..daed91a 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -965,16 +965,19 @@ static VALUE clogger_init_copy(VALUE clone, VALUE orig)
  */
 static VALUE respond_to(int argc, VALUE *argv, VALUE self)
 {
-	VALUE method, include_all;
-	rb_scan_args(argc, argv, "11", &method, &include_all);
-	if (NIL_P(include_all)) include_all = Qfalse;
-
 	struct clogger *c = clogger_get(self);
-	ID id = rb_to_id(method);
+	VALUE method, include_all;
+	ID id;
 
+	rb_scan_args(argc, argv, "11", &method, &include_all);
+	id = rb_to_id(method);
 	if (close_id == id)
 		return Qtrue;
-	return rb_respond_to(c->body, id);
+
+	if (argc == 1)
+		return rb_respond_to(c->body, id);
+
+	return rb_funcallv(c->body, respond_to_id, argc, argv);
 }
 
 /*
-- 
EW

  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-21  4:01 Pat Allan
2017-05-21  4:38 ` Eric Wong [this message]
2017-05-21  4:54   ` Eric Wong
2017-05-21  5:10     ` Pat Allan
2017-05-21  5:47       ` [PATCH v2] " Eric Wong

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://bogomips.org/clogger/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170521043848.GA25750@starla \
    --to=e@80x24.org \
    --cc=clogger-public@bogomips.org \
    --cc=pat@freelancing-gods.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

clogger RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/clogger-public
	git clone --mirror http://ou63pmih66umazou.onion/clogger-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.clogger
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.clogger

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox