CSharp bindings: user-defined string encoding and improved safety#14366
Open
Mbucari wants to merge 7 commits intoOSGeo:masterfrom
Open
CSharp bindings: user-defined string encoding and improved safety#14366Mbucari wants to merge 7 commits intoOSGeo:masterfrom
Mbucari wants to merge 7 commits intoOSGeo:masterfrom
Conversation
Expose $module.IStringMarshaller interfaces which have 2 methods: - `string FromNullTerminated(IntPtr pStr)` - Read native null-terminated data from a Gdal pointer and return a managed string. - `byte[] ToNullTerminated(string str)` - Create a null-terminated array of bytes from a managed string to send to Gdal. Public static properties `$module.StringMarshaller` can be used to get/set a custom marshaller interfaces. The default marshaller is internal `DefaultStringMarshaller`. String helper callback has been changed. When `SWIG_csharp_string_callback` is called, it decodes the unmanaged Gdal string to a managed .NET string (using StringMarshaller.ToNullTerminated()) and then returns a pointer to a pinned GCHandle of that string. StringFromPinnedGCHandle() is called from the C# methods to retrieve the string and free the GCHandle.
Contributor
|
It is probably going to be next week before I can look at this |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Creates an interface for users to create custom string Encoder/Decoders for Gdal to use for all string operations. This serves a purpose similar to #3825 by allowing users to manage how strings are encoded/decoded to/from Gdal.
Expose
$module.IStringEncoderinterfaces which have 2 methods:string FromNullTerminated(IntPtr pStr);- Read native null-terminated data from a Gdal pointer and return a managed string.byte[] ToNullTerminated(string str);- Create a null-terminated array of bytes from a managed string to send to Gdal.It also simplifies string marshalling changes made in recent PR by no longer requires C# to allocate/free any unmanaged memory. All string/byte[] objects are managed.
Here's an example of a custom StringEncoder.
@runette
What are related issues/pull requests?
#3825
#14283
Tasklist
Environment
Provide environment details, if relevant:
Mono and dotnet