| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/python/src/common.h" | 5 #include "mojo/public/python/src/common.h" |
| 6 | 6 |
| 7 #include <Python.h> | 7 #include <Python.h> |
| 8 | 8 |
| 9 #include "mojo/public/c/environment/async_waiter.h" | 9 #include "mojo/public/c/environment/async_waiter.h" |
| 10 #include "mojo/public/cpp/bindings/callback.h" | 10 #include "mojo/public/cpp/bindings/callback.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 ScopedGIL::~ScopedGIL() { | 35 ScopedGIL::~ScopedGIL() { |
| 36 PyGILState_Release(state_); | 36 PyGILState_Release(state_); |
| 37 } | 37 } |
| 38 | 38 |
| 39 ScopedPyRef::ScopedPyRef(PyObject* object) : object_(object) { | 39 ScopedPyRef::ScopedPyRef(PyObject* object) : object_(object) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 ScopedPyRef::ScopedPyRef(PyObject* object, ScopedPyRefAcquire) | 42 ScopedPyRef::ScopedPyRef(PyObject* object, ScopedPyRefAcquire) |
| 43 : object_(object) { | 43 : object_(object) { |
| 44 Py_XINCREF(object_); | 44 if (object_) |
| 45 Py_XINCREF(object_); |
| 46 } |
| 47 |
| 48 ScopedPyRef::ScopedPyRef(const ScopedPyRef& other) |
| 49 : ScopedPyRef(other, kAcquire) { |
| 45 } | 50 } |
| 46 | 51 |
| 47 PyObject* ScopedPyRef::Release() { | 52 PyObject* ScopedPyRef::Release() { |
| 48 PyObject* object = object_; | 53 PyObject* object = object_; |
| 49 object_ = nullptr; | 54 object_ = nullptr; |
| 50 return object; | 55 return object; |
| 51 } | 56 } |
| 52 | 57 |
| 53 ScopedPyRef::~ScopedPyRef() { | 58 ScopedPyRef::~ScopedPyRef() { |
| 54 if (object_) { | 59 if (object_) { |
| 55 ScopedGIL acquire_gil; | 60 ScopedGIL acquire_gil; |
| 56 Py_DECREF(object_); | 61 Py_DECREF(object_); |
| 57 } | 62 } |
| 58 } | 63 } |
| 59 | 64 |
| 60 ScopedPyRef::operator PyObject*() const { | 65 ScopedPyRef& ScopedPyRef::operator=(const ScopedPyRef& other) { |
| 61 return object_; | 66 if (other) |
| 67 Py_XINCREF(other); |
| 68 PyObject* old = object_; |
| 69 object_ = other; |
| 70 if (old) |
| 71 Py_DECREF(old); |
| 72 return *this; |
| 62 } | 73 } |
| 63 | 74 |
| 64 PythonClosure::PythonClosure(PyObject* callable, const mojo::Closure& quit) | 75 PythonClosure::PythonClosure(PyObject* callable, const mojo::Closure& quit) |
| 65 : callable_(callable, kAcquire), quit_(quit) { | 76 : callable_(callable, kAcquire), quit_(quit) { |
| 66 MOJO_DCHECK(callable); | 77 MOJO_DCHECK(callable); |
| 67 } | 78 } |
| 68 | 79 |
| 69 PythonClosure::~PythonClosure() {} | 80 PythonClosure::~PythonClosure() {} |
| 70 | 81 |
| 71 void PythonClosure::Run() const { | 82 void PythonClosure::Run() const { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 181 |
| 171 void PythonAsyncWaiter::CancelWait(MojoAsyncWaitID wait_id) { | 182 void PythonAsyncWaiter::CancelWait(MojoAsyncWaitID wait_id) { |
| 172 if (callbacks_.find(wait_id) != callbacks_.end()) { | 183 if (callbacks_.find(wait_id) != callbacks_.end()) { |
| 173 async_waiter_->CancelWait(wait_id); | 184 async_waiter_->CancelWait(wait_id); |
| 174 callbacks_.erase(wait_id); | 185 callbacks_.erase(wait_id); |
| 175 } | 186 } |
| 176 } | 187 } |
| 177 | 188 |
| 178 } // namespace python | 189 } // namespace python |
| 179 } // namespace mojo | 190 } // namespace mojo |
| OLD | NEW |