* [ruby-dev:48265] [ruby-trunk - Feature #9880] [Open] Dir#fileno
[not found] <redmine.issue-9880.20140529114037@ruby-lang.org>
@ 2014-05-29 11:40 ` akr
2014-05-30 16:04 ` [ruby-dev:48269] [ruby-trunk - Feature #9880] Dir#fileno akr
` (2 subsequent siblings)
3 siblings, 0 replies; 4+ messages in thread
From: akr @ 2014-05-29 11:40 UTC (permalink / raw
To: ruby-dev
Issue #9880 has been reported by Akira Tanaka.
----------------------------------------
Feature #9880: Dir#fileno
https://bugs.ruby-lang.org/issues/9880
* Author: Akira Tanaka
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
----------------------------------------
Dir#fileno を追加したいのですがどうでしょうか。
最近、fd を close せずに終わるテストを調べています。
そのために、テストの前後で、Dir.entries("/proc/#$$/fd") として、
fd が変化しているかどうか調べているのですが、
これには少し問題があります。
現在使われている fd のリストを得るために
Dir.entries("/proc/#{$$}/fd") とすると、
以下のようにひとつ余計なものが出てきます。
```
% ruby -ve '
system("ls /proc/#$$/fd")
p Dir.entries("/proc/#$$/fd")
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-18 trunk 45984) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6", "7"]
0 1 2 3 4 5 6
```
前後の system("ls /proc/#$$/fd") では 6 までしかないのに、
Dir.entries では 7 まで出てきます。
ひとつ余計な fd が出てくる理由は Dir.entries 自身がひとつ fd を使っているからです。
内部的には opendir がひとつ fd を生成します。
この挙動のため、テストが close しなかった fd ではなく、
Dir.entries が内部で使う fd が報告されることがあります。
というわけで、opendir の fd を取り除きたいのですが、
この fd を Ruby レベルで得るメソッドがありません。
しかし、POSIX では dirfd() という関数があって、DIR 構造体から
fd を取り出せます。
(4.3BSD Reno にあって、POSIX 2008 に入ったものです。)
というわけで、Dir#fileno を加えるのはどうでしょうか。
これがあれば、以下のように、/proc/#$$/fd を読むための fd を取り除けます。
```
% ./ruby -ve '
system("ls /proc/#$$/fd")
p Dir.open("/proc/#$$/fd") {|d|
a = []
while fn = d.read
a << fn
end
a - [d.fileno.to_s]
}
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-29 trunk 46224) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6"]
0 1 2 3 4 5 6
```
名前は Dir#dirfd と Dir#fileno のどちらかだと思うのですが、
IO#fileno との一貫性による覚えやすさをとって
Dir#fileno がいいんじゃないかと思っています。
あと、dirfd がないときは NotImplementedError です。
どうでしょうか。
---Files--------------------------------
dir-fileno.patch (1.51 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-dev:48269] [ruby-trunk - Feature #9880] Dir#fileno
[not found] <redmine.issue-9880.20140529114037@ruby-lang.org>
2014-05-29 11:40 ` [ruby-dev:48265] [ruby-trunk - Feature #9880] [Open] Dir#fileno akr
@ 2014-05-30 16:04 ` akr
2014-09-04 11:09 ` [ruby-dev:48519] " matz
2014-09-04 15:54 ` [ruby-dev:48521] [ruby-trunk - Feature #9880] [Closed] Dir#fileno akr
3 siblings, 0 replies; 4+ messages in thread
From: akr @ 2014-05-30 16:04 UTC (permalink / raw
To: ruby-dev
Issue #9880 has been updated by Akira Tanaka.
とりあえず現在の作業のために ext/-test-/dir/ に入れました。
これで ruby 本体についてはテストで close しなかった fd を
より確実に確認できるようになりました。
しかし、close を忘れるのは (残念ながら) 珍しいことではないので、
Dir#fileno を ruby 本体以外にも提供することにより、
この確認を容易にするのは良いことだと思っています。
----------------------------------------
Feature #9880: Dir#fileno
https://bugs.ruby-lang.org/issues/9880#change-46978
* Author: Akira Tanaka
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
----------------------------------------
Dir#fileno を追加したいのですがどうでしょうか。
最近、fd を close せずに終わるテストを調べています。
そのために、テストの前後で、Dir.entries("/proc/#$$/fd") として、
fd が変化しているかどうか調べているのですが、
これには少し問題があります。
現在使われている fd のリストを得るために
Dir.entries("/proc/#{$$}/fd") とすると、
以下のようにひとつ余計なものが出てきます。
```
% ruby -ve '
system("ls /proc/#$$/fd")
p Dir.entries("/proc/#$$/fd")
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-18 trunk 45984) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6", "7"]
0 1 2 3 4 5 6
```
前後の system("ls /proc/#$$/fd") では 6 までしかないのに、
Dir.entries では 7 まで出てきます。
ひとつ余計な fd が出てくる理由は Dir.entries 自身がひとつ fd を使っているからです。
内部的には opendir がひとつ fd を生成します。
この挙動のため、テストが close しなかった fd ではなく、
Dir.entries が内部で使う fd が報告されることがあります。
というわけで、opendir の fd を取り除きたいのですが、
この fd を Ruby レベルで得るメソッドがありません。
しかし、POSIX では dirfd() という関数があって、DIR 構造体から
fd を取り出せます。
(4.3BSD Reno にあって、POSIX 2008 に入ったものです。)
というわけで、Dir#fileno を加えるのはどうでしょうか。
これがあれば、以下のように、/proc/#$$/fd を読むための fd を取り除けます。
```
% ./ruby -ve '
system("ls /proc/#$$/fd")
p Dir.open("/proc/#$$/fd") {|d|
a = []
while fn = d.read
a << fn
end
a - [d.fileno.to_s]
}
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-29 trunk 46224) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6"]
0 1 2 3 4 5 6
```
名前は Dir#dirfd と Dir#fileno のどちらかだと思うのですが、
IO#fileno との一貫性による覚えやすさをとって
Dir#fileno がいいんじゃないかと思っています。
あと、dirfd がないときは NotImplementedError です。
どうでしょうか。
---Files--------------------------------
dir-fileno.patch (1.51 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-dev:48519] [ruby-trunk - Feature #9880] Dir#fileno
[not found] <redmine.issue-9880.20140529114037@ruby-lang.org>
2014-05-29 11:40 ` [ruby-dev:48265] [ruby-trunk - Feature #9880] [Open] Dir#fileno akr
2014-05-30 16:04 ` [ruby-dev:48269] [ruby-trunk - Feature #9880] Dir#fileno akr
@ 2014-09-04 11:09 ` matz
2014-09-04 15:54 ` [ruby-dev:48521] [ruby-trunk - Feature #9880] [Closed] Dir#fileno akr
3 siblings, 0 replies; 4+ messages in thread
From: matz @ 2014-09-04 11:09 UTC (permalink / raw
To: ruby-dev
Issue #9880 has been updated by Yukihiro Matsumoto.
Category set to core
Assignee set to Akira Tanaka
Target version set to current: 2.2.0
Dir#fileno accepted. But we have to address portability issues in the document.
Matz.
----------------------------------------
Feature #9880: Dir#fileno
https://bugs.ruby-lang.org/issues/9880#change-48650
* Author: Akira Tanaka
* Status: Open
* Priority: Normal
* Assignee: Akira Tanaka
* Category: core
* Target version: current: 2.2.0
----------------------------------------
Dir#fileno を追加したいのですがどうでしょうか。
最近、fd を close せずに終わるテストを調べています。
そのために、テストの前後で、Dir.entries("/proc/#$$/fd") として、
fd が変化しているかどうか調べているのですが、
これには少し問題があります。
現在使われている fd のリストを得るために
Dir.entries("/proc/#{$$}/fd") とすると、
以下のようにひとつ余計なものが出てきます。
```
% ruby -ve '
system("ls /proc/#$$/fd")
p Dir.entries("/proc/#$$/fd")
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-18 trunk 45984) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6", "7"]
0 1 2 3 4 5 6
```
前後の system("ls /proc/#$$/fd") では 6 までしかないのに、
Dir.entries では 7 まで出てきます。
ひとつ余計な fd が出てくる理由は Dir.entries 自身がひとつ fd を使っているからです。
内部的には opendir がひとつ fd を生成します。
この挙動のため、テストが close しなかった fd ではなく、
Dir.entries が内部で使う fd が報告されることがあります。
というわけで、opendir の fd を取り除きたいのですが、
この fd を Ruby レベルで得るメソッドがありません。
しかし、POSIX では dirfd() という関数があって、DIR 構造体から
fd を取り出せます。
(4.3BSD Reno にあって、POSIX 2008 に入ったものです。)
というわけで、Dir#fileno を加えるのはどうでしょうか。
これがあれば、以下のように、/proc/#$$/fd を読むための fd を取り除けます。
```
% ./ruby -ve '
system("ls /proc/#$$/fd")
p Dir.open("/proc/#$$/fd") {|d|
a = []
while fn = d.read
a << fn
end
a - [d.fileno.to_s]
}
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-29 trunk 46224) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6"]
0 1 2 3 4 5 6
```
名前は Dir#dirfd と Dir#fileno のどちらかだと思うのですが、
IO#fileno との一貫性による覚えやすさをとって
Dir#fileno がいいんじゃないかと思っています。
あと、dirfd がないときは NotImplementedError です。
どうでしょうか。
---Files--------------------------------
dir-fileno.patch (1.51 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-dev:48521] [ruby-trunk - Feature #9880] [Closed] Dir#fileno
[not found] <redmine.issue-9880.20140529114037@ruby-lang.org>
` (2 preceding siblings ...)
2014-09-04 11:09 ` [ruby-dev:48519] " matz
@ 2014-09-04 15:54 ` akr
3 siblings, 0 replies; 4+ messages in thread
From: akr @ 2014-09-04 15:54 UTC (permalink / raw
To: ruby-dev
Issue #9880 has been updated by Akira Tanaka.
Status changed from Open to Closed
% Done changed from 0 to 100
Applied in changeset r47387.
----------
* configure.in (dirfd): Check function.
* dir.c (dir_fileno): New method.
[ruby-dev:48265] [Feature #9880]
----------------------------------------
Feature #9880: Dir#fileno
https://bugs.ruby-lang.org/issues/9880#change-48659
* Author: Akira Tanaka
* Status: Closed
* Priority: Normal
* Assignee: Akira Tanaka
* Category: core
* Target version: current: 2.2.0
----------------------------------------
Dir#fileno を追加したいのですがどうでしょうか。
最近、fd を close せずに終わるテストを調べています。
そのために、テストの前後で、Dir.entries("/proc/#$$/fd") として、
fd が変化しているかどうか調べているのですが、
これには少し問題があります。
現在使われている fd のリストを得るために
Dir.entries("/proc/#{$$}/fd") とすると、
以下のようにひとつ余計なものが出てきます。
```
% ruby -ve '
system("ls /proc/#$$/fd")
p Dir.entries("/proc/#$$/fd")
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-18 trunk 45984) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6", "7"]
0 1 2 3 4 5 6
```
前後の system("ls /proc/#$$/fd") では 6 までしかないのに、
Dir.entries では 7 まで出てきます。
ひとつ余計な fd が出てくる理由は Dir.entries 自身がひとつ fd を使っているからです。
内部的には opendir がひとつ fd を生成します。
この挙動のため、テストが close しなかった fd ではなく、
Dir.entries が内部で使う fd が報告されることがあります。
というわけで、opendir の fd を取り除きたいのですが、
この fd を Ruby レベルで得るメソッドがありません。
しかし、POSIX では dirfd() という関数があって、DIR 構造体から
fd を取り出せます。
(4.3BSD Reno にあって、POSIX 2008 に入ったものです。)
というわけで、Dir#fileno を加えるのはどうでしょうか。
これがあれば、以下のように、/proc/#$$/fd を読むための fd を取り除けます。
```
% ./ruby -ve '
system("ls /proc/#$$/fd")
p Dir.open("/proc/#$$/fd") {|d|
a = []
while fn = d.read
a << fn
end
a - [d.fileno.to_s]
}
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-29 trunk 46224) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6"]
0 1 2 3 4 5 6
```
名前は Dir#dirfd と Dir#fileno のどちらかだと思うのですが、
IO#fileno との一貫性による覚えやすさをとって
Dir#fileno がいいんじゃないかと思っています。
あと、dirfd がないときは NotImplementedError です。
どうでしょうか。
---Files--------------------------------
dir-fileno.patch (1.51 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-04 16:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-9880.20140529114037@ruby-lang.org>
2014-05-29 11:40 ` [ruby-dev:48265] [ruby-trunk - Feature #9880] [Open] Dir#fileno akr
2014-05-30 16:04 ` [ruby-dev:48269] [ruby-trunk - Feature #9880] Dir#fileno akr
2014-09-04 11:09 ` [ruby-dev:48519] " matz
2014-09-04 15:54 ` [ruby-dev:48521] [ruby-trunk - Feature #9880] [Closed] Dir#fileno akr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).