From 0907589a79d05aeed9bc6bff783838b0eb25736b Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Fri, 28 Jun 2013 15:54:38 +0900 Subject: [PATCH] Fix the behavior of intermixed tests end edits in match to get the following recipe working: as: --- src/fccfg.c | 27 ++++++++++++++++----------- src/fcint.h | 1 + src/fcxml.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/fccfg.c b/src/fccfg.c index 9c0be24..3cf31e8 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -226,20 +226,25 @@ FcSubstDestroy (FcSubst *s) FcExpr * FcConfigAllocExpr (FcConfig *config) { - if (!config->expr_pool || config->expr_pool->next == config->expr_pool->end) - { - FcExprPage *new_page; + FcExpr *e; - new_page = malloc (sizeof (FcExprPage)); - if (!new_page) - return 0; + if (!config->expr_pool || config->expr_pool->next == config->expr_pool->end) + { + FcExprPage *new_page; - new_page->next_page = config->expr_pool; - new_page->next = new_page->exprs; - config->expr_pool = new_page; - } + new_page = malloc (sizeof (FcExprPage)); + if (!new_page) + return 0; - return config->expr_pool->next++; + new_page->next_page = config->expr_pool; + new_page->next = new_page->exprs; + config->expr_pool = new_page; + } + + e = config->expr_pool->next++; + FcRefInit (&e->ref, 1); + + return e; } FcConfig * diff --git a/src/fcint.h b/src/fcint.h index 0137dee..92777ea 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -240,6 +240,7 @@ typedef struct _FcExprName { typedef struct _FcExpr { FcOp op; + FcRef ref; union { int ival; double dval; diff --git a/src/fcxml.c b/src/fcxml.c index 7e03230..4b8049f 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -223,11 +223,24 @@ FcExprCreateOp (FcConfig *config, FcExpr *left, FcOp op, FcExpr *right) return e; } +static FcExpr * +FcExprReference (FcExpr *e) +{ + if (e) + { + FcRefInc (&e->ref); + } + + return e; +} + static void FcExprDestroy (FcExpr *e) { if (!e) return; + if (FcRefDec (&e->ref) != 1) + return; switch (FC_OP_GET_OP (e->op)) { case FcOpInteger: break; @@ -727,6 +740,21 @@ FcTestCreate (FcConfigParse *parse, return test; } +static FcTest * +FcTestDuplicate (FcTest *test) +{ + FcTest *retval = (FcTest *) malloc (sizeof (FcTest)); + + if (retval) + { + memcpy (retval, test, sizeof (FcTest)); + retval->next = NULL; + retval->expr = FcExprReference (test->expr); + } + + return retval; +} + static FcEdit * FcEditCreate (FcConfigParse *parse, FcObject object, @@ -2401,7 +2429,7 @@ FcParseMatch (FcConfigParse *parse) FcVStack *vstack; FcBool tested = FcFalse; FcSubstStack *sstack = NULL; - int len, pos = 0; + int len, pos = 0, i; kind_name = FcConfigGetAttribute (parse, "target"); if (!kind_name) @@ -2438,6 +2466,13 @@ FcParseMatch (FcConfigParse *parse) test = vstack->u.test; vstack->tag = FcVStackNone; tested = FcTrue; + for (i = 0; i < pos; i++) + { + FcTest *t = FcTestDuplicate(test); + + t->next = sstack[i].test; + sstack[i].test = t; + } break; case FcVStackEdit: /* due to the reverse traversal, node appears faster than