From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: kgio-public@bogomips.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7EBD91FDF3; Sat, 10 Jan 2015 11:14:50 +0000 (UTC) From: Eric Wong To: kgio-public@bogomips.org Cc: Eric Wong Subject: [PATCH] cleanup: avoid shadowing rb_str_subseq Date: Sat, 10 Jan 2015 11:14:47 +0000 Message-Id: <1420888488-29473-3-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.2.1.202.g55b961f List-Id: 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