Skip to content

Use *byte instead of unsafe.Pointer for C bridge methods #12

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

icedream
Copy link
Owner

No description provided.

@icedream icedream self-assigned this Mar 15, 2025
@icedream icedream changed the title Use *byte instead of unsafe.Pointer for C bridge methods. Use *byte instead of unsafe.Pointer for C bridge methods Mar 15, 2025
@icedream icedream force-pushed the master branch 5 times, most recently from 58a43e4 to 9c8daf3 Compare March 15, 2025 13:16
@icedream icedream force-pushed the typed-bridging branch 4 times, most recently from c82b0e4 to d45f7ee Compare March 15, 2025 13:23
@icedream icedream requested a review from Copilot April 3, 2025 12:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the C bridge method signatures to use *byte instead of unsafe.Pointer for improved type safety.

  • Update cPtrToSlice in native.go to accept a *byte pointer
  • Modify cgo_write_buffer and cgo_read_buffer functions to use *byte for their pointer parameters

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/native/native_internal_test.go Added tests to validate byte conversion functions
internal/native/native.go Updated cPtrToSlice to use *byte and adjusted pointer conversion
internal/native/cgo_write.go Changed cgo_write_buffer parameter type from unsafe.Pointer to *byte
internal/native/cgo_read.go Changed cgo_read_buffer parameter type from unsafe.Pointer to *byte
Comments suppressed due to low confidence (3)

internal/native/native.go:31

  • Ensure that all call sites for cPtrToSlice are updated to provide a *byte instead of an unsafe.Pointer to avoid unexpected runtime behavior.
func cPtrToSlice(ptr *byte, size int) []byte {

internal/native/cgo_write.go:18

  • Verify that the corresponding C declarations and any caller conversions are updated to work with *byte rather than unsafe.Pointer.
dataPtr *byte,

internal/native/cgo_read.go:23

  • Ensure that the C interface for cgo_read_buffer is modified accordingly to correctly pass a *byte pointer, avoiding potential pointer mismatches.
bufPtr *byte,

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