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

Side by Side Diff: mojo/public/python/src/python_system_helper.cc

Issue 552783004: mojo: Add a runloop utility in python (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « mojo/public/python/src/python_system_helper.h ('k') | mojo/python/tests/runloop_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/python/src/python_system_helper.h"
6
7 #include "Python.h"
8
9 #include "mojo/public/cpp/system/macros.h"
10 #include "mojo/public/cpp/utility/run_loop.h"
11
12 namespace {
13
14 class PythonClosure : public mojo::Closure::Runnable {
15 public:
16 PythonClosure(PyObject* callable) {
sdefresne 2014/09/16 16:35:59 If callable is NULL, then callable_ will be uninit
qsr 2014/09/17 11:15:48 Done.
17 if (callable) {
18 callable_ = callable;
19 Py_XINCREF(callable);
20 }
21 }
22
23 virtual ~PythonClosure() {
24 if (callable_)
25 Py_DECREF(callable_);
26 }
27
28 virtual void Run() const MOJO_OVERRIDE {
29 PyObject* empty_tuple = PyTuple_New(0);
sdefresne 2014/09/16 16:35:59 IIRC, Python function with a prototype returning a
qsr 2014/09/17 11:15:48 Changed to deal with the exception in the followin
30 if (!empty_tuple)
31 return;
32
33 PyObject* result = PyObject_CallObject(callable_, empty_tuple);
34 Py_DECREF(empty_tuple);
35 if (result)
36 Py_DECREF(result);
37 }
38
39 private:
40 PyObject* callable_;
41 };
42
43 } // namespace
44
45 namespace mojo {
46
47 Closure BuildClosure(PyObject* callable) {
48 if (!PyCallable_Check(callable))
49 return Closure();
50
51 return Closure(
52 static_cast<mojo::Closure::Runnable*>(new PythonClosure(callable)));
53 }
54
55 void InitRunLoop() {
56 mojo::RunLoop::SetUp();
57 }
58
59 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/python/src/python_system_helper.h ('k') | mojo/python/tests/runloop_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698