Pointers to native classes should _not_ be dereferenced by C#
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.5k
- Forks
- 124
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 9
Description
Actual behavior
The GdipDeleteRegion method gets a friendly overload that takes ref GpRegion instead of GpRegion*.
This might be fine, except that GpRegion* should never be dereferenced, since it's a pointer to a class on the C++ side. The struct defined in the metadata has an IntPtr field, but unlike HWND where that is just a copyable opaque value, GpRegion (and other GDI+ structs) actually represent C++ classes, and the 'field' in these structs is misleading. What would really be at that memory location is the first field in the C++ class, so copying around the struct in C# would lead to data corruption as anyone that re-takes the pointer to the struct would expect the full class fields where the struct is, and they wouldn't be there.
Expected behavior
Any extern methods that take a pointer to a native object should not have friendly overloads that replace the pointer with ref or other modifiers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing generation of the GdipDeleteRegion extern method and the metadata that describes GpRegion*. Check how pointer parameters are converted into friendly C# overloads. Done means native-object pointers no longer receive ref or other dereferencing overloads, with generated signatures or tests confirming the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100