Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ProjectController.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def Generate_plc_debug_cvars(self):
def Generate_embedded_plc_debugger(self, st_file):
dvars, externs, enums = self.Generate_plc_debug_cvars()

MD5 = hashlib.md5(open(st_file, "rb").read()).hexdigest()
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is opened without a context manager, relying on garbage collection to close the descriptor; wrap it in with open(st_file, "rb") as f: to ensure timely resource release: with open(st_file, "rb") as f: MD5 = hashlib.md5(f.read()).hexdigest().

Suggested change
MD5 = hashlib.md5(open(st_file, "rb").read()).hexdigest()
with open(st_file, "rb") as f:
MD5 = hashlib.md5(f.read()).hexdigest()

Copilot uses AI. Check for mistakes.

if MD5 is None:
raise ("Error building project: md5 object is null\n")
Comment on lines +166 to +167
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hexdigest() call always returns a 32-character string, so MD5 can never be None; additionally raise ("...") is invalid in Python 3 because a string is not an exception instance or class (will raise a TypeError if executed). Remove the unreachable conditional and, if a safeguard is still desired, raise a concrete exception type (e.g. raise RuntimeError("Failed to compute MD5")) after validating inputs earlier.

Suggested change
if MD5 is None:
raise ("Error building project: md5 object is null\n")

Copilot uses AI. Check for mistakes.


template = Environment(loader=self.__loader).get_template("debug.c.j2")
cfile = os.path.join(paths.AbsDir(self._csvfile), "debug.c")
debug_text = template.render(
Expand All @@ -170,17 +174,14 @@ def Generate_embedded_plc_debugger(self, st_file):
"vars": dvars,
"enums": enums,
"types": list(set(a.split("_", 1)[0] for a in enums)),
"md5": MD5,
}
)

with open(cfile, "w") as f:
f.write(debug_text)

# Wrap debugger code around (* comments *)
MD5 = hashlib.md5(open(st_file, "rb").read()).hexdigest()
if MD5 is None:
raise ("Error building project: md5 object is null\n")

# Add MD5 value to debug.cpp file
c_debug = 'char md5[] = "' + MD5 + '";\n' + debug_text

Expand Down
2 changes: 2 additions & 0 deletions templates/debug.c.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define SAME_ENDIANNESS 0
#define REVERSE_ENDIANNESS 1

char plc_program_md5[] = "{{ debug.md5 }}";

uint8_t endianness;

{% for v in debug.externs %}
Expand Down