ros2 / ros2/rosidl_python

Eliminate array resetting loop in _msg_support.c.em

Open Beginner friendly
#255 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
EmberScript
Stars
26
Forks
68
Avg merge
2d 13h
Merged PRs (30d)
1

Description

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.

https://github.com/ros2/rosidl_python/blob/01af6097d3ca820865df8826e43dafef51760275/rosidl_generator_py/resource/_msg_support.c.em#L589-L608

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rosidl_generator_py/resource/_msg_support.c.em at lines 589-608 and read the surrounding comment and array-handling code. Compare the available Python APIs against the project's supported Python versions, then verify that the generated message support code resets the array without the existing loop and preserves its behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
tooling
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.