[pypy-dev] Re: die cpythonobject, die!

Richard Emslie rxe at ukshells.co.uk
Wed Jul 14 17:32:59 CEST 2004

We need a sprint!  :-)  Think I've exhausted my pypy hacking for the 

Well, i'm not sure if this is much better than the last hack, but at least 
no references to SlotWrapperType anymore... ;-)

Instead of fake_function() as per last mail, add to the bottom of 
fake_type() similar to before, but only if our ctype has __call__.

def fake_type(space, cpy_type):
     # return W_Fake

     if hasattr(cpy_type, "__call__"):
         def call_args(self, args):
                 unwrappedargs = [space.unwrap(w_arg) for w_arg in args.args_w]
                 unwrappedkwds = dict([(key, space.unwrap(w_value))
                                       for key, w_value in args.kwds_w.items()])
             except UnwrapError, e:
                 raise UnwrapError('calling %s: %s' % (cpy_type, e))
                 assert callable(self.val), self.val
                 result = apply(self.val, unwrappedargs, unwrappedkwds)
             return space.wrap(result)

         setattr(W_Fake, "call_args", call_args)

     return W_Fake

Will also need some mods to DescrOperation()

     def get_and_call_args(space, w_descr, w_obj, args):
         descr = space.unwrap_builtin(w_descr)
         if hasattr(descr, "call_args"):
             # special-case Functions to avoid infinite recursion
## XXX Tmp comment out
##             if isinstance(descr.code, BuiltinCode):
##                 # this sub-special case is ONLY for performance reasons
##                 w_result = descr.code.performance_shortcut_call_meth(space,
##                                                                      w_obj, args)
##                 if w_result is not None:
##                     return w_result
             return descr.call_args(args.prepend(w_obj))
             w_impl = space.get(w_descr, w_obj)
             return space.call_args(w_impl, args)


On Wed, 14 Jul 2004, Michael Hudson wrote:

> Michael Hudson <mwh at python.net> writes:
>> Well, I think that could work but I'd prefer a solution with less
>> special casing.
>> How does CPython avoid the same problem?
> Well, that's fairly easy.  In PyPy almost every callable is a Function
> or Method, hence has a __get__:
>>>>> types.MethodType.im_func.__get__.__get__.__get__.__get__.__get__.__get__
> <method object at 0x4062ec8c>
> Hum, not sure what to do about that...
> Cheers,
> mwh
> --
>  surely, somewhere, somehow, in the history of computing, at least
>  one manual has been written that you could at least remotely
>  attempt to consider possibly glancing at.              -- Adam Rixey
> _______________________________________________
> pypy-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-dev

More information about the Pypy-dev mailing list