Feature #11273 ยป 0001-file.c-load-now-supports-reading-from-a-FIFO-file.patch
ChangeLog | ||
---|---|---|
1 |
Wed Jun 17 16:00:00 2015 Franck Verrot <franck@verrot.fr> |
|
2 | ||
3 |
file.c : `load` now supports reading from a FIFO file |
|
4 | ||
5 |
* file.c (rb_file_load_ok): `load` can now load not only regular files |
|
6 |
but also FIFOS. |
|
7 | ||
1 | 8 |
Wed Jun 17 15:15:53 2015 NAKAMURA Usaku <usa@ruby-lang.org> |
2 | 9 | |
3 | 10 |
* safe.c (safe_setter): of course, don't have to warn the limitation of |
NEWS | ||
---|---|---|
15 | 15 | |
16 | 16 |
=== Core classes updates (outstanding ones only) |
17 | 17 | |
18 |
* Kernel |
|
19 | ||
20 |
* Kernel.load now supports reading from a FIFO file. |
|
21 | ||
18 | 22 |
* Enumerable |
19 | 23 | |
20 | 24 |
* Enumerable#grep_v is added as inverse version of Enumerable#grep. |
file.c | ||
---|---|---|
115 | 115 |
#define STAT(p, s) stat((p), (s)) |
116 | 116 |
#endif |
117 | 117 | |
118 |
#ifdef S_IFIFO |
|
119 |
# ifndef S_ISFIFO |
|
120 |
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) |
|
121 |
# endif |
|
122 |
#endif |
|
123 | ||
118 | 124 |
#if defined(__BEOS__) || defined(__HAIKU__) /* should not change ID if -1 */ |
119 | 125 |
static int |
120 | 126 |
be_chown(const char *path, uid_t owner, gid_t group) |
... | ... | |
1367 | 1373 |
rb_file_pipe_p(VALUE obj, VALUE fname) |
1368 | 1374 |
{ |
1369 | 1375 |
#ifdef S_IFIFO |
1370 |
# ifndef S_ISFIFO |
|
1371 |
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) |
|
1372 |
# endif |
|
1373 | ||
1374 | 1376 |
struct stat st; |
1375 | 1377 | |
1376 | 1378 |
if (rb_stat(fname, &st) < 0) return Qfalse; |
... | ... | |
5639 | 5641 |
rb_update_max_fd(fd); |
5640 | 5642 |
#if !defined DOSISH |
5641 | 5643 |
{ |
5642 |
struct stat st; |
|
5643 |
if (fstat(fd, &st) || !S_ISREG(st.st_mode)) { |
|
5644 |
ret = 0; |
|
5645 |
} |
|
5644 |
struct stat st; |
|
5645 |
fstat(fd, &st); |
|
5646 | ||
5647 |
#ifdef S_IFIFO |
|
5648 |
if (!(S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode))) { |
|
5649 |
#else |
|
5650 |
if (!S_ISREG(st.st_mode)) { |
|
5651 |
#endif |
|
5652 |
ret = 0; |
|
5653 |
} |
|
5646 | 5654 |
} |
5647 | 5655 |
#endif |
5648 | 5656 |
(void)close(fd); |
test/ruby/test_require.rb | ||
---|---|---|
706 | 706 |
END |
707 | 707 |
} |
708 | 708 |
end unless /mswin|mingw/ =~ RUBY_PLATFORM |
709 | ||
710 |
def test_loading_from_fifo |
|
711 |
Dir.mktmpdir {|tmp| |
|
712 |
file = File.join(tmp,'fifo.rb') |
|
713 |
File.mkfifo(file) |
|
714 |
thread = Thread.new { open(file,'w') { |f| f.puts "class Foo; end" } } |
|
715 |
assert_separately([], <<-INPUT) |
|
716 |
assert_nothing_raised(LoadError) { load("#{ file }") } |
|
717 |
assert_nothing_raised(NameError) { Foo } |
|
718 |
INPUT |
|
719 |
} |
|
720 |
end unless /mswin|mingw/ =~ RUBY_PLATFORM |
|
721 | ||
709 | 722 |
end |
710 |
- |