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#] Issues with the C data interface implementation. #35809

Closed
teo-tsirpanis opened this issue May 28, 2023 · 0 comments · Fixed by #35810
Closed

[C#] Issues with the C data interface implementation. #35809

teo-tsirpanis opened this issue May 28, 2023 · 0 comments · Fixed by #35810
Assignees
Milestone

Comments

@teo-tsirpanis
Copy link
Contributor

Describe the bug, including details regarding any error messages, version, and platform.

I took a look at the code in the Apache.Arrow.C namespace and noticed the following things:

  • The native callbacks can use [UnmanagedCallersOnly] on supported frameworks (.NET 5+). This way, taking the pointer to them will be more efficient and does not involve delegates.
  • We are manually zeroing the structs we just allocated (
    ptr->length = 0;
    ptr->n_buffers = 0;
    ptr->offset = 0;
    ptr->buffers = null;
    ptr->n_children = 0;
    ptr->children = null;
    ptr->dictionary = null;
    ptr->null_count = 0;
    ptr->release = null;
    ptr->private_data = null;
    for example). We can zero them by just writing *ptr = default which is more efficient.
  • When releasing an exported array stream we don't free the GCHandle to the managed object, causing a memory leak.
  • When a function on an imported array fails, we don't include the result of get_last_error in the exception message.
  • We free the last exported array stream error message with Marshal.AllocCoTaskMem, while we had allocated it with Marshal.AllocHGlobal.
    Marshal.FreeCoTaskMem((IntPtr)LastError);
  • And more smaller stuff.

I will open a PR to address them.

Component(s)

C#

westonpace pushed a commit that referenced this issue Jul 6, 2023
### Rationale for this change

This PR fixes issues identified while reading the code of the `Apache.Arrow.C` namespace.

### What changes are included in this PR?

See each commit message for more details.

### Are these changes tested?

Using the existing test suite.

### Are there any user-facing changes?

No.
* Closes: #35809

Authored-by: Theodore Tsirpanis <teo@tsirpanis.gr>
Signed-off-by: Weston Pace <weston.pace@gmail.com>
@westonpace westonpace added this to the 13.0.0 milestone Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants