Skip to content

Commit 173513e

Browse files
authored
Merge pull request #5098 from brettfo/type-provider-15.7
Cherry-pick type provider fixes to 15.7
2 parents 1c56fef + b481145 commit 173513e

3 files changed

Lines changed: 31 additions & 25 deletions

File tree

src/absil/illib.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ module Shim =
12371237
interface IFileSystem with
12381238

12391239
member __.AssemblyLoadFrom(fileName: string) =
1240-
Assembly.LoadFrom fileName
1240+
Assembly.UnsafeLoadFrom fileName
12411241

12421242
member __.AssemblyLoad(assemblyName: AssemblyName) =
12431243
Assembly.Load assemblyName

src/absil/ilread.fs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,14 +3228,18 @@ and seekReadManifestResources (ctxt: ILMetadataReader) (mdv: BinaryView) (pectxt
32283228
let scoref = seekReadImplAsScopeRef ctxt mdv implIdx
32293229

32303230
let location =
3231-
match scoref with
3232-
| ILScopeRef.Local ->
3233-
let start = pectxtEager.anyV2P ("resource", offset + pectxtEager.resourcesAddr)
3234-
let resourceLength = seekReadInt32 pevEager start
3235-
let offsetOfBytesFromStartOfPhysicalPEFile = start + 4
3236-
ILResourceLocation.LocalIn (ctxt.fileName, offsetOfBytesFromStartOfPhysicalPEFile, resourceLength)
3237-
| ILScopeRef.Module mref -> ILResourceLocation.File (mref, offset)
3238-
| ILScopeRef.Assembly aref -> ILResourceLocation.Assembly aref
3231+
match scoref with
3232+
| ILScopeRef.Local ->
3233+
let start = pectxtEager.anyV2P ("resource", offset + pectxtEager.resourcesAddr)
3234+
let resourceLength = seekReadInt32 pevEager start
3235+
let offsetOfBytesFromStartOfPhysicalPEFile = start + 4
3236+
if pectxtEager.noFileOnDisk then
3237+
ILResourceLocation.LocalOut (seekReadBytes pevEager offsetOfBytesFromStartOfPhysicalPEFile resourceLength)
3238+
else
3239+
ILResourceLocation.LocalIn (ctxt.fileName, offsetOfBytesFromStartOfPhysicalPEFile, resourceLength)
3240+
3241+
| ILScopeRef.Module mref -> ILResourceLocation.File (mref, offset)
3242+
| ILScopeRef.Assembly aref -> ILResourceLocation.Assembly aref
32393243

32403244
let r =
32413245
{ Name= readStringHeap ctxt nameIdx

src/absil/ilwrite.fs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,22 +2679,24 @@ and GenEventPass3 cenv env (md: ILEventDef) =
26792679

26802680
let rec GetResourceAsManifestResourceRow cenv r =
26812681
let data, impl =
2682-
match r.Location with
2683-
| ILResourceLocation.LocalIn _
2684-
| ILResourceLocation.LocalOut _ ->
2685-
let bytes = r.GetBytes()
2686-
// Embedded managed resources must be word-aligned. However resource format is
2687-
// not specified in ECMA. Some mscorlib resources appear to be non-aligned - it seems it doesn't matter..
2688-
let offset = cenv.resources.Position
2689-
let alignedOffset = (align 0x8 offset)
2690-
let pad = alignedOffset - offset
2691-
let resourceSize = bytes.Length
2692-
cenv.resources.EmitPadding pad
2693-
cenv.resources.EmitInt32 resourceSize
2694-
cenv.resources.EmitBytes bytes
2695-
Data (alignedOffset, true), (i_File, 0)
2696-
| ILResourceLocation.File (mref, offset) -> ULong offset, (i_File, GetModuleRefAsFileIdx cenv mref)
2697-
| ILResourceLocation.Assembly aref -> ULong 0x0, (i_AssemblyRef, GetAssemblyRefAsIdx cenv aref)
2682+
let embedManagedResources (bytes:byte[]) =
2683+
// Embedded managed resources must be word-aligned. However resource format is
2684+
// not specified in ECMA. Some mscorlib resources appear to be non-aligned - it seems it doesn't matter..
2685+
let offset = cenv.resources.Position
2686+
let alignedOffset = (align 0x8 offset)
2687+
let pad = alignedOffset - offset
2688+
let resourceSize = bytes.Length
2689+
cenv.resources.EmitPadding pad
2690+
cenv.resources.EmitInt32 resourceSize
2691+
cenv.resources.EmitBytes bytes
2692+
Data (alignedOffset, true), (i_File, 0)
2693+
2694+
match r.Location with
2695+
| ILResourceLocation.LocalIn _ -> embedManagedResources (r.GetBytes())
2696+
| ILResourceLocation.LocalOut bytes -> embedManagedResources bytes
2697+
| ILResourceLocation.File (mref, offset) -> ULong offset, (i_File, GetModuleRefAsFileIdx cenv mref)
2698+
| ILResourceLocation.Assembly aref -> ULong 0x0, (i_AssemblyRef, GetAssemblyRefAsIdx cenv aref)
2699+
26982700
UnsharedRow
26992701
[| data
27002702
ULong (match r.Access with ILResourceAccess.Public -> 0x01 | ILResourceAccess.Private -> 0x02)

0 commit comments

Comments
 (0)