From e9bff5db5b83a5bcaf51f141a7d106e75a41539d Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Wed, 13 Oct 2010 21:57:18 +0100 Subject: [PATCH] Added explicit call declarations to a few functions to allow building with different call types in MSVC. --- juce_amalgamated.cpp | 48 +++++++++++-------- juce_amalgamated.h | 2 + .../audio_file_formats/flac/libFLAC/format.c | 4 +- .../oggvorbis/libvorbis-1.1.2/lib/floor1.c | 2 +- .../oggvorbis/libvorbis-1.1.2/lib/lsp.c | 2 +- .../oggvorbis/libvorbis-1.1.2/lib/psy.c | 2 +- .../libvorbis-1.1.2/lib/sharedbook.c | 2 +- src/core/juce_PlatformDefs.h | 2 + .../image_file_formats/juce_PNGLoader.cpp | 6 +-- src/native/windows/juce_win32_ASIO.cpp | 26 +++++----- src/native/windows/juce_win32_WASAPI.cpp | 2 + 11 files changed, 56 insertions(+), 42 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 1056139c9c..c01f121b88 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -620,6 +620,7 @@ */ #import #import + #endif #if JUCE_MSVC @@ -117414,7 +117415,7 @@ FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_S } /* used as the sort predicate for qsort() */ -static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r) +static int JUCE_CDECL seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r) { /* we don't just 'return l->sample_number - r->sample_number' since the result (FLAC__int64) might overflow an 'int' */ if(l->sample_number == r->sample_number) @@ -117434,7 +117435,7 @@ FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *se FLAC__ASSERT(0 != seek_table); /* sort the seekpoints */ - qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_); + qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (JUCE_CDECL *)(const void *, const void *))seekpoint_compare_); /* uniquify the seekpoints */ first = true; @@ -136207,7 +136208,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){ return(NULL); } -static int icomp(const void *a,const void *b){ +static int JUCE_CDECL icomp(const void *a,const void *b){ return(**(int **)a-**(int **)b); } @@ -138703,7 +138704,7 @@ static void cheby(float *g, int ord) { } } -static int comp(const void *a,const void *b){ +static int JUCE_CDECL comp(const void *a,const void *b){ return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b); } @@ -142004,7 +142005,7 @@ float **_vp_quantize_couple_memo(vorbis_block *vb, } /* this is for per-channel noise normalization */ -static int apsort(const void *a, const void *b){ +static int JUCE_CDECL apsort(const void *a, const void *b){ float f1=fabs(**(float**)a); float f2=fabs(**(float**)b); return (f1f2); @@ -143433,7 +143434,7 @@ int vorbis_book_init_encode(codebook *c,const static_codebook *s){ return(0); } -static int sort32a(const void *a,const void *b){ +static int JUCE_CDECL sort32a(const void *a,const void *b){ return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)- ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b); } @@ -237313,19 +237314,19 @@ namespace PNGHelpers { using namespace pnglibNamespace; - static void readCallback (png_structp png, png_bytep data, png_size_t length) + static void JUCE_CDECL readCallback (png_structp png, png_bytep data, png_size_t length) { static_cast (png_get_io_ptr (png))->read (data, (int) length); } - static void writeDataCallback (png_structp png, png_bytep data, png_size_t length) + static void JUCE_CDECL writeDataCallback (png_structp png, png_bytep data, png_size_t length) { static_cast (png_get_io_ptr (png))->write (data, (int) length); } struct PNGErrorStruct {}; - static void errorCallback (png_structp, png_const_charp) + static void JUCE_CDECL errorCallback (png_structp, png_const_charp) { throw PNGErrorStruct(); } @@ -249218,6 +249219,9 @@ void MidiOutput::sendMessageNow (const MidiMessage& message) #define log(a) {} #endif +#define JUCE_ASIOCALLBACK // should probably use this to define the callback type, but + // the asio header doesn't actually specify a calling convention for the functions.. + #if ASIO_DEBUGGING static void logError (const String& context, long error) { @@ -250362,7 +250366,7 @@ private: return error; } - void callback (const long index) + void JUCE_ASIOCALLBACK callback (const long index) { if (isStarted) { @@ -250507,7 +250511,7 @@ private: asioObject->outputReady(); } - static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) + static ASIOTime* JUCE_ASIOCALLBACK bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) { if (currentASIODev[0] != 0) currentASIODev[0]->callback (index); @@ -250515,7 +250519,7 @@ private: return 0; } - static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) + static ASIOTime* JUCE_ASIOCALLBACK bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) { if (currentASIODev[1] != 0) currentASIODev[1]->callback (index); @@ -250523,7 +250527,7 @@ private: return 0; } - static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) + static ASIOTime* JUCE_ASIOCALLBACK bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) { if (currentASIODev[2] != 0) currentASIODev[2]->callback (index); @@ -250531,40 +250535,40 @@ private: return 0; } - static void bufferSwitchCallback0 (long index, long) + static void JUCE_ASIOCALLBACK bufferSwitchCallback0 (long index, long) { if (currentASIODev[0] != 0) currentASIODev[0]->callback (index); } - static void bufferSwitchCallback1 (long index, long) + static void JUCE_ASIOCALLBACK bufferSwitchCallback1 (long index, long) { if (currentASIODev[1] != 0) currentASIODev[1]->callback (index); } - static void bufferSwitchCallback2 (long index, long) + static void JUCE_ASIOCALLBACK bufferSwitchCallback2 (long index, long) { if (currentASIODev[2] != 0) currentASIODev[2]->callback (index); } - static long asioMessagesCallback0 (long selector, long value, void*, double*) + static long JUCE_ASIOCALLBACK asioMessagesCallback0 (long selector, long value, void*, double*) { return asioMessagesCallback (selector, value, 0); } - static long asioMessagesCallback1 (long selector, long value, void*, double*) + static long JUCE_ASIOCALLBACK asioMessagesCallback1 (long selector, long value, void*, double*) { return asioMessagesCallback (selector, value, 1); } - static long asioMessagesCallback2 (long selector, long value, void*, double*) + static long JUCE_ASIOCALLBACK asioMessagesCallback2 (long selector, long value, void*, double*) { return asioMessagesCallback (selector, value, 2); } - static long asioMessagesCallback (long selector, long value, const int deviceIndex) + static long JUCE_ASIOCALLBACK asioMessagesCallback (long selector, long value, const int deviceIndex) { switch (selector) { @@ -250606,7 +250610,7 @@ private: return 0; } - static void sampleRateChangedCallback (ASIOSampleRate) throw() + static void JUCE_ASIOCALLBACK sampleRateChangedCallback (ASIOSampleRate) { } @@ -252708,6 +252712,8 @@ static void logFailure (HRESULT hr) #endif } +#undef check + static bool check (HRESULT hr) { logFailure (hr); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index f8e51dfcba..6eabb36a01 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -518,8 +518,10 @@ /** This macro defines the C calling convention used as the standard for Juce calls. */ #if JUCE_MSVC #define JUCE_CALLTYPE __stdcall + #define JUCE_CDECL __cdecl #else #define JUCE_CALLTYPE + #define JUCE_CDECL #endif // Debugging and assertion macros diff --git a/src/audio/audio_file_formats/flac/libFLAC/format.c b/src/audio/audio_file_formats/flac/libFLAC/format.c index cdec857e49..cd1aa72587 100644 --- a/src/audio/audio_file_formats/flac/libFLAC/format.c +++ b/src/audio/audio_file_formats/flac/libFLAC/format.c @@ -272,7 +272,7 @@ FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_S } /* used as the sort predicate for qsort() */ -static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r) +static int JUCE_CDECL seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r) { /* we don't just 'return l->sample_number - r->sample_number' since the result (FLAC__int64) might overflow an 'int' */ if(l->sample_number == r->sample_number) @@ -292,7 +292,7 @@ FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *se FLAC__ASSERT(0 != seek_table); /* sort the seekpoints */ - qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_); + qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (JUCE_CDECL *)(const void *, const void *))seekpoint_compare_); /* uniquify the seekpoints */ first = true; diff --git a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/floor1.c b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/floor1.c index d9b3c90f95..c79dc6c305 100644 --- a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/floor1.c +++ b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/floor1.c @@ -174,7 +174,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){ return(NULL); } -static int icomp(const void *a,const void *b){ +static int JUCE_CDECL icomp(const void *a,const void *b){ return(**(int **)a-**(int **)b); } diff --git a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/lsp.c b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/lsp.c index 07df823eab..01134534c7 100644 --- a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/lsp.c +++ b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/lsp.c @@ -298,7 +298,7 @@ static void cheby(float *g, int ord) { } } -static int comp(const void *a,const void *b){ +static int JUCE_CDECL comp(const void *a,const void *b){ return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b); } diff --git a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/psy.c b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/psy.c index 9acbd81d0e..6baa1c3d85 100644 --- a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/psy.c +++ b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/psy.c @@ -1018,7 +1018,7 @@ float **_vp_quantize_couple_memo(vorbis_block *vb, } /* this is for per-channel noise normalization */ -static int apsort(const void *a, const void *b){ +static int JUCE_CDECL apsort(const void *a, const void *b){ float f1=fabs(**(float**)a); float f2=fabs(**(float**)b); return (f1f2); diff --git a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/sharedbook.c b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/sharedbook.c index c547241019..803b431078 100644 --- a/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/sharedbook.c +++ b/src/audio/audio_file_formats/oggvorbis/libvorbis-1.1.2/lib/sharedbook.c @@ -304,7 +304,7 @@ int vorbis_book_init_encode(codebook *c,const static_codebook *s){ return(0); } -static int sort32a(const void *a,const void *b){ +static int JUCE_CDECL sort32a(const void *a,const void *b){ return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)- ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b); } diff --git a/src/core/juce_PlatformDefs.h b/src/core/juce_PlatformDefs.h index dc077fbbfe..0a35dad5a2 100644 --- a/src/core/juce_PlatformDefs.h +++ b/src/core/juce_PlatformDefs.h @@ -42,8 +42,10 @@ /** This macro defines the C calling convention used as the standard for Juce calls. */ #if JUCE_MSVC #define JUCE_CALLTYPE __stdcall + #define JUCE_CDECL __cdecl #else #define JUCE_CALLTYPE + #define JUCE_CDECL #endif //============================================================================== diff --git a/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp b/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp index f5d884da41..4e230f0b1e 100644 --- a/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp +++ b/src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp @@ -110,19 +110,19 @@ namespace PNGHelpers { using namespace pnglibNamespace; - static void readCallback (png_structp png, png_bytep data, png_size_t length) + static void JUCE_CDECL readCallback (png_structp png, png_bytep data, png_size_t length) { static_cast (png_get_io_ptr (png))->read (data, (int) length); } - static void writeDataCallback (png_structp png, png_bytep data, png_size_t length) + static void JUCE_CDECL writeDataCallback (png_structp png, png_bytep data, png_size_t length) { static_cast (png_get_io_ptr (png))->write (data, (int) length); } struct PNGErrorStruct {}; - static void errorCallback (png_structp, png_const_charp) + static void JUCE_CDECL errorCallback (png_structp, png_const_charp) { throw PNGErrorStruct(); } diff --git a/src/native/windows/juce_win32_ASIO.cpp b/src/native/windows/juce_win32_ASIO.cpp index 8d2c1ad614..309f023df3 100644 --- a/src/native/windows/juce_win32_ASIO.cpp +++ b/src/native/windows/juce_win32_ASIO.cpp @@ -38,6 +38,8 @@ #define log(a) {} #endif +#define JUCE_ASIOCALLBACK // should probably use this to define the callback type, but + // the asio header doesn't actually specify a calling convention for the functions.. //============================================================================== #if ASIO_DEBUGGING @@ -1192,7 +1194,7 @@ private: } //============================================================================== - void callback (const long index) + void JUCE_ASIOCALLBACK callback (const long index) { if (isStarted) { @@ -1338,7 +1340,7 @@ private: } //============================================================================== - static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) + static ASIOTime* JUCE_ASIOCALLBACK bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) { if (currentASIODev[0] != 0) currentASIODev[0]->callback (index); @@ -1346,7 +1348,7 @@ private: return 0; } - static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) + static ASIOTime* JUCE_ASIOCALLBACK bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) { if (currentASIODev[1] != 0) currentASIODev[1]->callback (index); @@ -1354,7 +1356,7 @@ private: return 0; } - static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) + static ASIOTime* JUCE_ASIOCALLBACK bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) { if (currentASIODev[2] != 0) currentASIODev[2]->callback (index); @@ -1362,41 +1364,41 @@ private: return 0; } - static void bufferSwitchCallback0 (long index, long) + static void JUCE_ASIOCALLBACK bufferSwitchCallback0 (long index, long) { if (currentASIODev[0] != 0) currentASIODev[0]->callback (index); } - static void bufferSwitchCallback1 (long index, long) + static void JUCE_ASIOCALLBACK bufferSwitchCallback1 (long index, long) { if (currentASIODev[1] != 0) currentASIODev[1]->callback (index); } - static void bufferSwitchCallback2 (long index, long) + static void JUCE_ASIOCALLBACK bufferSwitchCallback2 (long index, long) { if (currentASIODev[2] != 0) currentASIODev[2]->callback (index); } - static long asioMessagesCallback0 (long selector, long value, void*, double*) + static long JUCE_ASIOCALLBACK asioMessagesCallback0 (long selector, long value, void*, double*) { return asioMessagesCallback (selector, value, 0); } - static long asioMessagesCallback1 (long selector, long value, void*, double*) + static long JUCE_ASIOCALLBACK asioMessagesCallback1 (long selector, long value, void*, double*) { return asioMessagesCallback (selector, value, 1); } - static long asioMessagesCallback2 (long selector, long value, void*, double*) + static long JUCE_ASIOCALLBACK asioMessagesCallback2 (long selector, long value, void*, double*) { return asioMessagesCallback (selector, value, 2); } //============================================================================== - static long asioMessagesCallback (long selector, long value, const int deviceIndex) + static long JUCE_ASIOCALLBACK asioMessagesCallback (long selector, long value, const int deviceIndex) { switch (selector) { @@ -1438,7 +1440,7 @@ private: return 0; } - static void sampleRateChangedCallback (ASIOSampleRate) throw() + static void JUCE_ASIOCALLBACK sampleRateChangedCallback (ASIOSampleRate) { } diff --git a/src/native/windows/juce_win32_WASAPI.cpp b/src/native/windows/juce_win32_WASAPI.cpp index c1a003f8b3..8ba0b9d5e0 100644 --- a/src/native/windows/juce_win32_WASAPI.cpp +++ b/src/native/windows/juce_win32_WASAPI.cpp @@ -82,6 +82,8 @@ static void logFailure (HRESULT hr) #endif } +#undef check + static bool check (HRESULT hr) { logFailure (hr);