Skip to content

Conversation

@flowchartsman
Copy link
Contributor

@flowchartsman flowchartsman commented Apr 25, 2025

fixes #36

This change removes the last usage of unsafe from the package, which was used in a custom log2 implementation during acquireSemAll. This can be implemented using bits.Len64 instead, provided the number >0. Since the method is internal, a panic in place seems a sensible response to violating that expectation.

Copy link

@redloaf redloaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Comment on lines +547 to +549
if num <= 0 {
panic("aquireSemAll: num <= 0")
}
Copy link

@redloaf redloaf Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a slight behavior change but is more predictable. If num is negative, sem.TryAcquire can succeed and has the same effect as sem.Release(-num). However, it fails if there are any blocked Acquire calls. Before your changes, this has the potential to result in a sporadic panic for a condition that should probably always result in a panic (as you've written it).

Example and source

@jackc jackc merged commit 6591ec1 into jackc:master Apr 26, 2025
2 checks passed
@jackc
Copy link
Owner

jackc commented Apr 26, 2025

LGTM. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove reliance on package unsafe

3 participants