Description
As comment in the following code suggested, there exists a part of the code that uses a less ideal way to reset the array.
|
// clear the array, poor approach to remove potential default values |
|
Py_ssize_t length = PyObject_Length(field); |
|
if (-1 == length) { |
|
Py_DECREF(field); |
|
return NULL; |
|
} |
|
if (length > 0) { |
|
PyObject * pop = PyObject_GetAttrString(field, "pop"); |
|
assert(pop != NULL); |
|
for (Py_ssize_t i = 0; i < length; ++i) { |
|
PyObject * ret = PyObject_CallFunctionObjArgs(pop, NULL); |
|
if (!ret) { |
|
Py_DECREF(pop); |
|
Py_DECREF(field); |
|
return NULL; |
|
} |
|
Py_DECREF(ret); |
|
} |
|
Py_DECREF(pop); |
|
} |
This part can be improved by replacing with either
PyObject * ret = PyObject_CallMethodNoArgs(field, "clear"); but this only works with Python 3.13 or higher (reference)
PySequence_DelSlice(field, 0, length) that should work in any Python version
Motivation
This is discovered and suggested in a review from PR #250
Design / Implementation Considerations
No response
Additional Information
No response
Description
As comment in the following code suggested, there exists a part of the code that uses a less ideal way to reset the array.
rosidl_python/rosidl_generator_py/resource/_msg_support.c.em
Lines 589 to 608 in 01af609
This part can be improved by replacing with either
PyObject * ret = PyObject_CallMethodNoArgs(field, "clear");but this only works with Python 3.13 or higher (reference)PySequence_DelSlice(field, 0, length)that should work in any Python versionMotivation
This is discovered and suggested in a review from PR #250
Design / Implementation Considerations
No response
Additional Information
No response