Skip to content
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

C#: Implement function to throw on null pointers #85975

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Dec 9, 2023

Specifically: checks if a passed IntPtr is equal to IntPtr.Zero. Utilizes the same syntax as ArgumentNullException.ThrowIfNull; only the argument needs to be passed, with the argument name being automatically pulled via the CallerArgumentExpression attribute1. In addition to implementing this on the generated NativeCalls files, minor changes were also made to bindings_generator.cpp in order to give the resulting file proper formatting.

Footnotes

  1. https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callerargumentexpressionattribute

@Repiteo Repiteo requested a review from a team as a code owner December 9, 2023 20:03
@Chaosus Chaosus added this to the 4.3 milestone Dec 10, 2023
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, a few minor nit-picks but looks good to me otherwise.

• Specifically: checks if ptr == IntPtr.Zero
@Repiteo Repiteo force-pushed the c#-null-ptr-exception branch from bdc30c1 to a0db883 Compare December 17, 2023 14:52
@YuriSizov YuriSizov merged commit f478a59 into godotengine:master Dec 19, 2023
15 checks passed
@YuriSizov
Copy link
Contributor

Thanks!

@Repiteo Repiteo deleted the c#-null-ptr-exception branch December 19, 2023 12:54
@YuriSizov
Copy link
Contributor

YuriSizov commented Dec 21, 2023

Builds for the .NET version on the build server fail with this error, which I believe is related to this PR:

modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs(244,90): error CS0103: The name 'ptr' does not exist in the current context [modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]

See also #82983.

Fix: #86373.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants