Skip to content

fix: Platform calling-convention getters return null instead of throwing#22

Merged
tinysec merged 1 commit into
masterfrom
fix/platform-calling-convention-null
Jul 8, 2026
Merged

fix: Platform calling-convention getters return null instead of throwing#22
tinysec merged 1 commit into
masterfrom
fix/platform-calling-convention-null

Conversation

@tinysec

@tinysec tinysec commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

DefaultCallingConvention, Cdecl/Stdcall/FastcallCallingConvention, and SystemCallConvention wrapped their handle with CallingConvention.MustTakeHandle, which throws ArgumentNullException when the core returns a null handle. Python's default_calling_convention (and the four siblings) return None for an unset convention.

Switch each getter to CallingConvention.TakeHandle (same owner=true ownership — BNGetPlatform* returns an owned ref — but returns null on IntPtr.Zero) and widen the return type to CallingConvention?. Mirrors Architecture.GetCdeclCallingConvention which already does the null-safe thing via NewFromHandle.

Verification

  • Binding builds clean (0 warnings, 0 errors).
  • New E2E test: the default convention on linux-x86_64 is "sysv"; reaching .Name proves the handle is passed through TakeHandle with ownership intact. All five getters are reachable without throwing.

Note: every standard Binary Ninja platform defines all five calling conventions, so no fixture platform yields a natural null. The no-throw-on-null contract is guaranteed by TakeHandle (returns null on IntPtr.Zero); the test verifies the real-world non-null path.

DefaultCallingConvention, Cdecl/Stdcall/FastcallCallingConvention, and
SystemCallConvention wrapped their handle with CallingConvention.MustTakeHandle,
which throws ArgumentNullException when the core returns a null handle. Python's
default_calling_convention (and the four siblings) return None for an unset
convention. Switch each getter to CallingConvention.TakeHandle (same owner=true
ownership, but returns null on IntPtr.Zero) and widen the return type to
CallingConvention?, mirroring Architecture.GetCdeclCallingConvention which already
does this via NewFromHandle.
@tinysec tinysec merged commit 559d23b into master Jul 8, 2026
1 check passed
@tinysec tinysec deleted the fix/platform-calling-convention-null branch July 8, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant