kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] cleanup: avoid shadowing rb_str_subseq
@ 2015-01-10 11:14 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-01-10 11:14 UTC (permalink / raw)
  To: kgio-public; +Cc: Eric Wong

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-01-10 11:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-10 11:14 [PATCH] cleanup: avoid shadowing rb_str_subseq Eric Wong

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).