Commit 7186e58a authored by Nanshu Chen's avatar Nanshu Chen Committed by Facebook Github Bot

Py_INCREF/Py_DECREF when bridging coro task to python future and fix typo

Summary:
1. Py_INCREF when holding py future object in bridge function. Py_DECREF in a scope guard.
2. fix typo("folly::coroTask" should be "folly::coro::Task")

Reviewed By: yfeldblum, andriigrynenko

Differential Revision: D16341866

fbshipit-source-id: 1d5b946596cd86c4a949e2c66f007a6140046506
parent 60950182
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
/*
* This file serves as a helper for bridging folly::coroTask and python
* This file serves as a helper for bridging folly::coro::Task and python
* asyncio.future.
*/
......@@ -40,9 +40,13 @@ void bridgeCoroTask(
folly::coro::Task<T>&& coroFrom,
folly::Function<void(folly::Try<T>&&, PyObject*)> callback,
PyObject* userData) {
// We are handing over a pointer to a python object to c++ and need
// to make sure it isn't removed by python in that time.
Py_INCREF(userData);
auto guard = folly::makeGuard([=] { Py_DECREF(userData); });
std::move(coroFrom).scheduleOn(executor).start(
[callback = std::move(callback),
userData](folly::Try<T>&& result) mutable {
[callback = std::move(callback), userData, guard = std::move(guard)](
folly::Try<T>&& result) mutable {
callback(std::move(result), userData);
});
}
......
......@@ -16,7 +16,7 @@ from cpython.ref cimport PyObject
from folly cimport cFollyExecutor, cFollyTry
cdef extern from "folly/experimental/coro/Task.h" namespace "folly::coro" nogil:
cdef cppclass cFollyCoroTask "folly::coroTask"[T]:
cdef cppclass cFollyCoroTask "folly::coro::Task"[T]:
pass
cdef extern from "folly/python/coro.h" namespace "folly::python":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment