Merge pull request #94 from pesco/fix-49-stringmap-segfault
Fix #49 stringmap segfault
This commit is contained in:
commit
70da67adb5
3 changed files with 15 additions and 5 deletions
|
|
@ -81,7 +81,6 @@ static void *combine_entries(HHashSet *workset, void *dst, const void *src)
|
||||||
|
|
||||||
// add the mappings of src to dst, marking conflicts and adding the conflicting
|
// add the mappings of src to dst, marking conflicts and adding the conflicting
|
||||||
// values to workset.
|
// values to workset.
|
||||||
// note: reuses parts of src to build dst!
|
|
||||||
static void stringmap_merge(HHashSet *workset, HStringMap *dst, HStringMap *src)
|
static void stringmap_merge(HHashSet *workset, HStringMap *dst, HStringMap *src)
|
||||||
{
|
{
|
||||||
if(src->epsilon_branch) {
|
if(src->epsilon_branch) {
|
||||||
|
|
@ -118,13 +117,16 @@ static void stringmap_merge(HHashSet *workset, HStringMap *dst, HStringMap *src)
|
||||||
|
|
||||||
if(src_) {
|
if(src_) {
|
||||||
HStringMap *dst_ = h_hashtable_get(dst->char_branches, (void *)c);
|
HStringMap *dst_ = h_hashtable_get(dst->char_branches, (void *)c);
|
||||||
if(dst_)
|
if(dst_) {
|
||||||
stringmap_merge(workset, dst_, src_);
|
stringmap_merge(workset, dst_, src_);
|
||||||
else
|
} else {
|
||||||
|
if(src_->arena != dst->arena)
|
||||||
|
src_ = h_stringmap_copy(dst->arena, src_);
|
||||||
h_hashtable_put(dst->char_branches, (void *)c, src_);
|
h_hashtable_put(dst->char_branches, (void *)c, src_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate entries for the productions of A in the given table row. */
|
/* Generate entries for the productions of A in the given table row. */
|
||||||
|
|
|
||||||
|
|
@ -281,6 +281,13 @@ void h_stringmap_update(HStringMap *m, const HStringMap *n)
|
||||||
h_hashtable_merge(combine_stringmap, m->char_branches, n->char_branches);
|
h_hashtable_merge(combine_stringmap, m->char_branches, n->char_branches);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HStringMap *h_stringmap_copy(HArena *a, const HStringMap *m)
|
||||||
|
{
|
||||||
|
HStringMap *res = h_stringmap_new(a);
|
||||||
|
h_stringmap_update(res, m);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/* Replace all occurances of old in m with new.
|
/* Replace all occurances of old in m with new.
|
||||||
* If old is NULL, replace all values in m with new.
|
* If old is NULL, replace all values in m with new.
|
||||||
* If new is NULL, remove the respective values.
|
* If new is NULL, remove the respective values.
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ typedef struct HStringMap_ {
|
||||||
} HStringMap;
|
} HStringMap;
|
||||||
|
|
||||||
HStringMap *h_stringmap_new(HArena *a);
|
HStringMap *h_stringmap_new(HArena *a);
|
||||||
|
HStringMap *h_stringmap_copy(HArena *a, const HStringMap *m);
|
||||||
void h_stringmap_put_end(HStringMap *m, void *v);
|
void h_stringmap_put_end(HStringMap *m, void *v);
|
||||||
void h_stringmap_put_epsilon(HStringMap *m, void *v);
|
void h_stringmap_put_epsilon(HStringMap *m, void *v);
|
||||||
void h_stringmap_put_after(HStringMap *m, uint8_t c, HStringMap *ends);
|
void h_stringmap_put_after(HStringMap *m, uint8_t c, HStringMap *ends);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue