This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Implement support for copy constructors when marshalling in IJW #22805
Merged
jkoritzinsky
merged 7 commits into
dotnet:master
from
jkoritzinsky:copy-constructor-marshaler
Mar 19, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bd5c462
First pass of adding support for copy-constructors when marshalling.
jkoritzinsky 357c7b4
Merge branch 'master' of https://github.com/dotnet/coreclr into copy-…
jkoritzinsky 3e5c0aa
Implement minimal required x86-only path. Add tests.
jkoritzinsky 13a4e69
PR Feedback.
jkoritzinsky a3c20cc
Simplify assignment
jkoritzinsky ab73062
Make sure we get the right boolean type used.
jkoritzinsky 035db19
Merge branch 'master' of https://github.com/dotnet/coreclr into copy-…
jkoritzinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/src/Interop/IJW/CopyConstructorMarshaler/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| cmake_minimum_required (VERSION 2.6) | ||
| project (CopyConstructorMarshaler) | ||
| include_directories( ${INC_PLATFORM_DIR} ) | ||
| set(SOURCES IjwCopyConstructorMarshaler.cpp) | ||
|
|
||
| if (WIN32) | ||
| # 4365 - signed/unsigned mismatch | ||
| add_compile_options(/wd4365) | ||
|
|
||
| # IJW | ||
| add_compile_options(/clr) | ||
|
|
||
| # IJW requires the CRT as a dll, not linked in | ||
| add_compile_options(/MD$<$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>:d>) | ||
|
|
||
| # CMake enables /RTC1 and /EHsc by default, but they're not compatible with /clr, so remove them | ||
| if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1") | ||
| string(REPLACE "/RTC1" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") | ||
| endif() | ||
|
|
||
| if(CMAKE_CXX_FLAGS MATCHES "/EHsc") | ||
| string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
| endif() | ||
|
|
||
| # IJW isn't compatible with CFG | ||
| if(CMAKE_CXX_FLAGS MATCHES "/guard:cf") | ||
| string(REPLACE "/guard:cf" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
| endif() | ||
|
|
||
| # IJW isn't compatible with GR- | ||
| if(CMAKE_CXX_FLAGS MATCHES "/GR-") | ||
| string(REPLACE "/GR-" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
| endif() | ||
|
|
||
| endif() | ||
|
|
||
| # add the shared library | ||
| add_library (IjwCopyConstructorMarshaler SHARED ${SOURCES}) | ||
| target_link_libraries(IjwCopyConstructorMarshaler ${LINK_LIBRARIES_ADDITIONAL}) | ||
|
|
||
| # add the install targets | ||
| install (TARGETS IjwCopyConstructorMarshaler DESTINATION bin) |
66 changes: 66 additions & 0 deletions
66
tests/src/Interop/IJW/CopyConstructorMarshaler/CopyConstructorMarshaler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using System.Runtime.InteropServices; | ||
| using TestLibrary; | ||
|
|
||
| namespace CopyConstructorMarshaler | ||
| { | ||
| class CopyConstructorMarshaler | ||
| { | ||
| static int Main(string[] args) | ||
| { | ||
| if(Environment.OSVersion.Platform != PlatformID.Win32NT || TestLibrary.Utilities.IsWindows7) | ||
| { | ||
| return 100; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| // Load a fake mscoree.dll to avoid starting desktop | ||
| LoadLibraryEx(Path.Combine(Environment.CurrentDirectory, "mscoree.dll"), IntPtr.Zero, 0); | ||
|
|
||
| Assembly ijwNativeDll = Assembly.Load("IjwCopyConstructorMarshaler"); | ||
| Type testType = ijwNativeDll.GetType("TestClass"); | ||
| object testInstance = Activator.CreateInstance(testType); | ||
| MethodInfo testMethod = testType.GetMethod("PInvokeNumCopies"); | ||
|
|
||
| // PInvoke will copy twice. Once from argument to parameter, and once from the managed to native parameter. | ||
| Assert.AreEqual(2, (int)testMethod.Invoke(testInstance, null)); | ||
|
|
||
| testMethod = testType.GetMethod("ReversePInvokeNumCopies"); | ||
|
|
||
| // Reverse PInvoke will copy 3 times. Two are from the same paths as the PInvoke, | ||
| // and the third is from the reverse P/Invoke call. | ||
| Assert.AreEqual(3, (int)testMethod.Invoke(testInstance, null)); | ||
|
|
||
| testMethod = testType.GetMethod("PInvokeNumCopiesDerivedType"); | ||
|
|
||
| // PInvoke will copy twice. Once from argument to parameter, and once from the managed to native parameter. | ||
| Assert.AreEqual(2, (int)testMethod.Invoke(testInstance, null)); | ||
|
|
||
| testMethod = testType.GetMethod("ReversePInvokeNumCopiesDerivedType"); | ||
|
|
||
| // Reverse PInvoke will copy 3 times. Two are from the same paths as the PInvoke, | ||
| // and the third is from the reverse P/Invoke call. | ||
| Assert.AreEqual(3, (int)testMethod.Invoke(testInstance, null)); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine(ex); | ||
| return 101; | ||
| } | ||
| return 100; | ||
| } | ||
|
|
||
| [DllImport("kernel32.dll")] | ||
| static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, int dwFlags); | ||
|
|
||
| [DllImport("kernel32.dll")] | ||
| static extern IntPtr GetModuleHandle(string lpModuleName); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.