Skip to content

Commit

Permalink
Bug #107, 解决VS2010等老编译器找不到threadSafeInit、sizedDealloc相关符号
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Jul 24, 2024
1 parent 8f47d40 commit f323a7a
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ goto:eof
:BuildObj
echo BuildObj %1 %2 %3

cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Target=%2" "%~dp0Thunks\YY_Thunks.cpp"
cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /Zc:threadSafeInit- /Zc:sizedDealloc- /Zc:tlsGuards- /Zc:alignedNew- /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Target=%2" "%~dp0Thunks\YY_Thunks.cpp"
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

::生成weak符号,一些非必须符号安排为weak可以避免链接失败
Expand All @@ -52,7 +52,7 @@ echo BuildLib %1 %2 %3

md "Lib\\%1\\%Platform%"

cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"Lib\\%1\\%Platform%\\YY_Thunks_for_%1.obj" /Zl /c /D "__APPLY_CHROMIUM_WORKAROUNDS" /D "__USING_NTDLL_LIB" /D "NDEBUG" /D "YY_Thunks_Target=%2" /D "__FALLBACK_PREFIX=YY_Thunks_" "%~dp0Thunks\YY_Thunks.cpp"
cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /Zc:threadSafeInit- /Zc:sizedDealloc- /Zc:tlsGuards- /Zc:alignedNew- /arch:IA32 /Z7 /MT /Fo"Lib\\%1\\%Platform%\\YY_Thunks_for_%1.obj" /Zl /c /D "__APPLY_CHROMIUM_WORKAROUNDS" /D "__USING_NTDLL_LIB" /D "NDEBUG" /D "YY_Thunks_Target=%2" /D "__FALLBACK_PREFIX=YY_Thunks_" "%~dp0Thunks\YY_Thunks.cpp"

if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

Expand Down
99 changes: 99 additions & 0 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,105 @@ namespace YY::Thunks::internal
}
}

class CppAlloc
{
public:
_NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR
void* __CRTDECL operator new(
size_t _Size
)
{
return Alloc(_Size);
}

_NODISCARD _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR
void* __CRTDECL operator new(
size_t _Size,
::std::nothrow_t const&
) noexcept
{
return Alloc(_Size);
}

_NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR
void* __CRTDECL operator new[](
size_t _Size
)
{
return Alloc(_Size);
}

_NODISCARD _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR
void* __CRTDECL operator new[](
size_t _Size,
::std::nothrow_t const&
) noexcept
{
return Alloc(_Size);
}

/// <summary>
/// placement new
/// </summary>
/// <param name="_Size"></param>
/// <param name="_Block"></param>
/// <returns></returns>
void* __CRTDECL operator new(
size_t _Size,
void* _Block
)
{
return _Block;
}

void __CRTDECL operator delete(
void* _Block
) noexcept
{
Free(_Block);
}

void __CRTDECL operator delete(
void* _Block,
::std::nothrow_t const&
) noexcept
{
Free(_Block);
}

void __CRTDECL operator delete[](
void* _Block
) noexcept
{
Free(_Block);
}

void __CRTDECL operator delete[](
void* _Block,
::std::nothrow_t const&
) noexcept
{
Free(_Block);
}

void __CRTDECL operator delete(
void* _Block,
size_t _Size
) noexcept
{
Free(_Block);
}

void __CRTDECL operator delete[](
void* _Block,
size_t _Size
) noexcept
{
Free(_Block);
}
};


//代码块,分割任务
template<class Callback, typename... Params>
auto __forceinline Block(Callback&& _Callback, Params&&... args) -> decltype(_Callback(args...))
Expand Down
2 changes: 1 addition & 1 deletion src/Thunks/bcrypt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace YY::Thunks
Key,
};

class BCryptObject
class BCryptObject : public internal::CppAlloc
{
static constexpr auto kBCryptObjectMagic = 0x998u;

Expand Down
8 changes: 4 additions & 4 deletions src/Thunks/dwrite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace YY::Thunks::Fallback
namespace
{
#if (YY_Thunks_Target < __WindowsNT10_10240)
class DWriteRenderingParams : public IDWriteRenderingParams3
class DWriteRenderingParams : public IDWriteRenderingParams3, public internal::CppAlloc
{
private:
ULONG uRef = 1;
Expand Down Expand Up @@ -166,7 +166,7 @@ namespace YY::Thunks::Fallback
}
};

class DWriteFontCollection : public IDWriteFontCollection1
class DWriteFontCollection : public IDWriteFontCollection1, public internal::CppAlloc
{
private:
ULONG uRef = 1;
Expand Down Expand Up @@ -340,7 +340,7 @@ namespace YY::Thunks::Fallback
using IDWriteFontCollection::GetFontFamily;
};

class DWriteFontFallback : public IDWriteFontFallback
class DWriteFontFallback : public IDWriteFontFallback, public internal::CppAlloc
{
private:
ULONG uRef = 1;
Expand Down Expand Up @@ -446,7 +446,7 @@ namespace YY::Thunks::Fallback
}
};

class DWriteFactory : public IDWriteFactory3
class DWriteFactory : public IDWriteFactory3, public internal::CppAlloc
{
private:
ULONG uRef = 1;
Expand Down

0 comments on commit f323a7a

Please sign in to comment.