-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to
SafeHandle
for Unmanaged Pointers (#38)
* Move to `SafeHandle` for Unmanaged Pointers This is an API breaking change but should make the use of unsafe poiters in this library more reliable in some corner cases. Safe handles will ensure that the attached resources are always correctly released, even in exceptional circumstances. This also allows the `RureFfi` to be a tad more type safe in what it accepts. It's bad that we were somehow _less type safe_ than C. :-/ * Bump Version This new handle approach is not API or ABI backwards compatible. It is however _most likely_ source compatible.
- Loading branch information
1 parent
8c4068d
commit 7b688ee
Showing
18 changed files
with
259 additions
and
161 deletions.
There are no files selected for viewing
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,21 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace IronRure | ||
{ | ||
public sealed class CaptureNamesHandle : SafeHandle | ||
{ | ||
public CaptureNamesHandle() | ||
: base(IntPtr.Zero, true) | ||
{ | ||
} | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
RureFfi.rure_iter_capture_names_free(handle); | ||
return true; | ||
} | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace IronRure | ||
{ | ||
public sealed class CapturesHandle : SafeHandle | ||
{ | ||
public CapturesHandle() | ||
: base(IntPtr.Zero, true) | ||
{ | ||
} | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
RureFfi.rure_captures_free(handle); | ||
return true; | ||
} | ||
} | ||
} |
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
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,21 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace IronRure | ||
{ | ||
public sealed class OptionsHandle : SafeHandle | ||
{ | ||
public OptionsHandle() | ||
: base(IntPtr.Zero, true) | ||
{ | ||
} | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
RureFfi.rure_options_free(handle); | ||
return true; | ||
} | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace IronRure | ||
{ | ||
public sealed class RegexHandle : SafeHandle | ||
{ | ||
public RegexHandle() | ||
: base(IntPtr.Zero, true) | ||
{ | ||
} | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
RureFfi.rure_free(handle); | ||
return true; | ||
} | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace IronRure | ||
{ | ||
public sealed class RegexIterHandle : SafeHandle | ||
{ | ||
public RegexIterHandle() | ||
: base(IntPtr.Zero, true) | ||
{ | ||
} | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
RureFfi.rure_iter_free(handle); | ||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.