aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-01 20:08:55 -0700
committerEric Wong <normalperson@yhbt.net>2008-09-01 20:08:55 -0700
commit925843cfedcde221207ec1ab78f778dab22325f9 (patch)
tree2dcdd8497f7ca13af8a5f337b830f2dbe748c978 /src
parentbbe4560b180e8c432c7eb7f53664605390bf67ca (diff)
downloadmpd-925843cfedcde221207ec1ab78f778dab22325f9.tar.gz
mpd-925843cfedcde221207ec1ab78f778dab22325f9.tar.xz
mpd-925843cfedcde221207ec1ab78f778dab22325f9.zip
use deconst_ptr instead of duplicating deconst logic
Diffstat (limited to 'src')
-rw-r--r--src/audioOutputs/audioOutput_ao.c21
-rw-r--r--src/audioOutputs/audioOutput_shout.c12
-rw-r--r--src/charConv.c23
-rw-r--r--src/list.c9
-rw-r--r--src/mpd_types.h5
5 files changed, 15 insertions, 55 deletions
diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c
index e7e201add..ed8eaa796 100644
--- a/src/audioOutputs/audioOutput_ao.c
+++ b/src/audioOutputs/audioOutput_ao.c
@@ -199,23 +199,6 @@ static int audioOutputAo_openDevice(AudioOutput * audioOutput)
return 0;
}
-/**
- * For whatever reason, libao wants a non-const pointer. Let's hope
- * it does not write to the buffer, and use the union deconst hack to
- * work around this API misdesign.
- */
-static int ao_play_deconst(ao_device *device, const void *output_samples,
- uint_32 num_bytes)
-{
- union {
- const void *in;
- void *out;
- } u;
-
- u.in = output_samples;
- return ao_play(device, u.out, num_bytes);
-}
-
static int audioOutputAo_play(AudioOutput * audioOutput,
const char *playChunk, size_t size)
{
@@ -229,7 +212,9 @@ static int audioOutputAo_play(AudioOutput * audioOutput,
chunk_size = (size_t)ad->writeSize > size
? size : (size_t)ad->writeSize;
- if (ao_play_deconst(ad->device, playChunk, chunk_size) == 0) {
+ if (!ao_play(ad->device,
+ (char *)deconst_ptr(playChunk),
+ (uint_32)chunk_size)) {
audioOutputAo_error();
ERROR("closing audio device due to write error\n");
audioOutputAo_closeDevice(audioOutput);
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index 49d69eebd..c1f784986 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -390,11 +390,10 @@ static void myShout_closeDevice(AudioOutput * audioOutput)
static void addTag(ShoutData *sd, const char *name, char *value)
{
- if (value) {
- union const_hack u;
- u.in = name;
- vorbis_comment_add_tag(&(sd->vc), u.out, value);
- }
+ if (value)
+ vorbis_comment_add_tag(&(sd->vc),
+ (char *)deconst_ptr(name),
+ value);
}
static void copyTagToVorbisComment(ShoutData * sd)
@@ -637,7 +636,8 @@ static int myShout_play(AudioOutput * audioOutput,
for (i = 0; i < samples; i++) {
for (j = 0; j < sd->audioFormat->channels; j++) {
- vorbbuf[j][i] = (*((mpd_sint16 *) playChunk)) / 32768.0;
+ vorbbuf[j][i] =
+ (*((mpd_sint16 *)deconst_ptr(playChunk))) / 32768.0;
playChunk += bytes;
}
}
diff --git a/src/charConv.c b/src/charConv.c
index c205e93e4..60bcc655a 100644
--- a/src/charConv.c
+++ b/src/charConv.c
@@ -95,22 +95,6 @@ int setCharSetConversion(const char *to, const char *from)
#endif
}
-#ifdef HAVE_ICONV
-static inline size_t deconst_iconv(iconv_t cd,
- const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft)
-{
- union {
- const char **a;
- char **b;
- } deconst;
-
- deconst.a = inbuf;
-
- return iconv(cd, deconst.b, inbytesleft, outbuf, outbytesleft);
-}
-#endif
-
char *char_conv_str(char *dest, const char *string)
{
if (!char_conv_to)
@@ -132,11 +116,12 @@ char *char_conv_str(char *dest, const char *string)
dest[0] = '\0';
while (inleft) {
+ char *inbuf = deconst_ptr(string);
+
bufferPtr = buffer;
outleft = BUFFER_SIZE;
- err =
- deconst_iconv(char_conv_iconv, &string, &inleft,
- &bufferPtr, &outleft);
+ err = iconv(char_conv_iconv, &inbuf,
+ &inleft, &bufferPtr, &outleft);
if (outleft == BUFFER_SIZE
|| (err == (size_t)-1L && errno != E2BIG)) {
return NULL;
diff --git a/src/list.c b/src/list.c
index 0f1f31ad4..bc158c513 100644
--- a/src/list.c
+++ b/src/list.c
@@ -301,11 +301,6 @@ int deleteFromList(List * list, const char *key)
return 1;
}
-static void free_const_string(const char *p)
-{
- free((char *)p);
-}
-
void deleteNodeFromList(List * list, ListNode * node)
{
assert(list != NULL);
@@ -326,7 +321,7 @@ void deleteNodeFromList(List * list, ListNode * node)
}
if (list->strdupKeys)
- free_const_string(node->key);
+ free(deconst_ptr(node->key));
free(node);
list->numberOfNodes--;
@@ -353,7 +348,7 @@ void freeList(void *list)
while (tmpNode != NULL) {
tmpNode2 = tmpNode->nextNode;
if (((List *) list)->strdupKeys)
- free_const_string(tmpNode->key);
+ free(deconst_ptr(tmpNode->key));
if (((List *) list)->freeDataFunc) {
((List *) list)->freeDataFunc(tmpNode->data);
}
diff --git a/src/mpd_types.h b/src/mpd_types.h
index ed573c4a4..dbdfc6865 100644
--- a/src/mpd_types.h
+++ b/src/mpd_types.h
@@ -40,9 +40,4 @@ typedef unsigned long mpd_uint32;
typedef signed long mpd_sint32;
#endif
-union const_hack {
- const char *in;
- char *out;
-};
-
#endif