User Tools

Site Tools


info:swig

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
info:swig [2011-12-15 16:33]
sam [PySequence_Fast API]
info:swig [2012-02-08 22:00] (current)
sam [PyObject auto_ptr]
Line 11: Line 11:
  
 ==== PyObject auto_ptr ==== ==== PyObject auto_ptr ====
 +See http://​code.activestate.com/​recipes/​577985-automatic-python-pyobject-ref-count-management-in-/​
 +
 <code cpp> <code cpp>
 /* /*
  * auto_pyptr.h  * auto_pyptr.h
  *  *
 + * Originally from
  * http://​code.activestate.com/​recipes/​528875-automatic-ref-count-management-in-c-using-a-smart-/​  * http://​code.activestate.com/​recipes/​528875-automatic-ref-count-management-in-c-using-a-smart-/​
  */  */
Line 52: Line 55:
         if(ptr)         if(ptr)
             Py_INCREF(ptr);​             Py_INCREF(ptr);​
 +    }
 +
 +    /*
 +     * Implement cast to PyObject pointer so you don't have to call var.get()
 +     * every time you use the object.
 +     *
 +     * You still have to use get() in certain cases, notably varargs
 +     * (i.e. "​..."​). GCC will warn you that this will abort at runtime.
 +     */
 +    operator PyObject*() {
 +        return this->​get();​
     }     }
 }; };
info/swig.txt · Last modified: 2012-02-08 22:00 by sam