1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

va_copy is a C99ism

Should provide appropriate fallback implementation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shyouhei 2018-02-05 04:07:25 +00:00
parent bb6c0f03a7
commit 779c18bf23
6 changed files with 73 additions and 4 deletions

1
aclocal.m4 vendored
View file

@ -25,6 +25,7 @@ m4_include([tool/m4/ruby_check_setjmp.m4])
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])

View file

@ -1244,6 +1244,26 @@ AS_IF([test "$rb_cv_va_args_macro" = yes], [
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([

View file

@ -85,6 +85,25 @@ extern "C" {
# 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) \

4
mjit.c
View file

@ -119,10 +119,6 @@ extern int rb_thread_create_mjit_thread(void (*child_hook)(void), void (*worker_
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

View file

@ -0,0 +1,32 @@
# -*- 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

View file

@ -618,6 +618,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#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