kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: kgio-public@bogomips.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] cleanup: avoid shadowing rb_str_subseq
Date: Sat, 10 Jan 2015 11:14:47 +0000	[thread overview]
Message-ID: <1420888488-29473-3-git-send-email-e@80x24.org> (raw)

Define a MY_STR_SUBSEQ macro which checks arg counts correctly and
avoids throwing off people who may potentially want to debug this
code.
---
 ext/kgio/connect.c | 5 +----
 ext/kgio/kgio.h    | 4 +++-
 ext/kgio/write.c   | 2 +-
 ext/kgio/writev.c  | 2 +-
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/ext/kgio/connect.c b/ext/kgio/connect.c
index 19cfa8f..0a2ec0b 100644
--- a/ext/kgio/connect.c
+++ b/ext/kgio/connect.c
@@ -146,9 +146,6 @@ static const struct sockaddr *sockaddr_from(socklen_t *addrlen, VALUE addr)
 }
 
 #if defined(MSG_FASTOPEN) && defined(KGIO_WITHOUT_GVL)
-#ifndef HAVE_RB_STR_SUBSEQ
-#define rb_str_subseq rb_str_substr
-#endif
 struct tfo_args {
 	int fd;
 	const void *buf;
@@ -200,7 +197,7 @@ static VALUE fastopen(VALUE sock, VALUE buf, VALUE addr)
 	if ((size_t)w == a.buflen)
 		return Qnil;
 
-	return rb_str_subseq(str, w, a.buflen - w);
+	return MY_STR_SUBSEQ(str, w, a.buflen - w);
 }
 #endif /* MSG_FASTOPEN */
 
diff --git a/ext/kgio/kgio.h b/ext/kgio/kgio.h
index 7c992fb..c0630ae 100644
--- a/ext/kgio/kgio.h
+++ b/ext/kgio/kgio.h
@@ -99,7 +99,9 @@ static inline void kgio_autopush_write(VALUE io) { kgio_autopush_send(io); }
 
 /* prefer rb_str_subseq because we don't use negative offsets */
 #ifndef HAVE_RB_STR_SUBSEQ
-#define rb_str_subseq rb_str_substr
+#define MY_STR_SUBSEQ(str,beg,len) rb_str_substr((str),(beg),(len))
+#else
+#define MY_STR_SUBSEQ(str,beg,len) rb_str_subseq((str),(beg),(len))
 #endif
 
 #endif /* KGIO_H */
diff --git a/ext/kgio/write.c b/ext/kgio/write.c
index cdf97b1..ce4aa75 100644
--- a/ext/kgio/write.c
+++ b/ext/kgio/write.c
@@ -45,7 +45,7 @@ done:
 				a->ptr = RSTRING_PTR(a->buf) + written;
 				return -1;
 			} else if (written > 0) {
-				a->buf = rb_str_subseq(a->buf, written, a->len);
+				a->buf = MY_STR_SUBSEQ(a->buf, written, a->len);
 			} else {
 				a->buf = sym_wait_writable;
 			}
diff --git a/ext/kgio/writev.c b/ext/kgio/writev.c
index 9a8030a..9c1ca15 100644
--- a/ext/kgio/writev.c
+++ b/ext/kgio/writev.c
@@ -194,7 +194,7 @@ static long trim_writev_buffer(struct wrv_args *a, ssize_t n)
 	if (n < 0) {
 		VALUE str = rb_ary_entry(a->buf, 0);
 		long str_len = RSTRING_LEN(str);
-		str = rb_str_subseq(str, str_len + n, -n);
+		str = MY_STR_SUBSEQ(str, str_len + n, -n);
 		rb_ary_store(a->buf, 0, str);
 	}
 	return RARRAY_LEN(a->buf);
-- 
EW


                 reply	other threads:[~2015-01-10 11:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly 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://yhbt.net/kgio/

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

  git send-email \
    --in-reply-to=1420888488-29473-3-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=kgio-public@bogomips.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kgio.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).