Skip to content

Update wpiutil and ntcore native imports and native-backed structs#132

Open
ThadHouse wants to merge 2 commits into
mainfrom
codex/update-c-imports-in-wpiutil-and-ntcore
Open

Update wpiutil and ntcore native imports and native-backed structs#132
ThadHouse wants to merge 2 commits into
mainfrom
codex/update-c-imports-in-wpiutil-and-ntcore

Conversation

@ThadHouse
Copy link
Copy Markdown
Member

Motivation

  • Sync the C# P/Invoke declarations and native-backed structs in wpiutil and ntcore with the current upstream C API to restore correctness and interoperability.
  • Ensure marshaling and layout match upstream changes (raw frame timestamps, string allocation, pub/sub options, listener APIs, and native array helpers).

Description

  • Updated wpiutil native imports: replaced event/semaphore entry points with WPI_MakeEvent / WPI_MakeSemaphore, added WPI_CreateSignalObject, corrected return marshalling to signed int, and added string init/allocate APIs (WPI_InitString, WPI_InitStringWithLength, WPI_AllocateString, WPI_AllocateStringArray) in StringsNative.
  • Extended raw frame support by adding timestamp fields to NativeRawFrame, adding WPI_SetRawFrameData, propagating Timestamp and TimestampSource through RawFrameReader/RawFrameWriter, and adding Bgra + TimestampSource enum in PixelFormat.
  • Updated ntcore native imports and helpers: added NT_WaitForListenerQueue, NT_AddPolledListenerSingle, fixed NT_StopConnectionDataLog entry point, and added native array allocation/free APIs (NT_AllocateBooleanArray, NT_AllocateIntegerArray, NT_AllocateFloatArray, NT_AllocateDoubleArray and corresponding free functions) in NtCore.Free.
  • Brought several native-backed types in line with upstream: changed PubSubOptions to use pollStorage and an NtPublisher handle for ExcludePublisher (with a PollSize compatibility accessor), adjusted NetworkMode flags to include Client and MdnsAnnouncing, and corrected LogMessage marshalling to use the filename field.

Testing

  • Ran dotnet build src/ntcore/ntcore.csproj which succeeded after a restore. (succeeded)
  • Ran dotnet build src/cscore/cscore.csproj which succeeded after restore. (succeeded)
  • Attempted dotnet build src/ntcore/ntcore.csproj --no-restore which failed due to missing NuGet assets (expected without restore), then restored and rebuilt successfully. (initial failure due to restore; final build succeeded)
  • Ran git diff --check to ensure no spacing/whitespace issues. (succeeded)

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71e03077e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

public static partial class SynchronizationNative
{
[LibraryImport("wpiutil", EntryPoint = "WPI_CreateEvent")]
[LibraryImport("wpiutil", EntryPoint = "WPI_MakeEvent")]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use exported WPI_CreateEvent entry point

When code calls SynchronizationNative.CreateEvent, this import now asks the loader for WPI_MakeEvent, but the wpiutil C API still exports the C entry point as WPI_CreateEvent (the MakeEvent name is only the C++ wrapper name). This will throw EntryPointNotFoundException at runtime for any path that creates an event, so the entry point should remain WPI_CreateEvent.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're using out of date information here. The entry point has changed in wpilib.

public static partial void ResetEvent(WpiEventHandle handle);

[LibraryImport("wpiutil", EntryPoint = "WPI_CreateSemaphore")]
[LibraryImport("wpiutil", EntryPoint = "WPI_MakeSemaphore")]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use exported WPI_CreateSemaphore entry point

When code calls SynchronizationNative.CreateSemaphore, this import now looks for WPI_MakeSemaphore, but the native C ABI exports WPI_CreateSemaphore (the MakeSemaphore spelling is the C++ wrapper). Any semaphore creation will fail at runtime with EntryPointNotFoundException, so keep this P/Invoke bound to WPI_CreateSemaphore.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Again, you're using out of date information here.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant