Browse Source

Fix for win32 String::formatted. Minor clean-ups.

tags/2021-05-28
Julian Storer 14 years ago
parent
commit
bde96c1053
14 changed files with 90 additions and 128 deletions
  1. +43
    -62
      juce_amalgamated.cpp
  2. +2
    -2
      juce_amalgamated.h
  3. +2
    -3
      src/audio/audio_file_formats/juce_AudioFormatWriter.cpp
  4. +9
    -19
      src/audio/plugins/formats/juce_VSTPluginFormat.cpp
  5. +1
    -1
      src/core/juce_StandardHeader.h
  6. +3
    -3
      src/native/mac/juce_mac_NativeCode.mm
  7. +11
    -11
      src/native/mac/juce_mac_SystemStats.mm
  8. +1
    -2
      src/native/windows/juce_win32_ASIO.cpp
  9. +1
    -2
      src/native/windows/juce_win32_FileChooser.cpp
  10. +1
    -2
      src/native/windows/juce_win32_SystemStats.cpp
  11. +13
    -16
      src/text/juce_String.cpp
  12. +1
    -1
      src/text/juce_String.h
  13. +1
    -2
      src/text/juce_XmlDocument.cpp
  14. +1
    -2
      src/text/juce_XmlElement.cpp

+ 43
- 62
juce_amalgamated.cpp View File

@@ -13154,31 +13154,28 @@ bool String::containsNonWhitespaceChars() const throw()
return false;
}

const String String::formatted (const String& pf, ... )
// Note! The format parameter here MUST NOT be a reference, otherwise MS's va_start macro fails to work (but still compiles).
const String String::formatted (const String pf, ... )
{
va_list args;
va_start (args, pf);

size_t bufferSize = 256;

for (;;)
{
#if JUCE_LINUX && JUCE_64BIT
HeapBlock <wchar_t> temp (bufferSize);
va_list tempArgs;
va_copy (tempArgs, args);
const int num = (int) vswprintf (temp.getData(), bufferSize - 1, pf.toUTF32(), tempArgs);
va_end (tempArgs);
#elif JUCE_WINDOWS
va_list args;
va_start (args, pf);

#if JUCE_WINDOWS
HeapBlock <wchar_t> temp (bufferSize);
const int num = (int) _vsnwprintf (temp.getData(), bufferSize - 1, pf.toUTF16(), args);
#elif JUCE_ANDROID
const int num = (int) _vsnwprintf (temp.getData(), bufferSize - 1, pf.toWideCharPointer(), args);
#elif JUCE_ANDROID
HeapBlock <char> temp (bufferSize);
const int num = (int) vsnprintf (temp.getData(), bufferSize - 1, pf.toUTF8(), args);
#else
#else
HeapBlock <wchar_t> temp (bufferSize);
const int num = (int) vswprintf (temp.getData(), bufferSize - 1, pf.toUTF32(), args);
#endif
const int num = (int) vswprintf (temp.getData(), bufferSize - 1, pf.toWideCharPointer(), args);
#endif

va_end (args);

if (num > 0)
return String (temp);
@@ -14587,8 +14584,7 @@ namespace XmlIdentifierChars

/*static void generateIdentifierCharConstants()
{
uint32 n[8];
zerostruct (n);
uint32 n[8] = { 0 };
for (int i = 0; i < 256; ++i)
if (isIdentifierCharSlow (i))
n[i >> 5] |= (1 << (i & 31));
@@ -15453,8 +15449,7 @@ namespace XmlOutputFunctions

void generateLegalCharConstants()
{
uint8 n[32];
zerostruct (n);
uint8 n[32] = { 0 };
for (int i = 0; i < 256; ++i)
if (isLegalXmlCharSlow (i))
n[i >> 3] |= (1 << (i & 7));
@@ -21054,8 +21049,7 @@ bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
const int bufferSize = 16384;
AudioSampleBuffer tempBuffer (numChannels, bufferSize);

int* buffers [128];
zerostruct (buffers);
int* buffers [128] = { 0 };

for (int i = tempBuffer.getNumChannels(); --i >= 0;)
buffers[i] = reinterpret_cast<int*> (tempBuffer.getSampleData (i, 0));
@@ -21084,7 +21078,7 @@ bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
const double factor = 1.0 / std::numeric_limits<int>::max();

for (int i = 0; i < numToDo; ++i)
((float*) b)[i] = (float) (factor * b[i]);
reinterpret_cast<float*> (b)[i] = (float) (factor * b[i]);
}
else
{
@@ -33416,8 +33410,7 @@ public:
desc.name = name;

{
char buffer [512];
zerostruct (buffer);
char buffer [512] = { 0 };
dispatch (effGetEffectName, 0, 0, buffer, 0);

desc.descriptiveName = String (buffer).trim();
@@ -33433,8 +33426,7 @@ public:
desc.category = getCategory();

{
char buffer [kVstMaxVendorStrLen + 8];
zerostruct (buffer);
char buffer [kVstMaxVendorStrLen + 8] = { 0 };
dispatch (effGetVendorString, 0, 0, buffer, 0);
desc.manufacturerName = buffer;
}
@@ -35165,8 +35157,7 @@ const String VSTPluginInstance::getParameterName (int index)
{
jassert (index >= 0 && index < effect->numParams);

char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetParamName, index, 0, nm, 0);
return String (nm).trim();
}
@@ -35180,8 +35171,7 @@ const String VSTPluginInstance::getParameterLabel (int index) const
{
jassert (index >= 0 && index < effect->numParams);

char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetParamLabel, index, 0, nm, 0);
return String (nm).trim();
}
@@ -35195,8 +35185,7 @@ const String VSTPluginInstance::getParameterText (int index)
{
jassert (index >= 0 && index < effect->numParams);

char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetParamDisplay, index, 0, nm, 0);
return String (nm).trim();
}
@@ -35250,8 +35239,7 @@ const String VSTPluginInstance::getProgramName (int index)
}
else if (effect != 0)
{
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };

if (dispatch (effGetProgramNameIndexed,
jlimit (0, getNumPrograms(), index),
@@ -35281,8 +35269,7 @@ void VSTPluginInstance::updateStoredProgramNames()
{
if (effect != 0 && getNumPrograms() > 0)
{
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };

// only do this if the plugin can't use indexed names..
if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
@@ -35307,8 +35294,7 @@ const String VSTPluginInstance::getCurrentProgramName()
{
if (effect != 0)
{
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetProgramName, 0, 0, nm, 0);

const int index = getCurrentProgram();
@@ -35448,11 +35434,9 @@ void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& resul
else
{
// It's a shell plugin, so iterate all the subtypes...
char shellEffectName [64];

for (;;)
{
zerostruct (shellEffectName);
char shellEffectName [64] = { 0 };
const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);

if (uid == 0)
@@ -242426,9 +242410,8 @@ int SystemStats::getPageSize()

const String SystemStats::getLogonName()
{
TCHAR text [256];
TCHAR text [256] = { 0 };
DWORD len = numElementsInArray (text) - 2;
zerostruct (text);
GetUserName (text, &len);
return String (text, len);
}
@@ -248871,8 +248854,7 @@ namespace FileChooserHelpers

if (comp != 0)
{
WCHAR path [MAX_PATH * 2];
zerostruct (path);
WCHAR path [MAX_PATH * 2] = { 0 };
CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);

comp->selectedFileChanged (File (path));
@@ -254710,8 +254692,7 @@ private:

if (RegOpenKeyEx (hk, keyName.toUTF16(), 0, KEY_READ, &subKey) == ERROR_SUCCESS)
{
TCHAR buf [256];
zerostruct (buf);
TCHAR buf [256] = { 0 };
DWORD dtype = REG_SZ;
DWORD dsize = sizeof (buf);

@@ -266948,11 +266929,11 @@ class MessageQueue
public:
MessageQueue()
{
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 && ! JUCE_IOS
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 && ! JUCE_IOS
runLoop = CFRunLoopGetMain();
#else
#else
runLoop = CFRunLoopGetCurrent();
#endif
#endif

CFRunLoopSourceContext sourceContext;
zerostruct (sourceContext);
@@ -267262,13 +267243,13 @@ int PlatformUtilities::getOSXMinorVersionNumber()

bool SystemStats::isOperatingSystem64Bit()
{
#if JUCE_IOS
#if JUCE_IOS
return false;
#elif JUCE_64BIT
#elif JUCE_64BIT
return true;
#else
#else
return PlatformUtilities::getOSXMinorVersionNumber() >= 6;
#endif
#endif
}

int SystemStats::getMemorySizeInMegabytes()
@@ -267282,17 +267263,16 @@ int SystemStats::getMemorySizeInMegabytes()

const String SystemStats::getCpuVendor()
{
#if JUCE_INTEL
#if JUCE_INTEL
uint32 dummy = 0;
uint32 vendor[4];
zerostruct (vendor);
uint32 vendor[4] = { 0 };

SystemStatsHelpers::doCPUID (dummy, vendor[0], vendor[2], vendor[1], 0);

return String (reinterpret_cast <const char*> (vendor), 12);
#else
#else
return String::empty;
#endif
#endif
}

int SystemStats::getCpuSpeedInMegaherz()
@@ -267302,10 +267282,11 @@ int SystemStats::getCpuSpeedInMegaherz()
int mib[] = { CTL_HW, HW_CPU_FREQ };
sysctl (mib, 2, &speedHz, &speedSize, 0, 0);

#if JUCE_BIG_ENDIAN
#if JUCE_BIG_ENDIAN
if (speedSize == 4)
speedHz >>= 32;
#endif
#endif

return (int) (speedHz / 1000000);
}



+ 2
- 2
juce_amalgamated.h View File

@@ -73,7 +73,7 @@ namespace JuceDummyNamespace {}
*/
#define JUCE_MAJOR_VERSION 1
#define JUCE_MINOR_VERSION 53
#define JUCE_BUILDNUMBER 47
#define JUCE_BUILDNUMBER 48

/** Current Juce version number.

@@ -5012,7 +5012,7 @@ public:
on the platform, it may be using wchar_t or char character types, so that even string
literals can't be safely used as parameters if you're writing portable code.
*/
static const String formatted (const String& formatString, ... );
static const String formatted (const String formatString, ... );

// Numeric conversions..



+ 2
- 3
src/audio/audio_file_formats/juce_AudioFormatWriter.cpp View File

@@ -60,8 +60,7 @@ bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
const int bufferSize = 16384;
AudioSampleBuffer tempBuffer (numChannels, bufferSize);
int* buffers [128];
zerostruct (buffers);
int* buffers [128] = { 0 };
for (int i = tempBuffer.getNumChannels(); --i >= 0;)
buffers[i] = reinterpret_cast<int*> (tempBuffer.getSampleData (i, 0));
@@ -90,7 +89,7 @@ bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
const double factor = 1.0 / std::numeric_limits<int>::max();
for (int i = 0; i < numToDo; ++i)
((float*) b)[i] = (float) (factor * b[i]);
reinterpret_cast<float*> (b)[i] = (float) (factor * b[i]);
}
else
{


+ 9
- 19
src/audio/plugins/formats/juce_VSTPluginFormat.cpp View File

@@ -708,8 +708,7 @@ public:
desc.name = name;
{
char buffer [512];
zerostruct (buffer);
char buffer [512] = { 0 };
dispatch (effGetEffectName, 0, 0, buffer, 0);
desc.descriptiveName = String (buffer).trim();
@@ -725,8 +724,7 @@ public:
desc.category = getCategory();
{
char buffer [kVstMaxVendorStrLen + 8];
zerostruct (buffer);
char buffer [kVstMaxVendorStrLen + 8] = { 0 };
dispatch (effGetVendorString, 0, 0, buffer, 0);
desc.manufacturerName = buffer;
}
@@ -2489,8 +2487,7 @@ const String VSTPluginInstance::getParameterName (int index)
{
jassert (index >= 0 && index < effect->numParams);
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetParamName, index, 0, nm, 0);
return String (nm).trim();
}
@@ -2504,8 +2501,7 @@ const String VSTPluginInstance::getParameterLabel (int index) const
{
jassert (index >= 0 && index < effect->numParams);
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetParamLabel, index, 0, nm, 0);
return String (nm).trim();
}
@@ -2519,8 +2515,7 @@ const String VSTPluginInstance::getParameterText (int index)
{
jassert (index >= 0 && index < effect->numParams);
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetParamDisplay, index, 0, nm, 0);
return String (nm).trim();
}
@@ -2575,8 +2570,7 @@ const String VSTPluginInstance::getProgramName (int index)
}
else if (effect != 0)
{
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
if (dispatch (effGetProgramNameIndexed,
jlimit (0, getNumPrograms(), index),
@@ -2606,8 +2600,7 @@ void VSTPluginInstance::updateStoredProgramNames()
{
if (effect != 0 && getNumPrograms() > 0)
{
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
// only do this if the plugin can't use indexed names..
if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
@@ -2632,8 +2625,7 @@ const String VSTPluginInstance::getCurrentProgramName()
{
if (effect != 0)
{
char nm [256];
zerostruct (nm);
char nm [256] = { 0 };
dispatch (effGetProgramName, 0, 0, nm, 0);
const int index = getCurrentProgram();
@@ -2778,11 +2770,9 @@ void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& resul
else
{
// It's a shell plugin, so iterate all the subtypes...
char shellEffectName [64];
for (;;)
{
zerostruct (shellEffectName);
char shellEffectName [64] = { 0 };
const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
if (uid == 0)


+ 1
- 1
src/core/juce_StandardHeader.h View File

@@ -33,7 +33,7 @@
*/
#define JUCE_MAJOR_VERSION 1
#define JUCE_MINOR_VERSION 53
#define JUCE_BUILDNUMBER 47
#define JUCE_BUILDNUMBER 48
/** Current Juce version number.


+ 3
- 3
src/native/mac/juce_mac_NativeCode.mm View File

@@ -124,11 +124,11 @@ class MessageQueue
public:
MessageQueue()
{
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 && ! JUCE_IOS
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 && ! JUCE_IOS
runLoop = CFRunLoopGetMain();
#else
#else
runLoop = CFRunLoopGetCurrent();
#endif
#endif
CFRunLoopSourceContext sourceContext;
zerostruct (sourceContext);


+ 11
- 11
src/native/mac/juce_mac_SystemStats.mm View File

@@ -124,13 +124,13 @@ int PlatformUtilities::getOSXMinorVersionNumber()
bool SystemStats::isOperatingSystem64Bit()
{
#if JUCE_IOS
#if JUCE_IOS
return false;
#elif JUCE_64BIT
#elif JUCE_64BIT
return true;
#else
#else
return PlatformUtilities::getOSXMinorVersionNumber() >= 6;
#endif
#endif
}
int SystemStats::getMemorySizeInMegabytes()
@@ -144,17 +144,16 @@ int SystemStats::getMemorySizeInMegabytes()
const String SystemStats::getCpuVendor()
{
#if JUCE_INTEL
#if JUCE_INTEL
uint32 dummy = 0;
uint32 vendor[4];
zerostruct (vendor);
uint32 vendor[4] = { 0 };
SystemStatsHelpers::doCPUID (dummy, vendor[0], vendor[2], vendor[1], 0);
return String (reinterpret_cast <const char*> (vendor), 12);
#else
#else
return String::empty;
#endif
#endif
}
int SystemStats::getCpuSpeedInMegaherz()
@@ -164,10 +163,11 @@ int SystemStats::getCpuSpeedInMegaherz()
int mib[] = { CTL_HW, HW_CPU_FREQ };
sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
#if JUCE_BIG_ENDIAN
#if JUCE_BIG_ENDIAN
if (speedSize == 4)
speedHz >>= 32;
#endif
#endif
return (int) (speedHz / 1000000);
}


+ 1
- 2
src/native/windows/juce_win32_ASIO.cpp View File

@@ -1801,8 +1801,7 @@ private:
if (RegOpenKeyEx (hk, keyName.toUTF16(), 0, KEY_READ, &subKey) == ERROR_SUCCESS)
{
TCHAR buf [256];
zerostruct (buf);
TCHAR buf [256] = { 0 };
DWORD dtype = REG_SZ;
DWORD dsize = sizeof (buf);


+ 1
- 2
src/native/windows/juce_win32_FileChooser.cpp View File

@@ -100,8 +100,7 @@ namespace FileChooserHelpers
if (comp != 0)
{
WCHAR path [MAX_PATH * 2];
zerostruct (path);
WCHAR path [MAX_PATH * 2] = { 0 };
CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
comp->selectedFileChanged (File (path));


+ 1
- 2
src/native/windows/juce_win32_SystemStats.cpp View File

@@ -344,9 +344,8 @@ int SystemStats::getPageSize()
//==============================================================================
const String SystemStats::getLogonName()
{
TCHAR text [256];
TCHAR text [256] = { 0 };
DWORD len = numElementsInArray (text) - 2;
zerostruct (text);
GetUserName (text, &len);
return String (text, len);
}


+ 13
- 16
src/text/juce_String.cpp View File

@@ -1823,31 +1823,28 @@ bool String::containsNonWhitespaceChars() const throw()
return false;
}
const String String::formatted (const String& pf, ... )
// Note! The format parameter here MUST NOT be a reference, otherwise MS's va_start macro fails to work (but still compiles).
const String String::formatted (const String pf, ... )
{
va_list args;
va_start (args, pf);
size_t bufferSize = 256;
for (;;)
{
#if JUCE_LINUX && JUCE_64BIT
HeapBlock <wchar_t> temp (bufferSize);
va_list tempArgs;
va_copy (tempArgs, args);
const int num = (int) vswprintf (temp.getData(), bufferSize - 1, pf.toUTF32(), tempArgs);
va_end (tempArgs);
#elif JUCE_WINDOWS
va_list args;
va_start (args, pf);
#if JUCE_WINDOWS
HeapBlock <wchar_t> temp (bufferSize);
const int num = (int) _vsnwprintf (temp.getData(), bufferSize - 1, pf.toUTF16(), args);
#elif JUCE_ANDROID
const int num = (int) _vsnwprintf (temp.getData(), bufferSize - 1, pf.toWideCharPointer(), args);
#elif JUCE_ANDROID
HeapBlock <char> temp (bufferSize);
const int num = (int) vsnprintf (temp.getData(), bufferSize - 1, pf.toUTF8(), args);
#else
#else
HeapBlock <wchar_t> temp (bufferSize);
const int num = (int) vswprintf (temp.getData(), bufferSize - 1, pf.toUTF32(), args);
#endif
const int num = (int) vswprintf (temp.getData(), bufferSize - 1, pf.toWideCharPointer(), args);
#endif
va_end (args);
if (num > 0)
return String (temp);


+ 1
- 1
src/text/juce_String.h View File

@@ -878,7 +878,7 @@ public:
on the platform, it may be using wchar_t or char character types, so that even string
literals can't be safely used as parameters if you're writing portable code.
*/
static const String formatted (const String& formatString, ... );
static const String formatted (const String formatString, ... );
//==============================================================================
// Numeric conversions..


+ 1
- 2
src/text/juce_XmlDocument.cpp View File

@@ -91,8 +91,7 @@ namespace XmlIdentifierChars
/*static void generateIdentifierCharConstants()
{
uint32 n[8];
zerostruct (n);
uint32 n[8] = { 0 };
for (int i = 0; i < 256; ++i)
if (isIdentifierCharSlow (i))
n[i >> 5] |= (1 << (i & 31));


+ 1
- 2
src/text/juce_XmlElement.cpp View File

@@ -132,8 +132,7 @@ namespace XmlOutputFunctions
void generateLegalCharConstants()
{
uint8 n[32];
zerostruct (n);
uint8 n[32] = { 0 };
for (int i = 0; i < 256; ++i)
if (isLegalXmlCharSlow (i))
n[i >> 3] |= (1 << (i & 7));


Loading…
Cancel
Save