Index: third_party/mojo/src/mojo/public/python/src/common.cc |
diff --git a/third_party/mojo/src/mojo/public/python/src/common.cc b/third_party/mojo/src/mojo/public/python/src/common.cc |
index e2a832ab389d2903fd6ead2547a6b92934d17af0..d14d718c1f30769a7cd749c8a57b41bf91468b49 100644 |
--- a/third_party/mojo/src/mojo/public/python/src/common.cc |
+++ b/third_party/mojo/src/mojo/public/python/src/common.cc |
@@ -41,7 +41,12 @@ ScopedPyRef::ScopedPyRef(PyObject* object) : object_(object) { |
ScopedPyRef::ScopedPyRef(PyObject* object, ScopedPyRefAcquire) |
: object_(object) { |
- Py_XINCREF(object_); |
+ if (object_) |
+ Py_XINCREF(object_); |
+} |
+ |
+ScopedPyRef::ScopedPyRef(const ScopedPyRef& other) |
+ : ScopedPyRef(other, kAcquire) { |
} |
PyObject* ScopedPyRef::Release() { |
@@ -57,8 +62,14 @@ ScopedPyRef::~ScopedPyRef() { |
} |
} |
-ScopedPyRef::operator PyObject*() const { |
- return object_; |
+ScopedPyRef& ScopedPyRef::operator=(const ScopedPyRef& other) { |
+ if (other) |
+ Py_XINCREF(other); |
+ PyObject* old = object_; |
+ object_ = other; |
+ if (old) |
+ Py_DECREF(old); |
+ return *this; |
} |
PythonClosure::PythonClosure(PyObject* callable, const mojo::Closure& quit) |