Comments (5)
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.
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.
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.
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.
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)
- Regarding Migration of Jansson 2.7 to 2.14
- json_dumps can only convert objects HOT 1
- How to use jansson with non-blocking I/O? HOT 1
- thread safety of json_incref and json_decref
- Can't create DLL on Windows for Jansson 1.2
- Cannot compile Jansson (make check fail) HOT 1
- "jansson_config.h" missing and cannot include the library in cmakelist
- Create SECURITY.md HOT 1
- Error OOM HOT 2
- dump_string func can error return HOT 1
- json_int_t should be typedef'd as intmax_t
- Replacing values in a arbitrary JSON file HOT 1
- Target settings do not automatically populate when using CMake FetchContent
- janssonConfig.cmake only packaged on Fedora and OpenMandriva
- [question] multiple usage of json_set_alloc_funcs
- Keep GitHub Actions up-to-date with dependabot
- json_dumps real value 7.6 as 7.59....96 HOT 9
- conversion from JSON to string is not multithread-safe HOT 3
- conversion from string to JSON is not multithread-safe HOT 5
- json_unpack bug (jansson 2.13.1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jansson.