[pypy-dev] A problem with unbound methods

Samuele Pedroni pedronis at strakt.com
Thu Apr 6 13:33:58 CEST 2006


Antonio Cuni wrote:
> Hi,
> I have some problems for translating calls to unbound methods.
> Let's show with an example:
> 
> class MyClass:
>     def __init__(self, x):
>         self.x = x
> 
> class MyDerivedClass(MyClass):
>     def __init__(self, x):
>         MyClass.__init__(self, x)
> 
> During rtyping the field and method names are mangled, so the __init__ 
> method became something like 'o__init____variant0': as long as I call 
> bound methods this is not a problem because the low-level op oosend 
> contains the right mangled name, but difficult arises when I try to call 
> an unbound method such as the one showed above; the low-level op that I 
> obtain is this:
> 
> v9 = direct_call((<pypy.rpython.ootypesystem.ootype._static_meth object 
> at 0xb78e51ac>), self_1, x_2)
> 
> Let 'x = op.args[0].value':
> 
> (Pdb) x._name
> 'Base.__init__'
> (Pdb) x.graph.name
> 'Base.__init__'
> 
> As you can see I can read only the original unmangled name, but it is 
> useless because I've to deal with the mangled one.
> I've tried to search around for a place where to read that but I 
> couldn't find it. How can I do?
> 

you should not trust or use graph names in the backend, apart
for givin names to things. If a function is reused in more
than one class the information would not be useful (this can
happen in Python/RPython).
The graph would get the name based on the first class
under which it was found, this may be unrelated for example
for the class for self to the method name under which the graph
is attached.

Because there are too many variations about what is allowed in terms
of supporting functions vs. just methods, calling superclass
implementations of methods even when the method is overriden
in a subclass etc in the targets, right now it is up to the backend
to traverse and consider all classes and direct_calls and if the same
graph appears both attached to a method (or methods) in a class (or
classes) and in static method(s) in a direct call(s) decide what to do.
This is also true in general for graphs that appear as more than on
method in one place.

Strategies here may vary from using a single static method (e.g. in
Java) and having methods delegate to it, or if possible having just
the method if the types of the first arguments in the direct call
allow that approach ...


regards














More information about the Pypy-dev mailing list