Skip to content

Commit

Permalink
Merge pull request #5098 from brettfo/type-provider-15.7
Browse files Browse the repository at this point in the history
Cherry-pick type provider fixes to 15.7
  • Loading branch information
brettfo authored Jun 5, 2018
2 parents 1c56fef + b481145 commit 173513e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ module Shim =
interface IFileSystem with

member __.AssemblyLoadFrom(fileName: string) =
Assembly.LoadFrom fileName
Assembly.UnsafeLoadFrom fileName

member __.AssemblyLoad(assemblyName: AssemblyName) =
Assembly.Load assemblyName
Expand Down
20 changes: 12 additions & 8 deletions src/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3228,14 +3228,18 @@ and seekReadManifestResources (ctxt: ILMetadataReader) (mdv: BinaryView) (pectxt
let scoref = seekReadImplAsScopeRef ctxt mdv implIdx

let location =
match scoref with
| ILScopeRef.Local ->
let start = pectxtEager.anyV2P ("resource", offset + pectxtEager.resourcesAddr)
let resourceLength = seekReadInt32 pevEager start
let offsetOfBytesFromStartOfPhysicalPEFile = start + 4
ILResourceLocation.LocalIn (ctxt.fileName, offsetOfBytesFromStartOfPhysicalPEFile, resourceLength)
| ILScopeRef.Module mref -> ILResourceLocation.File (mref, offset)
| ILScopeRef.Assembly aref -> ILResourceLocation.Assembly aref
match scoref with
| ILScopeRef.Local ->
let start = pectxtEager.anyV2P ("resource", offset + pectxtEager.resourcesAddr)
let resourceLength = seekReadInt32 pevEager start
let offsetOfBytesFromStartOfPhysicalPEFile = start + 4
if pectxtEager.noFileOnDisk then
ILResourceLocation.LocalOut (seekReadBytes pevEager offsetOfBytesFromStartOfPhysicalPEFile resourceLength)
else
ILResourceLocation.LocalIn (ctxt.fileName, offsetOfBytesFromStartOfPhysicalPEFile, resourceLength)

| ILScopeRef.Module mref -> ILResourceLocation.File (mref, offset)
| ILScopeRef.Assembly aref -> ILResourceLocation.Assembly aref

let r =
{ Name= readStringHeap ctxt nameIdx
Expand Down
34 changes: 18 additions & 16 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2679,22 +2679,24 @@ and GenEventPass3 cenv env (md: ILEventDef) =

let rec GetResourceAsManifestResourceRow cenv r =
let data, impl =
match r.Location with
| ILResourceLocation.LocalIn _
| ILResourceLocation.LocalOut _ ->
let bytes = r.GetBytes()
// Embedded managed resources must be word-aligned. However resource format is
// not specified in ECMA. Some mscorlib resources appear to be non-aligned - it seems it doesn't matter..
let offset = cenv.resources.Position
let alignedOffset = (align 0x8 offset)
let pad = alignedOffset - offset
let resourceSize = bytes.Length
cenv.resources.EmitPadding pad
cenv.resources.EmitInt32 resourceSize
cenv.resources.EmitBytes bytes
Data (alignedOffset, true), (i_File, 0)
| ILResourceLocation.File (mref, offset) -> ULong offset, (i_File, GetModuleRefAsFileIdx cenv mref)
| ILResourceLocation.Assembly aref -> ULong 0x0, (i_AssemblyRef, GetAssemblyRefAsIdx cenv aref)
let embedManagedResources (bytes:byte[]) =
// Embedded managed resources must be word-aligned. However resource format is
// not specified in ECMA. Some mscorlib resources appear to be non-aligned - it seems it doesn't matter..
let offset = cenv.resources.Position
let alignedOffset = (align 0x8 offset)
let pad = alignedOffset - offset
let resourceSize = bytes.Length
cenv.resources.EmitPadding pad
cenv.resources.EmitInt32 resourceSize
cenv.resources.EmitBytes bytes
Data (alignedOffset, true), (i_File, 0)

match r.Location with
| ILResourceLocation.LocalIn _ -> embedManagedResources (r.GetBytes())
| ILResourceLocation.LocalOut bytes -> embedManagedResources bytes
| ILResourceLocation.File (mref, offset) -> ULong offset, (i_File, GetModuleRefAsFileIdx cenv mref)
| ILResourceLocation.Assembly aref -> ULong 0x0, (i_AssemblyRef, GetAssemblyRefAsIdx cenv aref)

UnsharedRow
[| data
ULong (match r.Access with ILResourceAccess.Public -> 0x01 | ILResourceAccess.Private -> 0x02)
Expand Down

0 comments on commit 173513e

Please sign in to comment.