Skip to content

Commit 39fce71

Browse files
KevinRansombrettfo
authored andcommitted
Fix TypeProviders with managed resources (#5036)
* Fix TypeProviders with managed resources * Revert "Fix TypeProviders with managed resources" This reverts commit 6f925b323bbe2cf2e1a24d887cb47234389c9ef5. * Fix Type Providers still don't compile in 15.7.2 #4972
1 parent 1c56fef commit 39fce71

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

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)