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 withCString #431

Merged
merged 1 commit into from
May 17, 2022
Merged

Add withCString #431

merged 1 commit into from
May 17, 2022

Conversation

dpwiz
Copy link
Contributor

@dpwiz dpwiz commented May 11, 2022

Like #254, but only adds one function. peekCString is basically fromPtr0.

src/Data/Text/Foreign.hs Outdated Show resolved Hide resolved
src/Data/Text/Foreign.hs Outdated Show resolved Hide resolved
@dpwiz
Copy link
Contributor Author

dpwiz commented May 12, 2022

So, what's would be the next step in this?

I can remove the I8 argument, bringing the function in line with GHC withCString. Users can get text length for free with (+ 1) . lengthWord8.
withCStringLenAndNul can be judged separately later.

@Lysxia
Copy link
Contributor

Lysxia commented May 16, 2022

Users can get text length for free with (+ 1) . lengthWord8.

I think that's worth mentioning in the doc.

Otherwise, LGTM. For reference, this is essentially the same logic as Data.ByteString.useAsCString.

@Bodigrim Bodigrim merged commit 3517e18 into haskell:master May 17, 2022
@dpwiz dpwiz deleted the withCString branch May 18, 2022 08:49
@Mikolaj
Copy link
Member

Mikolaj commented Aug 6, 2022

So is Data.Text.Foreign.useAsCString planned or is withCString close enough (I haven't yet wrapped my head around it, but I need to decide whether to wait for text 2.1 with my update of sdl2-ttf to text2 or just use withCString)?

@Bodigrim
Copy link
Contributor

Bodigrim commented Aug 6, 2022

@Mikolaj withCString is useAsCString in disguise.

@Mikolaj
Copy link
Member

Mikolaj commented Aug 7, 2022

Indeed, it's precisely what I needed and it works fine: haskell-game/sdl2-ttf#16

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

Successfully merging this pull request may close these issues.

None yet

5 participants