Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simplify managed MetadataImport creation#101353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
Always get the latest metadataimport instance.
The field on the managed object can becomestale during HotReload or EnC scenarios.
  • Loading branch information
@AaronRobinsonMSFT
AaronRobinsonMSFT committedApr 23, 2024
commita9bd0fc019e1bb0da939dc39cb6e162b51af4740
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -301,10 +301,16 @@ internal static unsafe MarshalAsAttribute GetMarshalAs(ConstArray nativeType, Ru
#endregion

#region Constructor
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern unsafe IntPtr GetMetadataImport(RuntimeModule module);

internal MetadataImport(RuntimeModule module)
{
ArgumentNullException.ThrowIfNull(module);
m_metadataImport2 = module.GetMDImport();

// The MetadataImport instance needs to be acquired in this manner
// since the instance can be replaced during HotReload and EnC scenarios.
m_metadataImport2 = GetMetadataImport(module);
}
#endregion

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,6 @@ internal sealed partial class RuntimeModule : Module
private RuntimeType m_runtimeType;
private readonly RuntimeAssembly m_runtimeAssembly;
private readonly IntPtr m_pData;
private readonly IntPtr m_metadataImport2;
#pragma warning restore CA1823, 169
#endregion

Expand DownExpand Up@@ -530,11 +529,6 @@ internal IntPtr GetUnderlyingNativeHandle()
{
return m_pData;
}

internal IntPtr GetMDImport()
{
return m_metadataImport2;
}
#endregion
}
}
2 changes: 1 addition & 1 deletionsrc/coreclr/vm/domainassembly.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -351,7 +351,7 @@ OBJECTREF DomainAssembly::GetExposedModuleObject()
GCPROTECT_BEGIN(refClass);

refClass = (REFLECTMODULEBASEREF) AllocateObject(CoreLibBinder::GetClass(CLASS__MODULE));
refClass->SetModuleDetails(GetModule(), GetModule()->GetMDImport());
refClass->SetModule(GetModule());

// Attach the reference to the assembly to keep the LoaderAllocator for this collectible type
// alive as long as a reference to the module is kept alive.
Expand Down
1 change: 1 addition & 0 deletionssrc/coreclr/vm/ecalllist.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -155,6 +155,7 @@ FCFuncStart(gCOMTypeHandleFuncs)
FCFuncEnd()

FCFuncStart(gMetaDataImport)
FCFuncElement("GetMetadataImport", MetaDataImport::GetMetadataImport)
FCFuncElement("GetDefaultValue", MetaDataImport::GetDefaultValue)
FCFuncElement("GetName", MetaDataImport::GetName)
FCFuncElement("GetUserString", MetaDataImport::GetUserString)
Expand Down
10 changes: 10 additions & 0 deletionssrc/coreclr/vm/managedmdimport.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,6 +67,16 @@ FCIMPL11(FC_BOOL_RET, MetaDataImport::GetMarshalAs,
}
FCIMPLEND

FCIMPL1(IMDInternalImport*, MetaDataImport::GetMetadataImport, ReflectModuleBaseObject * pModuleUNSAFE)
{
FCALL_CONTRACT;

REFLECTMODULEBASEREF refModule = (REFLECTMODULEBASEREF)ObjectToOBJECTREF(pModuleUNSAFE);
Module *pModule = refModule->GetModule();
return pModule->GetMDImport();
}
FCIMPLEND

FCIMPL6(HRESULT, MetaDataImport::GetDefaultValue, IMDInternalImport* pScope, mdToken tk, INT64* pDefaultValue, LPCWSTR* pStringValue, INT32* pLength, INT32* pCorElementType)
{
FCALL_CONTRACT;
Expand Down
1 change: 1 addition & 0 deletionssrc/coreclr/vm/managedmdimport.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@ typedef struct
class MetaDataImport
{
public:
static FCDECL1(IMDInternalImport*, GetMetadataImport, ReflectModuleBaseObject* pModuleUNSAFE);
static FCDECL2(HRESULT, GetScopeProps, IMDInternalImport* pScope, GUID* pmvid);
static FCDECL3(HRESULT, GetMemberRefProps, IMDInternalImport* pScope, mdMemberRef mr, ConstArray* ppvSigBlob);

Expand Down
6 changes: 1 addition & 5 deletionssrc/coreclr/vm/object.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1171,19 +1171,15 @@ class ReflectModuleBaseObject : public Object
OBJECTREF m_runtimeType;
OBJECTREF m_runtimeAssembly;
Module* m_pData; // Pointer to the Module
IMDInternalImport* m_metadataImport2;

protected:
ReflectModuleBaseObject() {LIMITED_METHOD_CONTRACT;}
~ReflectModuleBaseObject() {LIMITED_METHOD_CONTRACT;}

public:
voidSetModuleDetails(Module* p, IMDInternalImport* import) {
voidSetModule(Module* p) {
LIMITED_METHOD_CONTRACT;
_ASSERTE(p != NULL);
_ASSERTE(import != NULL);
m_pData = p;
m_metadataImport2 = import;
}
Module* GetModule() {
LIMITED_METHOD_CONTRACT;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp