Max Kellermann <[EMAIL PROTECTED]> wrote:
> Unfortunately, the C standard postulates that the argument to free()
> must be non-const.  This does not makes sense, and virtually prevents
> every pointer which must be freed at some time to be non-const.  Use
> the deconst hack (sorry for that) to allow us to free constant
> pointers.

Ugh, the amount of wrapper functions we have is getting to my nerves.
Also, I've seen xfree() in the past as a macro that NULLs its argument,
so I'd rather not use that function name for something that does
something completely different.

Instead, I'm just going to use this instead and remove all of
our other wrappers.

>From bbe4560b180e8c432c7eb7f53664605390bf67ca Mon Sep 17 00:00:00 2001
From: Eric Wong <[EMAIL PROTECTED]>
Date: Mon, 1 Sep 2008 20:01:41 -0700
Subject: [PATCH] provide a generic deconst_ptr function

This is generic enough to be used for various purposes. It will
only deconst their argument to work around various braindead
APIs without having to write a new wrapper each time we use one
of those braindead APIs.  It does not cast nor do do anything
other than quietly remove the const qualifier for those
braindead APIs.
---
 src/utils.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/utils.h b/src/utils.h
index 6a6e562..0001ba3 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -90,4 +90,15 @@ void xpthread_mutex_destroy(pthread_mutex_t *mutex);
 
 void xpthread_cond_destroy(pthread_cond_t *cond);
 
+/*
+ * Work-arounds for braindead APIs that require non-const pointers:
+ *   ao_play(), free(), vorbis_comment_add_tag(), iconv()
+ */
+static inline void * deconst_ptr(const void *ptr)
+{
+       union { const void *in; void *out; } u;
+       u.in = ptr;
+       return u.out;
+}
+
 #endif
-- 
Eric Wong

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to