From: Caleb Clausen Date: 2010-01-24T04:50:39+09:00 Subject: [ruby-core:27738] Re: [Feature #2619] Proposed method: Process.fork_supported? On 1/22/10, Charles Oliver Nutter wrote: > C: respond_to? should return true iff (A) and the method will never > raise NotImplementedError on the current platform > D: respond_to? should return true iff (C) and the method will not > raise system-level "not implemented" errors (like ENOTIMPL or ENOSYS) > Case C is hard; we would have to have special-cased code for each such > method to check at runtime if the current platform supports it, and > make a best guess from there. This logic would have to run for every > new process. > > Case D is probably not possible without a very large amount of work > and special-casing at compile time or runtime for all platforms. I don't know much about jruby, but I can't see why you say this is so difficult. It seems to me that fork_supported? (or whatever it should be called) could be implemented like this: module Platform def fork_supported? return @@fork_supported unless @@fork_supported==nil @@fork_supported= !!fork{} return @@fork_supported rescue Exception return @@fork_supported=false end end Does that not work right in jruby? In the general case, there are many such system methods that need to be checked; you wouldn't want to repeat the above for each one. But it can be generalized and dry'd up a little: module Platform SYSCALLNAME2TEST={ :fork => "!!fork{}", :ppid => "res=Process.ppid; res and res !=0", #etc } eval SYSCALLNAME2TEST.map{|name,test| " def #{name}_supported? return @@#{name}_supported unless @@#{name}_supported==nil @@#{name}_supported= (#{test}) return @@#{name}_supported rescue Exception return @@#{name}_supported=false end " }.join("\n") end Essentially, you're doing the same kind of tests that configure does, but at runtime instead of compile time. Maybe you have to do a different special test for each system call, but that's one line, or at most a few, for each one. So in all we're talking about, what, several hundred lines of (ruby) code? I don't see how any of this is difficult. Tedious, perhaps, but not that difficult. I wouldn't even characterize it as "a very large amount of work".