* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
#undef STRICT
#endif
+static void
+FcExprDestroy (FcExpr *e);
void
FcTestDestroy (FcTest *test)
free (test);
}
-FcExpr *
-FcExprCreateInteger (int i)
+static FcExpr *
+FcExprAlloc (void)
{
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
+ if (e)
+ FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
+
+ return e;
+}
+
+static FcExpr *
+FcExprCreateInteger (int i)
+{
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = FcOpInteger;
e->u.ival = i;
}
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateDouble (double d)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = FcOpDouble;
e->u.dval = d;
}
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateString (const FcChar8 *s)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = FcOpString;
e->u.sval = FcStrCopy (s);
}
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateMatrix (const FcMatrix *m)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = FcOpMatrix;
e->u.mval = FcMatrixCopy (m);
}
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateBool (FcBool b)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = FcOpBool;
e->u.bval = b;
}
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateNil (void)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateField (const char *field)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = FcOpField;
e->u.object = FcObjectFromName (field);
}
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateConst (const FcChar8 *constant)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = FcOpConst;
e->u.constant = FcStrCopy (constant);
}
return e;
}
-FcExpr *
+static FcExpr *
FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right)
{
- FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
-
+ FcExpr *e = FcExprAlloc ();
if (e)
{
- FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
e->op = op;
e->u.tree.left = left;
e->u.tree.right = right;
return e;
}
-void
+static void
FcExprDestroy (FcExpr *e)
{
if (!e)
free (e);
}
-char *
-FcConfigSaveField (const char *field)
-{
- return (char *) FcStrCopy ((FcChar8 *) field);
-}
-
typedef enum _FcElement {
FcElementNone,
FcElementFontconfig,
FcElement element;
FcChar8 **attr;
FcStrBuf str;
+ FcChar8 *attr_buf_static[16];
} FcPStack;
typedef enum _FcVStackTag {
}
static FcChar8 **
-FcConfigSaveAttr (const XML_Char **attr)
+FcConfigSaveAttr (const XML_Char **attr, FcChar8 **buf, int size_bytes)
{
int slen;
int i;
slen += strlen ((char *) attr[i]) + 1;
if (i == 0)
return 0;
- new = malloc ((i + 1) * sizeof (FcChar8 *) + slen);
- if (!new)
+ slen += (i + 1) * sizeof (FcChar8 *);
+ if (slen <= size_bytes)
+ new = buf;
+ else
{
- FcConfigMessage (0, FcSevereError, "out of memory");
- return 0;
+ new = malloc (slen);
+ if (!new)
+ {
+ FcConfigMessage (0, FcSevereError, "out of memory");
+ return 0;
+ }
+ FcMemAlloc (FC_MEM_ATTR, 1); /* size is too expensive */
}
- FcMemAlloc (FC_MEM_ATTR, 1); /* size is too expensive */
s = (FcChar8 *) (new + (i + 1));
for (i = 0; attr[i]; i++)
{
new->prev = parse->pstack;
new->element = element;
- new->attr = FcConfigSaveAttr (attr);
+ new->attr = FcConfigSaveAttr (attr, new->attr_buf_static, sizeof (new->attr_buf_static));
FcStrBufInit (&new->str, 0, 0);
parse->pstack = new;
return FcTrue;
old = parse->pstack;
parse->pstack = old->prev;
FcStrBufDestroy (&old->str);
- if (old->attr)
+ if (old->attr && old->attr != old->attr_buf_static)
{
FcMemFree (FC_MEM_ATTR, 1); /* size is to expensive */
free (old->attr);