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

How to read char* value from Deref() #173

Open
ljfuyuan opened this issue Oct 17, 2024 · 2 comments
Open

How to read char* value from Deref() #173

ljfuyuan opened this issue Oct 17, 2024 · 2 comments

Comments

@ljfuyuan
Copy link

Hello, I got a C function returns struct like this:

typedef struct Result {
  char *version;
} Result;

struct Result init(void);

With generated go is

type Result struct {
	Version        []byte
	ref67033404    *C.Result
	allocs67033404 interface{}
}

And Deref() does't set the Len for the Version []byte, So is there any way to read Version out since i can not get the length,

Thanks.

@xlab
Copy link
Owner

xlab commented Oct 18, 2024

Hi, it doesn't know len as in C the pointer just points to beginning. So you have to read the len value from somewhere or manually discover it reading byes until you meet \x00. You you can mark this pointer as safe string and it will automatically detect \x00 while copying the value.

@ljfuyuan
Copy link
Author

Hi, it doesn't know len as in C the pointer just points to beginning. So you have to read the len value from somewhere or manually discover it reading byes until you meet \x00. You you can mark this pointer as safe string and it will automatically detect \x00 while copying the value.

Thanks a lot for your answer. I have tried various ways to add Tip in TRANSLATOR, but I still can't find a way to mark it as a safe string. Can you give me some tips? Thanks again.

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

No branches or pull requests

2 participants