From d0ed5a93786881e2ddda99d0c83e4d1a216a3ca8 Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 29 Dec 2008 14:54:24 +0000 Subject: * ext/dl/test/test_base.rb: add libc search logic. this patch is written by Takehiro Kubo. [ruby-core:20963] [Bug #932] * ext/dl/dl.h: Add ",..." as the last argument. this patch is written by Takehiro Kubo. Bug #633 [ruby-core:19289] * ext/dl/lib/dl/stack.rb: add add_padding() to calculate alignment. this patch is written by Takehiro Kubo. Bug #633 [ruby-core:19289] * ext/dl/test/test_func.rb: atof()'s return value is double. this patch is written by Takehiro Kubo. Bug #633 [ruby-core:19289] * ext/dl/test/test_import.rb: - atof()'s return value is double. - The types of qsort's second and third argument are size_t. - fprintf()'s return value is int. this patch is written by Takehiro Kubo. Bug #633 [ruby-core:19289] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 25 +++++++++++++++ ext/dl/dl.h | 80 +++++++++++++++++++++++++++++++++------------- ext/dl/lib/dl/stack.rb | 18 +++++++---- ext/dl/test/test_base.rb | 13 ++++++-- ext/dl/test/test_func.rb | 2 +- ext/dl/test/test_import.rb | 4 +-- 6 files changed, 109 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1567ba38ba..587bba8cb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +Mon Dec 29 23:41:42 2008 Koichi Sasada + + * ext/dl/test/test_base.rb: add libc search logic. + this patch is written by Takehiro Kubo. + [ruby-core:20963] [Bug #932] + + * ext/dl/dl.h: Add ",..." as the last argument. + this patch is written by Takehiro Kubo. + Bug #633 [ruby-core:19289] + + * ext/dl/lib/dl/stack.rb: add add_padding() to calculate + alignment. this patch is written by Takehiro Kubo. + Bug #633 [ruby-core:19289] + + * ext/dl/test/test_func.rb: atof()'s return value is double. + this patch is written by Takehiro Kubo. + Bug #633 [ruby-core:19289] + + * ext/dl/test/test_import.rb: + - atof()'s return value is double. + - The types of qsort's second and third argument are size_t. + - fprintf()'s return value is int. + this patch is written by Takehiro Kubo. + Bug #633 [ruby-core:19289] + Mon Dec 29 22:37:17 2008 Yuki Sonoda (Yugui) * process.c (rb_waitpid): retries waitpid when EINTR. diff --git a/ext/dl/dl.h b/ext/dl/dl.h index 7b8ad077ae..87a59946cd 100644 --- a/ext/dl/dl.h +++ b/ext/dl/dl.h @@ -50,28 +50,64 @@ stack[15],stack[16],stack[17],stack[18],stack[19] #define DLSTACK_PROTO0 -#define DLSTACK_PROTO1 DLSTACK_TYPE -#define DLSTACK_PROTO2 DLSTACK_PROTO1, DLSTACK_TYPE -#define DLSTACK_PROTO3 DLSTACK_PROTO2, DLSTACK_TYPE -#define DLSTACK_PROTO4 DLSTACK_PROTO3, DLSTACK_TYPE -#define DLSTACK_PROTO4 DLSTACK_PROTO3, DLSTACK_TYPE -#define DLSTACK_PROTO5 DLSTACK_PROTO4, DLSTACK_TYPE -#define DLSTACK_PROTO6 DLSTACK_PROTO5, DLSTACK_TYPE -#define DLSTACK_PROTO7 DLSTACK_PROTO6, DLSTACK_TYPE -#define DLSTACK_PROTO8 DLSTACK_PROTO7, DLSTACK_TYPE -#define DLSTACK_PROTO9 DLSTACK_PROTO8, DLSTACK_TYPE -#define DLSTACK_PROTO10 DLSTACK_PROTO9, DLSTACK_TYPE -#define DLSTACK_PROTO11 DLSTACK_PROTO10, DLSTACK_TYPE -#define DLSTACK_PROTO12 DLSTACK_PROTO11, DLSTACK_TYPE -#define DLSTACK_PROTO13 DLSTACK_PROTO12, DLSTACK_TYPE -#define DLSTACK_PROTO14 DLSTACK_PROTO13, DLSTACK_TYPE -#define DLSTACK_PROTO14 DLSTACK_PROTO13, DLSTACK_TYPE -#define DLSTACK_PROTO15 DLSTACK_PROTO14, DLSTACK_TYPE -#define DLSTACK_PROTO16 DLSTACK_PROTO15, DLSTACK_TYPE -#define DLSTACK_PROTO17 DLSTACK_PROTO16, DLSTACK_TYPE -#define DLSTACK_PROTO18 DLSTACK_PROTO17, DLSTACK_TYPE -#define DLSTACK_PROTO19 DLSTACK_PROTO18, DLSTACK_TYPE -#define DLSTACK_PROTO20 DLSTACK_PROTO19, DLSTACK_TYPE +#define DLSTACK_PROTO1_ DLSTACK_TYPE +#define DLSTACK_PROTO2_ DLSTACK_PROTO1_, DLSTACK_TYPE +#define DLSTACK_PROTO3_ DLSTACK_PROTO2_, DLSTACK_TYPE +#define DLSTACK_PROTO4_ DLSTACK_PROTO3_, DLSTACK_TYPE +#define DLSTACK_PROTO4_ DLSTACK_PROTO3_, DLSTACK_TYPE +#define DLSTACK_PROTO5_ DLSTACK_PROTO4_, DLSTACK_TYPE +#define DLSTACK_PROTO6_ DLSTACK_PROTO5_, DLSTACK_TYPE +#define DLSTACK_PROTO7_ DLSTACK_PROTO6_, DLSTACK_TYPE +#define DLSTACK_PROTO8_ DLSTACK_PROTO7_, DLSTACK_TYPE +#define DLSTACK_PROTO9_ DLSTACK_PROTO8_, DLSTACK_TYPE +#define DLSTACK_PROTO10_ DLSTACK_PROTO9_, DLSTACK_TYPE +#define DLSTACK_PROTO11_ DLSTACK_PROTO10_, DLSTACK_TYPE +#define DLSTACK_PROTO12_ DLSTACK_PROTO11_, DLSTACK_TYPE +#define DLSTACK_PROTO13_ DLSTACK_PROTO12_, DLSTACK_TYPE +#define DLSTACK_PROTO14_ DLSTACK_PROTO13_, DLSTACK_TYPE +#define DLSTACK_PROTO14_ DLSTACK_PROTO13_, DLSTACK_TYPE +#define DLSTACK_PROTO15_ DLSTACK_PROTO14_, DLSTACK_TYPE +#define DLSTACK_PROTO16_ DLSTACK_PROTO15_, DLSTACK_TYPE +#define DLSTACK_PROTO17_ DLSTACK_PROTO16_, DLSTACK_TYPE +#define DLSTACK_PROTO18_ DLSTACK_PROTO17_, DLSTACK_TYPE +#define DLSTACK_PROTO19_ DLSTACK_PROTO18_, DLSTACK_TYPE +#define DLSTACK_PROTO20_ DLSTACK_PROTO19_, DLSTACK_TYPE + +/* + * Add ",..." as the last argument. + * This is required for variable argument functions such + * as fprintf() on x86_64-linux. + * + * http://refspecs.linuxfoundation.org/elf/x86_64-abi-0.95.pdf + * page 19: + * + * For calls that may call functions that use varargs or stdargs + * (prototype-less calls or calls to functions containing ellipsis + * (...) in the declaration) %al is used as hidden argument to + * specify the number of SSE registers used. + */ +#define DLSTACK_PROTO1 DLSTACK_PROTO1_, ... +#define DLSTACK_PROTO2 DLSTACK_PROTO2_, ... +#define DLSTACK_PROTO3 DLSTACK_PROTO3_, ... +#define DLSTACK_PROTO4 DLSTACK_PROTO4_, ... +#define DLSTACK_PROTO4 DLSTACK_PROTO4_, ... +#define DLSTACK_PROTO5 DLSTACK_PROTO5_, ... +#define DLSTACK_PROTO6 DLSTACK_PROTO6_, ... +#define DLSTACK_PROTO7 DLSTACK_PROTO7_, ... +#define DLSTACK_PROTO8 DLSTACK_PROTO8_, ... +#define DLSTACK_PROTO9 DLSTACK_PROTO9_, ... +#define DLSTACK_PROTO10 DLSTACK_PROTO10_, ... +#define DLSTACK_PROTO11 DLSTACK_PROTO11_, ... +#define DLSTACK_PROTO12 DLSTACK_PROTO12_, ... +#define DLSTACK_PROTO13 DLSTACK_PROTO13_, ... +#define DLSTACK_PROTO14 DLSTACK_PROTO14_, ... +#define DLSTACK_PROTO14 DLSTACK_PROTO14_, ... +#define DLSTACK_PROTO15 DLSTACK_PROTO15_, ... +#define DLSTACK_PROTO16 DLSTACK_PROTO16_, ... +#define DLSTACK_PROTO17 DLSTACK_PROTO17_, ... +#define DLSTACK_PROTO18 DLSTACK_PROTO18_, ... +#define DLSTACK_PROTO19 DLSTACK_PROTO19_, ... +#define DLSTACK_PROTO20 DLSTACK_PROTO20_, ... #define DLSTACK_ARGS0(stack) #define DLSTACK_ARGS1(stack) stack[0] diff --git a/ext/dl/lib/dl/stack.rb b/ext/dl/lib/dl/stack.rb index 9daf089775..99a24bc1ba 100644 --- a/ext/dl/lib/dl/stack.rb +++ b/ext/dl/lib/dl/stack.rb @@ -121,20 +121,26 @@ end @template = "" addr = 0 types.each{|t| - orig_addr = addr - addr = align(orig_addr, ALIGN_MAP[t]) - d = addr - orig_addr - if( d > 0 ) - @template << "x#{d}" - end + addr = add_padding(addr, ALIGN_MAP[t]) @template << PACK_MAP[t] addr += SIZE_MAP[t] } + addr = add_padding(addr, ALIGN_MAP[SIZEOF_VOIDP]) if( addr % SIZEOF_VOIDP == 0 ) @size = addr / SIZEOF_VOIDP else @size = (addr / SIZEOF_VOIDP) + 1 end end + + def add_padding(addr, align) + orig_addr = addr + addr = align(orig_addr, align) + d = addr - orig_addr + if( d > 0 ) + @template << "x#{d}" + end + addr + end end end diff --git a/ext/dl/test/test_base.rb b/ext/dl/test/test_base.rb index ff0fad7df5..11243dfebd 100644 --- a/ext/dl/test/test_base.rb +++ b/ext/dl/test/test_base.rb @@ -9,8 +9,17 @@ when /x86_64-linux/ LIBC_SO = "/lib64/libc.so.6" LIBM_SO = "/lib64/libm.so.6" when /linux/ - LIBC_SO = "/lib/libc.so.6" - LIBM_SO = "/lib/libm.so.6" + libdir = '/lib' + case [0].pack('L!').size + when 4 + # 32-bit ruby + libdir = '/lib32' if File.directory? '/lib32' + when 8 + # 64-bit ruby + libdir = '/lib64' if File.directory? '/lib64' + end + LIBC_SO = File.join(libdir, "libc.so.6") + LIBM_SO = File.join(libdir, "libm.so.6") when /mingw/, /mswin32/ LIBC_SO = "msvcrt.dll" LIBM_SO = "msvcrt.dll" diff --git a/ext/dl/test/test_func.rb b/ext/dl/test/test_func.rb index 887d38df95..be937719df 100644 --- a/ext/dl/test/test_func.rb +++ b/ext/dl/test/test_func.rb @@ -24,7 +24,7 @@ module DL end def test_atof() - f = Function.new(CFunc.new(@libc['atof'], TYPE_FLOAT, 'atof'), + f = Function.new(CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof'), [TYPE_VOIDP]) r = f.call("12.34") assert_match(12.00..13.00, r) diff --git a/ext/dl/test/test_import.rb b/ext/dl/test/test_import.rb index 90f21dc65d..6d493a6d23 100644 --- a/ext/dl/test/test_import.rb +++ b/ext/dl/test/test_import.rb @@ -11,10 +11,10 @@ module DL extern "void *strcpy(char*, char*)" extern "int isdigit(int)" - extern "float atof(string)" + extern "double atof(string)" extern "unsigned long strtoul(char*, char **, int)" extern "int qsort(void*, int, int, void*)" - extern "void fprintf(FILE*, char*)" + extern "int fprintf(FILE*, char*)" extern "int gettimeofday(timeval*, timezone*)" rescue nil QsortCallback = bind("void *qsort_callback(void*, void*)", :temp) -- cgit v1.2.3