Skip to content

Commit

Permalink
Implement mxmlOptions APIs to normalize all of the load/save option s…
Browse files Browse the repository at this point in the history
…tuff (Issue #312)
  • Loading branch information
michaelrsweet committed Mar 19, 2024
1 parent 726dc0d commit e676eb3
Show file tree
Hide file tree
Showing 18 changed files with 1,030 additions and 1,298 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
`MXML_TYPE_DIRECTIVE` node types (Issue #250)
- Added `mxmlLoadFilename` and `mxmlSaveFilename` functions (Issue #291)
- Added AFL fuzzing support (Issue #306)
- Added `mxmlOptions` APIs to replace the long list of callbacks and options for
each of the load and save functions (Issue #312)
- Added string copy/free callbacks to support alternate memory management of
strings.
- Renamed `mxml_type_t` enumerations to `MXML_TYPE_xxx` (Issue #251)
Expand Down
4 changes: 2 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ BUILDROOT = $(DSTROOT)$(DESTDIR)

DOCFILES = doc/mxml.epub doc/mxml.html doc/mxml-cover.png \
CHANGES.md LICENSE NOTICE README.md
PUBLIBOBJS = mxml-attr.o mxml-entity.o mxml-file.o mxml-get.o \
mxml-index.o mxml-node.o mxml-search.o mxml-set.o
PUBLIBOBJS = mxml-attr.o mxml-file.o mxml-get.o mxml-index.o \
mxml-node.o mxml-options.o mxml-search.o mxml-set.o
LIBOBJS = $(PUBLIBOBJS) mxml-private.o
OBJS = testmxml.o $(LIBOBJS)
ALLTARGETS = $(LIBMXML) testmxml
Expand Down
3 changes: 3 additions & 0 deletions doc/body.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ copyright: Copyright © 2003-2024, All Rights Reserved.
version: 4.0
...

> TODO: Update for mxmlOptions APIs!


Introduction
============

Expand Down
18 changes: 5 additions & 13 deletions mxml-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ mxmlElementSetAttr(mxml_node_t *node, // I - Element node
if (value)
{
if ((valuec = _mxml_strcopy(value)) == NULL)
{
_mxml_error("Unable to allocate memory for attribute '%s' in element %s.", name, node->value.element.name);
return;
}
}
else
{
Expand Down Expand Up @@ -218,10 +215,11 @@ mxmlElementSetAttrf(mxml_node_t *node, // I - Element node
vsnprintf(buffer, sizeof(buffer), format, ap);
va_end(ap);

if ((value = _mxml_strcopy(buffer)) == NULL)
_mxml_error("Unable to allocate memory for attribute '%s' in element %s.", name, node->value.element.name);
else if (!mxml_set_attr(node, name, value))
_mxml_strfree(value);
if ((value = _mxml_strcopy(buffer)) != NULL)
{
if (!mxml_set_attr(node, name, value))
_mxml_strfree(value);
}
}


Expand Down Expand Up @@ -253,19 +251,13 @@ mxml_set_attr(mxml_node_t *node, // I - Element node

// Add a new attribute...
if ((attr = realloc(node->value.element.attrs, (node->value.element.num_attrs + 1) * sizeof(_mxml_attr_t))) == NULL)
{
_mxml_error("Unable to allocate memory for attribute '%s' in element %s.", name, node->value.element.name);
return (false);
}

node->value.element.attrs = attr;
attr += node->value.element.num_attrs;

if ((attr->name = _mxml_strcopy(name)) == NULL)
{
_mxml_error("Unable to allocate memory for attribute '%s' in element %s.", name, node->value.element.name);
return (false);
}

attr->value = value;

Expand Down
Loading

0 comments on commit e676eb3

Please sign in to comment.