Skip to content

Commit f8f4630

Browse files
committedDec 6, 2022
8297963: Partially fix string expansion issues in UTIL_DEFUN_NAMED and related macros
Reviewed-by: ihse
1 parent 2a243a3 commit f8f4630

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed
 

‎make/autoconf/flags.m4

+4-4
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,14 @@ UTIL_DEFUN_NAMED([FLAGS_CXX_COMPILER_CHECK_ARGUMENTS],
503503
UTIL_DEFUN_NAMED([FLAGS_COMPILER_CHECK_ARGUMENTS],
504504
[*ARGUMENT IF_TRUE IF_FALSE PREFIX], [$@],
505505
[
506-
FLAGS_C_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARG_ARGUMENT],
506+
FLAGS_C_COMPILER_CHECK_ARGUMENTS(ARGUMENT: ARG_ARGUMENT,
507507
IF_TRUE: [C_COMP_SUPPORTS="yes"],
508508
IF_FALSE: [C_COMP_SUPPORTS="no"],
509-
PREFIX: [ARG_PREFIX])
510-
FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARG_ARGUMENT],
509+
PREFIX: ARG_PREFIX)
510+
FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: ARG_ARGUMENT,
511511
IF_TRUE: [CXX_COMP_SUPPORTS="yes"],
512512
IF_FALSE: [CXX_COMP_SUPPORTS="no"],
513-
PREFIX: [ARG_PREFIX])
513+
PREFIX: ARG_PREFIX)
514514
515515
AC_MSG_CHECKING([if both ARG_PREFIX[CC] and ARG_PREFIX[CXX] support "ARG_ARGUMENT"])
516516
supports=no

‎make/autoconf/util.m4

+25-20
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ m4_include([util_paths.m4])
5252
AC_DEFUN([UTIL_DEFUN_NAMED],
5353
[
5454
AC_DEFUN($1, [
55-
m4_foreach(arg, m4_split(m4_normalize($2)), [
55+
m4_foreach([arg], m4_split(m4_normalize($2)), [
5656
m4_if(m4_bregexp(arg, [^\*]), -1,
5757
[
5858
m4_set_add(legal_named_args, arg)
@@ -64,13 +64,18 @@ AC_DEFUN([UTIL_DEFUN_NAMED],
6464
)
6565
])
6666
67-
m4_foreach([arg], [$3], [
68-
m4_if(m4_bregexp(arg, [: ]), -1, m4_define([arg], m4_bpatsubst(arg, [:], [: ])))
69-
m4_define(arg_name, m4_substr(arg, 0, m4_bregexp(arg, [: ])))
67+
# Delicate quoting and unquoting sequence to ensure the actual value is passed along unchanged
68+
# For details on how this works, see https://git.openjdk.org/jdk/pull/11458#discussion_r1038173051
69+
# WARNING: Proceed at the risk of your own sanity, getting this to work has made me completely
70+
# incapable of feeling love or any other positive emotion
71+
# ~Julian
72+
m4_foreach([arg], m4_dquote(m4_dquote_elt($3)), [
73+
m4_if(m4_index(arg, [: ]), -1, [m4_define([arg], m4_dquote(m4_bpatsubst(m4_dquote(arg), [:], [: ])))])
74+
m4_define(arg_name, m4_substr(arg, 0, m4_index(arg, [: ])))
7075
m4_set_contains(legal_named_args, arg_name, [],[AC_MSG_ERROR([Internal error: m4_if(arg_name, , arg, arg_name) is not a valid named argument to [$1]. Valid arguments are 'm4_set_contents(defined_args, [ ]) m4_set_contents(legal_named_args, [ ])'.])])
7176
m4_set_remove(required_named_args, arg_name)
7277
m4_set_remove(legal_named_args, arg_name)
73-
m4_pushdef([ARG_][]arg_name, m4_bpatsubst(m4_substr(arg, m4_incr(m4_incr(m4_bregexp(arg, [: ])))), [^\s*], []))
78+
m4_pushdef([ARG_][]arg_name, m4_bpatsubst(m4_bpatsubst(m4_dquote(m4_dquote(arg)), arg_name[: ]), [^\s*]))
7479
m4_set_add(defined_args, arg_name)
7580
m4_undefine([arg_name])
7681
])
@@ -376,18 +381,18 @@ UTIL_DEFUN_NAMED([UTIL_ARG_ENABLE],
376381
m4_define(ARG_GIVEN, m4_translit(ARG_NAME, [a-z-], [A-Z_])[_GIVEN])
377382
378383
# If DESC is not specified, set it to a generic description.
379-
m4_define([ARG_DESC], m4_if(ARG_DESC, , [Enable the ARG_NAME feature], m4_normalize(ARG_DESC)))
384+
m4_define([ARG_DESC], m4_if(m4_quote(ARG_DESC), , [[Enable the ARG_NAME feature]], [m4_normalize(ARG_DESC)]))
380385
381386
# If CHECKING_MSG is not specified, set it to a generic description.
382-
m4_define([ARG_CHECKING_MSG], m4_if(ARG_CHECKING_MSG, , [for --enable-ARG_NAME], m4_normalize(ARG_CHECKING_MSG)))
387+
m4_define([ARG_CHECKING_MSG], m4_if(m4_quote(ARG_CHECKING_MSG), , [[for --enable-ARG_NAME]], [m4_normalize(ARG_CHECKING_MSG)]))
383388
384389
# If the code blocks are not given, set them to the empty statements to avoid
385390
# tripping up bash.
386-
m4_define([ARG_CHECK_AVAILABLE], m4_if(ARG_CHECK_AVAILABLE, , :, ARG_CHECK_AVAILABLE))
387-
m4_define([ARG_IF_GIVEN], m4_if(ARG_IF_GIVEN, , :, ARG_IF_GIVEN))
388-
m4_define([ARG_IF_NOT_GIVEN], m4_if(ARG_IF_NOT_GIVEN, , :, ARG_IF_NOT_GIVEN))
389-
m4_define([ARG_IF_ENABLED], m4_if(ARG_IF_ENABLED, , :, ARG_IF_ENABLED))
390-
m4_define([ARG_IF_DISABLED], m4_if(ARG_IF_DISABLED, , :, ARG_IF_DISABLED))
391+
m4_if(ARG_CHECK_AVAILABLE, , [m4_define([ARG_CHECK_AVAILABLE], [:])])
392+
m4_if(ARG_IF_GIVEN, , [m4_define([ARG_IF_GIVEN], [:])])
393+
m4_if(ARG_IF_NOT_GIVEN, , [m4_define([ARG_IF_NOT_GIVEN], [:])])
394+
m4_if(ARG_IF_ENABLED, , [m4_define([ARG_IF_ENABLED], [:])])
395+
m4_if(ARG_IF_DISABLED, , [m4_define([ARG_IF_DISABLED], [:])])
391396
392397
##########################
393398
# Part 2: Set up autoconf shell code
@@ -650,21 +655,21 @@ UTIL_DEFUN_NAMED([UTIL_ARG_WITH],
650655
m4_define(ARG_GIVEN, m4_translit(ARG_NAME, [a-z-], [A-Z_])[_GIVEN])
651656
652657
# If DESC is not specified, set it to a generic description.
653-
m4_define([ARG_DESC], m4_if(ARG_DESC, , [Give a value for the ARG_NAME feature], m4_normalize(ARG_DESC)))
658+
m4_define([ARG_DESC], m4_if(m4_quote(ARG_DESC), , [[Give a value for the ARG_NAME feature]], [m4_normalize(ARG_DESC)]))
654659
655660
# If CHECKING_MSG is not specified, set it to a generic description.
656-
m4_define([ARG_CHECKING_MSG], m4_if(ARG_CHECKING_MSG, , [for --with-ARG_NAME], m4_normalize(ARG_CHECKING_MSG)))
661+
m4_define([ARG_CHECKING_MSG], m4_if(m4_quote(ARG_CHECKING_MSG), , [[for --with-ARG_NAME]], [m4_normalize(ARG_CHECKING_MSG)]))
657662
658663
m4_define([ARG_HAS_AUTO_BLOCK], m4_if(ARG_IF_AUTO, , false, true))
659664
660665
# If the code blocks are not given, set them to the empty statements to avoid
661666
# tripping up bash.
662-
m4_define([ARG_CHECK_AVAILABLE], m4_if(ARG_CHECK_AVAILABLE, , :, ARG_CHECK_AVAILABLE))
663-
m4_define([ARG_CHECK_VALUE], m4_if(ARG_CHECK_VALUE, , :, ARG_CHECK_VALUE))
664-
m4_define([ARG_CHECK_FOR_FILES], m4_if(ARG_CHECK_FOR_FILES, , :, ARG_CHECK_FOR_FILES))
665-
m4_define([ARG_IF_AUTO], m4_if(ARG_IF_AUTO, , :, ARG_IF_AUTO))
666-
m4_define([ARG_IF_GIVEN], m4_if(ARG_IF_GIVEN, , :, ARG_IF_GIVEN))
667-
m4_define([ARG_IF_NOT_GIVEN], m4_if(ARG_IF_NOT_GIVEN, , :, ARG_IF_NOT_GIVEN))
667+
m4_if(ARG_CHECK_AVAILABLE, , [m4_define([ARG_CHECK_AVAILABLE], [:])])
668+
m4_if(ARG_CHECK_VALUE, , [m4_define([ARG_CHECK_VALUE], [:])])
669+
m4_if(ARG_CHECK_FOR_FILES, , [m4_define([ARG_CHECK_FOR_FILES], [:])])
670+
m4_if(ARG_IF_AUTO, , [m4_define([ARG_IF_AUTO], [:])])
671+
m4_if(ARG_IF_GIVEN, , [m4_define([ARG_IF_GIVEN], [:])])
672+
m4_if(ARG_IF_NOT_GIVEN, , [m4_define([ARG_IF_NOT_GIVEN], [:])])
668673
669674
##########################
670675
# Part 2: Set up autoconf shell code

0 commit comments

Comments
 (0)
Please sign in to comment.