apache / apache/datafusion

alter_fp_rounding_mode Is Not Panic Safe

Open
#7,356 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Describe the bug

alter_fp_rounding_mode makes use of `fesetround` in order to alter the rounding mode on various architectures

```
let current = fegetround();
fesetround(if UPPER { FE_UPWARD } else { FE_DOWNWARD });
let result = operation(lhs, rhs);
fesetround(current);
result
```

Unfortunately if `operation` panics, `fesetround` will never revert the rounding mode. `Drop` would be a more reliable way around this, although there are still situations where `Drop` may not be called

### To Reproduce

_No response_

### Expected behavior

Ideally we wouldn't modify global thread-local state at all, but I'm not sure if this can be avoided

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by locating alter_fp_rounding_mode and tracing its fesetround usage across the supported architectures. Reproduce the panic path around operation and determine whether the rounding mode is restored afterward; done means panic handling does not leave the thread-local rounding mode altered, subject to the platform constraints described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.