-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Custom Symbol/Library loading logic #84
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
573143b
Decouple Library and Symbol loading
sunkin351 523d4aa
Move Platform Loader cache location
sunkin351 3651021
Added file headers to new files
sunkin351 c61187b
Minor optimization to type gen code
sunkin351 6b103b5
Complete support for custom loading logic
sunkin351 d0aa77c
Alter interface to have one symbol loading method
sunkin351 73d19f9
Set new constructor arguments default values
sunkin351 76b66a2
Developer Nitpicks
sunkin351 53ef619
Pass custom loaders to object constructor
sunkin351 2aace3a
Developer nitpicks Round 2
sunkin351 f1a5ad1
Developer nitpicks Round 3
sunkin351 58fd73c
Custom Loading Logic Tests
sunkin351 341e59f
Moved loading override classes to `AdvancedDLSupport.Tests.Data.Classes`
sunkin351 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
51 changes: 51 additions & 0 deletions
51
AdvancedDLSupport.Tests/Data/Classes/LibraryLoadingOverride.cs
This file contains 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,51 @@ | ||
// | ||
// LibraryLoadingOverride.cs | ||
// | ||
// Copyright (c) 2018 Firwood Software | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using AdvancedDLSupport.Loaders; | ||
using JetBrains.Annotations; | ||
|
||
#pragma warning disable SA1600, CS1591 | ||
|
||
namespace AdvancedDLSupport.Tests.Data.Classes | ||
{ | ||
internal class LibraryLoadingOverride : ILibraryLoader | ||
{ | ||
private readonly ILibraryLoader _defaultLoader; | ||
|
||
public bool LoadLibraryCalled { get; private set; } | ||
|
||
public LibraryLoadingOverride(ILibraryLoader @default) | ||
{ | ||
_defaultLoader = @default; | ||
} | ||
|
||
public IntPtr LoadLibrary([CanBeNull] string path) | ||
{ | ||
LoadLibraryCalled = true; | ||
|
||
return _defaultLoader.LoadLibrary(path); | ||
} | ||
|
||
public bool CloseLibrary(IntPtr library) | ||
{ | ||
return _defaultLoader.CloseLibrary(library); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
AdvancedDLSupport.Tests/Data/Classes/SymbolLoadingOverride.cs
This file contains 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,46 @@ | ||
// | ||
// SymbolLoadingOverride.cs | ||
// | ||
// Copyright (c) 2018 Firwood Software | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using AdvancedDLSupport.Loaders; | ||
using JetBrains.Annotations; | ||
|
||
#pragma warning disable SA1600, CS1591 | ||
|
||
namespace AdvancedDLSupport.Tests.Data.Classes | ||
{ | ||
internal class SymbolLoadingOverride : ISymbolLoader | ||
{ | ||
private readonly ISymbolLoader _defaultLoader; | ||
|
||
public bool LoadSymbolCalled { get; private set; } | ||
|
||
public SymbolLoadingOverride(ISymbolLoader @default) | ||
{ | ||
_defaultLoader = @default; | ||
} | ||
|
||
public IntPtr LoadSymbol(IntPtr library, [NotNull] string symbolName) | ||
{ | ||
LoadSymbolCalled = true; | ||
|
||
return _defaultLoader.LoadSymbol(library, symbolName == "GetString" ? "GetNullString" : symbolName); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
AdvancedDLSupport.Tests/Data/Interfaces/ICustomLoadingLogicTests.cs
This file contains 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,30 @@ | ||
// | ||
// ICustomLoadingLogicTests.cs | ||
// | ||
// Copyright (c) 2018 Firwood Software | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#pragma warning disable SA1600, CS1591 | ||
|
||
namespace AdvancedDLSupport.Tests.Data | ||
{ | ||
public interface ICustomLoadingLogicTests | ||
{ | ||
int ReturnsOne(); | ||
|
||
int ReturnsTwo(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
AdvancedDLSupport.Tests/Tests/Integration/CustomLoadingLogicTests.cs
This file contains 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,73 @@ | ||
// | ||
// CustomLoadingLogicTests.cs | ||
// | ||
// Copyright (c) 2018 Firwood Software | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using AdvancedDLSupport.Tests.Data; | ||
using AdvancedDLSupport.Tests.Data.Classes; | ||
using AdvancedDLSupport.Tests.TestBases; | ||
using Xunit; | ||
|
||
#pragma warning disable SA1600, CS1591 | ||
|
||
namespace AdvancedDLSupport.Tests.Integration | ||
{ | ||
public class CustomLoadingLogicTests : LibraryTestBase<IStringLibrary> | ||
{ | ||
private const string LibraryName = "StringTests"; | ||
|
||
private LibraryLoadingOverride _libraryLogicOverride; | ||
private SymbolLoadingOverride _symbolLogicOverride; | ||
|
||
public CustomLoadingLogicTests() | ||
: base(LibraryName) | ||
{ | ||
} | ||
|
||
protected override ImplementationOptions GetImplementationOptions() | ||
{ | ||
return base.GetImplementationOptions() | ImplementationOptions.UseLazyBinding; | ||
} | ||
|
||
protected override NativeLibraryBuilder GetImplementationBuilder() | ||
{ | ||
return base.GetImplementationBuilder().WithLibraryLoader(@default => | ||
{ | ||
_libraryLogicOverride = new LibraryLoadingOverride(@default); | ||
return _libraryLogicOverride; | ||
}).WithSymbolLoader(@default => | ||
{ | ||
_symbolLogicOverride = new SymbolLoadingOverride(@default); | ||
return _symbolLogicOverride; | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void CustomLogicCalled() | ||
{ | ||
Library.GetString(); | ||
Assert.True(_libraryLogicOverride.LoadLibraryCalled); | ||
Assert.True(_symbolLogicOverride.LoadSymbolCalled); | ||
} | ||
|
||
[Fact] | ||
public void CustomLogicSuccessful() | ||
{ | ||
Assert.Equal(Library.GetString(), Library.GetNullString()); | ||
} | ||
} | ||
} |
This file contains 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,11 @@ | ||
#include <stdint.h> | ||
|
||
__declspec(dllexport) int32_t ReturnsOne() | ||
{ | ||
return 1; | ||
} | ||
|
||
__declspec(dllexport) int32_t ReturnsTwo() | ||
{ | ||
return 2; | ||
} |
This file contains 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,48 @@ | ||
// | ||
// ILibraryLoader.cs | ||
// | ||
// Copyright (c) 2018 Firwood Software | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace AdvancedDLSupport.Loaders | ||
{ | ||
/// <summary> | ||
/// Represents a class which can load libraries on a specific platform. | ||
/// </summary> | ||
public interface ILibraryLoader | ||
{ | ||
/// <summary> | ||
/// Load the given library. A null path signifies intent to load the main executable instead of an external | ||
/// library. | ||
/// </summary> | ||
/// <param name="path">The path to the library.</param> | ||
/// <returns>A handle to the library. This value carries no intrinsic meaning.</returns> | ||
/// <exception cref="LibraryLoadingException">Thrown if the library could not be loaded.</exception> | ||
[PublicAPI] | ||
IntPtr LoadLibrary([CanBeNull] string path); | ||
|
||
/// <summary> | ||
/// Closes the open handle to the given library. | ||
/// </summary> | ||
/// <param name="library">The handle to the library to close.</param> | ||
/// <returns>true if the library was closed successfully; otherwise, false.</returns> | ||
[PublicAPI] | ||
bool CloseLibrary(IntPtr library); | ||
} | ||
} |
This file contains 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 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,40 @@ | ||
// | ||
// ISymbolLoader.cs | ||
// | ||
// Copyright (c) 2018 Firwood Software | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace AdvancedDLSupport.Loaders | ||
{ | ||
/// <summary> | ||
/// Represents a class which can load symbols on a specific platform. | ||
/// </summary> | ||
public interface ISymbolLoader | ||
{ | ||
/// <summary> | ||
/// Load the given symbol. | ||
/// </summary> | ||
/// <param name="library">The handle to the library in which the symbol exists.</param> | ||
/// <param name="symbolName">The name of the symbol to load.</param> | ||
/// <exception cref="SymbolLoadingException">Thrown if the symbol could not be loaded.</exception> | ||
/// <returns>A handle to the symbol.</returns> | ||
[PublicAPI, Pure] | ||
IntPtr LoadSymbol(IntPtr library, [NotNull] string symbolName); | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: run an attribute cleanup sometime in the future.