fix regressions in lua's support for UTF-8 strings, likely created around the time of the sandboxing.

This commit is contained in:
zeromus 2016-05-23 14:33:36 -05:00
parent 491307b85c
commit 96416e13d9
8 changed files with 39 additions and 61 deletions

View File

@ -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();
//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));
//CP: fix for MBCS, changed to use cs1's length (reported by qingrui.li)
int result = ::luaL_loadbuffer(toState, cs1, strlen(cs1), 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; }
Marshal::FreeHGlobal(IntPtr(cs1));
Marshal::FreeHGlobal(IntPtr(cs2));
return result;
return ::luaL_loadbuffer(toState, lbuff, _buff->Length, lname);
}
static int luaL_loadfile(IntPtr luaState, String^ filename)

View File

@ -435,4 +435,9 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -1,7 +1,7 @@

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
@ -9,66 +9,33 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaInterface", "LuaInterfac
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

View File

@ -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>
@ -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>
@ -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>
@ -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>
@ -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>
@ -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>
@ -219,13 +219,13 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lua\src\lua514.vcxproj">
<Project>{0A82CC4C-9A27-461C-8DB0-A65AC6393748}</Project>
<Name>lua51</Name>
</ProjectReference>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<ProjectReference Include="..\Lua\src\lua514.vcxproj">
<Project>{0a82cc4c-9a27-461c-8db0-a65ac6393748}</Project>
<Name>lua51</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.