From: Ken Bloom Date: 2009-01-12T11:39:24+09:00 Subject: Re: Binding.of_caller examples don't work. On Sun, 11 Jan 2009 14:13:29 -0500, Trans wrote: > On Jan 11, 1:11 pm, "Pit Capitain" wrote: >> 2009/1/11 Phlip : >> >> > Trans wrote: >> >> Binding.of_caller is no longer possible. >> >> > Is a workaround available? >> >> It seems that the original idea of Florian Groß is still valid. > > Cool. But word or warning to Doug, I would not recommend using > #set_trace_func in a production application. It can slow things down > considerably. > > T. First, the version in the extensions gem uses Florian Groß's idea, so it's the same as what Philip posted, modulo the organization of initialization code and the like. Second, the trace function is only being used for a couple of calls before the continuation is called, and execution jumps back into Binding.of_caller at which point the trace function is removed. It wouldn't appear to me like it would hurt things too much. (Maybe it requires turning on an otherwise disabled feature in JRuby?) Third: it looks like this should be portable to Ruby 1.9. Ruby 1.9 no longer has Thread.critical, replacing it with Thread.exclusive (which takes a block). Although Thread.exclusive is not suitable for this function because the block exits before the function exits, it should be unnecessary to lock out other threads anymore, since you should be able to do a Thread.current.set_trace_func instead of Kernel#set_trace_func and have it affect only the current thread. --Ken -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/