File: ax_c_referenceable_passed_va_list.m4

package info (click to toggle)
sigscheme 0.8.5-4.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,752 kB
  • ctags: 7,396
  • sloc: lisp: 37,498; ansic: 30,976; sh: 10,329; makefile: 746; asm: 333; ruby: 288
file content (98 lines) | stat: -rw-r--r-- 2,852 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
##### http://autoconf-archive.cryp.to/ax_c_referenceable_passed_va_list.html
#
# SYNOPSIS
#
#   AX_C_REFERENCEABLE_PASSED_VA_LIST
#
# DESCRIPTION
#
#   Checks whether f(va_list va){ &va; } works as expected.
#
#   This macro uses compile-time detection and so is cross-compile
#   ready.
#
#   C99 mentioned passing a pointer to va_list to other functions
#   (footnote 212 of "7.15 Variable arguments <stdarg.h>"). However,
#   f(va_list va) { &va; } produces broken pointer on some environments
#   such as gcc on x86_64, although { va_list va; &va; } works as
#   expected. See the detection code of this file and any of pages
#   http://www.gnu.org/software/autoconf/manual/html_node/Function-Portability.html,
#   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14557, and
#   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20951 for further
#   information.
#
#   Although C99 does not define the operations f(va_list va) { &va; }
#   and &va itself as standard (footnotes are declared as "normative
#   part, information only"), certain situations need it. This macro
#   provides a type detection about va_list implementation to deal with
#   the operation.
#
#   Following workaround will probably work on such environments
#   although it does not ensure to be safe and portable. At least it is
#   working on x86_64-unknown-linux-gnu:
#
#    f(va_list va)
#    {
#      va_list *vap;
#
#    #if HAVE_REFERENCEABLE_PASSED_VA_LIST
#        vap = &va;
#    #else
#        vap = (va_list *)va;
#    #endif
#    }
#
# LAST MODIFICATION
#
#   2006-12-12
#
# COPYLEFT
#
#   Copyright (c) 2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
#
#   Copying and distribution of this file, with or without
#   modification, are permitted in any medium without royalty provided
#   the copyright notice and this notice are preserved.

AC_DEFUN([AX_C_REFERENCEABLE_PASSED_VA_LIST], [
  AC_CACHE_CHECK([whether f(va_list va){ &va; } works as expected],
    [ax_cv_c_referenceable_passed_va_list],
    [AC_LINK_IFELSE([[
#include <stdarg.h>

volatile va_list g_va;

void
vf(va_list callee_va)
{
  /* typeof(callee_va) differs from typeof(caller_va) by a compiler trick, if
   * va_list is implemented as an array. On such environment, this copy
   * operation fails. */
  g_va = callee_va;
}

void
f(int last, ...)
{
  va_list caller_va;

  va_start(caller_va, last);
  vf(caller_va);  /* passed as &caller_va[0] if va_list is an array type */
  va_end(caller_va);
}

int
main(int argc, char *argv[])
{
  f(0xdeadbeef, 0xfedbeef, 0xfeedee);

  return 0;
}
      ]],
      [ax_cv_c_referenceable_passed_va_list=yes],
      [ax_cv_c_referenceable_passed_va_list=no])])
  if test "x$ax_cv_c_referenceable_passed_va_list" = xyes; then
    AC_DEFINE([HAVE_REFERENCEABLE_PASSED_VA_LIST], [1],
              [Define to 1 if f(va_list va){ &va; } works as expected.])
  fi
])