[pypy-dev] Yet another trace tool!

Armin Rigo arigo at tunes.org
Mon Aug 30 19:00:59 CEST 2004


Hello Richard,

On Mon, Aug 30, 2004 at 05:36:50PM +0100, Richard Emslie wrote:
> """
>   Int i;
>   Ref r;
>   r = op_add(i, i); // calls Int op_add(const Int&, const Int&)
>                     // converts return type :-)
> 
>   r = op_add(i, r); // i converted to Ref as temporary  :-(
> """
> 
> but I assume the latter is not what you mean.

No: it *is* exactly what I mean.  There is no other way to do that with the C
API of CPython.  To add an int i and a PyObject* r you have no choice but do:

   tmp = PyInt_FromLong(i);
   res = PyNumber_Add(tmp, r);
   Py_DECREF(tmp);

This is exactly what the C++ compiler will generate with automatic
conversions.


Armin



More information about the Pypy-dev mailing list