[#35446] [Ruby 1.9 - Bug #4477][Open] Kernel:exec and backtick (`) don't work for certain system commands — Joachim Wuttke <j.wuttke@...>

10 messages 2011/03/07

[#35476] [Ruby 1.9 - Bug #4489][Open] [PATCH] Encodings with /-(unix|dos|mac)\Z/ — "James M. Lawrence" <quixoticsycophant@...>

20 messages 2011/03/10

[#35552] [Ruby 1.9 - Feature #4523][Open] Kernel#require to return the path of the loaded file — Alex Young <alex@...>

14 messages 2011/03/24

[#35565] [Ruby 1.9 - Feature #4531][Open] [PATCH 0/7] use poll() instead of select() in certain cases — Eric Wong <normalperson@...>

33 messages 2011/03/28

[#35566] [Ruby 1.9 - Feature #4532][Open] [PATCH] add IO#pread and IO#pwrite methods — Eric Wong <normalperson@...>

12 messages 2011/03/28

[#35586] [Ruby 1.9 - Feature #4538][Open] [PATCH (cleanup)] avoid unnecessary select() calls before doing I/O — Eric Wong <normalperson@...>

9 messages 2011/03/29

[ruby-core:35581] Re: [Ruby 1.9 - Feature #4532][Open] [PATCH] add IO#pread and IO#pwrite methods

From: KOSAKI Motohiro <kosaki.motohiro@...>
Date: 2011-03-29 11:59:10 UTC
List: ruby-core #35581
2011/3/29 Eric Wong <normalperson@yhbt.net>:
> KOSAKI Motohiro <kosaki.motohiro@gmail.com> wrote:
>> 2011/3/28 Eric Wong <normalperson@yhbt.net>:
>> > Issue #4532 has been reported by Eric Wong.
>> >
>> > ----------------------------------------
>> > Feature #4532: [PATCH] add IO#pread and IO#pwrite methods
>> > http://redmine.ruby-lang.org/issues/4532
>> >
>> > Author: Eric Wong
>> > Status: Open
>> > Priority: Normal
>> > Assignee:
>> > Category: core
>> > Target version: 1.9.x
>> >
>> >
>> > These methods are useful for safe/concurrent file I/O in
>> > multi-thread/process environments and also fairly standard
>> > nowadays especially in systems supporting pthreads.
>> >
>> > pread() is already used internally for IO.copy_stream
>>
>> Do we really need to introduce new method? Why can't we overload
>> IO.read and IO.write?
>> too complex?
>
> IO#read and IO#write take userspace buffers into account which
> makes no sense with pread/pwrite.

userspace buffer is implementation detail. no?

And, If pread is always behave as binary mode read method, your
documentation is much misleading. IMHO.

 *     f = File.new("testfile")
 *     f.pread(16, 0)   #=> "This is line one"


> I considered overloading IO#sysread and IO#syswrite, but it would be
> hard for users to determine whether offset is supported on their
> platform.

?? Why?
Do you have any example?


> New methods means IO.method_defined? and IO#respond_to? to be used.

OK, fair point.


> I'm not a fan of throwing NotImplementedError and faking with lseek() +
> read()/write() to be even worse since it loses the atomicity guarantee.

I disagree. I dislike following part of your patch.

#ifdef HAVE_PREAD
    rb_define_method(rb_cIO, "pread", rb_io_pread, -1);
#endif

This is very wrong style for new method. Eventually,  *all* users need to call
method_defined? before pread. Just NotImplementedError (or lseek emulation)
makes much simpler script.


> I also considered putting the new methods in File instead of IO, but
> sysseek is an IO method so I put it in IO.

I agree IO is better.

In This Thread