Comments (7)
Addendum: It looks as if the replacement simply does not take place in some cases. I tried to add a work around where I just leaked a reference to the old value. When I do this, the later emit alternates between showing the old and new values, depending on the value of the random seed.
from libucl.
It looks as if this is somewhat more complicated. The sequence is:
- Three properties in kh_ucl_hash_node_t values fields 0, 1, and 2.
- ucl_object_delete_key deletes the one in field 0
- ucl_object_replace_key replaces the one in field 2.
At the end of this, iterating over the fields shows the old and new versions of property 3.
This appears to happen only if the deleted property is the first one and another is renamed (removed / inserted at a fixed location). My guess is that the hash table is preserving insertion order by keeping an array of elements and having a hash map that points to them, but it isn't correctly updated in some corner cases.
Unfortunately, I have reached the limit of my ability to debug this code.
from libucl.
Yes, there is a hash + array to preserve order which makes things complicated. I will take a look shortly, thank you for your investigations!
from libucl.
Well, the whole deletion code is wrong in fact... I don't have a clear opinion about how to fix it. Khash pointers are not stable, so we cannot store them in an array. We also cannot store array index in ucl_object_t
. The only alternative is to rewrite this data structure to probably an intrusive double-linked list.
from libucl.
This line is totally wrong: https://github.com/vstakhov/libucl/blob/master/src/ucl_hash.c#L515
It address hash table via kh_value
using array indicies, which is just not correct. However, there is no way to do this procedure using kv_A
function, as array stores ucl_object_t
that has no array index stored nor access to the underlying hash element structure. Also, O(N) deletion is not something one would expect from a hash table...
from libucl.
O(n) deletion isn't ideal, but deleting keys in a config file is a fairly unusual case, so I'd much rather see O(n) deletion than deletion causing memory corruption.
from libucl.
Ok, I have updated the structure but hash table would now store pointers to entries not entries + each hash insertion would imply an additional malloc call :( It is very suboptimal so it might be revised at some point. However, I have not found any other way to keep order counting that khash uses open addressing so pointers safety is not an option, so I just cannot use pointers returned from khash in linked lists as they are invalidated on each hash resize.
from libucl.
Related Issues (20)
- Schema tests failed with latest master HOT 1
- Does registering variables from Python work and how can I use it?
- License of python bindings / Missing license file for python bindings HOT 1
- vcpkg port? HOT 2
- [DISCUSSION]: Using dot-notation for setting values HOT 1
- Release a new pip package HOT 2
- Heap-buffer-overflow in ucl_maybe_parse_number /src/libucl/src/ucl_parser.c HOT 1
- Cannot convert example from YAML to UCL using ucl_tool HOT 3
- Heap-buffer-overflow in ucl_skip_comments function of ucl_parser.c:182:11
- compile error due to undefined PRId64
- python/setup.py: incremental build fails due to already existing setup.py link
- Feature request: A parser flag to expand variables inside marco options. HOT 1
- How to load libucl through cmake
- Release `0.8.2` to PyPi.
- Parse error when including JSON HOT 1
- Heap-buffer-overflow in ucl_maybe_parse_number function of ucl_parser.c:182:11 HOT 2
- streamline API generates invalid json HOT 4
- gchar, gsize seem to be caused compilation error.
- README doesn't match actual behaviour HOT 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 libucl.