diff --git a/modules/yup_audio_basics/buffers/yup_FloatVectorOperations.cpp b/modules/yup_audio_basics/buffers/yup_FloatVectorOperations.cpp index 42c601386..4bb8bb1a3 100644 --- a/modules/yup_audio_basics/buffers/yup_FloatVectorOperations.cpp +++ b/modules/yup_audio_basics/buffers/yup_FloatVectorOperations.cpp @@ -1564,7 +1564,7 @@ void convertDoubleToFloat (float* dest, const double* src, Size num) noexcept float32x2_t f = vcvt_f32_f64 (d); vst1_f32 (dest + i, f); } -#elif JUCE_USE_SSE_INTRINSICS +#elif YUP_USE_SSE_INTRINSICS for (; i + 2 <= num; i += 2) { __m128d d = _mm_loadu_pd (src + i); @@ -1592,7 +1592,7 @@ void convertFloatToDouble (double* dest, const float* src, Size num) noexcept float64x2_t d = vcvt_f64_f32 (f); vst1q_f64 (dest + i, d); } -#elif JUCE_USE_SSE_INTRINSICS +#elif YUP_USE_SSE_INTRINSICS for (; i + 4 <= num; i += 4) { __m128 f = _mm_loadu_ps (src + i); diff --git a/modules/yup_core/streams/yup_MemoryOutputStream.cpp b/modules/yup_core/streams/yup_MemoryOutputStream.cpp index bfa5477bf..cd7242c62 100644 --- a/modules/yup_core/streams/yup_MemoryOutputStream.cpp +++ b/modules/yup_core/streams/yup_MemoryOutputStream.cpp @@ -99,7 +99,7 @@ char* MemoryOutputStream::prepareToWrite (size_t numBytes) if (blockToUse != nullptr) { if (storageNeeded >= blockToUse->getSize()) - blockToUse->ensureSize ((storageNeeded + jmin (storageNeeded / 2, (size_t) (1024 * 1024)) + 32) & (size_t) (31)); + blockToUse->ensureSize ((storageNeeded + jmin (storageNeeded / 2, (size_t) (1024 * 1024)) + 32) & ~(size_t) 31); data = static_cast (blockToUse->getData()); } @@ -226,4 +226,3 @@ OutputStream& YUP_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputS } } // namespace yup - diff --git a/modules/yup_core/system/yup_SystemStats.cpp b/modules/yup_core/system/yup_SystemStats.cpp index 0c7fa97d7..c81b3f0ce 100644 --- a/modules/yup_core/system/yup_SystemStats.cpp +++ b/modules/yup_core/system/yup_SystemStats.cpp @@ -57,11 +57,11 @@ String SystemStats::getYUPVersion() return "YUP v" YUP_STRINGIFY (YUP_MAJOR_VERSION) "." YUP_STRINGIFY (YUP_MINOR_VERSION) "." YUP_STRINGIFY (YUP_BUILDNUMBER); } -#if YUP_ANDROID && ! defined(YUP_DISABLE_YUP_VERSION_PRINTING) -#define YUP_DISABLE_YUP_VERSION_PRINTING 1 +#if YUP_ANDROID && ! defined(YUP_DISABLE_VERSION_PRINTING) +#define YUP_DISABLE_VERSION_PRINTING 1 #endif -#if YUP_DEBUG && ! YUP_DISABLE_YUP_VERSION_PRINTING +#if YUP_DEBUG && ! YUP_DISABLE_VERSION_PRINTING struct YupVersionPrinter { YupVersionPrinter() diff --git a/modules/yup_core/system/yup_TargetPlatform.h b/modules/yup_core/system/yup_TargetPlatform.h index d9f1c0ed7..03f491ac7 100644 --- a/modules/yup_core/system/yup_TargetPlatform.h +++ b/modules/yup_core/system/yup_TargetPlatform.h @@ -109,7 +109,7 @@ //============================================================================== #if YUP_WINDOWS #ifdef __MINGW32__ -#error "MingW is no longer supported by YUP!" +#error "MingW is an unsupported platform in YUP!" #endif #ifdef _MSC_VER diff --git a/modules/yup_python/bindings/yup_YupCore_bindings.h b/modules/yup_python/bindings/yup_YupCore_bindings.h index 6b7996834..d242aeb75 100644 --- a/modules/yup_python/bindings/yup_YupCore_bindings.h +++ b/modules/yup_python/bindings/yup_YupCore_bindings.h @@ -393,7 +393,7 @@ template struct PyInputStream : Base { private: -#if JUCE_WINDOWS && ! JUCE_MINGW +#if YUP_WINDOWS using ssize_t = pointer_sized_int; #endif @@ -878,13 +878,13 @@ struct PyThread : Base void run() override { -#if JUCE_PYTHON_THREAD_CATCH_EXCEPTION +#if YUP_PYTHON_THREAD_CATCH_EXCEPTION try { #endif PYBIND11_OVERRIDE_PURE (void, Base, run); -#if JUCE_PYTHON_THREAD_CATCH_EXCEPTION +#if YUP_PYTHON_THREAD_CATCH_EXCEPTION } catch (const pybind11::error_already_set& e) { diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index db6dc3b6b..50d248a84 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -30,7 +30,7 @@ yup_add_default_modules ("${CMAKE_CURRENT_LIST_DIR}/.." ENABLE_PYTHON ON DEFINITIONS YUP_STANDALONE_APPLICATION=1 - YUP_DISABLE_JUCE_VERSION_PRINTING=1 + YUP_DISABLE_VERSION_PRINTING=1 YUP_MODAL_LOOPS_PERMITTED=1 YUP_CATCH_UNHANDLED_EXCEPTIONS=1 YUP_LOG_ASSERTIONS=1 diff --git a/tests/yup_core/yup_MemoryOutputStream.cpp b/tests/yup_core/yup_MemoryOutputStream.cpp new file mode 100644 index 000000000..e92b43870 --- /dev/null +++ b/tests/yup_core/yup_MemoryOutputStream.cpp @@ -0,0 +1,49 @@ +/* + ============================================================================== + + This file is part of the YUP library. + Copyright (c) 2024 - kunitoki@gmail.com + + YUP is an open source library subject to open-source licensing. + + The code included in this file is provided under the terms of the ISC license + http://www.isc.org/downloads/software-support-policy/isc-license. Permission + to use, copy, modify, and/or distribute this software for any purpose with or + without fee is hereby granted provided that the above copyright notice and + this permission notice appear in all copies. + + YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER + EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE + DISCLAIMED. + + ============================================================================== +*/ + +#include + +#include + +using namespace yup; + +TEST (MemoryOutputStreamTests, WriteTextUtf16SupportsFullUnicodeCodepoints) +{ + static constexpr yup_wchar stringA[] { 0x1F600, 0x00 }; // Grinning face emoji + static constexpr yup_wchar stringB[] { 0xA, 0xB, 0xC, 0x0 }; // ASCII + static constexpr yup_wchar stringC[] { 0xAAAA, 0xBBBB, 0xCCCC, 0x0 }; // two-byte characters + + CharPointer_UTF32 pointers[] { CharPointer_UTF32 (stringA), + CharPointer_UTF32 (stringB), + CharPointer_UTF32 (stringC) }; + + for (auto originalPtr : pointers) + { + MemoryOutputStream stream; + EXPECT_TRUE (stream.writeText (String (originalPtr), true, false, "\n")); + EXPECT_NE (stream.getDataSize(), (size_t) 0); + + CharPointer_UTF16 writtenPtr { reinterpret_cast (stream.getData()) }; + + for (auto currentOriginal = originalPtr; ! currentOriginal.isEmpty(); ++currentOriginal, ++writtenPtr) + EXPECT_EQ (*currentOriginal, *writtenPtr); + } +} diff --git a/tests/yup_core/yup_String.cpp b/tests/yup_core/yup_String.cpp index bb9dcb64a..fa11ccd7a 100644 --- a/tests/yup_core/yup_String.cpp +++ b/tests/yup_core/yup_String.cpp @@ -895,6 +895,52 @@ TEST_F (StringTests, StringCreationFromData) EXPECT_TRUE (empty_from_data.isEmpty()); } +TEST_F (StringTests, CreateStringFromDataHandlesEncodings) +{ + const String expectedString (CharPointer_UTF8 ("glass \xc2\xbd full")); + const String emojiExpectedString (CharPointer_UTF8 ("hello JUCE \xf0\x9f\xa7\x83")); + + { + SCOPED_TRACE ("createStringFromData reads LE UTF-16"); + constexpr char buffer[] = "\xff\xfe\x67\x00\x6c\x00\x61\x00\x73\x00\x73\x00\x20\x00\xbd\x00\x20\x00\x66\x00\x75\x00\x6c\x00\x6c\x00"; + const auto actualString = String::createStringFromData (buffer, static_cast (sizeof (buffer))); + EXPECT_EQ (expectedString, actualString); + + constexpr char emojiBuffer[] = "\xff\xfe\x68\x00\x65\x00\x6c\x00\x6c\x00\x6f\x00\x20\x00\x4a\x00\x55\x00\x43\x00\x45\x00\x20\x00\x3e\xd8\xc3\xdd"; + const auto emojiActualString = String::createStringFromData (emojiBuffer, static_cast (sizeof (emojiBuffer))); + EXPECT_EQ (emojiExpectedString, emojiActualString); + } + + { + SCOPED_TRACE ("createStringFromData reads BE UTF-16"); + constexpr char buffer[] = "\xfe\xff\x00\x67\x00\x6c\x00\x61\x00\x73\x00\x73\x00\x20\x00\xbd\x00\x20\x00\x66\x00\x75\x00\x6c\x00\x6c"; + const auto actualString = String::createStringFromData (buffer, static_cast (sizeof (buffer))); + EXPECT_EQ (expectedString, actualString); + + constexpr char emojiBuffer[] = "\xfe\xff\x00\x68\x00\x65\x00\x6c\x00\x6c\x00\x6f\x00\x20\x00\x4a\x00\x55\x00\x43\x00\x45\x00\x20\xd8\x3e\xdd\xc3"; + const auto emojiActualString = String::createStringFromData (emojiBuffer, static_cast (sizeof (emojiBuffer))); + EXPECT_EQ (emojiExpectedString, emojiActualString); + } + + { + SCOPED_TRACE ("createStringFromData reads UTF-8"); + constexpr char buffer[] = "glass \xc2\xbd full"; + const auto actualString = String::createStringFromData (buffer, static_cast (sizeof (buffer))); + EXPECT_EQ (expectedString, actualString); + + constexpr char emojiBuffer[] = "hello JUCE \xf0\x9f\xa7\x83"; + const auto emojiActualString = String::createStringFromData (emojiBuffer, static_cast (sizeof (emojiBuffer))); + EXPECT_EQ (emojiExpectedString, emojiActualString); + } + + { + SCOPED_TRACE ("createStringFromData reads Windows 1252"); + constexpr char buffer[] = "glass \xBD full"; + const auto actualString = String::createStringFromData (buffer, static_cast (sizeof (buffer))); + EXPECT_EQ (expectedString, actualString); + } +} + TEST_F (StringTests, FromUTF8) { // Test fromUTF8