Skip to content

Commit

Permalink
Port CoreCLR's TypeNameBuilder to C#, and use it in Mono too (dotnet#…
Browse files Browse the repository at this point in the history
…33701)

* Port CoreCLR's TypeNameBuilder to C#, and use it in Mono too

Mono's System.Reflection.Emit creates type names that fail to be normalized or shaped in all ways that CoreCLR does.

Port CoreCLR's mixed-mode thread-unsafe implementation to thread-safe C#, and start using it in Mono for names in TypeBuilder.

Fixes issues with e.g. null-delimited type names being passed to different Reflection.Emit builders. Contributes to dotnet#2389.
  • Loading branch information
alexischr authored Apr 3, 2020
1 parent 07187e3 commit 3ab97fc
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
<Compile Include="$(BclSourcesRoot)\System\Reflection\Associates.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ConstructorInfo.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\CustomAttribute.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\AQNBuilder.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\AssemblyBuilder.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\AssemblyBuilderData.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\ConstructorBuilder.cs" />
Expand Down

This file was deleted.

19 changes: 0 additions & 19 deletions src/coreclr/src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,24 +434,6 @@ FCFuncStart(gMdUtf8String)
QCFuncElement("HashCaseInsensitive", MdUtf8String::HashCaseInsensitive)
FCFuncEnd()

FCFuncStart(gTypeNameBuilder)
QCFuncElement("CreateTypeNameBuilder", TypeNameBuilder::_CreateTypeNameBuilder)
QCFuncElement("ReleaseTypeNameBuilder", TypeNameBuilder::_ReleaseTypeNameBuilder)
QCFuncElement("OpenGenericArguments", TypeNameBuilder::_OpenGenericArguments)
QCFuncElement("CloseGenericArguments", TypeNameBuilder::_CloseGenericArguments)
QCFuncElement("OpenGenericArgument", TypeNameBuilder::_OpenGenericArgument)
QCFuncElement("CloseGenericArgument", TypeNameBuilder::_CloseGenericArgument)
QCFuncElement("AddName", TypeNameBuilder::_AddName)
QCFuncElement("AddPointer", TypeNameBuilder::_AddPointer)
QCFuncElement("AddByRef", TypeNameBuilder::_AddByRef)
QCFuncElement("AddSzArray", TypeNameBuilder::_AddSzArray)
QCFuncElement("AddArray", TypeNameBuilder::_AddArray)
QCFuncElement("AddAssemblySpec", TypeNameBuilder::_AddAssemblySpec)
QCFuncElement("ToString", TypeNameBuilder::_ToString)
QCFuncElement("Clear", TypeNameBuilder::_Clear)
FCFuncEnd()


FCFuncStart(gSafeTypeNameParserHandle)
QCFuncElement("_ReleaseTypeNameParser", TypeName::QReleaseTypeNameParser)
FCFuncEnd()
Expand Down Expand Up @@ -1315,7 +1297,6 @@ FCClassElement("TimerQueue", "System.Threading", gTimerFuncs)
FCClassElement("Type", "System", gSystem_Type)
FCClassElement("TypeBuilder", "System.Reflection.Emit", gCOMClassWriter)
FCClassElement("TypeLoadException", "System", gTypeLoadExceptionFuncs)
FCClassElement("TypeNameBuilder", "System.Reflection.Emit", gTypeNameBuilder)
FCClassElement("TypeNameParser", "System", gTypeNameParser)
FCClassElement("TypedReference", "System", gTypedReferenceFuncs)
#ifdef FEATURE_COMINTEROP
Expand Down
132 changes: 0 additions & 132 deletions src/coreclr/src/vm/typestring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,138 +28,6 @@
#include "ex.h"
#include "typedesc.h"

#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
TypeNameBuilder * QCALLTYPE TypeNameBuilder::_CreateTypeNameBuilder()
{
QCALL_CONTRACT;

TypeNameBuilder * retVal = NULL;
BEGIN_QCALL;
retVal = new TypeNameBuilder();
END_QCALL;

return retVal;
}

void QCALLTYPE TypeNameBuilder::_ReleaseTypeNameBuilder(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
delete pTnb;
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_ToString(TypeNameBuilder * pTnb, QCall::StringHandleOnStack retString)
{
QCALL_CONTRACT;

BEGIN_QCALL;
retString.Set(*pTnb->GetString());
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_AddName(TypeNameBuilder * pTnb, LPCWSTR wszName)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->AddName(wszName);
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_AddAssemblySpec(TypeNameBuilder * pTnb, LPCWSTR wszAssemblySpec)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->AddAssemblySpec(wszAssemblySpec);
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_OpenGenericArguments(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->OpenGenericArguments();
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_CloseGenericArguments(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->CloseGenericArguments();
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_OpenGenericArgument(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->OpenGenericArgument();
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_CloseGenericArgument(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->CloseGenericArgument();
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_AddPointer(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->AddPointer();
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_AddByRef(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->AddByRef();
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_AddSzArray(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->AddSzArray();
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_AddArray(TypeNameBuilder * pTnb, DWORD dwRank)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->AddArray(dwRank);
END_QCALL;
}

void QCALLTYPE TypeNameBuilder::_Clear(TypeNameBuilder * pTnb)
{
QCALL_CONTRACT;

BEGIN_QCALL;
pTnb->Clear();
END_QCALL;
}

#endif

//
// TypeNameBuilder
//
Expand Down
16 changes: 0 additions & 16 deletions src/coreclr/src/vm/typestring.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ class TypeString;

class TypeNameBuilder
{
public:
static void QCALLTYPE _ReleaseTypeNameBuilder(TypeNameBuilder * pTnb);
static TypeNameBuilder * QCALLTYPE _CreateTypeNameBuilder();
static void QCALLTYPE _OpenGenericArguments(TypeNameBuilder * pTnb);
static void QCALLTYPE _CloseGenericArguments(TypeNameBuilder *pTnb);
static void QCALLTYPE _OpenGenericArgument(TypeNameBuilder * pTnb);
static void QCALLTYPE _CloseGenericArgument(TypeNameBuilder * pTnb);
static void QCALLTYPE _AddName(TypeNameBuilder * pTnb, LPCWSTR wszName);
static void QCALLTYPE _AddPointer(TypeNameBuilder * pTnb);
static void QCALLTYPE _AddByRef(TypeNameBuilder * pTnb);
static void QCALLTYPE _AddSzArray(TypeNameBuilder * pTnb);
static void QCALLTYPE _AddArray(TypeNameBuilder * pTnb, DWORD dwRank);
static void QCALLTYPE _AddAssemblySpec(TypeNameBuilder * pTnb, LPCWSTR wszAssemblySpec);
static void QCALLTYPE _ToString(TypeNameBuilder * pTnb, QCall::StringHandleOnStack retString);
static void QCALLTYPE _Clear(TypeNameBuilder * pTnb);

private:
friend class TypeString;
friend SString* TypeName::ToString(SString*, BOOL, BOOL, BOOL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\SignatureToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\StackBehaviour.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\StringToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\TypeNameBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\TypeToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\EventAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\EventInfo.cs" />
Expand Down
Loading

0 comments on commit 3ab97fc

Please sign in to comment.