I've got class A wrapped with method foo implemented using %extend:
class A {
  ...
  %extend {
  void foo()
  {
    self->foo_impl();
  }
  }
Now I want to increase ref count to an A inside foo_impl, but I only got A* (as self). 
Question: how can I write/wrap function foo, so that I have an access both to A* and underlying PyObject*?
Thank you
I think it's not possible.  If you need to increase the refcount, it's because you don't want the C++ object to be destroyed when it goes out of scope because there is a pointer to that object elsewhere.  In that case, look at using the DISOWN typemap to ensure the target language doesn't think it "owns" the C++ object, so it won't get destroyed.
Python Swig wrapper: how access underlying PyObject