Skip to content

Commit

Permalink
fix: add hook free close
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Nov 26, 2023
1 parent 69ae626 commit a0e7e06
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions pkg/symbol/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ func (t *Table) Insert(sym *Symbol) error {
prev := t.symbols[sym.ID()]

if prev != nil {
if len(t.unlinks[sym.ID()]) == 0 {
if err := t.unload(prev); err != nil {
return err
}
if err := t.unload(prev); err != nil {
return err
}

Check warning on line 62 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L61-L62

Added lines #L61 - L62 were not covered by tests

if sym.Node != prev.Node {
Expand Down Expand Up @@ -172,9 +170,10 @@ func (t *Table) Insert(sym *Symbol) error {
t.unlinks[sym.ID()] = unlinks
} else {
delete(t.unlinks, sym.ID())
if err := t.load(sym); err != nil {
return err
}
}

if err := t.load(sym); err != nil {
return err
}

Check warning on line 177 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L176-L177

Added lines #L176 - L177 were not covered by tests

for name, locations := range t.linked[sym.ID()] {
Expand Down Expand Up @@ -232,9 +231,10 @@ func (t *Table) Insert(sym *Symbol) error {
t.unlinks[id] = unlinks
} else {
delete(t.unlinks, id)
if err := t.load(ref); err != nil {
return err
}
}

if err := t.load(ref); err != nil {
return err
}

Check warning on line 238 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L237-L238

Added lines #L237 - L238 were not covered by tests
}

Expand All @@ -247,6 +247,9 @@ func (t *Table) Free(id ulid.ULID) (bool, error) {
defer t.mu.Unlock()

if sym, ok := t.symbols[id]; ok {
if err := t.unload(sym); err != nil {
return false, err
}

Check warning on line 252 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L251-L252

Added lines #L251 - L252 were not covered by tests
if err := sym.Close(); err != nil {
return false, err
}
Expand Down Expand Up @@ -313,6 +316,9 @@ func (t *Table) Close() error {
defer t.mu.Unlock()

for id, sym := range t.symbols {
if err := t.unload(sym); err != nil {
return err
}
if err := sym.Close(); err != nil {
return err
}
Expand All @@ -326,6 +332,9 @@ func (t *Table) Close() error {
}

func (t *Table) load(sym *Symbol) error {
if len(t.unlinks[sym.ID()]) > 0 {
return nil
}
for _, hook := range t.loadHooks {
if err := hook.Load(sym.Node); err != nil {

Check warning on line 339 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L339

Added line #L339 was not covered by tests
return err
Expand All @@ -335,6 +344,9 @@ func (t *Table) load(sym *Symbol) error {
}

func (t *Table) unload(sym *Symbol) error {
if len(t.unlinks[sym.ID()]) > 0 {
return nil
}
for _, hook := range t.unloadHooks {
if err := hook.Unload(sym.Node); err != nil {

Check warning on line 351 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L351

Added line #L351 was not covered by tests
return err
Expand Down

0 comments on commit a0e7e06

Please sign in to comment.