Commit 990f741f authored by Josh Coalson's avatar Josh Coalson
Browse files

work around MSVC bug in set_metadata()

parent 527bdda7
......@@ -168,12 +168,26 @@ namespace FLAC {
bool File::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)
{
FLAC__ASSERT(is_valid());
#ifdef _MSC_VER
// MSVC++ can't handle:
// ::FLAC__StreamMetadata *m[num_blocks];
// so we do this ugly workaround
::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks];
#else
::FLAC__StreamMetadata *m[num_blocks];
#endif
for(unsigned i = 0; i < num_blocks; i++) {
// we can get away with this since we know the encoder will only correct the is_last flags
m[i] = const_cast< ::FLAC__StreamMetadata*>((::FLAC__StreamMetadata*)metadata[i]);
}
#ifdef _MSC_VER
// complete the hack
const bool ok = (bool)::FLAC__file_encoder_set_metadata(encoder_, m, num_blocks);
delete [] m;
return ok;
#else
return (bool)::FLAC__file_encoder_set_metadata(encoder_, m, num_blocks);
#endif
}
bool File::set_filename(const char *value)
......
......@@ -168,12 +168,26 @@ namespace FLAC {
bool SeekableStream::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)
{
FLAC__ASSERT(is_valid());
#ifdef _MSC_VER
// MSVC++ can't handle:
// ::FLAC__StreamMetadata *m[num_blocks];
// so we do this ugly workaround
::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks];
#else
::FLAC__StreamMetadata *m[num_blocks];
#endif
for(unsigned i = 0; i < num_blocks; i++) {
// we can get away with this since we know the encoder will only correct the is_last flags
m[i] = const_cast< ::FLAC__StreamMetadata*>((::FLAC__StreamMetadata*)metadata[i]);
}
#ifdef _MSC_VER
// complete the hack
const bool ok = (bool)::FLAC__seekable_stream_encoder_set_metadata(encoder_, m, num_blocks);
delete [] m;
return ok;
#else
return (bool)::FLAC__seekable_stream_encoder_set_metadata(encoder_, m, num_blocks);
#endif
}
SeekableStream::State SeekableStream::get_state() const
......
......@@ -169,12 +169,26 @@ namespace FLAC {
bool Stream::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)
{
FLAC__ASSERT(is_valid());
#ifdef _MSC_VER
// MSVC++ can't handle:
// ::FLAC__StreamMetadata *m[num_blocks];
// so we do this ugly workaround
::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks];
#else
::FLAC__StreamMetadata *m[num_blocks];
#endif
for(unsigned i = 0; i < num_blocks; i++) {
// we can get away with this since we know the encoder will only correct the is_last flags
m[i] = const_cast< ::FLAC__StreamMetadata*>((::FLAC__StreamMetadata*)metadata[i]);
}
#ifdef _MSC_VER
// complete the hack
const bool ok = (bool)::FLAC__stream_encoder_set_metadata(encoder_, m, num_blocks);
delete [] m;
return ok;
#else
return (bool)::FLAC__stream_encoder_set_metadata(encoder_, m, num_blocks);
#endif
}
Stream::State Stream::get_state() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment