ref: 387e9989a53af969dc9e3be1ca6869af21e189d6
parent: 67b53baa8913efadd8663f7317f565d6452c402e
author: evpobr <[email protected]>
date: Thu Nov 5 05:08:17 EST 2020
Eliminate ZERO_ALLOC macro It's no better than calloc().
--- a/src/common.h
+++ b/src/common.h
@@ -35,15 +35,6 @@
#define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
/*
-** Adds casting needed if compiled/included within cpp
-*/
-#ifdef __cplusplus
-#define ZERO_ALLOC(type, size) static_cast<type*>(calloc(1, size))
-#else // __cplusplus
-#define ZERO_ALLOC(type, size) calloc(1, size)
-#endif
-
-/*
** Inspiration : http://sourcefrog.net/weblog/software/languages/C/unused.html
*/
#ifdef UNUSED
--- a/src/samplerate.c
+++ b/src/samplerate.c
@@ -31,7 +31,7 @@
return NULL ;
} ;
- SRC_STATE *state = ZERO_ALLOC (SRC_STATE, sizeof (SRC_STATE)) ;
+ SRC_STATE *state = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
if (state == NULL)
{ if (error)
*error = SRC_ERR_MALLOC_FAILED ;
@@ -62,7 +62,7 @@
if (error)
*error = SRC_ERR_NO_ERROR ;
- if ((state = ZERO_ALLOC (SRC_STATE, sizeof (SRC_STATE))) == NULL)
+ if ((state = (SRC_STATE *) calloc (1, sizeof (SRC_STATE))) == NULL)
{ if (error)
*error = SRC_ERR_MALLOC_FAILED ;
return NULL ;
--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -170,7 +170,7 @@
if (state->private_data == NULL)
{
- priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv)) ;
+ priv = (LINEAR_DATA *) calloc (1, sizeof (LINEAR_DATA)) ;
if (priv)
{
priv->last_value = calloc (state->channels, sizeof (float)) ;
@@ -225,7 +225,7 @@
LINEAR_DATA *to_priv = NULL ;
LINEAR_DATA* from_priv = (LINEAR_DATA*) from->private_data ;
- if ((to_priv = ZERO_ALLOC (LINEAR_DATA, sizeof (LINEAR_DATA))) == NULL)
+ if ((to_priv = (LINEAR_DATA*) calloc (1, sizeof (LINEAR_DATA))) == NULL)
return SRC_ERR_MALLOC_FAILED ;
memcpy (to_priv, from_priv, sizeof (LINEAR_DATA)) ;
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -219,7 +219,7 @@
temp_filter.b_len *= state->channels ;
temp_filter.b_len += 1 ; // There is a <= check against samples_in_hand requiring a buffer bigger than the calculation above
- if ((filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER))) == NULL)
+ if ((filter = (SINC_FILTER *) calloc (1, sizeof (SINC_FILTER))) == NULL)
return SRC_ERR_MALLOC_FAILED ;
*filter = temp_filter ;
@@ -273,7 +273,7 @@
SINC_FILTER *to_filter = NULL ;
SINC_FILTER* from_filter = (SINC_FILTER*) from->private_data ;
- if ((to_filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER))) == NULL)
+ if ((to_filter = (SINC_FILTER *) calloc (1, sizeof (SINC_FILTER))) == NULL)
return SRC_ERR_MALLOC_FAILED ;
memcpy (to_filter, from_filter, sizeof (SINC_FILTER)) ;
to_filter->buffer = malloc (sizeof (float) * (from_filter->b_len + from->channels)) ;
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -161,7 +161,7 @@
if (state->private_data == NULL)
{
- priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv)) ;
+ priv = (ZOH_DATA *) calloc (1, sizeof (ZOH_DATA)) ;
if (priv)
{
priv->last_value = calloc (state->channels, sizeof (float)) ;
@@ -217,7 +217,7 @@
ZOH_DATA *to_priv = NULL ;
ZOH_DATA* from_priv = (ZOH_DATA*) from->private_data ;
- if ((to_priv = ZERO_ALLOC (ZOH_DATA, sizeof (ZOH_DATA))) == NULL)
+ if ((to_priv = (ZOH_DATA *) calloc (1, sizeof (ZOH_DATA))) == NULL)
return SRC_ERR_MALLOC_FAILED ;
memcpy (to_priv, from_priv, sizeof (ZOH_DATA)) ;