From: Eric Wong <normalperson@yhbt.net>
To: sleepy.penguin@librelist.com
Subject: [sleepy.penguin] [PATCH] inotify: cleanup Inotify::Event creation
Date: Sun, 28 Dec 2014 02:27:55 +0000 [thread overview]
Message-ID: <1419733675-6323-2-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: 1419733675-6323-1-git-send-email-normalperson@yhbt.net
We'll prefer using rb_str_new2 instead of rb_str_new(...,strlen)
to save binary size. While we're at it, explain why we cannot
take e->len into account for plain-old rb_str_new.
---
ext/sleepy_penguin/inotify.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/ext/sleepy_penguin/inotify.c b/ext/sleepy_penguin/inotify.c
index 1f2d4ac..b324227 100644
--- a/ext/sleepy_penguin/inotify.c
+++ b/ext/sleepy_penguin/inotify.c
@@ -124,8 +124,13 @@ static VALUE event_new(struct inotify_event *e)
VALUE cookie = UINT2NUM(e->cookie);
VALUE name;
- /* name may be zero-padded, so we do strlen() */
- name = e->len ? rb_str_new(e->name, strlen(e->name)) : Qnil;
+ /*
+ * e->name is zero-padded, so we may use rb_str_new2.
+ * We do not use rb_str_new(e->name, e->len) because
+ * e->len counts all \0 padding bytes, and there may be
+ * multiple padding bytes
+ */
+ name = e->len ? rb_str_new2(e->name) : Qnil;
return rb_struct_new(cEvent, wd, mask, cookie, name);
}
--
EW
prev parent reply other threads:[~2014-12-28 2:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-28 2:27 [sleepy.penguin] [PATCH] extconf: detect inotify_init1 in libc Eric Wong
2014-12-28 2:27 ` Eric Wong [this message]
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/sleepy_penguin/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1419733675-6323-2-git-send-email-normalperson@yhbt.net \
--to=normalperson@yhbt.net \
--cc=sleepy.penguin@librelist.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
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/sleepy_penguin.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).