sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: sleepy-penguin@bogomips.org
Subject: [PATCH 2/1] portability fixes for systems w/o splice, copy_file_range
Date: Sat, 11 Mar 2017 09:37:35 +0000	[thread overview]
Message-ID: <20170311093735.GA30623@plume> (raw)
In-Reply-To: <20170311010016.13003-1-e@80x24.org>

We need to support FreeBSD, at least.
---
 ext/sleepy_penguin/cfr.c            | 14 +++-----------
 ext/sleepy_penguin/init.c           | 12 ++++++++++++
 ext/sleepy_penguin/sleepy_penguin.h | 11 +++++++++++
 test/test_splice.rb                 |  2 +-
 test/test_splice_eintr.rb           |  2 +-
 5 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/ext/sleepy_penguin/cfr.c b/ext/sleepy_penguin/cfr.c
index acece4f..860c5f5 100644
--- a/ext/sleepy_penguin/cfr.c
+++ b/ext/sleepy_penguin/cfr.c
@@ -2,17 +2,6 @@
 #include "sp_copy.h"
 #include <unistd.h>
 
-#ifndef HAVE_COPY_FILE_RANGE
-#  include <sys/syscall.h>
-#  if !defined(__NR_copy_file_range)
-#    if defined(__x86_64__)
-#      define __NR_copy_file_range 326
-#    elif defined(__i386__)
-#      define __NR_copy_file_range 377
-#    endif /* supported arches */
-#  endif /* __NR_copy_file_range */
-#endif
-
 #ifdef __NR_copy_file_range
 static ssize_t my_cfr(int fd_in, off_t *off_in, int fd_out, off_t *off_out,
 		       size_t len, unsigned int flags)
@@ -26,6 +15,8 @@ static ssize_t my_cfr(int fd_in, off_t *off_in, int fd_out, off_t *off_out,
 		my_cfr((fd_in),(off_in),(fd_out),(off_out),(len),(flags))
 #endif
 
+#if defined(HAVE_COPY_FILE_RANGE) || \
+    (defined(__linux__) && defined(__NR_copy_file_range))
 static void *nogvl_cfr(void *ptr)
 {
 	struct copy_args *a = ptr;
@@ -68,3 +59,4 @@ void sleepy_penguin_init_cfr(void)
 
 	rb_define_singleton_method(mod, "__cfr", rb_sp_cfr, 6);
 }
+#endif /* !HAVE_COPY_FILE_RANGE */
diff --git a/ext/sleepy_penguin/init.c b/ext/sleepy_penguin/init.c
index 8295073..01bb52f 100644
--- a/ext/sleepy_penguin/init.c
+++ b/ext/sleepy_penguin/init.c
@@ -52,8 +52,20 @@ void sleepy_penguin_init_signalfd(void);
 #  define sleepy_penguin_init_signalfd() for(;0;)
 #endif
 
+#ifdef HAVE_SPLICE
 void sleepy_penguin_init_splice(void);
+#else
+#  define sleepy_penguin_init_splice() for(;0;)
+#endif
+
+#if defined(HAVE_COPY_FILE_RANGE) || \
+    (defined(__linux__) && defined(__NR_copy_file_range))
 void sleepy_penguin_init_cfr(void);
+#else
+#  define sleepy_penguin_init_cfr() for (;0;)
+#endif
+
+/* everyone */
 void sleepy_penguin_init_sendfile(void);
 
 static size_t l1_cache_line_size_detect(void)
diff --git a/ext/sleepy_penguin/sleepy_penguin.h b/ext/sleepy_penguin/sleepy_penguin.h
index 8aa514a..99ad0b7 100644
--- a/ext/sleepy_penguin/sleepy_penguin.h
+++ b/ext/sleepy_penguin/sleepy_penguin.h
@@ -92,4 +92,15 @@ void *rb_sp_gettlsbuf(size_t *size);
 
 int rb_sp_gc_for_fd(int err);
 
+#ifndef HAVE_COPY_FILE_RANGE
+#  include <sys/syscall.h>
+#  if !defined(__NR_copy_file_range) && defined(__linux__)
+#    if defined(__x86_64__)
+#      define __NR_copy_file_range 326
+#    elif defined(__i386__)
+#      define __NR_copy_file_range 377
+#    endif /* supported arches */
+#  endif /* __NR_copy_file_range */
+#endif
+
 #endif /* SLEEPY_PENGUIN_H */
diff --git a/test/test_splice.rb b/test/test_splice.rb
index 3650ee3..266f52b 100644
--- a/test/test_splice.rb
+++ b/test/test_splice.rb
@@ -249,4 +249,4 @@ class TestSplice < Test::Unit::TestCase
       assert Integer === SleepyPenguin.const_get("F_#{x.upcase}")
     }
   end
-end
+end if SleepyPenguin.respond_to?(:splice)
diff --git a/test/test_splice_eintr.rb b/test/test_splice_eintr.rb
index 41b6dd0..fb2dbbc 100644
--- a/test/test_splice_eintr.rb
+++ b/test/test_splice_eintr.rb
@@ -31,4 +31,4 @@ class Test_Splice_EINTR < Test::Unit::TestCase
     assert_equal 2, nr
     assert_equal 1, @usr1
   end
-end if defined?(RUBY_ENGINE)
+end if SleepyPenguin.respond_to?(:splice)
-- 
EW

      reply	other threads:[~2017-03-11  9:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-11  1:00 [PATCH] implement linux_sendfile support Eric Wong
2017-03-11  9:37 ` 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=20170311093735.GA30623@plume \
    --to=e@80x24.org \
    --cc=sleepy-penguin@bogomips.org \
    /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).