[flac-dev] Patch for cross compilation with MinGW32
Christoph Terasa
cterasa at googlemail.com
Sat Jun 23 19:23:17 PDT 2012
Hello,
I had some difficulties compiling the current git (
http://git.xiph.org/?p=flac.git;a=commit;h=a7e3705d051bafd1cae90f6605287cc1d9f2a18d
) using the Ubuntu 12.04 supplied MinGW32 cross compiler:
I configured the FLAC build with --host=i586-mingw32msvc
--target=i586-mingw32msvc --build=i586-linux but ran into several linker
problems. Are these options somehow wrong? It worked fine when I
compiled libogg-0.dll. Anyway, I attached a patch to allow cross
compilation with MinGW32 on my machine again:
First, I moved the implementation of *safe_malloc_mul_2op_ to alloc.h,
just like all the other alloc implementations, and removed the thereby
obsolete alloc.c implementation from grabbag.
Second, I just wrapped FLAC__clz_soft_uint32 with an #ifndef __MINGW32__.
I tested the patch for both Linux and MinGW32 compiles, and both result
in functional programs.
kind regards,
Christoph Terasa
-------------- next part --------------
diff --git include/share/alloc.h include/share/alloc.h
index 7aa17f7..3f2f2c7 100644
--- include/share/alloc.h
+++ include/share/alloc.h
@@ -110,7 +110,14 @@ static inline void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size
return safe_malloc_(size4);
}
-void *safe_malloc_mul_2op_(size_t size1, size_t size2) ;
+static inline void *safe_malloc_mul_2op_(size_t size1, size_t size2)
+{
+ if(!size1 || !size2)
+ return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
+ if(size1 > SIZE_MAX / size2)
+ return 0;
+ return malloc(size1*size2);
+}
static inline void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
{
diff --git src/libFLAC/include/private/bitmath.h src/libFLAC/include/private/bitmath.h
index 61b0e03..4de07b8 100644
--- src/libFLAC/include/private/bitmath.h
+++ src/libFLAC/include/private/bitmath.h
@@ -42,6 +42,7 @@
#endif
/* Will never be emitted for MSVC, GCC, Intel compilers */
+#ifndef __MINGW32__
inline unsigned int FLAC__clz_soft_uint32(unsigned int word)
{
static const unsigned char byte_to_unary_table[] = {
@@ -69,6 +70,7 @@ inline unsigned int FLAC__clz_soft_uint32(unsigned int word)
(word) > 0xff ? byte_to_unary_table[(word) >> 8] + 16 :
byte_to_unary_table[(word)] + 24;
}
+#endif
static inline unsigned int FLAC__clz_uint32(FLAC__uint32 v)
{
diff --git src/share/grabbag/Makefile.am src/share/grabbag/Makefile.am
index d871b83..3fd0299 100644
--- src/share/grabbag/Makefile.am
+++ src/share/grabbag/Makefile.am
@@ -7,7 +7,6 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include
noinst_LTLIBRARIES = libgrabbag.la
libgrabbag_la_SOURCES = \
- alloc.c \
cuesheet.c \
file.c \
picture.c \
diff --git src/share/grabbag/alloc.c src/share/grabbag/alloc.c
deleted file mode 100644
index 53381b8..0000000
--- src/share/grabbag/alloc.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* alloc - Convenience routines for safely allocating memory
- * Copyright (C) 2007,2008,2009 Josh Coalson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Xiph.org Foundation nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-
-#include "share/alloc.h"
-
-void *safe_malloc_mul_2op_(size_t size1, size_t size2)
-{
- if(!size1 || !size2)
- return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
- if(size1 > SIZE_MAX / size2)
- return 0;
- return malloc(size1*size2);
-}
More information about the flac-dev
mailing list