avoid busting bash's stack with a too big if body in configure
[m6w6/ext-psi] / m4 / psi_decl.m4
index 9b2d3eb6846fb032c67f707c5cac7b038025a61e..c331bbecc658fa4aa8a6f3e7655323cc6e15962d 100644 (file)
@@ -1,5 +1,5 @@
 AC_DEFUN(PSI_REDIR, [psi_symbol=ifelse([$2],[],[$1],[$2])
-       PSI_REDIRS="{\"$1\", (void(*)(void))$psi_symbol}, $PSI_REDIRS"])
+       cat >>$PSI_REDIRS <<<"  {\"$1\", (void(*)(void))$psi_symbol}, "])
 
 AC_DEFUN(PSI_FUNC_LIBC_MAIN, [
        AC_REQUIRE([AC_PROG_NM])
@@ -7,7 +7,7 @@ AC_DEFUN(PSI_FUNC_LIBC_MAIN, [
        AC_CACHE_CHECK(for libc start main symbol, psi_cv_libc_main, [
                psi_libc_main=
                AC_TRY_LINK(PSI_INCLUDES, [(void)0;], [
-                       psi_libc_main=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^\s+U / {print$[]3; exit}'`
+                       psi_libc_main=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
                ])
                psi_cv_libc_main=$psi_libc_main
        ])
@@ -22,7 +22,7 @@ AC_DEFUN(PSI_FUNC, [
                AC_TRY_LINK(PSI_INCLUDES, [
                        void (*fn)(void) = (void (*)(void)) $psi_symbol;
                ], [
-                       psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^\s+U '$psi_cv_libc_main'/ {next} /^\s+U / {print$[]3; exit}'`
+                       psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
                ])
                psi_cv_fn_$1=$psi_symbol_redirect
        ])
@@ -43,31 +43,32 @@ AC_DEFUN(PSI_FUNC, [
 AC_DEFUN(PSI_DECL_ARG, [
     m4_define([member_name], PSI_VAR_NAME($1))
     m4_define([member_type], PSI_VAR_TYPE($1))
-    m4_define([pointer_level], m4_len(m4_bpatsubst([$1], [[^*]])))
-       m4_define([array_size], [m4_bregexp([$1], [@<:@\([0-9]+\)@:>@], [\1])])
-       ifelse(array_size, [],
-               [m4_define([array_size], 0)],
-               [m4_define([pointer_level], m4_incr(pointer_level))]
-       )
+
+       PSI_TYPE_INDIRECTION([$1],, pl, as)
     if test -n "$psi_decl_args"; then
         psi_decl_args="$psi_decl_args, "
     fi
-    psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] pointer_level, array_size[}]"
+    psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
 ])
 
-dnl PSI_DECL(type func, args)
+dnl PSI_DECL(type func, args, flags)
 AC_DEFUN(PSI_DECL, [
        psi_decl_args=
        PSI_DECL_ARG($1)
        m4_case([$2],
                [(void)], [],
                [()], [],
-               [m4_map_args_sep([PSI_DECL_ARG(], [)], [], [m4_bregexp([$2], [(\(.*\))], [\1])])])
+               [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
        PSI_FUNC(PSI_VAR_NAME($1), [
-               PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS"
+               ifelse([$3], vararg, [
+                       cat >>$PSI_VA_DECLS <<<"        $psi_decl_args, {0}, "
+               ], [
+                       cat >>$PSI_DECLS <<<"   $psi_decl_args, {0}, "
+               ])
        ], [
                PSI_MACRO($1, $2, [
-                       PSI_DECLS="$psi_decl_args, {0}, $PSI_DECLS"
+                       ifelse([$3], vararg, AC_MSG_ERROR(varargs macro support is not implemented),[])
+                       cat >>$PSI_DECLS <<<"   $psi_decl_args, {0}, "
                ])
        ])
 ])