GithubHelp home page GithubHelp logo

Comments (9)

clyring avatar clyring commented on June 19, 2024

There is already a remark on this in the docstring for unsafeUseAsCStringLen: If 'Data.ByteString.empty' is given, it will pass @('Foreign.Ptr.nullPtr', 0)@.

I'm not sure there's much more that can reasonably be done here. But feel free to re-open if you have ideas.

from bytestring.

phadej avatar phadej commented on June 19, 2024

It's on unsafeUseAsCStringLen but the remark is not on unsafeUseAsCString

There is a shared remark, and different ones. It's hard to know which ones are actually shared (all of them, none?). The documentation is not clear there.

from bytestring.

clyring avatar clyring commented on June 19, 2024

Ah. And yet remarking about empty with unsafeUseAsCString would seem a bit off since that's already very likely wrong for null-termination reasons.

from bytestring.

phadej avatar phadej commented on June 19, 2024

And yet remarking about empty with unsafeUseAsCString would seem a bit off since that's already very likely wrong for null-termination reasons.

Why? unsafeUseAsCString doesn't do any null-termination, does it?

from bytestring.

clyring avatar clyring commented on June 19, 2024

Yes, exactly. unsafeUseAsCString doesn't add any null-termination, and the empty bytestring can't be expected to be null-terminated.

from bytestring.

phadej avatar phadej commented on June 19, 2024

But i'm not talking about null-termination, I'm talking that the pointer itself returned may be NULL.

I expect to see

-- If 'Data.ByteString.empty' is given, it will pass @'Foreign.Ptr.nullPtr'@.

for unsafeUseAsCString, or a shared comment in Using ByteStrings with functions for CStrings section


Also is it then a bug that unsafeUseAsCStringLen "" print doesn't give me a null pointer?

from bytestring.

clyring avatar clyring commented on June 19, 2024

I mean that a call unsafeUseAsCString empty someFunctionExpectingCString is already very suspicious because it will pass a pointer to a buffer that isn't null-terminated to someFunctionExpectingCString.

Also is it then a bug that unsafeUseAsCStringLen "" print doesn't give me a null pointer?

We make no guarantees about what underlying pointer is used in the empty result of packChars "".

from bytestring.

phadej avatar phadej commented on June 19, 2024

is already very suspicious because it will pass a pointer to a buffer that isn't null-terminated to

it might be, but it's irrelevant to this documentation issue. (The code I work one calls Data.ByteString.length elsewhere, so C code is called with length, it just doesn't get it from unsafeUseAsCString*.

from bytestring.

phadej avatar phadej commented on June 19, 2024

We make no guarantees about what underlying pointer is used in the empty result of packChars "".

Then the remark about empty should be further clarified, as there is a difference between empty and packChars "". Some values are equivalent to empty, and some aren't (and again, it's hard to say whether that is a bug or conscious decision). Another example is copy empty.

from bytestring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.