[pypy-dev] Yet another trace tool!

Armin Rigo arigo at tunes.org
Fri Aug 27 14:55:58 CEST 2004


Forgot attachements.  Here is the 1st one.  The other one later...

Armin
-------------- next part --------------
#include <Python.h>


class BorrowedRef {
protected:
  PyObject* o;
public:
  BorrowedRef(PyObject* p) :o(p) { }
  BorrowedRef(const BorrowedRef &ref) :o(ref.o) { }
  operator PyObject*() const { return o; }
};

class Ref: public BorrowedRef {
public:
  Ref(PyObject* p) :BorrowedRef(p) { }
  Ref(const BorrowedRef &ref) :BorrowedRef(ref) { Py_INCREF(o); }
  Ref(int n) :BorrowedRef(PyInt_FromLong(n)) { }
  ~Ref() { Py_DECREF(o); }
};

inline int op_add(int x, int y) { return x+y; }
inline Ref op_add(const BorrowedRef &x, const BorrowedRef &y) {
  return PyNumber_Add(x, y);
}


int main()
{
  int r1 = 1234;
  Ref r2 = PyString_FromString("hello");
  Ref r3 = op_add(r1, r2);
}


More information about the Pypy-dev mailing list