Comments (3)
In this implementation you're still using a static variable but it's hidden behind parson's API. How is that better than just referencing some static context from custom malloc/free functions? e.g.
static custom_alloc_ctx_t ctx;
void* custom_malloc_wrapper(size_t s)
{
return custom_malloc(&ctx, s);
}
void custom_free_wrapper(void *p)
{
custom_free(&ctx, p);
}
int main()
{
json_set_allocation_functions(custom_malloc_wrapper, custom_free_wrapper);
}
I might be missing something but I don't think adding json_set_allocation_ctx_functions
to the API is necessary because you could achieve same functionality with existing API.
from parson.
My thinking was that the users may not want or be able to use static variables in their code to hold the context.
You're right that it's hiding static variables in parson. Currently parson holds the allocator function pointers as static variables and my implementation adds pointer to context as I was aiming for smallest changes required for this to work. To really fix that parson would need to have some state object returned to user and passed to virtually all functions and remove the use of static variables altogether. Something like:
typedef struct {
JSON_Allocator_Ctx * ctx;
JSON_Malloc_Ctx_Function alloc_;
JSON_Free_Ctx_Function free_;
} JSON_Parson_State;
int main(void)
{
JSON_Parson_State state = json_init_parson_state();
json_set_allocation_functions(&state, custom_malloc_wrapper, custom_free_wrapper);
JSON_Value * v = json_parse_file(&state, "file.json");
/* ... */
json_value_free(&state, v);
/* and so on */
}
So this would mean far greater changes to the API. If you agree to such changes, I could prepare a patch.
from parson.
I realize that the only way would be to add some context to every function call but I strongly object against such change. I'm going to close this issue because the original functionality you suggested can be easily achieved using current API and "users may not want or be able to use static variables" is not very convincing.
from parson.
Related Issues (20)
- LLVM clang 4.0.3 compliation - "%g is unsupported" HOT 4
- Excess precision for small floating point numbers. HOT 16
- kgabis.github.com/parson returns 404 HOT 1
- Is it possible to add option to ignoring the last comma? HOT 3
- Build using meson HOT 13
- JSON Merge HOT 1
- Question on errors - Get information about what failed HOT 1
- why not check the "processed" in parson.c
- clublog-users.json.zip HOT 1
- scan-build bugs
- Accepting invalid array HOT 1
- EOF not enforced HOT 1
- Completion of error handling
- Improve exception handling
- Segmentation fault after invoking json_object_clear() and json_object_remove() back to back. HOT 1
- What if enclosingn [] is missing? HOT 3
- sprintf hard-deprecated on MacOS prevents compiling HOT 3
- Validate JSON inputs HOT 3
- Unstable memory access conflicts that occur when running on Win7 HOT 2
- json_serialize_to_string_pretty received signal SIGABRT, Aborted. HOT 3
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 parson.