about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-01-10 11:04:52 +0000
committerEric Wong <e@80x24.org>2015-01-10 11:07:23 +0000
commit14e47569804a5c517baafac5e3539b81a61cc017 (patch)
tree3d88d58af90697ff740821ba5eee6d5ffde4edda
parent60dd8f8ce6e98adaab242971791fbcd61f97bf3c (diff)
downloadkgio-14e47569804a5c517baafac5e3539b81a61cc017.tar.gz
Define a MY_STR_SUBSEQ macro which checks arg counts correctly and
avoids throwing off people who may potentially want to debug this
code.
-rw-r--r--ext/kgio/connect.c5
-rw-r--r--ext/kgio/kgio.h4
-rw-r--r--ext/kgio/write.c2
-rw-r--r--ext/kgio/writev.c2
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);