summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpmio/macro.c13
-rw-r--r--tests/rpmmacro.at37
2 files changed, 48 insertions, 2 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index 6b0201a4c..699fd3289 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -58,8 +58,8 @@ struct rpmMacroEntry_s {
struct rpmMacroContext_s {
rpmMacroEntry *tab; /*!< Macro entry table (array of pointers). */
int n; /*!< No. of macros. */
- int depth; /*!< Depth tracking when recursing from Lua */
- int level; /*!< Scope level tracking when recursing from Lua */
+ int depth; /*!< Depth tracking on external recursion */
+ int level; /*!< Scope level tracking when on external recursion */
pthread_mutex_t lock;
pthread_mutexattr_t lockattr;
};
@@ -586,7 +586,16 @@ static void doExpressionExpansion(MacroBuf mb, const char * expr, size_t len)
{
char *buf = rstrndup(expr, len);
char *result;
+ rpmMacroContext mc = mb->mc;
+ int odepth = mc->depth;
+ int olevel = mc->level;
+
+ mc->depth = mb->depth;
+ mc->level = mb->level;
result = rpmExprStrFlags(buf, RPMEXPR_EXPAND);
+ mc->depth = odepth;
+ mc->level = olevel;
+
if (!result) {
mb->error = 1;
goto exit;
diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at
index ffdbe26e2..99908d1eb 100644
--- a/tests/rpmmacro.at
+++ b/tests/rpmmacro.at
@@ -493,6 +493,43 @@ runroot rpm \
[])
AT_CLEANUP
+AT_SETUP([expression macro level])
+AT_KEYWORDS([macros])
+AT_CHECK([[
+runroot rpm \
+ --define 'expopt(r) %[%{undefined yyy} ? "aa " : "bb "]%{-r:the -r option was set}%{!-r:the -r option was not set}' \
+ --eval '%expopt' \
+ --eval '%expopt -r' \
+ --define 'yyy 1' \
+ --eval '%expopt' \
+ --eval '%expopt -r'
+]],
+[0],
+[aa the -r option was not set
+aa the -r option was set
+bb the -r option was not set
+bb the -r option was set
+],
+[])
+
+AT_CHECK([[
+runroot rpm \
+ --define 'expopt(r) %{expr:%{undefined yyy} ? "aa " : "bb "}%{-r:the -r option was set}%{!-r:the -r option was not set}' \
+ --eval '%expopt' \
+ --eval '%expopt -r' \
+ --define 'yyy 1' \
+ --eval '%expopt' \
+ --eval '%expopt -r'
+]],
+[0],
+[aa the -r option was not set
+aa the -r option was set
+bb the -r option was not set
+bb the -r option was set
+],
+[])
+AT_CLEANUP
+
AT_SETUP([short circuiting])
AT_KEYWORDS([macros])
AT_CHECK([