[pypy-dev] Yet another trace tool!
Richard Emslie
rxe at ukshells.co.uk
Fri Aug 27 17:12:14 MEST 2004
Hi Armin,
On Fri, 27 Aug 2004, Armin Rigo wrote:
...
>> Previous experience has shown that if the types are c++ classes/structs
>> then it does the job. But I do agree with your point.
>
> I see. If the things include primitive types then it gets more messy.
> Attached is an example where the call to op_add() is deemed ambiguous by the
> compiler, and I don't see how to solve that problem -- unless we don't use
> ints at all as the type of the variables, but only a custom class Integer
> containing an int field, as shown in the 2nd attachement. Sadly, this is
> elegant and fine with good C++ optimizers (e.g. Microsoft's) but g++ really
> produces bad code in this kind of situation.
>
Ahhh, I misunderstood. I was thinking along far more tedious lines of
creating every possible combination of arguments and not doing any
automatic conversion at all.
inline Ref op_add(const BorrowedRef &x, const BorrowedRef &y) ...
inline Ref op_add(int x, int y) ...
inline Ref op_add(int x, const BorrowedRef &y) ...
inline Ref op_add(const BorrowedRef &x, int y) ...
// Same again but returning ints
but the problem IIRC c++ doesn't support overloaded return results.
Maybe we create a hierarchical tree of refs (including custom classes for
int, float, etc like you suggested) and return the base type for each op
(I'm confused with lack of c++ knowhow, need to hack some!). I imagine
this shifts from compile time to run time (which kind of defeats the
purpose of what we are doing - but not too much).
> As you said, we should still try to do it this way, because it's not so
> involved and quite independent from other efforts like generating C code with
> conversions in the source.
>
> In your gencpp.h, what is the purpose of CPythonProxyObject and its own
> reference counter? It seems that class Handle could just use a PyObject*
> directly and the Py_INCREF/DECREF() macros to manipulate its refcount.
Probably because I hacked some old templated code - but I think you are
right since PyObject* is already ref counted. :-) Assignment to self is
always interesting (since you decrement, which collects and then increment
which then is on an invalid object - but still don't need layer of
indirection of CPythonProxyObject). Also I thought it was good idea not
to call Py_INCREF and PyDECREF too often - but that is plain silly. It
does make nulls easier though (but not much).
> I'll not be too much on IRC for the next 10 days or so, but I'll try to show
> up on Sunday.
>
Ok. Can you drop us a copy of genc.py which was doing something with the
annotations if that is ok (doesn't need to be any nice state)? Thanks.
Cheers,
Richard
More information about the pypy-dev
mailing list