Skip to content

timep v1.9.3#80

Merged
jkool702 merged 3 commits intomainfrom
HOTFIX/main
Nov 2, 2025
Merged

timep v1.9.3#80
jkool702 merged 3 commits intomainfrom
HOTFIX/main

Conversation

@jkool702
Copy link
Owner

@jkool702 jkool702 commented Nov 2, 2025

initial attempt at fix for issue where aa source-triggered return trap causes FNEST to get popped when it shouldnt be.

Summary by Sourcery

Fix incorrect popping of timep call stack frames when RETURN traps are triggered by sourced scripts by introducing source-depth tracking and refining trap logic.

Bug Fixes:

  • Prevent FNEST frames from being popped when a RETURN trap originates from a sourced file.

Enhancements:

  • Add timep_NUM_SOURCE and timep_IS_SOURCE_FLAG arrays to track BASH_SOURCE depth and distinguish real function returns from source-triggered traps.
  • Refactor timep_IS_FUNC_FLAG checks into if/elif blocks for clearer control flow.
  • Declare and initialize new global variables timep_BASH_SOURCE_N_PREV, timep_NUM_SOURCE, and timep_IS_SOURCE_FLAG.

Tests:

  • Update the update_all_tests.bash script to include the deepseek stress test and reorder test entries.

Chores:

  • Clean up minor whitespace issues and sed expression formatting.

…p causes FNEST to get popped when it shouldnt be
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 2, 2025

Reviewer's Guide

This PR enhances the return-trap handling by tracking BASH_SOURCE depth and per-frame source flags to prevent incorrect frame popping on source-triggered returns, refactors related conditional branches, declares and initializes new state variables, applies minor formatting cleanups, and updates the test script with a new deepseek test path.

Class diagram for updated frame and source tracking variables

classDiagram
    class timep {
        +timep_FNEST : array
        +timep_NEXEC_A : array
        +timep_NEXEC_HASH_A : array
        +timep_BASH_COMMAND_PREV : array
        +timep_NPIPE : array
        +timep_STARTTIME : array
        +timep_LINENO : array
        +timep_LINENO_OFFSET : array
        +timep_NUM_SOURCE : array [NEW]
        +timep_IS_SOURCE_FLAG : array [NEW]
        +timep_BASH_SOURCE_N_PREV : int [NEW]
    }
    timep_FNEST_CUR : int
    timep_NEXEC_CUR : int
    timep_NEXEC_HASH_CUR : int
    timep_FUNCNAME_STR : string
    timep_NEXEC_0 : string
    timep_BASH_SOURCE_N_PREV : int
    timep_NUM_SOURCE : array
    timep_IS_SOURCE_FLAG : array
    timep "1" -- "*" timep_NUM_SOURCE : tracks per-frame source depth
    timep "1" -- "*" timep_IS_SOURCE_FLAG : tracks per-frame source-triggered return
    timep "1" -- "1" timep_BASH_SOURCE_N_PREV : stores previous BASH_SOURCE depth
Loading

Flow diagram for enhanced return-trap frame popping logic

flowchart TD
    A["RETURN trap triggered"] --> B["Check FUNCNAME stack length"]
    B --> C["Check BASH_SOURCE depth vs timep_NUM_SOURCE[timep_FNEST_CUR]"]
    C -->|BASH_SOURCE depth < timep_NUM_SOURCE| D["Pop frame and unset variables"]
    C -->|BASH_SOURCE depth == timep_NUM_SOURCE & !timep_IS_SOURCE_FLAG| D
    C -->|BASH_SOURCE depth == timep_NUM_SOURCE & timep_IS_SOURCE_FLAG| E["Set timep_IS_SOURCE_FLAG[timep_FNEST_CUR]=false"]
    D --> F["Update FUNCNAME_STR, NEXEC_0, FNEST_CUR, NEXEC_CUR, NEXEC_HASH_CUR"]
    E --> F
    F --> G["Continue trap handling"]
Loading

File-Level Changes

Change Details Files
Enhanced return-trap popping logic with source-depth guard
  • Wrap existing unset/pop operations in a conditional that checks BASH_SOURCE length vs stored depth and a source-flag
  • Add an elif branch to clear the source-flag instead of popping when depth matches and source-flag is true
timep.bash
Introduced BASH_SOURCE depth and source-flag tracking
  • Declare new arrays timep_NUM_SOURCE and timep_IS_SOURCE_FLAG in the global state block
  • Capture current BASH_SOURCE length into timep_BASH_SOURCE_N_PREV at key points
  • Initialize timep_NUM_SOURCE and timep_IS_SOURCE_FLAG in the BASH_ENV setup and on function entry
timep.bash
Refactored function-entry branch into if/elif structure for source detection
  • Replace ${timep_IS_FUNC_FLAG} && { ... } with if ${timep_IS_FUNC_FLAG}; then ... elif ...; fi
  • Within the elif, set the source-flag when BASH_SOURCE count decreases
timep.bash
Applied formatting and whitespace cleanups
  • Removed trailing semicolons and extra spaces
  • Aligned sed command pipelines for consistency
  • Fixed indentation and brace placement in several code blocks
timep.bash
Updated test suite script to include deepseek tests
  • Added TESTS/deepseek/deepseek_stress_test.bash to the test list
  • Reordered GLM test entries for logical grouping
TESTS/update_all_tests.bash

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Add inline comments around the new source‐depth tracking logic in _timep_getFuncSrc to explain the popping vs. source‐trap conditions for future maintainers.
  • Organize the new global arrays (timep_NUM_SOURCE and timep_IS_SOURCE_FLAG) near related variables in the declaration block to improve readability and consistent grouping.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Add inline comments around the new source‐depth tracking logic in _timep_getFuncSrc to explain the popping vs. source‐trap conditions for future maintainers.
- Organize the new global arrays (timep_NUM_SOURCE and timep_IS_SOURCE_FLAG) near related variables in the declaration block to improve readability and consistent grouping.

## Individual Comments

### Comment 1
<location> `timep.bash:467` </location>
<code_context>
+        timep_NEXEC_CUR="${timep_NEXEC_A[-1]}"
+        timep_NEXEC_HASH_CUR="${timep_NEXEC_HASH_A[-1]}"
+    elif (( ${#BASH_SOURCE[@]} == timep_NUM_SOURCE[${timep_FNEST_CUR}] )) && ${timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]}; then
+        timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]=false
+    fi
 }
</code_context>

<issue_to_address>
**suggestion:** Directly assigning 'false' to an array element may not be portable across all Bash versions.

Some Bash versions treat array elements as strings, so 'false' may not work as a boolean. Use '0'/'1' or string checks for consistency.

Suggested implementation:

```shell
    elif (( ${#BASH_SOURCE[@]} == timep_NUM_SOURCE[${timep_FNEST_CUR}] )) && [[ "${timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]}" == "1" ]]; then
        timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]="0"

```

You should also update any other code that checks or sets `timep_IS_SOURCE_FLAG[...]` to use `"1"` for true and `"0"` for false, and use string comparison (`== "1"` or `== "0"`) instead of relying on Bash's boolean evaluation.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

timep_NEXEC_CUR="${timep_NEXEC_A[-1]}"
timep_NEXEC_HASH_CUR="${timep_NEXEC_HASH_A[-1]}"
elif (( ${#BASH_SOURCE[@]} == timep_NUM_SOURCE[${timep_FNEST_CUR}] )) && ${timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]}; then
timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]=false
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Directly assigning 'false' to an array element may not be portable across all Bash versions.

Some Bash versions treat array elements as strings, so 'false' may not work as a boolean. Use '0'/'1' or string checks for consistency.

Suggested implementation:

    elif (( ${#BASH_SOURCE[@]} == timep_NUM_SOURCE[${timep_FNEST_CUR}] )) && [[ "${timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]}" == "1" ]]; then
        timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]="0"

You should also update any other code that checks or sets timep_IS_SOURCE_FLAG[...] to use "1" for true and "0" for false, and use string comparison (== "1" or == "0") instead of relying on Bash's boolean evaluation.

@jkool702 jkool702 merged commit a5e0268 into main Nov 2, 2025
2 of 3 checks passed
@jkool702 jkool702 deleted the HOTFIX/main branch November 2, 2025 06:47
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.

1 participant