Skip to content

Make IRB::VERSION available for library users - #1

Merged
hsbt merged 1 commit into
ruby:masterfrom
stomar:irb-version
Oct 9, 2018
Merged

hsbt merged 1 commit into
ruby:masterfrom
stomar:irb-version

Conversation

@stomar

@stomar stomar commented Oct 4, 2018 •

Copy link
Copy Markdown
Contributor

IRB::VERSION is defined and used in the gemspec, but not available for irb users. The PR makes it available in irb sessions.

Edit: The build fail seems to be unrelated.

@marcandre

Copy link
Copy Markdown
Member

Seems like a good idea. Would be a good idea to replace those require with require_relative too.

@stomar

stomar commented Oct 5, 2018

Copy link
Copy Markdown
Contributor Author

I believe require should be preferred, because require_relative doesn‘t properly detect multiple requires, afaik. Also, there is no need for it, because the lib dir is in the load path anyway for an installed gem.

@marcandre

marcandre commented Oct 5, 2018 •

Copy link
Copy Markdown
Member

AFAIK, require_relative does detect multiple requires. Let me know if I'm wrong.
It's also faster because it doesn't have to lookup the load path...

@stomar

stomar commented Oct 5, 2018 •

Copy link
Copy Markdown
Contributor Author

Honestly, I do not know... possibly/probably(?) outdated information.

But anyway I think this would best be considered in a different PR or on Redmine. Your suggestion would apply to most of the standard libraries and extensions in Ruby trunk, I guess.

@marcandre

Copy link
Copy Markdown
Member

Your suggestion would apply to most of the standard libraries and extensions in Ruby trunk, I guess.

Sure, I'll have a look.

@marcandre

Copy link
Copy Markdown
Member

You probably want to remove the useless require 'irb/lib' on line 357

Always require `irb/version' to provide IRB::VERSION at any time,
not only when IRB.version is called previously.
@marcandre

Copy link
Copy Markdown
Member

@hsbt
hsbt merged commit 18db998 into ruby:master Oct 9, 2018
@stomar

stomar commented Oct 10, 2018

Copy link
Copy Markdown
Contributor Author

@marcandre Thanks for the reference, seems I got it mixed up :)

@stomar
stomar deleted the irb-version branch October 10, 2018 20:58
ko1 added a commit to ko1/irb that referenced this pull request Dec 12, 2025
The following `test_irb_fg_jobs_and_kill_commands` expects that after `fg 0`
Thread#1 should be `sleep_forever`.

```ruby
    def test_irb_fg_jobs_and_kill_commands
      out = run_ruby_file do
        type "irb"
        type "fg 0"
        type "jobs"
        type "kill 1"
        type "exit"
      end

      assert_match(/#0->irb on main \(#<Thread:0x.+ run>: running\)/, out)
      assert_match(/ruby#1->irb#1 on main \(#<Thread:0x.+ sleep_forever>: stop\)/, out)
    end
  end
```

However, the following switching method expects that

```
    def switch(key)
      th, irb = search(key)
      ...
      th.run
      Thread.stop
```

(1) resume target thread
(2) Suspend current thread (-> sleep_forever)

`th.run` calls `Thread.pass` internally and maybe the context swtich to
resumed thread (#0 in this case).

Thread #0 should switch to ruby#1 before `jobs` command.
Until Ruby 3.4, I/O operation makes context switching to another ready thread,
so that several I/O output can resume `ruby#1`.

However, our planning new thread scheduler delays context switching on I/O
operations, so the thread ruby#1 still running (because `Thread.stop` is not called yet).

This patch add `Thraed.pass` to make workaround for this test.
tompng pushed a commit that referenced this pull request Dec 12, 2025
The following `test_irb_fg_jobs_and_kill_commands` expects that after `fg 0`
Thread#1 should be `sleep_forever`.

```ruby
    def test_irb_fg_jobs_and_kill_commands
      out = run_ruby_file do
        type "irb"
        type "fg 0"
        type "jobs"
        type "kill 1"
        type "exit"
      end

      assert_match(/#0->irb on main \(#<Thread:0x.+ run>: running\)/, out)
      assert_match(/#1->irb#1 on main \(#<Thread:0x.+ sleep_forever>: stop\)/, out)
    end
  end
```

However, the following switching method expects that

```
    def switch(key)
      th, irb = search(key)
      ...
      th.run
      Thread.stop
```

(1) resume target thread
(2) Suspend current thread (-> sleep_forever)

`th.run` calls `Thread.pass` internally and maybe the context swtich to
resumed thread (#0 in this case).

Thread #0 should switch to #1 before `jobs` command.
Until Ruby 3.4, I/O operation makes context switching to another ready thread,
so that several I/O output can resume `#1`.

However, our planning new thread scheduler delays context switching on I/O
operations, so the thread #1 still running (because `Thread.stop` is not called yet).

This patch add `Thraed.pass` to make workaround for this test.
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.

3 participants