[前][次][番号順一覧][スレッド一覧]

ruby-changes:50102

From: shyouhei <ko1@a...>
Date: Mon, 5 Feb 2018 13:07:29 +0900 (JST)
Subject: [ruby-changes:50102] shyouhei:r62220 (trunk): va_copy is a C99ism

shyouhei	2018-02-05 13:07:25 +0900 (Mon, 05 Feb 2018)

  New Revision: 62220

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62220

  Log:
    va_copy is a C99ism
    
    Should provide appropriate fallback implementation.

  Added files:
    trunk/tool/m4/ruby_check_va_copy.m4
  Modified files:
    trunk/aclocal.m4
    trunk/configure.ac
    trunk/internal.h
    trunk/mjit.c
    trunk/win32/Makefile.sub
Index: win32/Makefile.sub
===================================================================
--- win32/Makefile.sub	(revision 62219)
+++ win32/Makefile.sub	(revision 62220)
@@ -618,6 +618,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/ https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L618
 #define HAVE_PROTOTYPES 1
 #define TOKEN_PASTE(x,y) x##y
 #define HAVE_STDARG_PROTOTYPES 1
+#define HAVE_VA_COPY 1
 !if $(MSC_VER) > 1100
 #define NORETURN(x) __declspec(noreturn) x
 !endif
Index: mjit.c
===================================================================
--- mjit.c	(revision 62219)
+++ mjit.c	(revision 62220)
@@ -119,10 +119,6 @@ extern int rb_thread_create_mjit_thread( https://github.com/ruby/ruby/blob/trunk/mjit.c#L119
 typedef intptr_t pid_t;
 #endif
 
-#ifndef va_copy
-#define va_copy(dest, src) ((dest) = (src))
-#endif
-
 /* Atomically set function pointer if possible. */
 #ifdef _WIN32
 # ifdef InterlockedExchangePointer
Index: tool/m4/ruby_check_va_copy.m4
===================================================================
--- tool/m4/ruby_check_va_copy.m4	(nonexistent)
+++ tool/m4/ruby_check_va_copy.m4	(revision 62220)
@@ -0,0 +1,32 @@ https://github.com/ruby/ruby/blob/trunk/tool/m4/ruby_check_va_copy.m4#L1
+# -*- Autoconf -*-
+m4_define(RUBY_CHECK_VA_COPY, [
+    if test "x$rb_cv_va_copy" = x; then
+        AC_TRY_RUN(
+[#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#define CONFTEST_VA_COPY(dst, src) $2
+void
+conftest(int n, ...)
+{
+    va_list ap, ap2;
+    int i;
+    va_start(ap, n);
+    CONFTEST_VA_COPY(ap2, ap);
+    for (i = 0; i < n; i++) if ((int)va_arg(ap, int) != n - i - 1) abort();
+    CONFTEST_VA_COPY(ap, ap2);
+    for (i = 0; i < n; i++) if ((int)va_arg(ap, int) != n - i - 1) abort();
+    va_end(ap);
+}
+int
+main()
+{
+    conftest(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
+    exit(0);
+}],
+	rb_cv_va_copy=[$1],
+        rb_cv_va_copy="",
+        rb_cv_va_copy="")dnl
+    fi
+])dnl
+dnl
Index: configure.ac
===================================================================
--- configure.ac	(revision 62219)
+++ configure.ac	(revision 62220)
@@ -1244,6 +1244,26 @@ AS_IF([test "$rb_cv_va_args_macro" = yes https://github.com/ruby/ruby/blob/trunk/configure.ac#L1244
   AC_DEFINE(HAVE_VA_ARGS_MACRO)
 ])
 
+AC_CACHE_CHECK([appropriate way to simulate va_copy], rb_cv_va_copy, [dnl
+    RUBY_CHECK_VA_COPY([va_copy], [va_copy((dst),(src))])
+    RUBY_CHECK_VA_COPY([VA_COPY macro], [VA_COPY((dst),(src))])
+    RUBY_CHECK_VA_COPY([__va_copy], [__va_copy((dst),(src))])
+    RUBY_CHECK_VA_COPY([__builtin_va_copy], [__builtin_va_copy((dst),(src))])
+    RUBY_CHECK_VA_COPY([va_copy via struct assignment],
+        [do (dst) = (src); while (0)])
+    RUBY_CHECK_VA_COPY([va_copy via pointer assignment],
+        [do *(dst) = *(src); while (0)])
+    RUBY_CHECK_VA_COPY([va_copy via memcpy],
+        [memcpy(&(dst), &(src), sizeof(va_list))])
+])
+if test "x$rb_cv_va_copy" = x; then
+    AC_ERROR([no way to simulate va_copy])
+else
+    m4_pushdef([macro], AS_TR_CPP(HAVE_$1))
+    AC_DEFINE_UNQUOTED(macro($rb_cv_va_copy))
+    m4_popdef([macro])
+fi
+
 AC_CACHE_CHECK([for alignas() syntax], rb_cv_have_alignas, [
 rb_cv_have_alignas=no
 RUBY_WERROR_FLAG([
Index: aclocal.m4
===================================================================
--- aclocal.m4	(revision 62219)
+++ aclocal.m4	(revision 62220)
@@ -25,6 +25,7 @@ m4_include([tool/m4/ruby_check_setjmp.m4 https://github.com/ruby/ruby/blob/trunk/aclocal.m4#L25
 m4_include([tool/m4/ruby_check_signedness.m4])
 m4_include([tool/m4/ruby_check_sizeof.m4])
 m4_include([tool/m4/ruby_check_sysconf.m4])
+m4_include([tool/m4/ruby_check_va_copy.m4])
 m4_include([tool/m4/ruby_cppoutfile.m4])
 m4_include([tool/m4/ruby_decl_attribute.m4])
 m4_include([tool/m4/ruby_default_arch.m4])
Index: internal.h
===================================================================
--- internal.h	(revision 62219)
+++ internal.h	(revision 62220)
@@ -85,6 +85,25 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L85
 # define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)]
 #endif
 
+#if defined(HAVE_VA_COPY)
+/* OK, nothing to do */
+#elif defined(HAVE_VA_COPY_MACRO)
+#define va_copy(dst, src) VA_COPY((dst), (src))
+#elif defined(HAVE___VA_COPY)
+#define va_copy(dst, src) __va_copy((dst), (src))
+#elif defined(HAVE___BUILTIN_VA_COPY)
+#define va_copy(dst, src) __builtin_va_copy((dst), (src))
+#elif defined(HAVE_VA_COPY_VIA_STRUCT_ASSIGNMENT)
+#define va_copy(dst, src) do (dst) = (src); while (0)
+#elif defined(HAVE_VA_COPY_VIA_POINTER_ASSIGNMENT)
+#define va_copy(dst, src) do *(dst) = *(src); while (0)
+#elif defined(HAVE_VA_COPY_VIA_MEMCPY)
+#include <string.h>
+#define va_copy(dst, src) memcpy(&(dst), &(src), sizeof(va_list))
+#else
+#error >>>> no way to simuate va_copy <<<<
+#endif
+
 #define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1)
 #define SIGNED_INTEGER_MAX(sint_type) \
   (sint_type) \

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]