gimp r27333 - in trunk: . plug-ins/metadata
- From: neo svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r27333 - in trunk: . plug-ins/metadata
- Date: Sun, 19 Oct 2008 16:55:42 +0000 (UTC)
Author: neo
Date: Sun Oct 19 16:55:42 2008
New Revision: 27333
URL: http://svn.gnome.org/viewvc/gimp?rev=27333&view=rev
Log:
2008-10-19 Sven Neumann <sven gimp org>
* plug-ins/metadata/xmp-parse.c: use GSlice to allocate structs.
Modified:
trunk/ChangeLog
trunk/plug-ins/metadata/xmp-parse.c
Modified: trunk/plug-ins/metadata/xmp-parse.c
==============================================================================
--- trunk/plug-ins/metadata/xmp-parse.c (original)
+++ trunk/plug-ins/metadata/xmp-parse.c Sun Oct 19 16:55:42 2008
@@ -247,6 +247,7 @@
va_start (args, format);
s = g_strdup_vprintf (format, args);
va_end (args);
+
g_markup_parse_context_get_position (context->markup_context,
&line_number,
&char_number);
@@ -336,10 +337,12 @@
if (string == NULL)
return TRUE;
+
/* XML accepts only 4 ASCII chars as whitespace and no other UNICODE chars */
for (p = string; *p; ++p)
if (*p != ' ' && *p != '\t' && *p != '\r' && *p != '\n')
return FALSE;
+
return TRUE;
}
@@ -359,6 +362,7 @@
context->xmp_prefix_len = strlen (prefix);
return;
}
+
if (! strcmp (uri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
{
g_free (context->rdf_prefix);
@@ -366,12 +370,14 @@
context->rdf_prefix_len = strlen (prefix);
return;
}
- ns = g_new (XMLNameSpace, 1);
+
+ ns = g_slice_new0 (XMLNameSpace);
ns->depth = context->depth;
ns->uri = g_strdup (uri);
ns->prefix = g_strdup (prefix);
ns->prefix_len = strlen (prefix);
context->namespaces = g_slist_prepend (context->namespaces, ns);
+
if (context->parser->start_schema)
ns->ns_user_data = (*context->parser->start_schema) (context,
ns->uri,
@@ -391,7 +397,9 @@
if (context->namespaces == NULL)
return;
+
ns = context->namespaces->data;
+
while (ns->depth >= context->depth)
{
if (context->parser->end_schema)
@@ -401,10 +409,13 @@
error);
g_free (ns->uri);
g_free (ns->prefix);
+ g_slice_free (XMLNameSpace, ns);
+
context->namespaces = g_slist_delete_link (context->namespaces,
context->namespaces);
if (context->namespaces == NULL)
break;
+
ns = context->namespaces->data;
}
}
@@ -416,6 +427,7 @@
{
if (ns == NULL)
return FALSE;
+
return ((strncmp (name, ns->prefix, ns->prefix_len) == 0)
&& (name[ns->prefix_len] == ':'));
}
@@ -429,6 +441,7 @@
{
if (prefix == NULL)
return FALSE;
+
return ((strncmp (name, prefix, prefix_len) == 0)
&& (strlen (name) > prefix_len + 1)
&& (name[prefix_len] == ':')
@@ -461,12 +474,14 @@
g_return_val_if_fail (context->property == NULL, NULL);
g_return_val_if_fail (context->prop_cur_value == -1, NULL);
+
/* element_name is a new property if it starts with a known prefix */
for (list = context->namespaces;
list != NULL;
list = g_slist_next (list))
{
ns = list->data;
+
if (has_ns_prefix (element_name, ns))
{
context->property = g_strdup (element_name + ns->prefix_len + 1);
@@ -476,6 +491,7 @@
return ns;
}
}
+
return NULL;
}
@@ -490,8 +506,10 @@
gchar *value)
{
g_return_if_fail (context->property != NULL);
+
if (type == XMP_PTYPE_TEXT || type == XMP_PTYPE_RESOURCE)
g_return_if_fail (context->prop_cur_value < 0);
+
if (context->property_type != type)
{
/* make sure that we are not mixing different types in this property */
@@ -515,6 +533,7 @@
}
else
g_assert (name == NULL);
+
context->prop_cur_value++;
context->prop_value[context->prop_cur_value] = value;
context->prop_value[context->prop_cur_value + 1] = NULL;
@@ -530,6 +549,7 @@
g_return_if_fail (context->property != NULL);
g_return_if_fail (context->prop_cur_value >= 0);
g_return_if_fail (context->prop_missing_value == TRUE);
+
context->prop_value[context->prop_cur_value] = value;
context->prop_missing_value = FALSE;
}
@@ -541,6 +561,7 @@
{
g_return_if_fail (context->property != NULL);
g_return_if_fail (context->prop_cur_value >= 0);
+
if (context->parser->set_property)
(*context->parser->set_property) (context,
context->property,
@@ -549,6 +570,7 @@
context->property_ns->ns_user_data,
context->user_data,
error);
+
if (! (context->flags & XMP_FLAG_DEFER_VALUE_FREE))
{
while (context->prop_cur_value >= 0)
@@ -556,8 +578,10 @@
g_free (context->prop_value[context->prop_cur_value]);
context->prop_cur_value--;
}
+
g_free (context->prop_value);
}
+
context->prop_value = NULL;
context->prop_cur_value = -1;
context->prop_max_value = 0;
@@ -1188,7 +1212,8 @@
* @parser: a #XMPParser
* @flags: one or more #XMPParseFlags
* @user_data: user data to pass to #GMarkupParser functions
- * @user_data_dnotify: user data destroy notifier called when the parse context is freed
+ * @user_data_dnotify: user data destroy notifier called when the
+ * parse context is freed
*
* Creates a new XMP parse context. A parse context is used to parse
* documents. You can feed any number of documents containing XMP
@@ -1204,11 +1229,11 @@
gpointer user_data,
GDestroyNotify user_data_dnotify)
{
- XMPParseContext *context;
+ XMPParseContext *context;
g_return_val_if_fail (parser != NULL, NULL);
- context = g_new (XMPParseContext, 1);
+ context = g_slice_new0 (XMPParseContext);
context->parser = parser;
context->flags = flags;
@@ -1251,12 +1276,14 @@
xmp_parse_context_free (XMPParseContext *context)
{
g_return_if_fail (context != NULL);
+
if (context->user_data_dnotify)
(* context->user_data_dnotify) (context->user_data);
g_slist_free (context->namespaces);
g_free (context->xmp_prefix);
g_free (context->rdf_prefix);
+
if (! (context->flags & XMP_FLAG_DEFER_VALUE_FREE))
{
while (context->prop_cur_value >= 0)
@@ -1266,8 +1293,9 @@
}
g_free (context->prop_value);
}
+
g_free (context->property);
- g_free (context);
+ g_slice_free (XMPParseContext, context);
}
/**
@@ -1310,20 +1338,26 @@
*/
/* FIXME: wrong, wrong, wrong! but useful for simple tests... */
gint i, e;
+
for (i = 0; i < text_len - 20; i++)
if (! strncmp (text + i, "<?xpacket begin=", 16))
{
for (e = i; e < text_len - 10; e++)
if (! strncmp (text + e, "<?xpacket end=", 14))
break;
+
while ((e < text_len) && *(text + e) != '>')
e++;
+
return g_markup_parse_context_parse (context->markup_context,
text + i, e - i + 1, error);
}
+
parse_error (context, error, XMP_ERROR_NO_XPACKET, NULL);
+
return FALSE;
}
+
return g_markup_parse_context_parse (context->markup_context,
text, text_len, error);
}
@@ -1350,5 +1384,6 @@
if (context->state == STATE_START)
parse_error (context, error, XMP_ERROR_NO_XPACKET, NULL);
+
return g_markup_parse_context_end_parse (context->markup_context, error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]