Added ndn_realloc
diff --git a/Makefile.am b/Makefile.am
index 0e49f84..eec64ed 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,7 +33,8 @@
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.c ndn-cpp/c/encoding/BinaryXMLStructureDecoder.h \
ndn-cpp/c/transport/TcpTransport.c ndn-cpp/c/transport/TcpTransport.c \
ndn-cpp/c/util/DynamicUCharArray.c ndn-cpp/c/util/DynamicUCharArray.h \
- ndn-cpp/c/util/ndn_memory.c ndn-cpp/c/util/ndn_memory.h
+ ndn-cpp/c/util/ndn_memory.c ndn-cpp/c/util/ndn_memory.h \
+ ndn-cpp/c/util/ndn_realloc.c ndn-cpp/c/util/ndn_realloc.h
libndn_cpp_a_SOURCES = \
config.h ndn-cpp/common.hpp \
diff --git a/Makefile.in b/Makefile.in
index dc90771..1fe0fe3 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -149,7 +149,8 @@
ndn-cpp/c/transport/TcpTransport.$(OBJEXT) \
ndn-cpp/c/transport/TcpTransport.$(OBJEXT) \
ndn-cpp/c/util/DynamicUCharArray.$(OBJEXT) \
- ndn-cpp/c/util/ndn_memory.$(OBJEXT)
+ ndn-cpp/c/util/ndn_memory.$(OBJEXT) \
+ ndn-cpp/c/util/ndn_realloc.$(OBJEXT)
libndn_c_a_OBJECTS = $(am_libndn_c_a_OBJECTS)
libndn_cpp_a_AR = $(AR) $(ARFLAGS)
libndn_cpp_a_LIBADD =
@@ -434,7 +435,8 @@
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.c ndn-cpp/c/encoding/BinaryXMLStructureDecoder.h \
ndn-cpp/c/transport/TcpTransport.c ndn-cpp/c/transport/TcpTransport.c \
ndn-cpp/c/util/DynamicUCharArray.c ndn-cpp/c/util/DynamicUCharArray.h \
- ndn-cpp/c/util/ndn_memory.c ndn-cpp/c/util/ndn_memory.h
+ ndn-cpp/c/util/ndn_memory.c ndn-cpp/c/util/ndn_memory.h \
+ ndn-cpp/c/util/ndn_realloc.c ndn-cpp/c/util/ndn_realloc.h
libndn_cpp_a_SOURCES = \
config.h ndn-cpp/common.hpp \
@@ -609,6 +611,8 @@
ndn-cpp/c/util/$(DEPDIR)/$(am__dirstamp)
ndn-cpp/c/util/ndn_memory.$(OBJEXT): ndn-cpp/c/util/$(am__dirstamp) \
ndn-cpp/c/util/$(DEPDIR)/$(am__dirstamp)
+ndn-cpp/c/util/ndn_realloc.$(OBJEXT): ndn-cpp/c/util/$(am__dirstamp) \
+ ndn-cpp/c/util/$(DEPDIR)/$(am__dirstamp)
libndn-c.a: $(libndn_c_a_OBJECTS) $(libndn_c_a_DEPENDENCIES) $(EXTRA_libndn_c_a_DEPENDENCIES)
$(AM_V_at)-rm -f libndn-c.a
@@ -764,6 +768,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/transport/$(DEPDIR)/TcpTransport.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/util/$(DEPDIR)/DynamicUCharArray.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/util/$(DEPDIR)/ndn_memory.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/util/$(DEPDIR)/ndn_realloc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/$(DEPDIR)/BinaryXMLElementReader.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/$(DEPDIR)/BinaryXMLWireFormat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/$(DEPDIR)/WireFormat.Po@am__quote@
diff --git a/ndn-cpp/c/util/ndn_realloc.c b/ndn-cpp/c/util/ndn_realloc.c
new file mode 100644
index 0000000..397834b
--- /dev/null
+++ b/ndn-cpp/c/util/ndn_realloc.c
@@ -0,0 +1,12 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <stdlib.h>
+#include "ndn_realloc.h"
+
+unsigned char *ndn_realloc(unsigned char *array, unsigned int length)
+{
+ return (unsigned char *)realloc(array, length);
+}
diff --git a/ndn-cpp/c/util/ndn_realloc.h b/ndn-cpp/c/util/ndn_realloc.h
new file mode 100644
index 0000000..db9470d
--- /dev/null
+++ b/ndn-cpp/c/util/ndn_realloc.h
@@ -0,0 +1,26 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_NDN_REALLOC_H
+#define NDN_NDN_REALLOC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Wrap the C stdlib realloc to convert to/from void * to unsigned char *.
+ * This can be used by ndn_DynamicUCharArray_init.
+ * @param array the allocated array buffer to realloc
+ * @param length the length for the new array buffer
+ * @return the new allocated array buffer
+ */
+unsigned char *ndn_realloc(unsigned char *array, unsigned int length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/ndn-cpp/encoding/BinaryXMLEncoder.hpp b/ndn-cpp/encoding/BinaryXMLEncoder.hpp
index a879963..2ae5196 100644
--- a/ndn-cpp/encoding/BinaryXMLEncoder.hpp
+++ b/ndn-cpp/encoding/BinaryXMLEncoder.hpp
@@ -6,8 +6,8 @@
#ifndef NDN_BINARYXMLENCODER_HPP
#define NDN_BINARYXMLENCODER_HPP
-#include <cstdlib>
#include <vector>
+#include "../c/util/ndn_realloc.h"
#include "../c/encoding/BinaryXMLEncoder.h"
namespace ndn {
@@ -23,18 +23,7 @@
BinaryXMLEncoder()
{
const unsigned int initialLength = 16;
- ndn_BinaryXMLEncoder_init(this, (unsigned char *)malloc(initialLength), initialLength, simpleRealloc);
- }
-
- /**
- * Wrap the C stdlib realloc to convert to/from void * to unsigned char *.
- * @param array the allocated array buffer to realloc
- * @param length the length for the new array buffer
- * @return the new allocated array buffer
- */
- static unsigned char *simpleRealloc(unsigned char *array, unsigned int length)
- {
- return (unsigned char *)realloc(array, length);
+ ndn_BinaryXMLEncoder_init(this, (unsigned char *)malloc(initialLength), initialLength, ndn_realloc);
}
/**