Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1020)

Unified Diff: mojo/public/python/src/common.cc

Issue 942013003: Python handler: Pass a python object to content handled application. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/python/src/common.cc
diff --git a/mojo/public/python/src/common.cc b/mojo/public/python/src/common.cc
index e2a832ab389d2903fd6ead2547a6b92934d17af0..d14d718c1f30769a7cd749c8a57b41bf91468b49 100644
--- a/mojo/public/python/src/common.cc
+++ b/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)

Powered by Google App Engine
This is Rietveld 408576698