From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 1D667202C1; Sat, 11 Mar 2017 09:37:36 +0000 (UTC) Date: Sat, 11 Mar 2017 09:37:35 +0000 From: Eric Wong To: sleepy-penguin@bogomips.org Subject: [PATCH 2/1] portability fixes for systems w/o splice, copy_file_range Message-ID: <20170311093735.GA30623@plume> References: <20170311010016.13003-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20170311010016.13003-1-e@80x24.org> List-Id: 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 -#ifndef HAVE_COPY_FILE_RANGE -# include -# 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 +# 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