Skip to content

Commit fa0c9ac

Browse files
authored
Merge pull request #10785 from bwbarrett/cleanup/push-pop-as-subroutines
build: Use shell function for OPAL_VAR_SCOPE
2 parents 769591a + a8c829c commit fa0c9ac

5 files changed

+87
-79
lines changed

config/ompi_fortran_check_f08_assumed_rank.m4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ AC_DEFUN([OMPI_FORTRAN_CHECK_F08_ASSUMED_RANK], [
3939
###################################
4040

4141
AC_DEFUN([_OMPI_FORTRAN_CHECK_F08_ASSUMED_RANK], [
42-
OPAL_VAR_SCOPE_PUSH([happy])
42+
OPAL_VAR_SCOPE_PUSH([f08_assumed_rank_happy])
4343

4444
# If we were called here, it means that the value was not cached,
4545
# so we need to check several different things. Since CACHE_CHECK
@@ -50,9 +50,9 @@ AC_DEFUN([_OMPI_FORTRAN_CHECK_F08_ASSUMED_RANK], [
5050
# Check for the F08 type(*),dimension(..) syntax
5151
OMPI_FORTRAN_CHECK_IGNORE_TKR_SUB([!], [TYPE(*), DIMENSION(..)],
5252
[TYPE(*), DIMENSION(..)],
53-
[happy=yes], [happy=no])
53+
[f08_assumed_rank_happy=yes], [f08_assumed_rank_happy=no])
5454

55-
AS_VAR_SET(fortran_f08_assumed_rank, [$happy]);
55+
AS_VAR_SET(fortran_f08_assumed_rank, [$f08_assumed_rank_happy]);
5656

5757
# Now put the original CACHE_CHECK MSG_CHECKING back so that it can
5858
# output the MSG_RESULT.

config/ompi_fortran_check_ignore_tkr.m4

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dnl $HEADER$
2323
# Does this compiler support (void*)-like functionality for MPI choice
2424
# buffers? If so, which flavor?
2525
AC_DEFUN([OMPI_FORTRAN_CHECK_IGNORE_TKR], [
26-
OPAL_VAR_SCOPE_PUSH([result happy type predecl])
26+
OPAL_VAR_SCOPE_PUSH([result ignore_tkr_happy type predecl])
2727

2828
OMPI_FORTRAN_IGNORE_TKR_PREDECL=
2929
OMPI_FORTRAN_IGNORE_TKR_TYPE=
@@ -41,11 +41,11 @@ AC_DEFUN([OMPI_FORTRAN_CHECK_IGNORE_TKR], [
4141
AS_VAR_COPY([result], [fortran_ignore_tkr_data])
4242

4343
# Parse the result
44-
happy=`echo $result | cut -d: -f1`
44+
ignore_tkr_happy=`echo $result | cut -d: -f1`
4545
type=`echo $result | cut -d: -f2`
4646
predecl=`echo $result | cut -d: -f3-`
4747

48-
AS_IF([test $happy -eq 1],
48+
AS_IF([test $ignore_tkr_happy -eq 1],
4949
[OMPI_FORTRAN_IGNORE_TKR_PREDECL=$predecl
5050
OMPI_FORTRAN_IGNORE_TKR_TYPE=$type
5151
$1],
@@ -58,7 +58,7 @@ AC_DEFUN([OMPI_FORTRAN_CHECK_IGNORE_TKR], [
5858
################
5959

6060
AC_DEFUN([_OMPI_FORTRAN_CHECK_IGNORE_TKR], [
61-
OPAL_VAR_SCOPE_PUSH([happy ompi_fortran_ignore_tkr_predecl ompi_fortran_ignore_tkr_type])
61+
OPAL_VAR_SCOPE_PUSH([internal_ignore_tkr_happy ompi_fortran_ignore_tkr_predecl ompi_fortran_ignore_tkr_type])
6262

6363
# If we were called here, it means that the value was not cached,
6464
# so we need to check several different things. Since CACHE_CHECK
@@ -74,43 +74,43 @@ AC_DEFUN([_OMPI_FORTRAN_CHECK_IGNORE_TKR], [
7474
OMPI_FORTRAN_CHECK_IGNORE_TKR_SUB(
7575
[!], [type(*)],
7676
[TYPE(*), DIMENSION(*)],
77-
[happy=1], [happy=0])
77+
[internal_ignore_tkr_happy=1], [internal_ignore_tkr_happy=0])
7878

7979
# GCC compilers
80-
AS_IF([test $happy -eq 0],
80+
AS_IF([test $internal_ignore_tkr_happy -eq 0],
8181
[OMPI_FORTRAN_CHECK_IGNORE_TKR_SUB(
8282
[!GCC\$ ATTRIBUTES NO_ARG_CHECK ::], [type(*), dimension(*)],
8383
[!GCC\$ ATTRIBUTES NO_ARG_CHECK],
84-
[happy=1], [happy=0])])
84+
[internal_ignore_tkr_happy=1], [internal_ignore_tkr_happy=0])])
8585
# Intel compilers
86-
AS_IF([test $happy -eq 0],
86+
AS_IF([test $internal_ignore_tkr_happy -eq 0],
8787
[OMPI_FORTRAN_CHECK_IGNORE_TKR_SUB(
8888
[!DEC\$ ATTRIBUTES NO_ARG_CHECK ::], [real, dimension(*)],
8989
[!DEC\$ ATTRIBUTES NO_ARG_CHECK],
90-
[happy=1], [happy=0])])
90+
[internal_ignore_tkr_happy=1], [internal_ignore_tkr_happy=0])])
9191
# Solaris Studio compilers
9292
# Note that due to a compiler bug, we have been advised by Oracle to
9393
# use the "character(*)" type
94-
AS_IF([test $happy -eq 0],
94+
AS_IF([test $internal_ignore_tkr_happy -eq 0],
9595
[OMPI_FORTRAN_CHECK_IGNORE_TKR_SUB(
9696
[!\$PRAGMA IGNORE_TKR], [character(*)],
9797
[!\$PRAGMA IGNORE_TKR],
98-
[happy=1], [happy=0])])
98+
[internal_ignore_tkr_happy=1], [internal_ignore_tkr_happy=0])])
9999
# Cray compilers
100-
AS_IF([test $happy -eq 0],
100+
AS_IF([test $internal_ignore_tkr_happy -eq 0],
101101
[OMPI_FORTRAN_CHECK_IGNORE_TKR_SUB(
102102
[!DIR\$ IGNORE_TKR], [real, dimension(*)],
103103
[!DIR\$ IGNORE_TKR],
104-
[happy=1], [happy=0])])
104+
[internal_ignore_tkr_happy=1], [internal_ignore_tkr_happy=0])])
105105
# IBM compilers
106-
AS_IF([test $happy -eq 0],
106+
AS_IF([test $internal_ignore_tkr_happy -eq 0],
107107
[OMPI_FORTRAN_CHECK_IGNORE_TKR_SUB(
108108
[!IBM* IGNORE_TKR], [real, dimension(*)],
109109
[!IBM* IGNORE_TKR],
110-
[happy=1], [happy=0])])
110+
[internal_ignore_tkr_happy=1], [internal_ignore_tkr_happy=0])])
111111

112112
AS_VAR_SET(fortran_ignore_tkr_data,
113-
[${happy}:${ompi_fortran_ignore_tkr_type}:${ompi_fortran_ignore_tkr_predecl}])
113+
[${internal_ignore_tkr_happy}:${ompi_fortran_ignore_tkr_type}:${ompi_fortran_ignore_tkr_predecl}])
114114

115115
# Now put the original CACHE_CHECK MSG_CHECKING back so that it can
116116
# output the MSG_RESULT.

config/ompi_fortran_check_real16_c_equiv.m4

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ dnl
2424
# OMPI_FORTRAN_CHECK_REAL16_C_EQUIV
2525
# ----------------------------------------------------
2626
AC_DEFUN([OMPI_FORTRAN_CHECK_REAL16_C_EQUIV],[
27-
unset happy
28-
OPAL_VAR_SCOPE_PUSH([happy define_value msg CFLAGS_save])
27+
OPAL_VAR_SCOPE_PUSH([fortran_real16_happy define_value msg CFLAGS_save])
2928
AS_VAR_PUSHDEF([real16_matches_c_var], [ompi_cv_real16_c_equiv])
3029

3130
# We have to do this as a cache check for cross-compilation platforms
@@ -42,15 +41,15 @@ AC_DEFUN([OMPI_FORTRAN_CHECK_REAL16_C_EQUIV],[
4241
OMPI_FORTRAN_CHECK_REAL16_EQUIV_TYPE([$OMPI_FORTRAN_REAL16_C_TYPE], [L])
4342
# If that didn't work, see if we have a compiler-specific
4443
# type that might work
45-
AS_IF([test "$happy" = "no"],
46-
[AC_MSG_RESULT([$happy])
44+
AS_IF([test "$fortran_real16_happy" = "no"],
45+
[AC_MSG_RESULT([$fortran_real16_happy])
4746
# Intel compiler has a special type that should work
4847
AS_IF([test "$opal_cv_c_compiler_vendor" = "intel"],
4948
[AC_MSG_CHECKING([if intel compiler _Quad == REAL*16])
5049
CFLAGS_save="$CFLAGS"
5150
OPAL_FLAGS_APPEND_UNIQ([CFLAGS], ["-Qoption,cpp,--extended_float_types"])
5251
OMPI_FORTRAN_CHECK_REAL16_EQUIV_TYPE([_Quad], [q])
53-
AS_IF([test "$happy" = "yes"],
52+
AS_IF([test "$fortran_real16_happy" = "yes"],
5453
[OMPI_FORTRAN_REAL16_C_TYPE="_Quad"
5554
AC_MSG_RESULT([works!])],
5655
[CFLAGS="$CFLAGS_save"
@@ -59,7 +58,7 @@ AC_DEFUN([OMPI_FORTRAN_CHECK_REAL16_C_EQUIV],[
5958
AS_IF([test "$opal_cv_c_compiler_vendor" = "gnu" && test "$ac_cv_type___float128" = "yes"],
6059
[AC_MSG_CHECKING([if gnu compiler __float128 == REAL*16])
6160
OMPI_FORTRAN_CHECK_REAL16_EQUIV_TYPE([__float128], [q])
62-
AS_IF([test "$happy" = "yes"],
61+
AS_IF([test "$fortran_real16_happy" = "yes"],
6362
[OMPI_FORTRAN_REAL16_C_TYPE="__float128"
6463
AC_MSG_RESULT([works!])],
6564
[AC_MSG_RESULT([does not work])])
@@ -68,7 +67,7 @@ AC_DEFUN([OMPI_FORTRAN_CHECK_REAL16_C_EQUIV],[
6867
# AC_CACHE_CHECK will automatically AC_MSG_RESULT
6968
AC_MSG_CHECKING([for C type matching bit representation of REAL*16])
7069
])
71-
AS_VAR_SET(real16_matches_c_var, [$happy])
70+
AS_VAR_SET(real16_matches_c_var, [$fortran_real16_happy])
7271
],[
7372
# No fortran bindings or no REAL*16
7473
AS_IF([test "$OMPI_TRY_FORTRAN_BINDINGS" = "$OMPI_FORTRAN_NO_BINDINGS"],
@@ -134,15 +133,15 @@ EOF
134133
# Compile and link
135134
OPAL_LOG_COMMAND([$CC $CFLAGS -I. -c conftest_c.c],
136135
[OPAL_LOG_COMMAND([$FC $FCFLAGS conftest_f.f conftest_c.o -o conftest $LDFLAGS $LIBS],
137-
[happy="yes"], [happy="no"])], [happy="no"])
138-
AS_IF([test "$happy" = "no"],
136+
[fortran_real16_happy="yes"], [fortran_real16_happy="no"])], [fortran_real16_happy="no"])
137+
AS_IF([test "$fortran_real16_happy" = "no"],
139138
[AC_MSG_RESULT([Could not determine if REAL*16 bit-matches C type])],
140139
# If it worked so far, try running to see what we get
141-
[AS_IF([test "$happy" = "yes" && test "$cross_compiling" = "yes"],
140+
[AS_IF([test "$fortran_real16_happy" = "yes" && test "$cross_compiling" = "yes"],
142141
[AC_MSG_RESULT([Error!])
143142
AC_MSG_ERROR([Can not determine if REAL*16 bit-matches C if cross compiling])],
144143
[OPAL_LOG_COMMAND([./conftest],
145-
[happy=`cat conftestval`],
144+
[fortran_real16_happy=`cat conftestval`],
146145
[AC_MSG_RESULT([Error!])
147146
AC_MSG_ERROR([Could not determine if REAL*16 bit-matches C type])
148147
])

config/ompi_fortran_get_alignment.m4

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ dnl
5555
# OMPI_FORTRAN_GET_ALIGNMENT(type, shell variable to set)
5656
# ----------------------------------------------------
5757
AC_DEFUN([OMPI_FORTRAN_GET_ALIGNMENT],[
58-
unset happy
59-
OPAL_VAR_SCOPE_PUSH([happy ompi_conftest_h])
58+
OPAL_VAR_SCOPE_PUSH([fortran_get_alignment_happy ompi_conftest_h])
6059
# Use of m4_translit suggested by Eric Blake:
6160
# http://lists.gnu.org/archive/html/bug-autoconf/2010-10/msg00016.html
6261
AS_VAR_PUSHDEF([type_var],
@@ -112,9 +111,11 @@ EOF
112111

113112
OPAL_LOG_COMMAND([$CC $CFLAGS -I. -c conftest.c],
114113
[OPAL_LOG_COMMAND([$FC $FCFLAGS conftestf.f conftest.o -o conftest $LDFLAGS $LIBS],
115-
[happy="yes"], [happy="no"])], [happy="no"])
114+
[fortran_get_alignment_happy="yes"],
115+
[fortran_get_alignment_happy="no"])],
116+
[fortran_get_alignment_happy="no"])
116117

117-
if test "$happy" = "no" ; then
118+
if test "$fortran_get_alignment_happy" = "no" ; then
118119
AC_MSG_RESULT([Error!])
119120
AC_MSG_ERROR([Could not determine alignment of $1])
120121
fi

config/opal_functions.m4

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -496,60 +496,68 @@ dnl #######################################################################
496496
dnl #######################################################################
497497
dnl #######################################################################
498498

499-
# Declare some variables; use OPAL_VAR_SCOPE_POP to ensure that they
500-
# are cleaned up / undefined.
501-
AC_DEFUN([OPAL_VAR_SCOPE_PUSH],[
502-
# Is the private index set? If not, set it.
503-
if test "x$opal_scope_index" = "x"; then
504-
opal_scope_index=1
505-
fi
506-
499+
AC_DEFUN([OPAL_VAR_SCOPE_INIT],
500+
[opal_var_scope_push()
501+
{
502+
opal_var_scope_push_lineno=$[]1
503+
shift
507504
# First, check to see if any of these variables are already set.
508505
# This is a simple sanity check to ensure we're not already
509506
# overwriting pre-existing variables (that have a non-empty
510507
# value). It's not a perfect check, but at least it's something.
511-
for opal_var in $1; do
512-
opal_str="opal_str=\"\$$opal_var\""
513-
eval $opal_str
514-
515-
if test "x$opal_str" != "x"; then
516-
AC_MSG_WARN([Found configure shell variable clash at line $LINENO!])
517-
AC_MSG_WARN([[OPAL_VAR_SCOPE_PUSH] called on "$opal_var",])
518-
AC_MSG_WARN([but it is already defined with value "$opal_str"])
519-
AC_MSG_WARN([This usually indicates an error in configure.])
520-
AC_MSG_ERROR([Cannot continue])
521-
fi
508+
for opal_var_scope_tmp_var in $[]@; do
509+
AS_VAR_SET_IF([$opal_var_scope_tmp_var],
510+
[AS_VAR_COPY([opal_var_scope_tmp_var_val], [$opal_var_scope_tmp_var])
511+
AC_MSG_WARN([Found configure shell variable clash at line $opal_var_scope_push_lineno!])
512+
AC_MSG_WARN([[OPAL_VAR_SCOPE_PUSH] called on "$opal_var_scope_tmp_var",])
513+
AC_MSG_WARN([but it is already defined with value "$opal_var_scope_tmp_var_val"])
514+
AC_MSG_WARN([This usually indicates an error in configure.])
515+
AC_MSG_ERROR([Cannot continue])])
522516
done
517+
AS_UNSET([opal_var_scope_push_lineno])
518+
AS_UNSET([opal_var_scope_tmp_var])
519+
AS_UNSET([opal_var_scope_tmp_var_val])
520+
}
523521

524-
# Ok, we passed the simple sanity check. Save all these names so
525-
# that we can unset them at the end of the scope.
526-
opal_str="opal_scope_$opal_scope_index=\"$1\""
527-
eval $opal_str
528-
unset opal_str
529-
530-
env | grep opal_scope
531-
opal_scope_index=`expr $opal_scope_index + 1`
522+
opal_var_scope_pop()
523+
{
524+
# Iterate over all the variables and unset them all
525+
for opal_var_scope_tmp_var in $[]@; do
526+
AS_UNSET([$opal_var_scope_tmp_var])
527+
done
528+
AS_UNSET([opal_var_scope_tmp_var])
529+
}])
530+
531+
# OPAL_VAR_SCOPE_PUSH(vars list)
532+
# ------------------------------
533+
# Scope-check that the vars in the space-separated vars list are not already
534+
# in use. Generate a configure-time error if a conflict is found. Note that
535+
# the in use check is defined as "defined", so even if a var in vars list is
536+
# set outside of OPAL_VAR_SCOPE_PUSH, the check will still trip.
537+
AC_DEFUN([OPAL_VAR_SCOPE_PUSH],[
538+
AC_REQUIRE([OPAL_VAR_SCOPE_INIT])dnl
539+
m4_pushdef([opal_var_scope_stack], [$1])dnl
540+
m4_foreach_w([opal_var_scope_var], [$1],
541+
[m4_set_add([opal_var_scope_active_set], opal_var_scope_var,
542+
[], [m4_fatal([OPAL_VAR_SCOPE_PUSH found the variable ]opal_var_scope_var[
543+
active in a previous scope.])])])dnl
544+
opal_var_scope_push ${LINENO} $1
532545
])dnl
533546

534-
# Unset a bunch of variables that were previously set
547+
# OPAL_VAR_SCOPE_POP()
548+
# --------------------
549+
# Unset the last set of variables set in OPAL_VAR_SCOPE_POP. Every call to
550+
# OPAL_VAR_SCOPE_PUSH should have a matched call to this macro.
535551
AC_DEFUN([OPAL_VAR_SCOPE_POP],[
536-
# Unwind the index
537-
opal_scope_index=`expr $opal_scope_index - 1`
538-
opal_scope_test=`expr $opal_scope_index \> 0`
539-
if test "$opal_scope_test" = "0"; then
540-
AC_MSG_WARN([[OPAL_VAR_SCOPE_POP] popped too many OPAL configure scopes.])
541-
AC_MSG_WARN([This usually indicates an error in configure.])
542-
AC_MSG_ERROR([Cannot continue])
543-
fi
544-
545-
# Get the variable names from that index
546-
opal_str="opal_str=\"\$opal_scope_$opal_scope_index\""
547-
eval $opal_str
548-
549-
# Iterate over all the variables and unset them all
550-
for opal_var in $opal_str; do
551-
unset $opal_var
552-
done
552+
AC_REQUIRE([OPAL_VAR_SCOPE_INIT])dnl
553+
m4_ifdef([opal_var_scope_stack], [],
554+
[m4_fatal([OPAL_VAR_SCOPE_POP was called without a defined
555+
variable stack. This usually means that OPAL_VAR_SCOPE_POP was called more
556+
times than OPAL_VAR_SCOPE_PUSH.])])dnl
557+
m4_foreach_w([opal_var_scope_var], opal_var_scope_stack,
558+
[m4_set_remove([opal_var_scope_active_set], opal_var_scope_var)])dnl
559+
opal_var_scope_pop opal_var_scope_stack
560+
m4_popdef([opal_var_scope_stack])dnl
553561
])dnl
554562

555563

0 commit comments

Comments
 (0)