Make ndn_DynamicUCharArray realloc take a self pointer.
diff --git a/ndn-cpp/c/encoding/binary-xml-element-reader.h b/ndn-cpp/c/encoding/binary-xml-element-reader.h
index 85ea934..4edd145 100644
--- a/ndn-cpp/c/encoding/binary-xml-element-reader.h
+++ b/ndn-cpp/c/encoding/binary-xml-element-reader.h
@@ -57,7 +57,7 @@
*/
static inline void ndn_BinaryXmlElementReader_init
(struct ndn_BinaryXmlElementReader *self, struct ndn_ElementListener *elementListener,
- unsigned char *buffer, unsigned int bufferLength, unsigned char * (*reallocFunction)(unsigned char *, unsigned int))
+ unsigned char *buffer, unsigned int bufferLength, unsigned char * (*reallocFunction)(struct ndn_DynamicUCharArray *self, unsigned char *, unsigned int))
{
self->elementListener = elementListener;
ndn_BinaryXmlStructureDecoder_init(&self->structureDecoder);
diff --git a/ndn-cpp/c/encoding/binary-xml-encoder.h b/ndn-cpp/c/encoding/binary-xml-encoder.h
index ba67e8f..5ebd4ac 100644
--- a/ndn-cpp/c/encoding/binary-xml-encoder.h
+++ b/ndn-cpp/c/encoding/binary-xml-encoder.h
@@ -32,7 +32,7 @@
*/
static inline void ndn_BinaryXmlEncoder_init
(struct ndn_BinaryXmlEncoder *self, unsigned char *outputArray, unsigned int outputArrayLength,
- unsigned char * (*reallocFunction)(unsigned char *, unsigned int))
+ unsigned char * (*reallocFunction)(struct ndn_DynamicUCharArray *self, unsigned char *, unsigned int))
{
ndn_DynamicUCharArray_init(&self->output, outputArray, outputArrayLength, reallocFunction);
self->offset = 0;
diff --git a/ndn-cpp/c/util/dynamic-uchar-array.c b/ndn-cpp/c/util/dynamic-uchar-array.c
index 208544f..d961e7f 100644
--- a/ndn-cpp/c/util/dynamic-uchar-array.c
+++ b/ndn-cpp/c/util/dynamic-uchar-array.c
@@ -16,7 +16,7 @@
// The needed length is much greater, so use it.
newLength = length;
- unsigned char *newArray = (*self->realloc)(self->array, newLength);
+ unsigned char *newArray = (*self->realloc)(self, self->array, newLength);
if (!newArray)
return NDN_ERROR_DynamicUCharArray_realloc_failed;
diff --git a/ndn-cpp/c/util/dynamic-uchar-array.h b/ndn-cpp/c/util/dynamic-uchar-array.h
index cdcdcdd..101b5f3 100644
--- a/ndn-cpp/c/util/dynamic-uchar-array.h
+++ b/ndn-cpp/c/util/dynamic-uchar-array.h
@@ -16,10 +16,12 @@
struct ndn_DynamicUCharArray {
unsigned char *array; /**< the allocated array buffer */
unsigned int length; /**< the length of the allocated array buffer */
- unsigned char * (*realloc)(unsigned char *array, unsigned int length); /**< a pointer to a function that reallocates array and returns a new pointer to a buffer of
- * length bytes, or 0 for error. On success, the contents of the old buffer are copied to the new one.
- * On success, the original array pointer will no longer be used.
- * This function pointer may be 0 (which causes an error if a reallocate is necessary). */
+ unsigned char * (*realloc)
+ (struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length); /**< a pointer to a function that reallocates array and returns a new pointer to a buffer of
+ * length bytes, or 0 for error. On success, the contents of the old buffer are copied to the new one.
+ * On success, the original array pointer will no longer be used.
+ * self is a pointer to the struct ndn_DynamicUCharArray which is calling realloc.
+ * This function pointer may be 0 (which causes an error if a reallocate is necessary). */
};
/**
@@ -30,7 +32,8 @@
* @param reallocFunction see ndn_DynamicUCharArray_ensureLength. This may be 0.
*/
static inline void ndn_DynamicUCharArray_init
- (struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length, unsigned char * (*reallocFunction)(unsigned char *, unsigned int))
+ (struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length,
+ unsigned char * (*reallocFunction)(struct ndn_DynamicUCharArray *self, unsigned char *, unsigned int))
{
self->array = array;
self->length = length;
diff --git a/ndn-cpp/c/util/ndn_realloc.c b/ndn-cpp/c/util/ndn_realloc.c
index 397834b..bbc5e15 100644
--- a/ndn-cpp/c/util/ndn_realloc.c
+++ b/ndn-cpp/c/util/ndn_realloc.c
@@ -6,7 +6,7 @@
#include <stdlib.h>
#include "ndn_realloc.h"
-unsigned char *ndn_realloc(unsigned char *array, unsigned int length)
+unsigned char *ndn_realloc(struct ndn_DynamicUCharArray *self, 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
index bca997a..148fc2c 100644
--- a/ndn-cpp/c/util/ndn_realloc.h
+++ b/ndn-cpp/c/util/ndn_realloc.h
@@ -6,6 +6,8 @@
#ifndef NDN_NDN_REALLOC_H
#define NDN_NDN_REALLOC_H
+#include "dynamic-uchar-array.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -13,11 +15,12 @@
/**
* 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
+ * @param self This is ignored.
+ * @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);
+unsigned char *ndn_realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length);
#ifdef __cplusplus
}