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

Add getting strings from string constants #52

Merged
merged 1 commit into from
Sep 10, 2023

Conversation

rj45
Copy link
Contributor

@rj45 rj45 commented Sep 2, 2023

Here's the updated version of this change.

It turns out that other constants can also be turned into strings allowing you to get their binary value, so I am also using this to get the value of structs and arrays of words. There is probably a better way than converting it to a string (especially as utf8 might make things complicated) but I haven't looked more into it.

@aykevl aykevl merged commit 5874309 into tinygo-org:master Sep 10, 2023
6 checks passed
@aykevl
Copy link
Member

aykevl commented Sep 18, 2023

FYI: there was a bug in this PR, see 9edb640.

@rj45
Copy link
Contributor Author

rj45 commented Sep 19, 2023

Thanks for fixing that @aykevl, alas I don't have a windows box to test these things on. I thought the original type was unsigned long but size_t makes sense. I realize now that unsigned long would be 32 bit on windows and it needs to be 64 bit. I will use size_t in the future for lengths.

@aykevl
Copy link
Member

aykevl commented Oct 1, 2023

I will use size_t in the future for lengths.

Always use the type as indicated in the original signature. In this case, the signature is as follows:

const char *LLVMGetAsString(LLVMValueRef C, size_t *Length);

It says size_t, so that's what you should use. If it said unsigned long, C.ulong would be the Go type. That way, the type is always the same, no matter how that particular type is defined on a given platform.

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.

2 participants