Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
  • Loading branch information
mdboom and ericsnowcurrently committed Jul 30, 2024
1 parent 398988d commit d6c54ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ PC/launcher.c must also be updated.
*/

#define PYC_MAGIC_NUMBER 3603
#define PYC_MAGIC_NUMBER_TOKEN ((uint32_t)PYC_MAGIC_NUMBER | ((uint32_t)'\r' << 16) | ((uint32_t)'\n' << 24))
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
((uint32_t)PYC_MAGIC_NUMBER | ((uint32_t)'\r' << 16) | ((uint32_t)'\n' << 24))


#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3119,7 +3119,7 @@ def test_magic_number_endianness(self):
magic_number = (_imp.pyc_magic_number).to_bytes(2, 'little') + b'\r\n'
raw_magic_number = int.from_bytes(magic_number, 'little')

assert raw_magic_number == _imp.pyc_magic_number_token
self.assertEqual(raw_magic_number, _imp._pyc_magic_number_token)


if __name__ == '__main__':
Expand Down
4 changes: 3 additions & 1 deletion Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -4814,7 +4814,9 @@ imp_module_exec(PyObject *module)
return -1;
}

if (PyModule_AddIntConstant(module, "pyc_magic_number_token", PYC_MAGIC_NUMBER_TOKEN) < 0) {
if (PyModule_AddIntConstant(
module, "pyc_magic_number_token", PYC_MAGIC_NUMBER_TOKEN) < 0)
{
return -1;
}

Expand Down

0 comments on commit d6c54ee

Please sign in to comment.