Skip to content

Commit

Permalink
fix regressions in lua's support for UTF-8 strings, likely created ar…
Browse files Browse the repository at this point in the history
…ound the time of the sandboxing.
  • Loading branch information
zeromus committed May 23, 2016
1 parent 491307b commit 96416e1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 62 deletions.
26 changes: 16 additions & 10 deletions LuaInterface/Lua/src/LuaDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,22 @@ namespace Lua511

static int luaL_loadbuffer(IntPtr luaState, String^ buff, String^ name)
{
char *cs1 = (char *) Marshal::StringToHGlobalAnsi(buff).ToPointer();
char *cs2 = (char *) Marshal::StringToHGlobalAnsi(name).ToPointer();

//CP: fix for MBCS, changed to use cs1's length (reported by qingrui.li)
int result = ::luaL_loadbuffer(toState, cs1, strlen(cs1), cs2);

Marshal::FreeHGlobal(IntPtr(cs1));
Marshal::FreeHGlobal(IntPtr(cs2));

return result;
//zero 23-may-2016 - get rid of this GARBAGE. lua can load UTF-8, why not use that?
//char *cs1 = (char *) Marshal::StringToHGlobalAnsi(buff).ToPointer();
//char *cs2 = (char *) Marshal::StringToHGlobalAnsi(name).ToPointer();
////CP: fix for MBCS, changed to use cs1's length (reported by qingrui.li)
//int result = ::luaL_loadbuffer(toState, cs1, strlen(cs1), cs2);
//Marshal::FreeHGlobal(IntPtr(cs1));
//Marshal::FreeHGlobal(IntPtr(cs2));

array<System::Byte> ^ _buff = System::Text::Encoding::UTF8->GetBytes(buff);
array<System::Byte> ^ _name = System::Text::Encoding::UTF8->GetBytes(name);
char* lbuff = "", *lname = nullptr;
pin_ptr<System::Byte> p_buff, p_name;
if(buff->Length != 0) { p_buff = &_buff[0]; lbuff = (char*)(System::Byte*)p_buff; }
if(name->Length != 0) { p_name= &_name[0]; lname = (char*)(System::Byte*)p_name; }

return ::luaL_loadbuffer(toState, lbuff, _buff->Length, lname);
}

static int luaL_loadfile(IntPtr luaState, String^ filename)
Expand Down
5 changes: 5 additions & 0 deletions LuaInterface/Lua/src/lua514.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,9 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties />
</VisualStudio>
</ProjectExtensions>
</Project>
51 changes: 9 additions & 42 deletions LuaInterface/LuaInterface.sln
Original file line number Diff line number Diff line change
@@ -1,74 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua51", "Lua\src\lua514.vcxproj", "{0A82CC4C-9A27-461C-8DB0-A65AC6393748}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaInterface", "LuaInterface\LuaInterface.csproj", "{F55CABBB-4108-4A39-94E1-581FD46DC021}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x64 = Release|x64
Release|x86 = Release|x86
Release-LUAPERKS|Any CPU = Release-LUAPERKS|Any CPU
Release-LUAPERKS|Mixed Platforms = Release-LUAPERKS|Mixed Platforms
Release-LUAPERKS|Win32 = Release-LUAPERKS|Win32
Release-LUAPERKS|x64 = Release-LUAPERKS|x64
Release-LUAPERKS|x86 = Release-LUAPERKS|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|Any CPU.ActiveCfg = Debug|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|Win32.ActiveCfg = Debug|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|Win32.Build.0 = Debug|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|x64.ActiveCfg = Debug|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|x86.ActiveCfg = Debug|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|Any CPU.ActiveCfg = Release|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|Mixed Platforms.Build.0 = Release|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|Win32.ActiveCfg = Release|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|Win32.Build.0 = Release|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|x64.Build.0 = Debug|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|x86.ActiveCfg = Debug|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Debug|x86.Build.0 = Debug|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|x64.ActiveCfg = Release|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|x64.Build.0 = Release|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|x86.ActiveCfg = Release|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|Any CPU.ActiveCfg = Release-LUAPERKS|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|Mixed Platforms.ActiveCfg = Release-LUAPERKS|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|Mixed Platforms.Build.0 = Release-LUAPERKS|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|Win32.ActiveCfg = Release-LUAPERKS|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|Win32.Build.0 = Release-LUAPERKS|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|x86.ActiveCfg = Release|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release|x86.Build.0 = Release|Win32
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|x64.ActiveCfg = Release-LUAPERKS|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|x64.Build.0 = Release-LUAPERKS|x64
{0A82CC4C-9A27-461C-8DB0-A65AC6393748}.Release-LUAPERKS|x86.ActiveCfg = Release-LUAPERKS|Win32
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|Win32.ActiveCfg = Debug|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|x64.ActiveCfg = Debug|x64
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|x64.Build.0 = Debug|x64
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|x86.ActiveCfg = Debug|x86
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|Any CPU.Build.0 = Release|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|Win32.ActiveCfg = Release|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Debug|x86.Build.0 = Debug|x86
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|x64.ActiveCfg = Release|x64
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|x64.Build.0 = Release|x64
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|x86.ActiveCfg = Release|x86
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|Any CPU.ActiveCfg = Release-LUAPERKS|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|Any CPU.Build.0 = Release-LUAPERKS|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|Mixed Platforms.ActiveCfg = Release-LUAPERKS|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|Mixed Platforms.Build.0 = Release-LUAPERKS|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|Win32.ActiveCfg = Release-LUAPERKS|Any CPU
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|x86.Build.0 = Release|x86
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|x64.ActiveCfg = Release-LUAPERKS|x64
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|x64.Build.0 = Release-LUAPERKS|x64
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release-LUAPERKS|x86.ActiveCfg = Release-LUAPERKS|x86
Expand Down
20 changes: 10 additions & 10 deletions LuaInterface/LuaInterface/LuaInterface.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\references\</OutputPath>
<OutputPath>..\..\references\x86\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -61,7 +61,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\references\</OutputPath>
<OutputPath>..\..\references\x86\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -86,7 +86,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<OutputPath>..\..\references\x86\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -100,7 +100,7 @@
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<OutputPath>..\..\references\x86\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -131,7 +131,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<OutputPath>..\..\references\x64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
Expand All @@ -145,7 +145,7 @@
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<OutputPath>..\..\references\x64\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -218,15 +218,15 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lua\src\lua514.vcxproj">
<Project>{0A82CC4C-9A27-461C-8DB0-A65AC6393748}</Project>
<Project>{0a82cc4c-9a27-461c-8db0-a65ac6393748}</Project>
<Name>lua51</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Binary file modified References/x64/LuaInterface.dll
Binary file not shown.
Binary file modified References/x64/lua51.dll
Binary file not shown.
Binary file modified References/x86/LuaInterface.dll
Binary file not shown.
Binary file modified References/x86/lua51.dll
Binary file not shown.

0 comments on commit 96416e1

Please sign in to comment.