summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-12-14 23:14:09 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2013-12-14 23:14:09 (GMT)
commit8e48b931091cbc99abeffacc7af80f363495ec23 (patch)
tree8aec6c47ec54e425884f646b08a9e28b216b3ebe
parenta4e3ccd6abb97d05121635112bdca44fc0e440b0 (diff)
downloadlibparserutils-8e48b931091cbc99abeffacc7af80f363495ec23.tar.gz
libparserutils-8e48b931091cbc99abeffacc7af80f363495ec23.tar.bz2
Remove client allocation function.
-rw-r--r--include/parserutils/charset/codec.h1
-rw-r--r--include/parserutils/functypes.h3
-rw-r--r--include/parserutils/input/inputstream.h1
-rw-r--r--include/parserutils/utils/buffer.h6
-rw-r--r--include/parserutils/utils/stack.h2
-rw-r--r--include/parserutils/utils/vector.h3
-rw-r--r--src/charset/codec.c12
-rw-r--r--src/charset/codecs/codec_8859.c6
-rw-r--r--src/charset/codecs/codec_ascii.c8
-rw-r--r--src/charset/codecs/codec_ext8.c6
-rw-r--r--src/charset/codecs/codec_impl.h4
-rw-r--r--src/charset/codecs/codec_utf16.c8
-rw-r--r--src/charset/codecs/codec_utf8.c6
-rw-r--r--src/input/filter.c25
-rw-r--r--src/input/filter.h2
-rw-r--r--src/input/inputstream.c29
-rw-r--r--src/utils/buffer.c25
-rw-r--r--src/utils/stack.c26
-rw-r--r--src/utils/vector.c28
-rw-r--r--test/cscodec-8859.c12
-rw-r--r--test/cscodec-ext8.c12
-rw-r--r--test/cscodec-utf16.c11
-rw-r--r--test/cscodec-utf8.c11
-rw-r--r--test/filter.c10
-rw-r--r--test/inputstream.c9
-rw-r--r--test/regression/filter-badenc-segv.c10
-rw-r--r--test/regression/filter-segv.c10
-rw-r--r--test/regression/stream-nomem.c9
28 files changed, 72 insertions, 223 deletions
diff --git a/include/parserutils/charset/codec.h b/include/parserutils/charset/codec.h
index 96934a6..0365643 100644
--- a/include/parserutils/charset/codec.h
+++ b/include/parserutils/charset/codec.h
@@ -90,7 +90,6 @@ typedef union parserutils_charset_codec_optparams {
/* Create a charset codec */
parserutils_error parserutils_charset_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec);
/* Destroy a charset codec */
parserutils_error parserutils_charset_codec_destroy(
diff --git a/include/parserutils/functypes.h b/include/parserutils/functypes.h
index 7ff626d..174bca2 100644
--- a/include/parserutils/functypes.h
+++ b/include/parserutils/functypes.h
@@ -19,9 +19,6 @@ extern "C"
#include <parserutils/types.h>
-/* Type of allocation function for parserutils */
-typedef void *(*parserutils_alloc)(void *ptr, size_t size, void *pw);
-
#ifdef __cplusplus
}
#endif
diff --git a/include/parserutils/input/inputstream.h b/include/parserutils/input/inputstream.h
index 1fd95e9..eb33307 100644
--- a/include/parserutils/input/inputstream.h
+++ b/include/parserutils/input/inputstream.h
@@ -48,7 +48,6 @@ typedef struct parserutils_inputstream
/* Create an input stream */
parserutils_error parserutils_inputstream_create(const char *enc,
uint32_t encsrc, parserutils_charset_detect_func csdetect,
- parserutils_alloc alloc, void *pw,
parserutils_inputstream **stream);
/* Destroy an input stream */
parserutils_error parserutils_inputstream_destroy(
diff --git a/include/parserutils/utils/buffer.h b/include/parserutils/utils/buffer.h
index cf3cb02..9425070 100644
--- a/include/parserutils/utils/buffer.h
+++ b/include/parserutils/utils/buffer.h
@@ -21,14 +21,10 @@ struct parserutils_buffer
uint8_t *data;
size_t length;
size_t allocated;
-
- parserutils_alloc alloc;
- void *pw;
};
typedef struct parserutils_buffer parserutils_buffer;
-parserutils_error parserutils_buffer_create(parserutils_alloc alloc,
- void *pw, parserutils_buffer **buffer);
+parserutils_error parserutils_buffer_create(parserutils_buffer **buffer);
parserutils_error parserutils_buffer_destroy(parserutils_buffer *buffer);
parserutils_error parserutils_buffer_append(parserutils_buffer *buffer,
diff --git a/include/parserutils/utils/stack.h b/include/parserutils/utils/stack.h
index 5bfe412..60f2d71 100644
--- a/include/parserutils/utils/stack.h
+++ b/include/parserutils/utils/stack.h
@@ -22,7 +22,7 @@ struct parserutils_stack;
typedef struct parserutils_stack parserutils_stack;
parserutils_error parserutils_stack_create(size_t item_size, size_t chunk_size,
- parserutils_alloc alloc, void *pw, parserutils_stack **stack);
+ parserutils_stack **stack);
parserutils_error parserutils_stack_destroy(parserutils_stack *stack);
parserutils_error parserutils_stack_push(parserutils_stack *stack,
diff --git a/include/parserutils/utils/vector.h b/include/parserutils/utils/vector.h
index ca4f06a..f01f00e 100644
--- a/include/parserutils/utils/vector.h
+++ b/include/parserutils/utils/vector.h
@@ -22,8 +22,7 @@ struct parserutils_vector;
typedef struct parserutils_vector parserutils_vector;
parserutils_error parserutils_vector_create(size_t item_size,
- size_t chunk_size, parserutils_alloc alloc, void *pw,
- parserutils_vector **vector);
+ size_t chunk_size, parserutils_vector **vector);
parserutils_error parserutils_vector_destroy(parserutils_vector *vector);
parserutils_error parserutils_vector_append(parserutils_vector *vector,
diff --git a/src/charset/codec.c b/src/charset/codec.c
index ed095cc..3267f1f 100644
--- a/src/charset/codec.c
+++ b/src/charset/codec.c
@@ -29,8 +29,6 @@ static parserutils_charset_handler *handler_table[] = {
* Create a charset codec
*
* \param charset Target charset
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data (may be NULL)
* \param codec Pointer to location to receive codec instance
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
@@ -38,7 +36,6 @@ static parserutils_charset_handler *handler_table[] = {
* PARSERUTILS_BADENCODING on unsupported charset
*/
parserutils_error parserutils_charset_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec)
{
parserutils_charset_codec *c;
@@ -46,7 +43,7 @@ parserutils_error parserutils_charset_codec_create(const char *charset,
const parserutils_charset_aliases_canon * canon;
parserutils_error error;
- if (charset == NULL || alloc == NULL || codec == NULL)
+ if (charset == NULL || codec == NULL)
return PARSERUTILS_BADPARM;
/* Canonicalise parserutils_charset name. */
@@ -66,7 +63,7 @@ parserutils_error parserutils_charset_codec_create(const char *charset,
return PARSERUTILS_BADENCODING;
/* Instantiate class */
- error = (*handler)->create(canon->name, alloc, pw, &c);
+ error = (*handler)->create(canon->name, &c);
if (error != PARSERUTILS_OK)
return error;
@@ -75,9 +72,6 @@ parserutils_error parserutils_charset_codec_create(const char *charset,
c->errormode = PARSERUTILS_CHARSET_CODEC_ERROR_LOOSE;
- c->alloc = alloc;
- c->alloc_pw = pw;
-
*codec = c;
return PARSERUTILS_OK;
@@ -97,7 +91,7 @@ parserutils_error parserutils_charset_codec_destroy(
codec->handler.destroy(codec);
- codec->alloc(codec, 0, codec->alloc_pw);
+ free(codec);
return PARSERUTILS_OK;
}
diff --git a/src/charset/codecs/codec_8859.c b/src/charset/codecs/codec_8859.c
index d323ca0..0ab4c32 100644
--- a/src/charset/codecs/codec_8859.c
+++ b/src/charset/codecs/codec_8859.c
@@ -64,7 +64,6 @@ typedef struct charset_8859_codec {
static bool charset_8859_codec_handles_charset(const char *charset);
static parserutils_error charset_8859_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec);
static parserutils_error charset_8859_codec_destroy(
parserutils_charset_codec *codec);
@@ -123,15 +122,12 @@ bool charset_8859_codec_handles_charset(const char *charset)
* Create an ISO-8859-n codec
*
* \param charset The charset to read from / write to
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data (may be NULL)
* \param codec Pointer to location to receive codec
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhausion
*/
parserutils_error charset_8859_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec)
{
uint32_t i;
@@ -149,7 +145,7 @@ parserutils_error charset_8859_codec_create(const char *charset,
assert(table != NULL);
- c = alloc(NULL, sizeof(charset_8859_codec), pw);
+ c = malloc(sizeof(charset_8859_codec));
if (c == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/charset/codecs/codec_ascii.c b/src/charset/codecs/codec_ascii.c
index b73280c..64991df 100644
--- a/src/charset/codecs/codec_ascii.c
+++ b/src/charset/codecs/codec_ascii.c
@@ -37,8 +37,7 @@ typedef struct charset_ascii_codec {
static bool charset_ascii_codec_handles_charset(const char *charset);
static parserutils_error charset_ascii_codec_create(
- const char *charset, parserutils_alloc alloc, void *pw,
- parserutils_charset_codec **codec);
+ const char *charset, parserutils_charset_codec **codec);
static parserutils_error charset_ascii_codec_destroy(
parserutils_charset_codec *codec);
static parserutils_error charset_ascii_codec_encode(
@@ -90,22 +89,19 @@ bool charset_ascii_codec_handles_charset(const char *charset)
* Create a US-ASCII codec
*
* \param charset The charset to read from / write to
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data (may be NULL)
* \param codec Pointer to location to receive codec
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhausion
*/
parserutils_error charset_ascii_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec)
{
charset_ascii_codec *c;
UNUSED(charset);
- c = alloc(NULL, sizeof(charset_ascii_codec), pw);
+ c = malloc(sizeof(charset_ascii_codec));
if (c == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/charset/codecs/codec_ext8.c b/src/charset/codecs/codec_ext8.c
index 5e7cb8a..eb9c898 100644
--- a/src/charset/codecs/codec_ext8.c
+++ b/src/charset/codecs/codec_ext8.c
@@ -58,7 +58,6 @@ typedef struct charset_ext8_codec {
static bool charset_ext8_codec_handles_charset(const char *charset);
static parserutils_error charset_ext8_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec);
static parserutils_error charset_ext8_codec_destroy(
parserutils_charset_codec *codec);
@@ -117,15 +116,12 @@ bool charset_ext8_codec_handles_charset(const char *charset)
* Create an extended 8bit codec
*
* \param charset The charset to read from / write to
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data (may be NULL)
* \param codec Pointer to location to receive codec
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhausion
*/
parserutils_error charset_ext8_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec)
{
uint32_t i;
@@ -143,7 +139,7 @@ parserutils_error charset_ext8_codec_create(const char *charset,
assert(table != NULL);
- c = alloc(NULL, sizeof(charset_ext8_codec), pw);
+ c = malloc(sizeof(charset_ext8_codec));
if (c == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/charset/codecs/codec_impl.h b/src/charset/codecs/codec_impl.h
index 09f622c..a14a3f6 100644
--- a/src/charset/codecs/codec_impl.h
+++ b/src/charset/codecs/codec_impl.h
@@ -21,9 +21,6 @@ struct parserutils_charset_codec {
parserutils_charset_codec_errormode errormode; /**< error mode */
- parserutils_alloc alloc; /**< allocation function */
- void *alloc_pw; /**< private word */
-
struct {
parserutils_error (*destroy)(parserutils_charset_codec *codec);
parserutils_error (*encode)(parserutils_charset_codec *codec,
@@ -42,7 +39,6 @@ struct parserutils_charset_codec {
typedef struct parserutils_charset_handler {
bool (*handles_charset)(const char *charset);
parserutils_error (*create)(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec);
} parserutils_charset_handler;
diff --git a/src/charset/codecs/codec_utf16.c b/src/charset/codecs/codec_utf16.c
index 8dbcae1..19d8bbb 100644
--- a/src/charset/codecs/codec_utf16.c
+++ b/src/charset/codecs/codec_utf16.c
@@ -42,8 +42,7 @@ typedef struct charset_utf16_codec {
} charset_utf16_codec;
static bool charset_utf16_codec_handles_charset(const char *charset);
-static parserutils_error charset_utf16_codec_create(
- const char *charset, parserutils_alloc alloc, void *pw,
+static parserutils_error charset_utf16_codec_create(const char *charset,
parserutils_charset_codec **codec);
static parserutils_error charset_utf16_codec_destroy(
parserutils_charset_codec *codec);
@@ -82,22 +81,19 @@ bool charset_utf16_codec_handles_charset(const char *charset)
* Create a UTF-16 codec
*
* \param charset The charset to read from / write to
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data (may be NULL)
* \param codec Pointer to location to receive codec
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhausion
*/
parserutils_error charset_utf16_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec)
{
charset_utf16_codec *c;
UNUSED(charset);
- c = alloc(NULL, sizeof(charset_utf16_codec), pw);
+ c = malloc(sizeof(charset_utf16_codec));
if (c == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/charset/codecs/codec_utf8.c b/src/charset/codecs/codec_utf8.c
index ceae951..4de7273 100644
--- a/src/charset/codecs/codec_utf8.c
+++ b/src/charset/codecs/codec_utf8.c
@@ -43,7 +43,6 @@ typedef struct charset_utf8_codec {
static bool charset_utf8_codec_handles_charset(const char *charset);
static parserutils_error charset_utf8_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec);
static parserutils_error charset_utf8_codec_destroy(
parserutils_charset_codec *codec);
@@ -83,22 +82,19 @@ bool charset_utf8_codec_handles_charset(const char *charset)
* Create a UTF-8 codec
*
* \param charset The charset to read from / write to
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data (may be NULL)
* \param codec Pointer to location to receive codec
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhausion
*/
parserutils_error charset_utf8_codec_create(const char *charset,
- parserutils_alloc alloc, void *pw,
parserutils_charset_codec **codec)
{
charset_utf8_codec *c;
UNUSED(charset);
- c = alloc(NULL, sizeof(charset_utf8_codec), pw);
+ c = malloc(sizeof(charset_utf8_codec));
if (c == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/input/filter.c b/src/input/filter.c
index b24ab56..f2d2c20 100644
--- a/src/input/filter.c
+++ b/src/input/filter.c
@@ -39,9 +39,6 @@ struct parserutils_filter {
struct {
uint16_t encoding; /**< Input encoding */
} settings; /**< Filter settings */
-
- parserutils_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Client private data */
};
static parserutils_error filter_set_defaults(parserutils_filter *input);
@@ -52,8 +49,6 @@ static parserutils_error filter_set_encoding(parserutils_filter *input,
* Create an input filter
*
* \param int_enc Desired encoding of document
- * \param alloc Function used to (de)allocate data
- * \param pw Pointer to client-specific private data (may be NULL)
* \param filter Pointer to location to receive filter instance
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
@@ -61,15 +56,15 @@ static parserutils_error filter_set_encoding(parserutils_filter *input,
* PARSERUTILS_BADENCODING if the encoding is unsupported
*/
parserutils_error parserutils__filter_create(const char *int_enc,
- parserutils_alloc alloc, void *pw, parserutils_filter **filter)
+ parserutils_filter **filter)
{
parserutils_filter *f;
parserutils_error error;
- if (int_enc == NULL || alloc == NULL || filter == NULL)
+ if (int_enc == NULL || filter == NULL)
return PARSERUTILS_BADPARM;
- f = alloc(NULL, sizeof(parserutils_filter), pw);
+ f = malloc(sizeof(parserutils_filter));
if (f == NULL)
return PARSERUTILS_NOMEM;
@@ -78,7 +73,7 @@ parserutils_error parserutils__filter_create(const char *int_enc,
f->int_enc = parserutils_charset_mibenum_from_name(
int_enc, strlen(int_enc));
if (f->int_enc == 0) {
- alloc(f, 0, pw);
+ free(f);
return PARSERUTILS_BADENCODING;
}
#else
@@ -87,12 +82,9 @@ parserutils_error parserutils__filter_create(const char *int_enc,
f->pivot_len = 0;
#endif
- f->alloc = alloc;
- f->pw = pw;
-
error = filter_set_defaults(f);
if (error != PARSERUTILS_OK) {
- f->alloc(f, 0, pw);
+ free(f);
return error;
}
@@ -104,7 +96,7 @@ parserutils_error parserutils__filter_create(const char *int_enc,
parserutils_charset_codec_destroy(f->read_codec);
f->read_codec = NULL;
}
- f->alloc(f, 0, pw);
+ free(f);
return error;
}
#endif
@@ -142,7 +134,7 @@ parserutils_error parserutils__filter_destroy(parserutils_filter *input)
}
#endif
- input->alloc(input, 0, input->pw);
+ free(input);
return PARSERUTILS_OK;
}
@@ -405,8 +397,7 @@ parserutils_error filter_set_encoding(parserutils_filter *input,
input->read_codec = NULL;
}
- error = parserutils_charset_codec_create(enc, input->alloc,
- input->pw, &input->read_codec);
+ error = parserutils_charset_codec_create(enc, &input->read_codec);
if (error != PARSERUTILS_OK)
return error;
#endif
diff --git a/src/input/filter.h b/src/input/filter.h
index 13473f2..7f4c309 100644
--- a/src/input/filter.h
+++ b/src/input/filter.h
@@ -36,7 +36,7 @@ typedef union parserutils_filter_optparams {
/* Create an input filter */
parserutils_error parserutils__filter_create(const char *int_enc,
- parserutils_alloc alloc, void *pw, parserutils_filter **filter);
+ parserutils_filter **filter);
/* Destroy an input filter */
parserutils_error parserutils__filter_destroy(parserutils_filter *input);
diff --git a/src/input/inputstream.c b/src/input/inputstream.c
index 686ff65..da6653c 100644
--- a/src/input/inputstream.c
+++ b/src/input/inputstream.c
@@ -33,9 +33,6 @@ typedef struct parserutils_inputstream_private {
parserutils_filter *input; /**< Charset conversion filter */
parserutils_charset_detect_func csdetect; /**< Charset detection func.*/
-
- parserutils_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Client private data */
} parserutils_inputstream_private;
static inline parserutils_error parserutils_inputstream_refill_buffer(
@@ -49,8 +46,6 @@ static inline parserutils_error parserutils_inputstream_strip_bom(
* \param enc Document charset, or NULL to autodetect
* \param encsrc Value for encoding source, if specified, or 0
* \param csdetect Charset detection function, or NULL
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data (may be NULL)
* \param stream Pointer to location to receive stream instance
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
@@ -63,29 +58,28 @@ static inline parserutils_error parserutils_inputstream_strip_bom(
*/
parserutils_error parserutils_inputstream_create(const char *enc,
uint32_t encsrc, parserutils_charset_detect_func csdetect,
- parserutils_alloc alloc, void *pw,
parserutils_inputstream **stream)
{
parserutils_inputstream_private *s;
parserutils_error error;
- if (alloc == NULL || stream == NULL)
+ if (stream == NULL)
return PARSERUTILS_BADPARM;
- s = alloc(NULL, sizeof(parserutils_inputstream_private), pw);
+ s = malloc(sizeof(parserutils_inputstream_private));
if (s == NULL)
return PARSERUTILS_NOMEM;
- error = parserutils_buffer_create(alloc, pw, &s->raw);
+ error = parserutils_buffer_create(&s->raw);
if (error != PARSERUTILS_OK) {
- alloc(s, 0, pw);
+ free(s);
return error;
}
- error = parserutils_buffer_create(alloc, pw, &s->public.utf8);
+ error = parserutils_buffer_create(&s->public.utf8);
if (error != PARSERUTILS_OK) {
parserutils_buffer_destroy(s->raw);
- alloc(s, 0, pw);
+ free(s);
return error;
}
@@ -93,11 +87,11 @@ parserutils_error parserutils_inputstream_create(const char *enc,
s->public.had_eof = false;
s->done_first_chunk = false;
- error = parserutils__filter_create("UTF-8", alloc, pw, &s->input);
+ error = parserutils__filter_create("UTF-8", &s->input);
if (error != PARSERUTILS_OK) {
parserutils_buffer_destroy(s->public.utf8);
parserutils_buffer_destroy(s->raw);
- alloc(s, 0, pw);
+ free(s);
return error;
}
@@ -119,7 +113,7 @@ parserutils_error parserutils_inputstream_create(const char *enc,
parserutils__filter_destroy(s->input);
parserutils_buffer_destroy(s->public.utf8);
parserutils_buffer_destroy(s->raw);
- alloc(s, 0, pw);
+ free(s);
return error;
}
@@ -131,9 +125,6 @@ parserutils_error parserutils_inputstream_create(const char *enc,
s->csdetect = csdetect;
- s->alloc = alloc;
- s->pw = pw;
-
*stream = (parserutils_inputstream *) s;
return PARSERUTILS_OK;
@@ -157,7 +148,7 @@ parserutils_error parserutils_inputstream_destroy(
parserutils__filter_destroy(s->input);
parserutils_buffer_destroy(s->public.utf8);
parserutils_buffer_destroy(s->raw);
- s->alloc(s, 0, s->pw);
+ free(s);
return PARSERUTILS_OK;
}
diff --git a/src/utils/buffer.c b/src/utils/buffer.c
index 384e9a9..5a2a7ce 100644
--- a/src/utils/buffer.c
+++ b/src/utils/buffer.c
@@ -14,37 +14,31 @@
/**
* Create a memory buffer
*
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param buffer Pointer to location to receive memory buffer
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhausion
*/
-parserutils_error parserutils_buffer_create(parserutils_alloc alloc, void *pw,
- parserutils_buffer **buffer)
+parserutils_error parserutils_buffer_create(parserutils_buffer **buffer)
{
parserutils_buffer *b;
- if (alloc == NULL || buffer == NULL)
+ if (buffer == NULL)
return PARSERUTILS_BADPARM;
- b = alloc(NULL, sizeof(parserutils_buffer), pw);
+ b = malloc(sizeof(parserutils_buffer));
if (b == NULL)
return PARSERUTILS_NOMEM;
- b->data = alloc(NULL, DEFAULT_SIZE, pw);
+ b->data = malloc(DEFAULT_SIZE);
if (b->data == NULL) {
- alloc(b, 0, pw);
+ free(b);
return PARSERUTILS_NOMEM;
}
b->length = 0;
b->allocated = DEFAULT_SIZE;
- b->alloc = alloc;
- b->pw = pw;
-
*buffer = b;
return PARSERUTILS_OK;
@@ -61,8 +55,8 @@ parserutils_error parserutils_buffer_destroy(parserutils_buffer *buffer)
if (buffer == NULL)
return PARSERUTILS_BADPARM;
- buffer->alloc(buffer->data, 0, buffer->pw);
- buffer->alloc(buffer, 0, buffer->pw);
+ free(buffer->data);
+ free(buffer);
return PARSERUTILS_OK;
}
@@ -155,8 +149,7 @@ parserutils_error parserutils_buffer_discard(parserutils_buffer *buffer,
*/
parserutils_error parserutils_buffer_grow(parserutils_buffer *buffer)
{
- uint8_t *temp = buffer->alloc(buffer->data,
- buffer->allocated * 2, buffer->pw);
+ uint8_t *temp = realloc(buffer->data, buffer->allocated * 2);
if (temp == NULL)
return PARSERUTILS_NOMEM;
@@ -176,7 +169,7 @@ parserutils_error parserutils_buffer_randomise(parserutils_buffer *buffer)
return PARSERUTILS_BADPARM;
#ifndef NDEBUG
- temp = buffer->alloc(NULL, buffer->allocated, buffer->pw);
+ temp = malloc(buffer->allocated);
if (temp == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/utils/stack.c b/src/utils/stack.c
index 725a23a..539ec9d 100644
--- a/src/utils/stack.c
+++ b/src/utils/stack.c
@@ -20,9 +20,6 @@ struct parserutils_stack
size_t items_allocated; /**< Number of slots allocated */
int32_t current_item; /**< Index of current item */
void *items; /**< Items in stack */
-
- parserutils_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Client-specific data */
};
/**
@@ -30,28 +27,26 @@ struct parserutils_stack
*
* \param item_size Length, in bytes, of an item in the stack
* \param chunk_size Number of stack slots in a chunk
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param stack Pointer to location to receive stack instance
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters
* PARSERUTILS_NOMEM on memory exhaustion
*/
parserutils_error parserutils_stack_create(size_t item_size, size_t chunk_size,
- parserutils_alloc alloc, void *pw, parserutils_stack **stack)
+ parserutils_stack **stack)
{
parserutils_stack *s;
- if (item_size == 0 || chunk_size == 0 || alloc == NULL || stack == NULL)
+ if (item_size == 0 || chunk_size == 0 || stack == NULL)
return PARSERUTILS_BADPARM;
- s = alloc(NULL, sizeof(parserutils_stack), pw);
+ s = malloc(sizeof(parserutils_stack));
if (s == NULL)
return PARSERUTILS_NOMEM;
- s->items = alloc(NULL, item_size * chunk_size, pw);
+ s->items = malloc(item_size * chunk_size);
if (s->items == NULL) {
- alloc(s, 0, pw);
+ free(s);
return PARSERUTILS_NOMEM;
}
@@ -60,9 +55,6 @@ parserutils_error parserutils_stack_create(size_t item_size, size_t chunk_size,
s->items_allocated = chunk_size;
s->current_item = -1;
- s->alloc = alloc;
- s->pw = pw;
-
*stack = s;
return PARSERUTILS_OK;
@@ -79,8 +71,8 @@ parserutils_error parserutils_stack_destroy(parserutils_stack *stack)
if (stack == NULL)
return PARSERUTILS_BADPARM;
- stack->alloc(stack->items, 0, stack->pw);
- stack->alloc(stack, 0, stack->pw);
+ free(stack->items);
+ free(stack);
return PARSERUTILS_OK;
}
@@ -107,9 +99,9 @@ parserutils_error parserutils_stack_push(parserutils_stack *stack,
slot = stack->current_item + 1;
if ((size_t) slot >= stack->items_allocated) {
- void *temp = stack->alloc(stack->items,
+ void *temp = realloc(stack->items,
(stack->items_allocated + stack->chunk_size) *
- stack->item_size, stack->pw);
+ stack->item_size);
if (temp == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/utils/vector.c b/src/utils/vector.c
index ab895e3..15c948b 100644
--- a/src/utils/vector.c
+++ b/src/utils/vector.c
@@ -20,9 +20,6 @@ struct parserutils_vector
size_t items_allocated; /**< Number of slots allocated */
int32_t current_item; /**< Index of current item */
void *items; /**< Items in vector */
-
- parserutils_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Client-specific data */
};
/**
@@ -30,30 +27,26 @@ struct parserutils_vector
*
* \param item_size Length, in bytes, of an item in the vector
* \param chunk_size Number of vector slots in a chunk
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param vector Pointer to location to receive vector instance
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhaustion
*/
parserutils_error parserutils_vector_create(size_t item_size,
- size_t chunk_size, parserutils_alloc alloc, void *pw,
- parserutils_vector **vector)
+ size_t chunk_size, parserutils_vector **vector)
{
parserutils_vector *v;
- if (item_size == 0 || chunk_size == 0 || alloc == NULL ||
- vector == NULL)
+ if (item_size == 0 || chunk_size == 0 || vector == NULL)
return PARSERUTILS_BADPARM;
- v = alloc(NULL, sizeof(parserutils_vector), pw);
+ v = malloc(sizeof(parserutils_vector));
if (v == NULL)
return PARSERUTILS_NOMEM;
- v->items = alloc(NULL, item_size * chunk_size, pw);
+ v->items = malloc(item_size * chunk_size);
if (v->items == NULL) {
- alloc(v, 0, pw);
+ free(v);
return PARSERUTILS_NOMEM;
}
@@ -62,9 +55,6 @@ parserutils_error parserutils_vector_create(size_t item_size,
v->items_allocated = chunk_size;
v->current_item = -1;
- v->alloc = alloc;
- v->pw = pw;
-
*vector = v;
return PARSERUTILS_OK;
@@ -81,8 +71,8 @@ parserutils_error parserutils_vector_destroy(parserutils_vector *vector)
if (vector == NULL)
return PARSERUTILS_BADPARM;
- vector->alloc(vector->items, 0, vector->pw);
- vector->alloc(vector, 0, vector->pw);
+ free(vector->items);
+ free(vector);
return PARSERUTILS_OK;
}
@@ -109,9 +99,9 @@ parserutils_error parserutils_vector_append(parserutils_vector *vector,
slot = vector->current_item + 1;
if ((size_t) slot >= vector->items_allocated) {
- void *temp = vector->alloc(vector->items,
+ void *temp = realloc(vector->items,
(vector->items_allocated + vector->chunk_size) *
- vector->item_size, vector->pw);
+ vector->item_size);
if (temp == NULL)
return PARSERUTILS_NOMEM;
diff --git a/test/cscodec-8859.c b/test/cscodec-8859.c
index d47fb2a..2f7448d 100644
--- a/test/cscodec-8859.c
+++ b/test/cscodec-8859.c
@@ -30,13 +30,6 @@ typedef struct line_ctx {
static bool handle_line(const char *data, size_t datalen, void *pw);
static void run_test(line_ctx *ctx);
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_charset_codec *codec;
@@ -48,7 +41,7 @@ int main(int argc, char **argv)
}
assert(parserutils_charset_codec_create("NATS-SEFI-ADD",
- myrealloc, NULL, &codec) == PARSERUTILS_BADENCODING);
+ &codec) == PARSERUTILS_BADENCODING);
ctx.buflen = parse_filesize(argv[1]);
if (ctx.buflen == 0)
@@ -174,8 +167,7 @@ bool handle_line(const char *data, size_t datalen, void *pw)
enc_name[end - enc] = 0;
assert(parserutils_charset_codec_create(enc_name,
- myrealloc, NULL, &ctx->codec) ==
- PARSERUTILS_OK);
+ &ctx->codec) == PARSERUTILS_OK);
ctx->hadenc = true;
diff --git a/test/cscodec-ext8.c b/test/cscodec-ext8.c
index d47fb2a..2f7448d 100644
--- a/test/cscodec-ext8.c
+++ b/test/cscodec-ext8.c
@@ -30,13 +30,6 @@ typedef struct line_ctx {
static bool handle_line(const char *data, size_t datalen, void *pw);
static void run_test(line_ctx *ctx);
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_charset_codec *codec;
@@ -48,7 +41,7 @@ int main(int argc, char **argv)
}
assert(parserutils_charset_codec_create("NATS-SEFI-ADD",
- myrealloc, NULL, &codec) == PARSERUTILS_BADENCODING);
+ &codec) == PARSERUTILS_BADENCODING);
ctx.buflen = parse_filesize(argv[1]);
if (ctx.buflen == 0)
@@ -174,8 +167,7 @@ bool handle_line(const char *data, size_t datalen, void *pw)
enc_name[end - enc] = 0;
assert(parserutils_charset_codec_create(enc_name,
- myrealloc, NULL, &ctx->codec) ==
- PARSERUTILS_OK);
+ &ctx->codec) == PARSERUTILS_OK);
ctx->hadenc = true;
diff --git a/test/cscodec-utf16.c b/test/cscodec-utf16.c
index f29e4d1..835c65e 100644
--- a/test/cscodec-utf16.c
+++ b/test/cscodec-utf16.c
@@ -33,13 +33,6 @@ typedef struct line_ctx {
static bool handle_line(const char *data, size_t datalen, void *pw);
static void run_test(line_ctx *ctx);
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_charset_codec *codec;
@@ -51,9 +44,9 @@ int main(int argc, char **argv)
}
assert(parserutils_charset_codec_create("NATS-SEFI-ADD",
- myrealloc, NULL, &codec) == PARSERUTILS_BADENCODING);
+ &codec) == PARSERUTILS_BADENCODING);
- assert(parserutils_charset_codec_create("UTF-16", myrealloc, NULL,
+ assert(parserutils_charset_codec_create("UTF-16",
&ctx.codec) == PARSERUTILS_OK);
ctx.buflen = parse_filesize(argv[1]);
diff --git a/test/cscodec-utf8.c b/test/cscodec-utf8.c
index 6b1d4de..daf8035 100644
--- a/test/cscodec-utf8.c
+++ b/test/cscodec-utf8.c
@@ -28,13 +28,6 @@ typedef struct line_ctx {
static bool handle_line(const char *data, size_t datalen, void *pw);
static void run_test(line_ctx *ctx);
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_charset_codec *codec;
@@ -46,9 +39,9 @@ int main(int argc, char **argv)
}
assert(parserutils_charset_codec_create("NATS-SEFI-ADD",
- myrealloc, NULL, &codec) == PARSERUTILS_BADENCODING);
+ &codec) == PARSERUTILS_BADENCODING);
- assert(parserutils_charset_codec_create("UTF-8", myrealloc, NULL,
+ assert(parserutils_charset_codec_create("UTF-8",
&ctx.codec) == PARSERUTILS_OK);
ctx.buflen = parse_filesize(argv[1]);
diff --git a/test/filter.c b/test/filter.c
index a34ade3..25c94a9 100644
--- a/test/filter.c
+++ b/test/filter.c
@@ -11,13 +11,6 @@
#include "testutils.h"
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_filter_optparams params;
@@ -31,8 +24,7 @@ int main(int argc, char **argv)
UNUSED(argv);
/* Create input filter */
- assert(parserutils__filter_create("UTF-8", myrealloc, NULL, &input) ==
- PARSERUTILS_OK);
+ assert(parserutils__filter_create("UTF-8", &input) == PARSERUTILS_OK);
/* Convert filter to UTF-8 encoding */
params.encoding.name = "UTF-8";
diff --git a/test/inputstream.c b/test/inputstream.c
index d8c6454..91694b0 100644
--- a/test/inputstream.c
+++ b/test/inputstream.c
@@ -14,13 +14,6 @@ const char * const __dynamic_da_name = "InputStream";
int __dynamic_da_max_size = 128*1024*1024;
#endif
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_inputstream *stream;
@@ -37,7 +30,7 @@ int main(int argc, char **argv)
}
assert(parserutils_inputstream_create("UTF-8", 1, NULL,
- myrealloc, NULL, &stream) == PARSERUTILS_OK);
+ &stream) == PARSERUTILS_OK);
fp = fopen(argv[1], "rb");
if (fp == NULL) {
diff --git a/test/regression/filter-badenc-segv.c b/test/regression/filter-badenc-segv.c
index f44ac59..2581f7a 100644
--- a/test/regression/filter-badenc-segv.c
+++ b/test/regression/filter-badenc-segv.c
@@ -7,13 +7,6 @@
#include "testutils.h"
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_filter *input;
@@ -29,8 +22,7 @@ int main(int argc, char **argv)
UNUSED(argc);
UNUSED(argv);
- assert(parserutils__filter_create("UTF-8", myrealloc, NULL, &input) ==
- PARSERUTILS_OK);
+ assert(parserutils__filter_create("UTF-8", &input) == PARSERUTILS_OK);
params.encoding.name = "GBK";
assert(parserutils__filter_setopt(input,
diff --git a/test/regression/filter-segv.c b/test/regression/filter-segv.c
index 364d8b1..59960e9 100644
--- a/test/regression/filter-segv.c
+++ b/test/regression/filter-segv.c
@@ -7,13 +7,6 @@
#include "testutils.h"
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_filter *input;
@@ -21,8 +14,7 @@ int main(int argc, char **argv)
UNUSED(argc);
UNUSED(argv);
- assert(parserutils__filter_create("UTF-8", myrealloc, NULL, &input) ==
- PARSERUTILS_OK);
+ assert(parserutils__filter_create("UTF-8", &input) == PARSERUTILS_OK);
parserutils__filter_destroy(input);
diff --git a/test/regression/stream-nomem.c b/test/regression/stream-nomem.c
index 4545bea..32aee2b 100644
--- a/test/regression/stream-nomem.c
+++ b/test/regression/stream-nomem.c
@@ -8,13 +8,6 @@
#include "testutils.h"
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
int main(int argc, char **argv)
{
parserutils_inputstream *stream;
@@ -48,7 +41,7 @@ int main(int argc, char **argv)
input_buffer[BUFFER_SIZE - 8] = '1';
assert(parserutils_inputstream_create("UTF-8", 0,
- NULL, myrealloc, NULL, &stream) == PARSERUTILS_OK);
+ NULL, &stream) == PARSERUTILS_OK);
assert(parserutils_inputstream_append(stream,
input_buffer, BUFFER_SIZE) == PARSERUTILS_OK);