From d676187beb1be892844188ed0d8bbee27ed35032 Mon Sep 17 00:00:00 2001 From: Jerome Haltom Date: Mon, 9 Dec 2024 16:16:26 -0600 Subject: [PATCH] CopyTo works. But this isn't perfect. Writing to an existing constant set isn't supported, since it would be appending constants, potentially needing to rewrite instruction arguments to their wide formats. --- src/IKVM.ByteCode.Tests/Decoding/CodeDecoderTests.cs | 2 +- src/IKVM.ByteCode/Decoding/CodeAttribute.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/IKVM.ByteCode.Tests/Decoding/CodeDecoderTests.cs b/src/IKVM.ByteCode.Tests/Decoding/CodeDecoderTests.cs index b2ff60b..8d19644 100644 --- a/src/IKVM.ByteCode.Tests/Decoding/CodeDecoderTests.cs +++ b/src/IKVM.ByteCode.Tests/Decoding/CodeDecoderTests.cs @@ -158,7 +158,7 @@ public void CanCopyToWithConstant() ]); var buffer1 = new BlobBuilder(); - new CodeBuilder(buffer1).LoadConstant(new StringConstantHandle(1)).Pop().Return(); + new CodeBuilder(buffer1).LoadConstant(new IntegerConstantHandle(1)).Pop().Return(); var code1 = new CodeDecoder(buffer1.ToArray()); // copy from decoder into new builder diff --git a/src/IKVM.ByteCode/Decoding/CodeAttribute.cs b/src/IKVM.ByteCode/Decoding/CodeAttribute.cs index ae9492e..9c17ea5 100644 --- a/src/IKVM.ByteCode/Decoding/CodeAttribute.cs +++ b/src/IKVM.ByteCode/Decoding/CodeAttribute.cs @@ -70,7 +70,6 @@ public readonly void CopyTo(TConstantView constant where TConstantPool : IConstantPool { // copy code to new blob - var codeOffset = (int)Code.Length; var code = new BlobBuilder((int)Code.Length); new CodeDecoder(Code).CopyTo(constantView, constantPool, new CodeBuilder(code)); @@ -80,7 +79,7 @@ public readonly void CopyTo(TConstantView constant // add code attribute with copied values var excp = ExceptionTable; - encoder.Code(constantPool.Get(AttributeName.Code), MaxStack, MaxLocals, code, e => excp.CopyTo(constantView, constantPool, ref e, codeOffset), attr); + encoder.Code(constantPool.Get(AttributeName.Code), MaxStack, MaxLocals, code, e => excp.CopyTo(constantView, constantPool, ref e, 0), attr); } }