* [sleepy.penguin] [PATCH] extconf: detect inotify_init1 in libc
@ 2014-12-28 2:27 Eric Wong
2014-12-28 2:27 ` [sleepy.penguin] [PATCH] inotify: cleanup Inotify::Event creation Eric Wong
0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2014-12-28 2:27 UTC (permalink / raw)
To: sleepy.penguin
Many systems have inotify_init1 nowadays, so use inotify_init1
if it is available to avoid unnecessary syscalls.
---
ext/sleepy_penguin/extconf.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/ext/sleepy_penguin/extconf.rb b/ext/sleepy_penguin/extconf.rb
index 407c947..eda7fcd 100644
--- a/ext/sleepy_penguin/extconf.rb
+++ b/ext/sleepy_penguin/extconf.rb
@@ -20,6 +20,7 @@ end
have_type('clockid_t', 'time.h')
have_func('clock_gettime', 'time.h')
have_func('epoll_create1', %w(sys/epoll.h))
+have_func('inotify_init1', %w(sys/inotify.h))
have_func('rb_thread_call_without_gvl')
have_func('rb_thread_blocking_region')
have_func('rb_thread_io_blocking_region')
--
EW
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [sleepy.penguin] [PATCH] inotify: cleanup Inotify::Event creation
2014-12-28 2:27 [sleepy.penguin] [PATCH] extconf: detect inotify_init1 in libc Eric Wong
@ 2014-12-28 2:27 ` Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2014-12-28 2:27 UTC (permalink / raw)
To: sleepy.penguin
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-12-28 2:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-28 2:27 [sleepy.penguin] [PATCH] extconf: detect inotify_init1 in libc Eric Wong
2014-12-28 2:27 ` [sleepy.penguin] [PATCH] inotify: cleanup Inotify::Event creation Eric Wong
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).