Skip to content

Commit 5b345a8

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Properly handle errors in AsyncLazyValue::lookupFutureGetSet
Summary: This function returned Py_None on error, sometimes with a Python exception set. When it was used, it was always assumed to be returning a valid PyGetSetDescrObject. Make this properly bubble up errors and check for the result being nullptr. Reviewed By: DinoV Differential Revision: D96863549 fbshipit-source-id: ab735431967b0ade14ba04aca572ebf4f8e83fc9
1 parent 3e12ac0 commit 5b345a8

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

cinderx/async_lazy_value.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,24 @@ BorrowedRef<PyTypeObject> AsyncLazyValueState::cancelledError() {
137137
}
138138

139139
// Lookups up a get/set with the specific name. Returns the function if it's
140-
// found or Py_None if it isn't.
140+
// found.
141141
Ref<PyGetSetDescrObject> AsyncLazyValueState::lookupFutureGetSet(
142142
const char* name) {
143143
auto future_type = futureType();
144144
if (future_type == nullptr) {
145-
return Ref<>::create(Py_None);
145+
return nullptr;
146146
}
147147
auto func = Ref<PyGetSetDescrObject>::steal(
148148
PyObject_GetAttrString(future_type, name));
149-
if (func == nullptr || Py_TYPE(func) != &PyGetSetDescr_Type) {
150-
return Ref<>::create(Py_None);
149+
if (func == nullptr) {
150+
return nullptr;
151+
}
152+
if (Py_TYPE(func) != &PyGetSetDescr_Type) {
153+
PyErr_Format(
154+
PyExc_TypeError,
155+
"Expected descr object, got %s",
156+
Py_TYPE(func)->tp_name);
157+
return nullptr;
151158
}
152159

153160
return func;
@@ -335,7 +342,11 @@ static int future_cancel_impl(FutureObj* fut, PyObject* msg) {
335342
(Py_TYPE(obj) == (PyTypeObject*)get_state()->asyncLazyValueComputeType())
336343

337344
static PyObject* FutureObj_get_traceback(PyObject* fut) {
338-
return get_state()->futureSourceTraceback()->d_getset->get(fut, nullptr);
345+
auto traceback = get_state()->futureSourceTraceback();
346+
if (traceback == nullptr) {
347+
return nullptr;
348+
}
349+
return traceback->d_getset->get(fut, nullptr);
339350
}
340351

341352
static PyObject* FutureLike_get_traceback(PyObject* fut) {

0 commit comments

Comments
 (0)