Giter VIP home page Giter VIP logo

Comments (5)

akheron avatar akheron commented on May 29, 2024

Hi and thanks for the report.

The 'o' format allows you to extract a raw json_t *, which can then possibly be changed by the user (by using e.g. json_string_set_value()). When using the 'O' format, the reference count of the extracted value is increased, so even json_unpack() itself may modify root or value contained in it. For these reasons, root cannot be const.

from jansson.

neoxic avatar neoxic commented on May 29, 2024

Oh, I got you. Nevertheless, that is a subtle constraint because simple tree reading couldn't be achieved in const-methods if you wanted to use json_t* as a member of a class (i.e. a permanent state handler). Only temporary usage would be possible (my case btw). You could consider using some kind of 'mutable' or 'const_cast' analog for reference couters to avoid that. Anyway, thanks again!
P.S. Can't wait for a version with 'json_dump_callback' to come out!:)

from jansson.

akheron avatar akheron commented on May 29, 2024

You could consider using some kind of 'mutable' or 'const_cast' analog for reference couters to avoid that.

What do you mean? AFAICS, the only possibility would be to have a separate json_unpack_const() that doesn't have the O format, and would extract o items as const json_t *. The latter is subtle, of course, as there's no way to determine the types of variable arguments in the vararg function.

Can't wait for a version with 'json_dump_callback' to come out!:)

I'll try to hurry with that :)

from jansson.

neoxic avatar neoxic commented on May 29, 2024

Well, it would be enough to have two signatures of just one json_unpack() function if it were C++.:) Sad. However, json_unpack_const() looks pretty good to me anyway. The main goal would be to give some suitable way to extract data from constant states as the json_dump() does that while encoding. Up to you, of course.:) Thanks for the great work! I am on the way to give it a try under really heavy load...

from jansson.

akheron avatar akheron commented on May 29, 2024

I think the best would be to document why the argument is not const, and state it explicitly that (json_t *)const_variable is safe as long as the o and espcially O formats are not used.

from jansson.

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.