Copilot commented on code in PR #50409:
URL: https://github.com/apache/arrow/pull/50409#discussion_r3589149226
##########
python/pyarrow/src/arrow/python/datetime.cc:
##########
@@ -596,7 +602,7 @@ Result<std::string> TzinfoToString(PyObject* tzinfo) {
PyObject* MonthDayNanoIntervalToNamedTuple(
const MonthDayNanoIntervalType::MonthDayNanos& interval) {
- OwnedRef tuple(PyStructSequence_New(&MonthDayNanoTupleType));
+ OwnedRef tuple(PyStructSequence_New(MonthDayNanoTupleType));
if (ARROW_PREDICT_FALSE(tuple.obj() == nullptr)) {
Review Comment:
MonthDayNanoIntervalToNamedTuple() calls
PyStructSequence_New(MonthDayNanoTupleType) without ensuring
MonthDayNanoTupleType has been initialized (it is nullptr until
NewMonthDayNanoTupleType() runs). This can crash when converting
MonthDayNanoInterval scalars/arrays before any type inference path initializes
the struct sequence type.
##########
python/pyarrow/src/arrow/python/python_to_arrow.cc:
##########
@@ -1050,8 +1049,8 @@ class PyStructConverter : public
StructConverter<PyConverter, PyConverterTrait>
PyObject* unicode =
PyUnicode_FromStringAndSize(field_name.c_str(), field_name.size());
RETURN_IF_PYERROR();
- PyList_SET_ITEM(bytes_field_names_.obj(), i, bytes);
- PyList_SET_ITEM(unicode_field_names_.obj(), i, unicode);
+ PyList_SetItem(bytes_field_names_.obj(), i, bytes);
+ PyList_SetItem(unicode_field_names_.obj(), i, unicode);
Review Comment:
PyList_SetItem() can fail and will set a Python exception; unlike the
PyList_SET_ITEM macro it returns an error code. The current code ignores the
return value, so Init() could continue with a pending Python error and
partially-initialized lists.
##########
python/pyarrow/src/arrow/python/python_to_arrow.cc:
##########
@@ -1266,7 +1265,7 @@ Status ConvertToSequenceAndInferSize(PyObject* obj,
PyObject** seq, int64_t* siz
RETURN_IF_PYERROR();
break;
}
- PyList_SET_ITEM(lst, i, item);
+ PyList_SetItem(lst, i, item);
Review Comment:
PyList_SetItem() return value is ignored in the iterator-exhaustion path. If
it fails, the function will proceed with a pending Python error and leak the
partially built list.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]