[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <871pjhk8g6.fsf@yellow.woof>
Date: Thu, 22 Jan 2026 15:50:33 +0100
From: Nam Cao <namcao@...utronix.de>
To: Wander Lairson Costa <wander@...hat.com>, Steven Rostedt
<rostedt@...dmis.org>, Gabriele Monaco <gmonaco@...hat.com>, Wander
Lairson Costa <wander@...hat.com>, open list
<linux-kernel@...r.kernel.org>, "open list:RUNTIME VERIFICATION (RV)"
<linux-trace-kernel@...r.kernel.org>
Subject: Re: [PATCH 06/26] rv/rvgen: use context managers for file operations
Wander Lairson Costa <wander@...hat.com> writes:
> Replace manual file open and close operations with context managers
> throughout the rvgen codebase. The previous implementation used
> explicit open() and close() calls, which could lead to resource leaks
> if exceptions occurred between opening and closing the file handles.
>
> This change affects three file operations: reading DOT specification
> files in the automata parser, reading template files in the generator
> base class, and writing generated monitor files. All now use the with
> statement to ensure proper resource cleanup even in error conditions.
>
> Context managers provide automatic cleanup through the with statement,
> which guarantees that file handles are closed when the with block
> exits regardless of whether an exception occurred. This follows PEP
> 343 recommendations and is the standard Python idiom for resource
> management. The change also reduces code verbosity while improving
> safety and maintainability.
>
> Signed-off-by: Wander Lairson Costa <wander@...hat.com>
Reviewed-by: Nam Cao <namcao@...utronix.de>
Powered by blists - more mailing lists