[Fontconfig] [PATCH 2/2] Use const more often

Keith Packard keithp at keithp.com
Thu Dec 31 12:49:19 PST 2009


This eliminates several warnings about improper const usage as well as
making it more prevalent in the implementation.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 fc-lang/fc-lang.c |    6 +++---
 src/fccache.c     |    2 +-
 src/fccfg.c       |    8 ++++----
 src/fcint.h       |   18 +++++++++---------
 src/fcxml.c       |   14 +++++++-------
 5 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c
index 21d568d..5b776b7 100644
--- a/fc-lang/fc-lang.c
+++ b/fc-lang/fc-lang.c
@@ -129,7 +129,7 @@ static const FcCharSet *
 scan (FILE *f, char *file, FcCharSetFreezer *freezer)
 {
     FcCharSet	    *c = 0;
-    FcCharSet	    *n;
+    const FcCharSet *n;
     int		    start, end, ucs4;
     char	    line[1024];
     int		    lineno = 0;
@@ -155,7 +155,7 @@ scan (FILE *f, char *file, FcCharSetFreezer *freezer)
 		c = FcCharSetCreate ();
 	    if (!FcCharSetMerge (c, n, NULL))
 		fatal (file, lineno, "out of memory");
-	    FcCharSetDestroy (n);
+	    FcCharSetDestroy ((FcCharSet *) n);
 	    continue;
 	}
 	if (strchr (line, '-'))
@@ -232,7 +232,7 @@ typedef struct _Entry {
 static int compare (const void *a, const void *b)
 {
     const Entry const *as = a, *bs = b;
-    return FcStrCmpIgnoreCase (as->file, bs->file);
+    return FcStrCmpIgnoreCase ((const FcChar8 *) as->file, (const FcChar8 *) bs->file);
 }
 
 #define MAX_LANG	    1024
diff --git a/src/fccache.c b/src/fccache.c
index a59e0a3..b00de08 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -944,7 +944,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
      */
     if (cache->size < FC_CACHE_MIN_MMAP &&
 	(skip = FcCacheFindByAddr (cache)) &&
-	FcStat (cache_hashed, &cache_stat))
+	FcStat ((const char *) cache_hashed, &cache_stat))
     {
 	skip->cache_dev = cache_stat.st_dev;
 	skip->cache_ino = cache_stat.st_ino;
diff --git a/src/fccfg.c b/src/fccfg.c
index 0f89b57..ee9dadc 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -866,7 +866,7 @@ FcConfigCompareValue (const FcValue	*left_o,
 #define FcDoubleTrunc(d)	((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
 
 static FcValue
-FcConfigEvaluate (FcPattern *p, FcExpr *e)
+FcConfigEvaluate (FcPattern *p, const FcExpr *e)
 {
     FcValue	v, vl, vr;
     FcResult	r;
@@ -908,7 +908,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
 	v = FcValueSave (v);
 	break;
     case FcOpConst:
-	if (FcNameConstant (e->u.constant, &v.u.i))
+	if (FcNameConstant ((FcChar8 *) e->u.constant, &v.u.i))
 	    v.type = FcTypeInteger;
 	else
 	    v.type = FcTypeVoid;
@@ -1136,7 +1136,7 @@ FcConfigMatchValueList (FcPattern	*p,
 			FcValueList	*values)
 {
     FcValueList	    *ret = 0;
-    FcExpr	    *e = t->expr;
+    const FcExpr    *e = t->expr;
     FcValue	    value;
     FcValueList	    *v;
     
@@ -1177,7 +1177,7 @@ FcConfigMatchValueList (FcPattern	*p,
 }
 
 static FcValueList *
-FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
+FcConfigValues (FcPattern *p, const FcExpr *e, FcValueBinding binding)
 {
     FcValueList	*l;
     
diff --git a/src/fcint.h b/src/fcint.h
index 233b4c3..b847779 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -233,16 +233,16 @@ typedef enum _FcOp {
 typedef struct _FcExpr {
     FcOp   op;
     union {
-	int	    ival;
-	double	    dval;
-	FcChar8	    *sval;
-	FcMatrix    *mval;
-	FcBool	    bval;
-	FcCharSet   *cval;
-	FcObject    object;
-	FcChar8	    *constant;
+	int	    	ival;
+	double	    	dval;
+	const FcChar8	*sval;
+	const FcMatrix	*mval;
+	FcBool	    	bval;
+	const FcCharSet *cval;
+	FcObject    	object;
+	const FcChar8	*constant;
 	struct {
-	    struct _FcExpr *left, *right;
+	    const struct _FcExpr *left, *right;
 	} tree;
     } u;
 } FcExpr;
diff --git a/src/fcxml.c b/src/fcxml.c
index 9428468..6a5a452 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -61,7 +61,7 @@
 #endif
 
 static void
-FcExprDestroy (FcExpr *e);
+FcExprDestroy (const FcExpr *e);
 
 void
 FcTestDestroy (FcTest *test)
@@ -171,7 +171,7 @@ FcExprCreateOp (FcConfig *config, FcExpr *left, FcOp op, FcExpr *right)
 }
 
 static void
-FcExprDestroy (FcExpr *e)
+FcExprDestroy (const FcExpr *e)
 {
     if (!e)
 	return;
@@ -183,10 +183,10 @@ FcExprDestroy (FcExpr *e)
     case FcOpString:
 	break;
     case FcOpMatrix:
-	FcMatrixFree (e->u.mval);
+	FcMatrixFree ((FcMatrix *) e->u.mval);
 	break;
     case FcOpCharSet:
-	FcCharSetDestroy (e->u.cval);
+	FcCharSetDestroy ((FcCharSet *) e->u.cval);
 	break;
     case FcOpBool:
 	break;
@@ -232,7 +232,7 @@ FcExprDestroy (FcExpr *e)
 	break;
     }
 
-    e->op = FcOpNil;
+    ((FcExpr *) e)->op = FcOpNil;
 }
 
 void
@@ -525,7 +525,7 @@ FcTypecheckValue (FcConfigParse *parse, FcType value, FcType type)
 }
 
 static void
-FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
+FcTypecheckExpr (FcConfigParse *parse, const FcExpr *expr, FcType type)
 {
     const FcObjectType	*o;
     const FcConstant	*c;
@@ -559,7 +559,7 @@ FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
 	    FcTypecheckValue (parse, o->type, type);
 	break;
     case FcOpConst:
-	c = FcNameGetConstant (expr->u.constant);
+	c = FcNameGetConstant ((FcChar8 *) expr->u.constant);
 	if (c)
 	{
 	    o = FcNameGetObjectType (c->object);
-- 
1.6.5.7



More information about the Fontconfig mailing list