int show_trace (char * str, va_list marker) { CQuickBytes buffer; int count = -1; int i = 1; while (count < 0) { # if _MSC_VER < 1400 HRESULT hr; if (FAILED(hr = buffer.ReSize (STRING_BUFFER_LEN * i))) die("Resize failed.", hr); #else buffer.ReSizeThrows (STRING_BUFFER_LEN * i); #endif count = _vsnprintf ((char *) buffer.Ptr(), STRING_BUFFER_LEN * i, str, marker); i *= 2; } fprintf (stderr, "%s", (char *) buffer.Ptr()); return count; }
//***************************************************************************** // translating signature from one scope to another scope // // Implements public API code:IMetaDataEmit::TranslateSigWithScope. // Implements internal API code:IMetaDataHelper::TranslateSigWithScope. //***************************************************************************** STDMETHODIMP RegMeta::TranslateSigWithScope( // S_OK or error. IMetaDataAssemblyImport *pAssemImport, // [IN] importing assembly interface const void *pbHashValue, // [IN] Hash Blob for Assembly. ULONG cbHashValue, // [IN] Count of bytes. IMetaDataImport *pImport, // [IN] importing interface PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature IMetaDataAssemblyEmit *pAssemEmit,// [IN] emit assembly interface IMetaDataEmit *pEmit, // [IN] emit interface PCOR_SIGNATURE pvTranslatedSig, // [OUT] buffer to hold translated signature ULONG cbTranslatedSigMax, ULONG *pcbTranslatedSig) // [OUT] count of bytes in the translated signature { #ifdef FEATURE_METADATA_EMIT HRESULT hr = S_OK; IMDCommon *pAssemImportMDCommon = NULL; IMDCommon *pImportMDCommon = NULL; BEGIN_ENTRYPOINT_NOTHROW; RegMeta *pRegMetaAssemEmit = static_cast<RegMeta*>(pAssemEmit); RegMeta *pRegMetaEmit = NULL; CQuickBytes qkSigEmit; ULONG cbEmit; pRegMetaEmit = static_cast<RegMeta*>(pEmit); { // This function can cause new TypeRef being introduced. LOCKWRITE(); IfFailGo(m_pStgdb->m_MiniMd.PreUpdate()); _ASSERTE(pvTranslatedSig && pcbTranslatedSig); if (pAssemImport) { IfFailGo(pAssemImport->QueryInterface(IID_IMDCommon, (void**)&pAssemImportMDCommon)); } IMetaModelCommon *pAssemImportMetaModelCommon = pAssemImportMDCommon ? pAssemImportMDCommon->GetMetaModelCommon() : 0; IfFailGo(pImport->QueryInterface(IID_IMDCommon, (void**)&pImportMDCommon)); IMetaModelCommon *pImportMetaModelCommon = pImportMDCommon->GetMetaModelCommon(); IfFailGo( ImportHelper::MergeUpdateTokenInSig( // S_OK or error. pRegMetaAssemEmit ? &(pRegMetaAssemEmit->m_pStgdb->m_MiniMd) : 0, // The assembly emit scope. &(pRegMetaEmit->m_pStgdb->m_MiniMd), // The emit scope. pAssemImportMetaModelCommon, // Assembly where the signature is from. pbHashValue, // Hash value for the import assembly. cbHashValue, // Size in bytes. pImportMetaModelCommon, // The scope where signature is from. pbSigBlob, // signature from the imported scope NULL, // Internal OID mapping structure. &qkSigEmit, // [OUT] translated signature 0, // start from first byte of the signature 0, // don't care how many bytes consumed &cbEmit)); // [OUT] total number of bytes write to pqkSigEmit memcpy(pvTranslatedSig, qkSigEmit.Ptr(), cbEmit > cbTranslatedSigMax ? cbTranslatedSigMax :cbEmit ); *pcbTranslatedSig = cbEmit; if (cbEmit > cbTranslatedSigMax) hr = CLDB_S_TRUNCATION; } ErrExit: END_ENTRYPOINT_NOTHROW; if (pAssemImportMDCommon) pAssemImportMDCommon->Release(); if (pImportMDCommon) pImportMDCommon->Release(); return hr; #else //!FEATURE_METADATA_EMIT return E_NOTIMPL; #endif //!FEATURE_METADATA_EMIT } // RegMeta::TranslateSigWithScope
//****************************************************************************** // // GetMemberRefToken // This function will return a MemberRef token given a MethodDef token and the module where the MethodDef/FieldDef is defined. // //****************************************************************************** INT32 QCALLTYPE COMModule::GetMemberRef(QCall::ModuleHandle pModule, QCall::ModuleHandle pRefedModule, INT32 tr, INT32 token) { QCALL_CONTRACT; mdMemberRef memberRefE = 0; BEGIN_QCALL; RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); _ASSERTE( pRCW ); LPCUTF8 szName; ULONG cbComSig; PCCOR_SIGNATURE pvComSig; if (TypeFromToken(token) == mdtMethodDef) { IfFailThrow(pRefedModule->GetMDImport()->GetNameOfMethodDef(token, &szName)); IfFailThrow(pRefedModule->GetMDImport()->GetSigOfMethodDef(token, &cbComSig, &pvComSig)); } else { IfFailThrow(pRefedModule->GetMDImport()->GetNameOfFieldDef(token, &szName)); IfFailThrow(pRefedModule->GetMDImport()->GetSigOfFieldDef(token, &cbComSig, &pvComSig)); } MAKE_WIDEPTR_FROMUTF8(wzName, szName); // Translate the method sig into this scope // Assembly * pRefedAssembly = pRefedModule->GetAssembly(); Assembly * pRefingAssembly = pModule->GetAssembly(); if (pRefedAssembly->IsCollectible() && pRefedAssembly != pRefingAssembly) { if (pRefingAssembly->IsCollectible()) pRefingAssembly->GetLoaderAllocator()->EnsureReference(pRefedAssembly->GetLoaderAllocator()); else COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleBoundNonCollectible")); } SafeComHolderPreemp<IMetaDataAssemblyEmit> pAssemblyEmit; IfFailThrow( pRefingAssembly->GetManifestModule()->GetEmitter()->QueryInterface(IID_IMetaDataAssemblyEmit, (void **) &pAssemblyEmit) ); CQuickBytes qbNewSig; ULONG cbNewSig; IfFailThrow( pRefedModule->GetMDImport()->TranslateSigWithScope( pRefedAssembly->GetManifestImport(), NULL, 0, // hash value pvComSig, cbComSig, pAssemblyEmit, // Emit assembly scope. pRCW->GetEmitter(), &qbNewSig, &cbNewSig) ); mdTypeRef tref; if (TypeFromToken(tr) == mdtTypeDef) { // define a TypeRef using the TypeDef DefineTypeRefHelper(pRCW->GetEmitter(), tr, &tref); } else tref = tr; // Define the memberRef IfFailThrow( pRCW->GetEmitter()->DefineMemberRef(tref, wzName, (PCCOR_SIGNATURE) qbNewSig.Ptr(), cbNewSig, &memberRefE) ); END_QCALL; // assign output parameter return (INT32)memberRefE; }